0% found this document useful (0 votes)
68 views

Image Compression (Chapter 8) : CS474/674 - Prof. Bebis

The document discusses image compression techniques. It begins by explaining the goals of image compression which are to reduce the large amounts of data and bandwidth required to store and transmit digital images. It then describes two main approaches to image compression - lossless and lossy compression, with lossy allowing for higher compression ratios but not perfectly preserving the original image. The document goes on to explain different types of data redundancy that compression aims to reduce, including coding, interpixel, and psychovisual redundancy. Specific lossless compression techniques like Huffman coding, arithmetic coding, LZW coding are then described in detail.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Image Compression (Chapter 8) : CS474/674 - Prof. Bebis

The document discusses image compression techniques. It begins by explaining the goals of image compression which are to reduce the large amounts of data and bandwidth required to store and transmit digital images. It then describes two main approaches to image compression - lossless and lossy compression, with lossy allowing for higher compression ratios but not perfectly preserving the original image. The document goes on to explain different types of data redundancy that compression aims to reduce, including coding, interpixel, and psychovisual redundancy. Specific lossless compression techniques like Huffman coding, arithmetic coding, LZW coding are then described in detail.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

Image Compression (Chapter 8)

CS474/674 – Prof. Bebis


Goal of Image Compression
• Digital images require huge amounts of space for
storage and large bandwidths for transmission.
– A 640 x 480 color image requires close to 1MB of space.
• The goal of image compression is to reduce the amount
of data required to represent a digital image.
– Reduce storage requirements and increase transmission rates.
Approaches

• Lossless
– Information preserving
– Low compression ratios

• Lossy
– Not information preserving
– High compression ratios

• Trade-off: image quality vs compression ratio


Data ≠ Information

• Data and information are not synonymous terms!

• Data is the means by which information is conveyed.

• Data compression aims to reduce the amount of data


required to represent a given quantity of information
while preserving as much information as possible.
Data vs Information (cont’d)
• The same amount of information can be represented
by various amount of data, e.g.:

Ex1: Your wife, Helen, will meet you at Logan Airport


in Boston at 5 minutes past 6:00 pm tomorrow
night

Ex2: Your wife will meet you at Logan Airport at 5


minutes past 6:00 pm tomorrow night

Ex3: Helen will meet you at Logan at 6:00 pm


tomorrow night
Data Redundancy

compression

Compression ratio:
Data Redundancy (cont’d)

• Relative data redundancy:

Example:
Types of Data Redundancy

(1) Coding
(2) Interpixel
(3) Psychovisual

• Compression attempts to reduce one or more of these


redundancy types.
Coding Redundancy
• Code: a list of symbols (letters, numbers, bits etc.)
• Code word: a sequence of symbols used to represent a
piece of information or an event (e.g., gray levels).
• Code word length: number of symbols in each code
word
Coding Redundancy (cont’d)

N x M image
rk: k-th gray level Expected value:
P(rk): probability of rk E ( X ) = ∑ xP( X = x)
x
l(rk): # of bits for rk
Coding Redundancy (con’d)
• l(rk) = constant length

Example:
Coding Redundancy (cont’d)
• l(rk) = variable length
• Consider the probability of the gray levels:

variable length
Interpixel redundancy
• Interpixel redundancy implies that any pixel value can be
reasonably predicted by its neighbors (i.e., correlated).


f ( x) o g ( x) = ∫ f ( x) g ( x + a )da
−∞

autocorrelation: f(x)=g(x)
Interpixel redundancy (cont’d)
• To reduce interpixel redundnacy, the data must be
transformed in another format (i.e., through a transformation)
– e.g., thresholding, differences between adjacent pixels, DFT

• Example: (profile – line 100)

original threshold

thresholded

(1+10) bits/pair
Psychovisual redundancy

• The human eye does not respond with equal sensitivity to


all visual information.

• It is more sensitive to the lower frequencies than to the


higher frequencies in the visual spectrum.

• Idea: discard data that is perceptually insignificant!


Psychovisual redundancy (cont’d)
Example: quantization
256 gray levels 16 gray levels 16 gray levels

i.e., add to each pixel a


C=8/4 = 2:1 small pseudo-random number
prior to quantization
Image Compression Model
Image Compression Model (cont’d)

• Mapper: transforms input data in a way that facilitates


reduction of interpixel redundancies.
Image Compression Model (cont’d)

• Quantizer: reduces the accuracy of the mapper’s output in


accordance with some pre-established fidelity criteria.
Image Compression Model (cont’d)

• Symbol encoder: assigns the shortest code to the most


frequently occurring output values.
Image Compression Models (cont’d)

• Inverse operations are performed.

• But … quantization is irreversible in general.


Fidelity Criteria

• How close is to ?

• Criteria
– Subjective: based on human observers
– Objective: mathematically defined criteria
Subjective Fidelity Criteria
Objective Fidelity Criteria

• Root mean square error (RMS)

• Mean-square signal-to-noise ratio (SNR)


Objective Fidelity Criteria (cont’d)

RMSE = 5.17 RMSE = 15.67 RMSE = 14.17


