Sei sulla pagina 1di 54

DIGITAL IMAGE PROCESSING

IMAGE COMPRESSION
by
Paresh Kamble

Introduction
Image Compression: It is the Art & Science of
reducing the amount of data required to
represent an image.
It is the most useful and commercially successful
technologies in the field of Digital Image
Processing.
The number of images compressed and
decompressed daily is innumerable.

Introduction
To understand the need for compact image
representation, consider the amount of data
required to represent a 2 hour Standard Definition
(SD) using 720 x 480 x 24 bit pixel arrays.
A video is a sequence of video frames where each
frame is a full color still image.
Because video player must display the frames
sequentially at rates near 30fps, SD video data
must be accessed at
30fps x (720x480)ppf x 3bpp = 31,104,000 bps
fps frames per second,
ppf pixels per frame,

Introduction
Thus a 2 hour movie consists of
31,104,000 bps x (602) sph x 2 hrs

2.24 x 1011

bytes.
OR

224GB of data
sph = second per hour
Twenty seven 8.5GB dual layer DVDs are needed
to store it.
To put a 2hr movie on a single DVD, each frame
must be compressed by a factor of around 26.3.
The compression must be even higher for HD,
where image resolution reach 1920 x 1080 x 24

Introduction
Web page images & High-resolution digital
camera photos also are also compressed to save
storage space & reduce transmission time.
Residential Internet connection delivers data at
speeds ranging from 56kbps (conventional phone
line) to more than 12mbps (broadband).
Time required to transmit a small 128 x 128 x 24
bit full color image over this range of speed is
from 7.0 to 0.03 sec.
Compression can reduce the transmission time by
a factor of around 2 to 10 or more.
Similarly, number of uncompressed full color
images that an 8 Megapixel digital camera can
store on a 1GB Memory card can be increased.

Introduction
Along with these applications , image
compression plays an important role in many
other areas including:

Fundamentals
Data Compression: It refers to the process of
reducing the amount of data required to
represent a given quantity of information.

Data
Vs

Information
Data and Information are not the same thing;
data are the means by which information is
conveyed.
Because various amount of data can be used to

Fundamentals

Fundamentals
Let b & b denote the number of bits in two
representations of the same information, the
relative data redundancy R of the representation
with b bits is
R = 1 (1/C);
where, C commonly called the compression
ratio, is defined as
C = b / b
If C = 10 (or 10:1), for larger representation has
10 bits of data for every 1 bit of data in smaller
representation.
So, R = 0.9, indicating that 90% of its data is
redundant.

Fundamentals
2D intensity arrays suffers from 3 principal types
of data redundancies:
1) Coding redundancy: A code is a system of
symbols used to represent a body of information
or sets of events.
Each piece of event is assigned a code word
(code symbol). The number of symbols in each
code word is its length.
The 8-bit codes that are used to represent the
intensities in most 2D intensity arrays contain
more bits than are needed to represent the
intensities.

Fundamentals
2) Spatial & Temporal redundancy:
Because the pixels of most 2D intensity arrays are
correlated spatially, information is replicated
unnecessarily.
In video sequence, temporally correlated pixels
also duplicate information.
3) Irrelevant Information:
Most 2D intensity arrays contain information that
is ignored by the human visual system. It is
redundant in the sense that it is not used.

Fundamentals
1) Coding Redundancy:
) Assume a discrete random variable rk in interval
[0 L-1] is used to represent the intensities of an
M x N image.
) Also the each rk occurs with probability pr (rk).
) pr(rk) = nk / MN
k = 0, 1, 2, .L-1
----(a)
) Where, L is no. of intensity values &
nk is no. of times kth intensity appears in the
image.
If no. of bits used to represent each value of rk is
l(rk), then avg no of bits required to represent
each pixel is
L-1

Fundamentals

If the intensities are represented using a natural


m-bits fixed length code, the RHS reduces to m
bits.
i.e. Lavg = m where m is substituted for l(rk).
Constant m can be taken out the summation
leaving only sum of pr(rk) for 0 k L-1, which
= 1.

