Professional Documents
Culture Documents
1
www.imageprocessingbook.com
Chapter 8
Image
Compression
www.ImageProcessingPlace.com
Why Compression?
• Storage
– Image data is by its nature multidimensional and tend
to take up a lot of space
• Computational expenses
– Encryption of data is computationally expensive
• Transmission time & costs
– ISPs charge by the data amount, phone companies by
the time unit
• Limited hardware resources (memory, CPU etc)
– Cell phones with cameras, USB memory sticks
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 3
www.imageprocessingbook.com
Why Compression?
We need maximum utilization of storage devices & quick
transmission.
Compression Types
The fundamental task of image compression is to reduce
the amount of data required to represent the image. This
is done by transforming and removing image data
redundancies
Compression Types
• Lossless compression algorithms
The original data is reconstructed perfectly
Theoretical limit on maximal compression
Practical compression ratios of <10 : 1 (still images)
• Lossy compression algorithms
Decompression results in an approximation of the
original image
Maximal compression rate is a function of
reconstruction quality
Practical compression ratios of >10 : 1 (still images)
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 6
www.imageprocessingbook.com
Image Compression
Image Compression
1. Compression Ratio
A larger number implies a better compression
2. Bits per Pixel
A smaller number implies a better compression
Background
>> b = imread(‘bubbles.tif’);
>> imwrite(b,'bubbles.png')
>> imwrite(b,'bubbles.jpg')
>> imwrite(b,'bubbles', 'jpg')
>> imwrite(b,'bubbles.jpg','quality',50)
Background
Compression Ratio: CR = n1 / n2
where n1 and n2 denote the umber of information carrying units (usually bits)
in the original image f(x, y) and encoded image f^(x, y), resp.
Compression Ratio
Example: Image 256 X 256 pixels, 256 level grayscale can be
compressed file size 6554 byte.
65536
Compressio n Ratio 10
6554
Redundancy Types
• Coding Redundancy
• Interpixel Redundancy
• Psychovisual Redundancy
Redundancy Types
• Coding Redundancy
– Which is present when less than optimal code
words are used
– It is due to inefficiencies in data representations
Redundancy Types
• Interpixel redundancy
– It is defined as failure to identify and utilize data relationships
– If a pixel value can be reasonably predicted from its
neighboring (or preceeding / following) pixels the image is said
to contain interpixel redundancy
– Interpixel redundancy depends on the resolution of the image
o The higher the (spatial) resolution of an image, the more probable it is
that two neighboring pixels will depict the same object
o The higher the frame rate in a video stream, the more probable it is that
the corresponding pixel in the following frame will depict the same
object
These types of predictions are made more difficult by the presence of noise
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 17
www.imageprocessingbook.com
Redundancy Types
• Psychovisual Redundancy
– Which is due to data that is ignored by the human
visual system
– Some information is more important to the human
visual system than other types of information
Redundancy Types
• Psychovisual Redundancy
– Psychovisual redundancy stem from the fact that the human eye does not
respond with equal intensity to all visual information
– The human visual system does not rely on quantitative analysis of individual
pixel values when interpreting an image – an observer searches for distinct
features and mentally combines them into recognizable groupings
– In this process certain information is relatively less important than other – this
information is called psychovisually redudant
– Psychovisually redundant image information can be identified and removed –
a process referred to as quantization
– Quantization eliminates data and therefore results in lossy data compression
– Reconstruction errors introduced by quantization can be evaluated objectively
or subjectively depending on the application need & specifications
Redundancy Types
Quantization Effects
• Compression
Compressed
Compressed
Input
Input Preprocessing
Preprocessing Encoding
Encoding File
File
• Decompression
Compressed
Compressed Decoding
Decoding Postprocessing
Postprocessing Output
Output
File
File
Coding Redundancy
Pr(rk) = nk / n, k = 1, 2,…, L
L
Lavg l (rk ) pr (rk ) (Average number of bits per pixel)
k 1
where l(rk) is the number of bits used to represent each value
of rk.
Coding Redundancy
Exercise:
1. Find CR , RD ?
Huffman Coding
• Provides a data representation with the smallest
possible number of code symbols per source
symbol (when coding the symbols of an
information source individually)
• Huffman code construction is done in five steps:
1. Find the histogram probabilities
2. Order the input probabilities (large small)
3. Add two smallest
4. Repeat steps 2 & 3, until two probabilities are left
5. Backward along the tree by assigning 0 and 1
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 26
www.imageprocessingbook.com
Huffman Coding
Step 1: Histogram Probability
40
30 p0 = 20/100 = 0.2
20 p1 = 30/100 = 0.3
10 p2 = 10/100 = 0.1
0 1 2 3 p3 = 40/100 = 0.4
Step 2: Order
p3 0.4
p1 0.3
p0 0.2
p2 0.1
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 27
www.imageprocessingbook.com
Huffman Coding
Huffman Coding
Huffman Coding
• The original Image : average 2 bits/pixel
3
La li pi 3(0.2) 2(0.3) 3(0.1) 1(0.4) 1.9
i 0
Huffman Coding
3
Entropy pi log 2 ( pi )
i 0
Coding Redundancy
Huffman Codes – Another Example
Given image:
119 123 168 119 Gray- Code
123 119 168 168 level
119 119 107 119 a1 107
107 107 119 119
a2 119
Histogram: a3 123
3 8 2 3 a4 168
Probability:
0.1875 0.5000 0.1250 0.1875
Coding Redundancy
Huffman Codes – Another Example
Coding Redundancy
Huffman Codes – Another Example
It contains the smallest possible number of bits per gray-level value.
For our given 4 X 4 image:
Gray- Code
f= level
119 123 168 119
a1 107 011
123 119 168 168
119 119 107 119 a2 119 1
107 107 119 119 a3 123 010
a4 168 00
Fig. 8.2(b) yields the 29-bit string:
Coding Redundancy
Huffman Codes – Matlab
>> f = repmat([3 3 1 3 3 3 3 3 2 3], 1, 50); % Data to encode
Coding Redundancy
Huffman Codes – Matlab
>> dict{1,:}
ans =
1
ans =
1 1
>> dict{2,:}
ans =
2
ans =
1 0
>> dict{3,:}
ans =
3
ans =
0
Coding Redundancy
Huffman Codes – Matlab
>> hf = huffmanenco(f, dict); % Encode the data.
>> df = huffmandeco(hf, dict); % Decode the code.
Coding Redundancy
Huffman Codes
Exercise: [2, Problem 8.12]
(a) How many unique Huffman codes are there for a three-symbol
source?
(b) Construct them.
References
1. Gonzalez R. C., Woods R. E., Eddins S. L., Digital Image
Processing Using Matlab, Pearson Education, 2006.
2. Gonzalez R. C., Woods R. E., Digital Image Processing,
Pearson Education, 2006.
3. http://www.imageprocessingplace.com/
4. http://www.cs.umu.se/kurser/TDBC30/VT05/