Lossless Compression
Lossless Methods: Taxonomy
Huffman Coding (coding redundancy)

• A variable-length coding technique.


• Optimal code (i.e., minimizes the number of code
symbols per source symbol).

• Assumption: symbols are encoded one at a time!


Huffman Coding (cont’d)
• Forward Pass
1. Sort probabilities per symbol
2. Combine the lowest two probabilities
3. Repeat Step2 until only two probabilities remain.
Huffman Coding (cont’d)

• Backward Pass
Assign code symbols going backwards
Huffman Coding (cont’d)
• Lavg using Huffman coding:

• Lavg assuming binary codes:


Huffman Coding/Decoding

• After the code has been created, coding/decoding can


be implemented using a look-up table.
• Note that decoding is done unambiguously.
Arithmetic (or Range) Coding
(coding redundancy)
• No assumption on encode source symbols one at a
time.
– Sequences of source symbols are encoded together.
– There is no one-to-one correspondence between source
symbols and code words.

• Slower than Huffman coding but typically achieves


better compression.
Arithmetic Coding (cont’d)

• A sequence of source symbols is assigned a single


arithmetic code word which corresponds to a sub-
interval in [0,1].

• As the number of symbols in the message increases,


the interval used to represent it becomes smaller.

• Smaller intervals require more information units (i.e.,


bits) to be represented.
Arithmetic Coding (cont’d)

Encode message: a1 a2 a3 a3 a4

1) Assume message occupies [0, 1)

0 1

2) Subdivide [0, 1) based on the probability of αi

3) Update interval by processing source symbols


Example

Encode
a1 a2 a3 a3 a4

[0.06752, 0.0688)
or,
0.068
Example

• The message a1 a2 a3 a3 a4 is encoded using 3 decimal


digits or 3/5 = 0.6 decimal digits per source symbol.

• The entropy of this message is:

-(3 x 0.2log10(0.2)+0.4log10(0.4))=0.5786 digits/symbol

Note: finite precision arithmetic might cause problems


due to truncations!
Arithmetic Decoding
1.0 0.8 0.72 0.592 0.5728

a4
0.8 0.72 0.688 0.5856 0.57152

Decode 0.572
a3
0.4 0.56 0.624 0.5728 056896

a2
a3 a3 a1 a2 a4
0.2 0.48 0.592 0.5664 0.56768

a1
0.0 0.4
0.56 0.56 0.5664
LZW Coding (interpixel redundancy)

• Requires no priori knowledge of pixel probability


distribution values.

• Assigns fixed length code words to variable length


sequences.

• Patented Algorithm US 4,558,302

• Included in GIF and TIFF and PDF file formats


LZW Coding
• A codebook (or dictionary) needs to be constructed.

• Initially, the first 256 entries of the dictionary are assigned


to the gray levels 0,1,2,..,255 (i.e., assuming 8 bits/pixel)

Initial Dictionary
Consider a 4x4, 8 bit image Dictionary Location Entry

39 39 126 126 0 0
39 39 126 126 1 1
. .
39 39 126 126 255 255
39 39 126 126 256 -

511 -
LZW Coding (cont’d)
As the encoder examines image
39 39 126 126 pixels, gray level sequences
39 39 126 126 (i.e., blocks) that are not in the
39 39 126 126 dictionary are assigned to a new
39 39 126 126 entry.
Dictionary Location Entry

0 0
1 1
- Is 39 in the dictionary……..Yes
. . - What about 39-39………….No
255 255
256 - 39-39
- Then add 39-39 in entry 256
511 -
Example
39 39 126 126 Concatenated Sequence: CS = CR + P
39 39 126 126
(CR) (P)
39 39 126 126
39 39 126 126
CR = empty
If CS is found:
(1) No Output
(2) CR=CS
else:
(1) Output D(CR)
(2) Add CS to D
(3) CR=P
Decoding LZW

• The dictionary which was used for encoding need not


be sent with the image.

• Can be built on the “fly” by the decoder as it reads the


received code words.
Differential Pulse Code Modulation (DPCM)
Coding (interpixel redundancy)
• A predictive coding approach.
• Each pixel value (except at the boundaries) is predicted
based on its neighbors (e.g., linear combination) to get a
predicted image.
• The difference between the original and predicted
images yields a differential or residual image.
– i.e., has much less dynamic range of pixel values.
• The differential image is encoded using Huffman
coding.
Run-length coding (RLC)
(interpixel redundancy)
• Used to reduce the size of a repeating string of characters
(i.e., runs):

1 1 1 1 1 0 0 0 0 0 0 1  (1,5) (0, 6) (1, 1)


a a a b b b b b b c c  (a,3) (b, 6) (c, 2)

• Encodes a run of symbols into two bytes: (symbol, count)


• Can compress any type of data but cannot achieve high
compression ratios compared to other compression methods.
Bit-plane coding (interpixel redundancy)

• An effective technique to reduce inter pixel redundancy


is to process each bit plane individually.

(1) Decompose an image into a series of binary images.