rk
l2(rk)
r87 = 87
2
r128 = 128
1
r186 = 186

pr(rk)

code 1

l1(rk)

0.25

01010111

01

0.47

10000000

0.25

11000100

code 2

000

Fundamentals
With respect to the above table, If a natural 8-bit
binary code is used to represent its 4 possible
intensities, Lavg = 8, coz l1(rk) = 8 bits for all rk.
On the other hand, If code 2 scheme is used, the avg
length of encoded pixels is,
Lavg = 0.25(2) + 0.47(1) + 0.25(3) + 0.03(3) = 1.81
bits.
Total no. of bits rqd to represent entire image = MNL avg
= 256 x 256 x 1.81 = 118,621
Resulting compression
C = 256 x 256 x 8 / 118,621 = 8 / 1.81 4.42
Relative redundancy
R = 1 1/4.42 = 0.774
Thus, 77.4% of data in original 8-bit 2D intensity array
is redundant.

Fidelity Criteria
Fidelity Criteria:
Removal of irrelevant visual information involves a
loss of real or quantitative image information.

Since information is lost, a means of quantifying the


nature of loss is needed.

Objective fidelity criteria


Subjective fidelity
criteria
Objective fidelity criteria: When information loss can
be expressed as a mathematical function of input &
output of a compression process. Eg RMS error
between 2 images.
Error between two images
e(x, y) = f(x, y) f(x, y)
So, total error between two images
M-1

N-1

[f(x, y) f(x, y)]


x=0 y = 0

Fidelity Criteria
RMS error is given by
M-1

N-1

erms = [(1/MN) [f(x, y) f(x, y)]2]1/2


x=0 y = 0

If f(x, y) is considered to be the sum of original


image f(x, y) & an error or noise signal e(x, y),
the Mean Square SNR of output image denoted
by SNRrms can be defined as
M-1 N-1

f(x, y)2
SNRrms =

x=0 y = 0

M-1 N-1

[f(x, y) f(x, y)]2


x=0 y = 0

Fidelity Criteria
Subjective fidelity criteria:
A Decompressed image is presented to a cross
section of viewers and averaging their evaluations.

It can be done by using an absolute rating scale


Or
By means of side by side comparisons of f(x, y) &
f(x, y).

Side by Side comparison can be done with a scale


such as
{-3, -2, -1, 0, 1, 2, 3}
to represent the subjective valuations
{much worse, worse, slightly worse, the same,
slightly better, better, much better} respectively.

Image Compression Models

The image compression system is composed of 2


distinct functional component: an encoder & a
decoder.

Encoder performs Compression


while
Decoder performs Decompression.

Both operations can be performed in Software, as in


case of Web browsers & many commercial image
editing programs.

Or in a combination of hardware & firmware, as in DVD


Players.

A codec is a device which performs coding &


decoding.

Image Compression Models

Input image f(x,..) is fed into the encoder, which


creates a compressed representation of input.

It is stored for future for later use or transmitted


for storage and use at a remote location.

When the compressed image is given to decoder, a


reconstructed output image f(x,..) is generated.

In still image applications, the encoded input and


decoder output are f(x, y) & f(x, y) resp.

In video applications, they are f(x, y, t) & f(x, y, t)


where t is time.

If both functions are equal then the system is


called lossless, error free. If not then it s referred to
as lossy.

Image Compression Models

Mapper

Quantize
r

Symbol
coder

Symbol
Decode
r

Inverse
Mapper

Image Compression Models


Encoding or Compression process:
Encoder is used to remove the redundancies
through a series of 3 independent operations.
Mapper: It transforms f(x,) into a format
designed to reduce spatial and temporal
redundancies.
It is reversible
It may / may not reduce the amount of data to
represent image.
Ex. Run Length coding

In video applications, mapper uses previous


frames to remove temporal redundancies.

Image Compression Models


