Module 4
Module 4
Image Compression
Image Compression
Types of redundancy
✓ Compression algorithms are developed by taking
advantage of the redundancy that is inherent in image
data
1. Coding redundancy
✓ Occurs when the data used to represent the image is not
utilized in an optimal manner
2. Interpixel redundancy
✓ Occurs because adjacent pixels tend to be highly correlated,
in most images the brightness levels do not change rapidly,
but change gradually
3. Interband redundancy
✓ Occurs in color images due to the correlation between bands
within an image – if we extract the red, green and blue bands
they look similar
4. Psychovisual redundancy
✓ Some information is more important to the human visual
system than other types of information
Department of Computer Science & Engineering-Bangalore Campus
19ECS352 - Image Processing. Dr. Justin Varghese Slide 15
Interpixel redundancy
• Interpixel redundancy implies that pixel values are
correlated (i.e., a pixel value can be reasonably predicted
by its neighbors).
histograms
auto-correlation
f ( x) o g ( x) = f ( x) g ( x + a)da
−
auto-correlation: f(x)=g(x)
Department of Computer Science & Engineering-Bangalore Campus
19ECS352 - Image Processing. Dr. Justin Varghese Slide 16
Example:
threshold
original
11 ……………0000……………………..11…..000…..
thresholded
(1+10) bits/pair
Department of Computer Science & Engineering-Bangalore Campus
19ECS352 - Image Processing. Dr. Justin Varghese Slide 17
Psychovisual redundancy
1. The compressor
2. The decompressor
Coding - Definitions
• Code: a list of symbols (letters, numbers, bits etc.)
• Code word: a sequence of symbols used to represent
some information (e.g., gray levels).
• Code word length: number of symbols in a code
word.
Coding Redundancy
Let us assume, that a discrete random variable rk in the interval [0,1]
represent the gray level of an image:
nk
pr (rk ) = k = 0,1, 2,, L − 1
n
If the number of bits used to represent each value of rk is l(rk), then the
average number of bits required to represent each pixel:
L −1
Lavg = l (rk ) pr (rk )
k =0
The total number bits required to code an MxN image:
M .N .Lavg
◼ Huffman Coding
Huffman coding
Huffman coding assigns shorter codes to symbols that
occur more frequently and longer codes to those that
occur less frequently. For example, imagine we have a
text file that uses only five characters (A, B, C, D, E).
Before we can assign bit patterns to each character, we
assign each character a weight based on its frequency of
use. In this example, assume that the frequency of the
characters is as shown in Table 15.1.
Encoding
Let us see how to encode text using the code
for our five characters. Figure 15.6 shows the
original and the encoded text.
Decoding
P(B) = 0.51
CS 414 - Spring
Department of Computer Science & Engineering-Bangalore Campus
2012
19ECS352 - Image Processing. Dr. Justin Varghese Slide 30
P(CE) = 0.20
P(DA) = 0.29
CS 414 - Spring
Department of Computer Science & Engineering-Bangalore Campus
2012
19ECS352 - Image Processing. Dr. Justin Varghese Slide 31
0 1
P(CE) = 0.20
P(DA) = 0.29
0 1
0 1
CS 414 - Spring
Department of Computer Science & Engineering-Bangalore Campus
2012
19ECS352 - Image Processing. Dr. Justin Varghese Slide 32
0 1
P(CE) = 0.20
P(DA) = 0.29
0 1
0 1
CS 414 - Spring
Department of Computer Science & Engineering-Bangalore Campus
2012
19ECS352 - Image Processing. Dr. Justin Varghese Slide 33
Huffman Decoding
Huffman Example
• Construct the Huffman
Symbol (S) P(S)
coding tree (in class)
A 0.25
B 0.30
C 0.12
D 0.15
E 0.18
Characteristics of Solution
A 01
B 11
C 100
D 101
E 00
Example Encoding/Decoding
B 11
C 100
Decode “0101100”
D 101
E 00
H = 2.24 bits
= .25(2) + B 0.30 11
.30(2) + C 0.12 100
.12(3) +
.15(3) + D 0.15 101
.18(2) E 0.18 00
L = 2.27 bits
• H ≤Code Length ≤ H + 1
Example
L = .01(1) +
.99(1)
=1
Group Exercise
• Compute Entropy (H) Symbol (S) P(S)
A 0.1
• Build Huffman tree B 0.2
C 0.4
• Compute average D 0.2
code length
E 0.1
• Code “BCCADE”
Department of Computer Science & Engineering-Bangalore Campus
19ECS352 - Image Processing. Dr. Justin Varghese Slide 42
Limitations
• Diverges from lower limit when probability of
a particular symbol becomes high
– always uses an integral number of bits
Run-length encoding
Run-length encoding
The method can be even more efficient if the data uses only two symbols (for
example 0 and 1) in its bit pattern and one symbol is more frequent than the
other.
Run-length encoding
Arithmetic Coding
Arithmetic Coding
Arithmetic Coding
Encoding a1 a2 a3 a3 a4
• LZW Limitations
*The last character of a pattern is the first character of the next pattern.
• The patterns are of the form: C0C1 . . . Cn-1Cn. The prefix of a pattern consists of
all the pattern characters except the last: C0C1 . . . Cn-1
1. BA is not in the Dictionary; insert BA, output the code for its prefix: code(B)
2. AB is not in the Dictionary; insert AB, output the code for its prefix: code(A)
3. BA is in the Dictionary.
BAA is not in Dictionary; insert BAA, output the code for its prefix: code(BA)
4. AB is in the Dictionary.
ABA is not in the Dictionary; insert ABA, output the code for its prefix: code(AB)
5. AA is not in the Dictionary; insert AA, output the code for its prefix: code(A)
6. AA is in the Dictionary and it is the last pattern; output its code: code(AA)
1. BA is not in the Dictionary; insert BA, output the code for its prefix: code(B)
2. AB is not in the Dictionary; insert AB, output the code for its prefix: code(A)
3. BA is in the Dictionary.
BAA is not in Dictionary; insert BAA, output the code for its prefix: code(BA)
4. AB is in the Dictionary.
ABR is not in the Dictionary; insert ABR, output the code for its prefix: code(AB)
5. RR is not in the Dictionary; insert RR, output the code for its prefix: code(R)
6. RR is in the Dictionary.
RRA is not in the Dictionary and it is the last pattern; insert RRA, output code for its prefix:
code(RR), then output code for last character: code(A)
LZW: Limitations
• What happens when the dictionary gets too large?
• One approach is to clear entries 256-4095 and start building the dictionary again.
Exercises
Example
39 39 126 126
39 39 126 126
Concatenated Sequence: CS = CR + P
39 39 126 126 (CR) (P)
39 39 126 126
CR = empty
repeat
P=next pixel
CS=CR + P
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
Predictive
Difference
Huffman
EnCoder Lossless
Coding
68
Department of Computer Science & Engineering-Bangalore Campus
19ECS352 - Image Processing. Dr. Justin Varghese Slide 69
Wavelet Transform
Wavelet Transform
Wavelet Transform
Wavelet Transform
◼ Wavelet
◼ Small wave
◼ Means the window function is of finite length
◼ Mother Wavelet
◼ A prototype for generating the other window functions
◼ All the used windows are its dilated or compressed and shifted
versions
Wavelet Transform
◼ Wavelet Transform
◼ An alternative approach to the short time Fourier transform to
overcome the resolution problem
◼ Similar to STFT: signal is multiplied with a function
◼ Multiresolution Analysis
◼ Analyze the signal at different frequencies with different
resolutions
◼ Good time resolution and poor frequency resolution at high
frequencies
◼ Good frequency resolution and poor time resolution at low
frequencies
◼ More suitable for short duration of higher frequency; and longer
duration of lower frequency components
Wavelet Transform
Haar Wavelet
LPF
Input Signal
HPF
◼ The former process produces twice the data it began with: N input
samples produce N approximations coefficients and N detail
coefficients.
◼ To correct this, we Down sample (or: Decimate) the filter output by
two, by simply throwing away every second coefficient.
Decomposition
Reconstruction
Questions?
Thank You