(2) Compress each binary image (e.g., using run-length


coding)
Combining Huffman Coding
with Run-length Coding
• Assuming that a message has been encoded using
Huffman coding, additional compression can be
achieved using run-length coding.

e.g., (0,1)(1,1)(0,1)(1,0)(0,2)(1,4)(0,2)
Lossy Compression
• Transform the image into a domain where compression
can be performed more efficiently (i.e., reduce interpixel
redundancies).
~ (N/n)2 subimages
Example: Fourier Transform

The magnitude of the


FT decreases, as u, v
increase!

K << N
K-1 K-1
Transform Selection

• T(u,v) can be computed using various


transformations, for example:
– DFT
– DCT (Discrete Cosine Transform)
– KLT (Karhunen-Loeve Transformation)
DCT

forward

inverse

if u=0 if v=0
if u>0 if v>0
DCT (cont’d)

• Basis set of functions for a 4x4 image (i.e.,cosines of


different frequencies).
DCT (cont’d)
DFT WHT DCT
8 x 8 subimages

64 coefficients
per subimage

50% of the
coefficients
truncated

RMS error: 2.32 1.78 1.13


DCT (cont’d)
• DCT minimizes "blocking artifacts" (i.e., boundaries
between subimages do not become very visible).

DFT
i.e., n-point periodicity
gives rise to
discontinuities!

DCT
i.e., 2n-point periodicity
prevents
discontinuities!
DCT (cont’d)

• Subimage size selection:

original 2 x 2 subimages 4 x 4 subimages 8 x 8 subimages


JPEG Compression

• JPEG is an image compression standard which was


accepted as an international standard in 1992.
• Developed by the Joint Photographic Expert Group of
the ISO/IEC for coding and compression of color/gray
scale images.
• Yields acceptable compression in the 10:1 range.
• A scheme for video compression based on JPEG
called Motion JPEG (MJPEG) exists
JPEG Compression (cont’d)

• JPEG uses DCT for handling interpixel redundancy.

• Modes of operation:
(1) Sequential DCT-based encoding
(2) Progressive DCT-based encoding
(3) Lossless encoding
(4) Hierarchical encoding
JPEG Compression
(Sequential DCT-based encoding)

Entropy
encoder

Entropy
decoder
JPEG Steps

1. Divide the image into 8x8 subimages;

For each subimage do:


2. Shift the gray-levels in the range [-128, 127]
- DCT requires range be centered around 0
3. Apply DCT (i.e., 64 coefficients)
1 DC coefficient: F(0,0)
63 AC coefficients: F(u,v)
Example

(i.e., non-centered
spectrum)
JPEG Steps

4. Quantize the coefficients (i.e., reduce the amplitude of


coefficients that do not contribute a lot).

Q(u,v): quantization table


Example

• Quantization Table Q[i][j]


Example (cont’d)

Quantization
JPEG Steps (cont’d)

5. Order the coefficients using zig-zag ordering


- Place non-zero coefficients first
- Create long runs of zeros (i.e., good for run-length encoding)
Example
JPEG Steps (cont’d)

6. Form intermediate symbol sequence and encode coefficients:

6.1 DC coefficients: predictive encoding

6.2 AC coefficients: variable length coding


Intermediate Coding

DC

symbol_1 (SIZE) symbol_2 (AMPLITUDE)


end of block
DC (6) (61)
symbol_1 (RUN-LENGTH, SIZE) symbol_2 (AMPLITUDE)
AC (0,2) (-3)
SIZE: # bits for encoding amplitude
RUN-LENGTH: run of zeros
DC/AC Symbol Encoding
symbol_1 symbol_2
• DC encoding (SIZE) (AMPLITUDE)

predictive [-2048, 2047]=


coding: [-211, 211-1]
1 ≤SIZE≤11
• AC encoding

0 0 0 0 0 0 476
(6,9)(476)
= [-210, 210-1]
1 ≤SIZE≤10
If RUN-LENGTH > 15, use symbol (15,0) , i.e., RUN-LENGTH=16
Entropy Encoding (e.g, variable length)
Entropy Encoding (e.g, Huffman)
Symbol_1 Symbol_2
(Variable Length Code (VLC)) (Variable Length Integer (VLI))

(1,4)(12)  (111110110 1100)


VLC VLI
Effect of “Quality”

10 (8k bytes) 50 (21k bytes) 90 (58k bytes)

worst quality, best quality,


highest compression lowest compression
Effect of “Quality” (cont’d)
Lossy Methods: Taxonomy
Lossless Differential Pulse Code
Modulation (DPCM) Coding
• Each pixel value (except at the boundaries) is predicted
based on certain neighbors (e.g., linear combination) to
get a predicted image.
• The difference between the original and predicted
images yields a differential or residual image.
• Encode differential image using Huffman coding.

xm dm Entropy
Encoder

Predictor
pm
Lossy Differential Pulse Code
Modulation (DPCM) Coding
• Similar to lossless DPCM except that (i) it uses
quantization and (ii) the pixels are predicted from the
“reconstructed” values of certain neighbors.

You might also like