Quantizer: It keeps irrelevant information out of
compressed representations.

This operation is irreversible.

It must be omitted when error free compression


is desired.

In video applications, bit rate of encoded output


is often measured and used to adjust the
operation of the quantizer so that a
predetermined average output is maintained.

The visual quality of the output can vary from


frame to frame as a function of image content.

Image Compression Models


Symbol Encoder: Generates a fixed or variable
length code to represent the quantizer output
and maps the output in accordance with the
code.

Shortest code words are assigned to the most


frequently occurring quantizer output values.
Thus minimizing coding redundancy.

It is reversible.

Upon its completion, the input image has been


processed for the removal of all 3 redundancies.

Image Compression Models


Decoding or Decompression process:

Quantization results in irreversible loss, an


inverse quantizer block is not included in the
decoder block.

Some Basic Compression Methods


Huffman Coding:
Most popular technique for removing coding
redundancies.

It yields smallest possible code symbol per source


symbol.

Original Source
Symbol Probability
a2
a6
a1
a4
a3
a5

0.4
0.3
0.1
0.1
0.06
0.04

Source reduction
1
2
0.4
0.3
0.1
0.1
0.1

0.4
0.3
0.2
0.1

3
0.4
0.3
0.3

4
0.6
0.4

Some Basic Compression Methods


Huffman Coding:
Original Source
Symbol Probability Code
4
a2
0.6 0
a6
0.4 1
a1
a4
a3
a5

Source reduction
2
3

0.4

0.4 1

0.4 1

0.3

00

0.3 00

0.3 00 0.3 00

0.1
0.1
0.06
0.04

0.4 1

011
0.1 011 0.2 010 0.3 01
0100
0.1 0100 0.1 011
01010 0.1 0101
01011

Lavg = (0.4)(1) + (0.3)(2) + (0.1)(3) + (0.06)(5) + (0.04)(5)


= 2.2 bits / pixel.

Some Basic Compression Methods


Huffman Coding:
It is instantaneous.
Coz each code word in a string of code symbols
ca be decoded without referencing succeeding
symbols.

It is uniquely decodable.
Coz any string of code symbols can be decoded
by examining individual symbols of string from
left to right.

Ex. 010100111100

Some Basic Compression Methods


Huffman Coding:
It is instantaneous.
Coz each code word in a string of code symbols ca
be decoded without referencing succeeding symbols.

It is uniquely decodable.
Coz any string of code symbols can be decoded by
examining individual symbols of string from left to
right.

Ex. 01010 011 1 1 00


First valid code:
01010 a3,
011 a1,
Thus, completely decoding the message, we get,
a3a1a2a2a6

Some Basic Compression Methods


Arithmetic coding:
It generates non block codes.
One to One correspondence between source
symbols and code words does not exist.
Instead, an entire sequence of source symbols is
assigned a single arithmetic code.
Code word defines an integer of real numbers
between 0 & 1.
As No. of symbols in msg.
interval to represent it
no. of bits to
represent info
Each symbol of msg
size of interval in
accordance with its probability of occurrence.

Some Basic Compression Methods


Basic Arithmetic coding process:
5 symbol message, a1a2a3a3a4 from 4 symbol
source is coded.

Source
Symbol

Probability

Initial
Subinterval

a1

0.2

[0.0, 0.2)

a2

0.2

[0.2, 0.4)

a3

0.4

[0.4, 0.8)

a4

0.2

[0.8, 1.0)

Some Basic Compression Methods


Arithmetic coding:
a1
a2
1

0.2

a3

a3

0.08

a4

0.072

0.0688

a4

a4

a4

a4

a3

a3

a3

a3

a2

a2

a2

a2

a1

a1

a1

a1

a4

a3

a2
a1
0

0.04

0.056

0.0624

Some Basic Compression Methods


Arithmetic coding:
a1
a2
1

0.2

a3

a3

0.08

a4

0.072

0.0688

a4

a4

a4

a4

a3

a3

a3

a3

