Unit 7-Image Data Compression
Unit 7-Image Data Compression
Compression
What is Image Compression ?
Image
10 10 20
20 20 20 Compressed data 10032006
20 20 10
Compression Fundamentals
• Image compression involves reducing the size of image data files, while
retaining necessary information
Compression Ratio =
Compression can be achieved because we
have a lot of redundant data in any information
• Coding redundancy
• Inter-pixel redundancy
• Pyscho-visual redundancy
Coding Redundancy
• Information is always represented in different forms of codes
• There are many coding techniques which convert an information into a code
• Coding techniques assigns a unique code to the symbols of message / pixels
of image
• Wrong choice of coding technique creates unnecessary additional bits
• The extra bits are called redundancy
• Coding redundancy is caused due to poor selection of coding technique
Inter-pixel Redundancies
• Neighboring pixels in the same image are correlated (not
statistically independent)
• Inter-pixel correlation is called as inter-pixel spatial redundancy
• Inter-pixel redundancy in successive frames of a video is called
inter-pixel temporal redundancy
• The visual contribution of a single pixel is redundant and can be
guessed from the values of its neighbors
Example :
• Consider an image with a constant background
• The visual nature of the image background is given by many pixels
that are not actually necessary
Psycho-visual Redundancy
• Pyscho-visual redundancy is related to vision
• The eye and the brain do not respond to all visual information with same
sensitivity
• The human eye cannot see all the grey levels
• Eliminating such grey levels do not affect the interpretation of the image by
the brain
• Psycho-visual redundancy deals with the information which is psycho-visually
(pyscho-acoustic) redundant based on human perception
• Information that is not perceived by human senses (seen or heard) can be
removed to achieve compression
• Example: When 256 levels are reduced by grouping to 16 levels, objects are
still recognizable. The compression is 2:1, but an objectionable graininess and
contouring effect results
Psycho-visual Redundancy
• If the image will be used for visual observation (i.e illustration on the web, etc)
• A lot of information is psycho-visually redundant.
• It can be removed without changing the visual quality of the image
• This kind of compression is irreversible
Fidelity
• The degree of exactness with which the data is reproduced
• Fidelity criterion is used to determine important information to be
retained when compressing files.
• Fidelity criteria is divided into 2 classes :
i. Objective fidelity criteria
ii. Subjective fidelity criteria
Objective Fidelity Criteria
• Objective fidelity criteria measures amount of error in decompressed
image.
• The smaller the value of error, the better is the quality of compressed
image
Distortion Measures/Error Metrics/
Objective Fidelity Criteria
• Errors are measured using:
1. Mean – Square - Error
2. Signal to Noise ratio (SNR)
3. Peak Signal to Noise ratio
Mean Square Error (MSE)
• Mean Square Error (MSE) for two dimensional data (eg image)
• For input image , f(x,y) and Reconstructed image of size M x N
Root Mean Square Error (RMSE)
Signal to Noise Ratio (SNR)
𝑆𝑖𝑛𝑎𝑙 𝑃𝑜𝑤𝑒𝑟 𝑃 𝑠
𝑆𝑁𝑅= =
𝑁𝑜𝑖𝑠𝑒 𝑃𝑜𝑤𝑒𝑟 𝑃 𝑛
For input image , f(x,y)
[∑ ∑ ]
𝑀− 1 𝑁 −1
1
Signal Power = 𝑓 2 (𝑥 , 𝑦 )
𝑀×𝑁 𝑥=0 𝑦= 0
Reconstructed image ,
2
255
𝑃𝑆𝑁𝑅=10 𝑙𝑜𝑔10
𝑀𝑆𝐸
Subjective Fidelity Criteria
Example
• 2x2 original image and reconstructed image is as given. Find RMSE
Original Reconstructed
5 4 4 4
2 3 1 2
General Image Compression Models
𝑓 (𝑥 , 𝑦) Source Channel Source
Channel ^𝑓 ( 𝑥 , 𝑦)
Channel
Encoder Encoder decoder decoder
• The source encoder is responsible for removing redundancy (coding, inter-pixel, pyscho-visual)
and outputs a set of symbols
• The channel encoder improves the noise immunity of the output of source encoder.
• Channel encoder ensures robustness against channel noise
• The job of channel decoder and source decoders is to get back the original signal.
• Run length coding is used to eliminate or reduce interpixel redundancies.
• Huffman encoding is used to eliminate or reduce coding redundancies
General Image Compression Models
• Compression has two types i.e. Lossy and Lossless technique.
• A typical image compression system comprises of two main blocks
• An Encoder (Compressor) and Decoder (Decompressor).
• The image f(x,y) is fed to the encoder which encodes the image so as
to make it suitable for transmission.
• The decoder receives this transmitted signal and reconstructs the
output image f(x,y).
• If the system is an error free one f(x,y) will be a replica of f(x,y).
Classification of data compression
techniques
X Y
Compression
Xc Reconstruction
Algorithm Algorithm
X=Y X≠Y
Lossless Data Compression
In other words, characters with high probability (frequency) will be coded with
shorter code than characters with small probability
Steps of Huffman coding
1. for the given grey levels, write down the list of probabilities
2. Sort the list in descending order
3. Add the smallest (last) two probabilities
4. Again sort the probabilities and repest the process until just one
value is left
Compute the Huffman code for the given data
{1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,4,4,4,4,5,5,5,6,6,7}
si ni Pi = ni / Total count
si Pi
1 7 7/28 = 0.25 1 0.25
2 6 6/28 = 0.21 2 0.21
3 5 5/28=0.18 3 0.18
4 4 4/28=0.14
4 0.14
5 3 3/28=0.11
5 0.11
6 2 2/28=0.07
6 0.07
7 1 1/28=0.04
7 0.04
Total
count
= 28
si Pi Place in
Pi Pi
descending Pi Pi
order 0.57
0.25 0.32 0.43
1 0.25 0.25 0.43
0.32 1
2 0.21 0.21 0.22 0.25
0.21 0.21 0.25 0.57
3 0.18 0.18
4 0.14 0.14 0.18 0.22 0.43
5 0.11 0.11 0.14 0.32
0.43
0.57
0.22 0.21
0.32 0.25
0.11 0.11
0.18 0.14
0.07 0.04
1
1 0
0.43
0.57 1 0
1 0 0.22 0.21 (2)
1
0.32
0 0.25 (1) 1 0
0.11 (5) 0.11
0.18 (3) 0.14 (4) 1 0
0.07 (6) 0.04 (7)
0
si Huffman code
1 10
2 00
Final Huffman code 3 111
table for each symbol / 4 110
pixel value
5 011
6 0101
7 0100
Example 2
Compute the Huffman code for the given data
{a,a,a,a,a,a,b,b,b,c,c,c,c,c,c,d,d,d,d,d,d,d,d,d,d,e,e,e,e,f,f}
si ni Pi = ni / Total count
a 6 6/31 = 0.193 si Pi
b 3 3/31 = 0.096 a 0.193
c 6 6/31=0.193 b 0.096
d 10 10/31=0.323 c 0.193
e 4 4/31=0.129
d 0.323
f 2 2/31=0.065
e 0.129
Total
count f 0.065
= 31
Pi Pi
si Pi Place in
Pi Pi 0.61
descendi 0.386
0.323 0.386 1
ng order 0.323 0.323
0.193 0.29 0.29 0.61
a 0.193 0.323
0.193 0.193
b 0.096 0.193 0.386
0.161 0.193
c 0.193 0.193
0.129 0.29
d 0.323 0.129
e 0.129 0.096
f 0.065 0.065 0.161
1
0.386
0.61
0.193 0.193
0.323 0.29
0.161 0.129
0.096 0.065
1
1 0
0.386
0.61 1 0
1 0
0.193 0.193
0.323 0.29 (a) (c)
(d)
1 0
0.161 0.129
1 0
(e)
0.096 0.065
(b) (f)
si Hamming code
a 01
b 1011
c 00
d 11
e 100
f 1010
Image compression standards
Lossy Compression
• Many methods of lossy compression have been developed.
• However, a family of techniques known as TRANSFORM CODING has
proven to be most valuable
Transform Coding method of
Lossy Compression
• We transform the image using some transformation
• Discard the pixels coefficients that are nearly zero
• When these images are reconstructed using inverse transform, we get
compressed image in which little information is lost.
• JPEG is very simple and easy to use standard that is based on the Discrete
Cosine Transform (DCT)
JPEG
• JPEG is a sophisticated lossy/lossless compression method for color or grayscale
still images (not movies).
• It does not handle bi-level (black and white) images very well.
• It also works best on continuous-tone images, where adjacent pixels have
similar colors.
• One advantage of JPEG is the use of many parameters, allowing the user to adjust
• amount of the data lost (and thus also the compression ratio) over a very wide
range
• Often, the eye cannot see any image degradation even at compression ratios of
10:1 or 20:1.
• There are two main modes:
• lossy (also called baseline) and lossless (which typically produces compression
ratios of around 0)
• Most implementations support just the lossy mode
Image Compression for Binary
image
• A binary image is one that consists of pixels that can have one of exactly two colors,
usually black and white.
• Binary images are also called bi-level
• This means that each pixel is stored as a single bit—i.e., a 0 or 1.
• A binary image can be stored in memory as a bitmap, a packed array of bits.
• A 640×480 image requires 37.5 KB of storage.
• Because of the small size of the image files, fax machine and document management
solutions usually use this format.
• Most binary images also compress well with simple run-length compression
schemes.
Example
• Consider the below 7 x 8 binary image .
• To store this we require 56 bytes
2W1B1W1B2W 10 bytes
1W1B3W1B1W 10 bytes
8B 2 bytes
3W1B3W 6 bytes
Total bytes after run length
3W1B3W 6 bytes coding : 52 bytes
3W1B3W 6 bytes
3W1B3W 6 bytes