a2

a2

a2

a2

a1

a1

a1

a1

a4

a3

a2
a1
0

0.04

0.056

0.0624

Some Basic Compression Methods


Arithmetic coding:
a1
a2
1

0.2

a3

a3

0.08

a4

0.072

0.0688

a4

a4

a4

a4

a3

a3

a3

a3

a2

a2

a2

a2

a1

a1

a1

a1

a4

a3

a2
a1
0

0.04

0.056

0.0624

Some Basic Compression Methods


Arithmetic coding:
a1
a2
1

0.2

a3

a3

0.08

a4

0.072

0.0688

a4

a4

a4

a4

a3

a3

a3

a3

a2

a2

a2

a2

a1

a1

a1

a1

a4

a3

a2
a1
0

0.04

0.056

0.0624

Some Basic Compression Methods


Arithmetic coding:
a1
a2
1

0.2

a3

a3

0.08

a4

0.072

0.0688

a4

a4

a4

a4

a3

a3

a3

a3

a2

a2

a2

a2

a1

a1

a1

a1

a4

a3

a2
a1
0

0.04

0.056

0.0624

Some Basic Compression Methods


Arithmetic coding: Encoding Sequence
a1
a2
a3
1

0.2

0.08

a3

a4

0.072

0.0688

a4

a4

a4

a4

a3

a3

a3

a3

a2

a2

a2

a2

a1

a1

a1

a1

a4

a3

a2
a1
0

0.04

0.056

0.0624

Some Basic Compression Methods


The final message symbol narrows to [0.06752,
0.0688).
Any number between this interval can be used to
represent the message.
Eg. 0.068
3 decimal digits are used to represent the 5 symbol
message.

Some Basic Compression Methods


LZW Coding:

LZW Lempel-Ziv-Welch coding

Error free compression approach that also


addresses spatial redundancies in an image.

It assigns fixed-length code words to variable


length sequences of source symbols.

It requires no prior knowledge of probability of


occurrence of the symbols to be encoded.

Some Basic Compression Methods


LZW Coding:

It is conceptually very simple.

Initially, a codebook or dictionary containing the


source symbols to be coded is constructed.

For an 8-bit BW images, the first 256 words of


dictionary are assigned to intensities 0, 1, 2, .,
255.

Some Basic Compression Methods


LZW Coding:
Consider the 4 x 4 8-bit image having a vertical edge.
39 39 126 126
39 39 126 126
39 39 126 126
39 39 126 126
A 512-word dictionary with following content is
assumed:
Dictionary Location
Entry
0
0
1
1
.
.

255
256
.
511

.
.

255
.
-

Some Basic Compression Methods


Currently
Recognized
Sequence
39
39
126
126
39
39-39
126
126-126
39
39-39
39-39-126
126
126
126-39
39
39-126
126

Pixel Being
Processed
39
39
126
126
39
39
126
126
39
39
126
126
39
39
126
126

Encoded
Output

Dictionary
Location

Dictionary
Entry

39
39
126
126

256
257
258
259

39-39
39-126
126-126
126-39

256

260

39-39-126

258
260
259
257
126

261
262
263
264

126-126-39
39-39-126126-39-39
39-126-126

Some Basic Compression Methods


Unique feature of LZW coding:

Coding dictionary or code book is created while


data are being encoded.

Some Basic Compression Methods


Bit-plane coding:
Another effective method to reduce interpixel
redundancies.
Images bit planes are processed individually.
Based on decomposing a multilevel (monochrome /
color) image into a series of binary images &
compressing each binary using any binary
compression method.
Bit plane decomposition:
Gray levels of an m-bit gray level image can be
represented in form of base 2 polynomial.
am-12m-1+am-22m-2+..+a121+a020 (1)

Some Basic Compression Methods

A simple method of decomposing the image into


a collection of binary image is to separate the m
coefficients of the polynomial into m-1 bit planes.

Disadvantage:

Small changes in gray level can have significant


impact on complexity of bit planes.

Ex. If two adjacent pixels have intensity of 127


(01111111) and 128 (10000000), every bit plane
will contain a corresponding 0 to 1 (or 1 to 0)
transition.

Some Basic Compression Methods


Alternate decomposition approach:
Reduces the effect of small gray level variations.

Requires the representation of image into m-bit gray


code.

m-bit gray code gm-1..g2g1g0 can be computed from


gi = ai xor ai+1 0 i m-2
gm-1 = am-1

This code has unique property that successive code


words differ by only 1 bit position.

Small changes in gray level are less likely to affect


all m bit planes.
Ex. 127 (11000000) & 128 (01000000).

Some Basic Compression Methods


Run-Length Coding:

Standard compression approach used in


facsimile (FAX).

Basic concept is to code each contiguous group


of 0s & 1s encountered in L to R scan of a row
by its length & to develop a convention for
determining the value of run.

Most common approach for determining the


value of run:
i) Specify value of first run of each row.
ii) To assume each row begins with a white run
whose run length may in fact be zero.

Some Basic Compression Methods

Although Run length coding is in itself an effective


method of compressing an image, additional
compression can be realized by variable-length coding.

Black & white run lengths may be coded separately


using variable-length codes.

Ex. If aj represent a black run of length j, we can estimate


its probability.

The approximate run-length entropy of the image is:


HRL = (H0 + H1) / (L0 + L1)
where, L0 & L1 denote average values of black & white
run lengths resp.
Above equation also provides an estimate of the
average no. of bits per pixel required to code the run
lengths in a binary image.

Some Basic Compression Methods


Lossless predictive coding:

Based on eliminating the interpixel redundancies


of closely spaced pixels by extracting & coding
only the new information in each pixel.

New information: difference between the actual &


predicted value of that pixel.

Some Basic Compression Methods


Figure shows basic component of a lossless
predictive coding system.

It consists of an encoder & a decoder each


containing an identical predictor.

As each successive pixel of input image f(n) is


introduced to the encoder, predictor generates its
anticipated value.
Output of the predictor is then rounded to the
nearest integer f(n)bar & used to form the
difference or prediction error.

Some Basic Compression Methods


It is coded using a variable length to generate the next
element of the compressed data stream.
The decoder reconstruct the fn from the received
variable-length code words & perform the inverse
operation
f(n) = e(n) + f(n)bar
f(n)bar is generated by prediction formed by a linear
combination of m previous pixels.
m

f(n)bar = round[ i f(n-i)]


predictor

where, m order of linear

i=1

round function used to denote rounding


i for i = 1, 2, 3, .. m are prediction coefficients.

Some Basic Compression Methods


Lossy Predictive coding:

Some Basic Compression Methods


Lossy Predictive coding:
In this method we add a quantizer to the lossless
predictive coding model.
It replaces the nearest integer function & is placed
between symbol encoder & point where prediction
error forms.
It maps the prediction error into a limited range of
outputs denoted by (n), which establish the amount
of compression & distortion.
In order to accommodate the insertion of the
quantization step, the error free encoder must be
altered so that the predictions by the encoder &
decoder are equivalent.

Some Basic Compression Methods


Lossy Predictive coding:
This is accomplished by placing the predictor
within a feedback loop, where its input (n)dot is
generated as a function of past predictions &
quantized errors.
(n)dot = e(n)dot + f(n)bar
This closed loop configuration prevents error
buildup at the decoders output.

Some Basic Compression Methods


Questions asked in RTMNU exams
1) Enlist different image compression techniques.
Explain any one in brief.
2) Huffman coding algorithm for image compression
3) aeiou!
4) Explain generalized image compression model
with neat block diagram.
5) Discuss about image compression. Explain the
need of image compression in image processing.
6) Short note on image compression standard.
7) Short note on Lossy Predictive coding.
8) Short note on LZW coding.
9) Explain various types of data redundancies used
in digital image compression.

Potrebbero piacerti anche