Chapter 8
Chapter 8
Image Compression
Image Compression
Data and Information
• Data and information
– Data are means by which information is conveyed
– Various amount of information may be needed to
represent the same amount of information
– Suppose information of interest is story; words are used
to relate the information
– If two individuals use a different number of words to tell
the same story, two different versions of the story are
created, and at least one includes nonessential data.
• One contains data (or words) that either provide no relevant
information or simply restate that which is already known. It is
called redundancy.
Data Redundancy and
Compression
• Data redundancy
– Relative data redundancy RD for the data set n1
1 n1
RD = 1- CR =
CR n2
– CR: compression ratio
– n1, n2: number of information carrying units in two data
sets that represent the same information
– Compression ratio, 10 (or 10:1) means that first data set
has 10 information carrying units for every 1 unit in
second or compressed data set.
• First data set has 90% redundant data
• Data compression
– Reducing the amount of data required to represent a
given quantity of information
Data Redundancy
In digital image compression, three basic
data redundancy:
– Coding redundancy
– Interpixel redundancy
– Psychovisual redundancy
Coding Redundancy
• In most images, certain gray levels are more
probable than others
• Assigning fewer bits to the more probable
gray levels to the less probable ones
achieves data compression, called variable-
length coding.
• If the gray levels of an image are coded in a
way that uses more code symbols than
absolutely necessary to represent each gray
level,
– the resulting image has coding redundancy.
Coding Redundancy - Example
nk
pr (rk ) =
n
L -1
Lavg = å l (rk ) pr (rk )
k =0
Autocorrelation
Coefficients by
Eq 8.1-6
Any given pixel
can be
predicted from
its neighbors
Psychovisual Redundancy
• The eye does not respond with equal
sensitivity to all visual information.
Certain information simply has less
relative importance than other information
in normal visual processing
• In general, an observer searches for
distinguishing features such as edges
or textural regions and mentally combines
them into recognizable groupings.
Psychovisual Redundancy
https://slideplayer.com/slide/12988598/
Psychovisual Redundancy
Table 8.2
åå [ ]
é 1 M -1 N -1
ˆf (x, y ) - f (x, y ) 2 ù
erms =ê ú
ë MN x =0 y =0 û
– Mean-square signal-to-noise ratio (SNRms)
åå [ ]
M -1 N -1
ˆf ( x, y ) 2
x =0 y =0
SNRms =
åå [ ]
M -1 N -1
ˆf ( x, y ) - f ( x, y ) 2
x =0 y =0
– Root-mean-square SNRms (SNRrms)
Fidelity Criteria
Chapter 8
Image Compression
Image Compression model
Source Encoder
Source Decoder
j =1
Data 3
Lossy
Information
Data 2
Lossless
Data 1
011100010111 à a1 a2 a6 a5 a2
Entropy = -0.4log0.4-0.3log0.3-0.2*log0.1 - 0.06*log0.6
-0.04*log0.04= 2.14 bits/symbol
Theoretical lower limit
https://www.youtube.com/watch?v=cF-Q5j7RUEw
https://www.youtube.com/watch?v=-qMm9hhvp9Y
Chapter 8
Image Compression
Binary Image Compression
- RLC
• Developed in 1950s
• Standard compression approach in FAX
coding
• Approach
– Code each contiguous group of 0’s or 1’s
encountered in a left to right scan of a row by
its length
– Establish a convention for determining the
value of the run
– Code black and white run lengths separately
using variable-length coding
https://api.video/what-is/run-length-encoding
Example
Original image 2 127 128
3 32 33
1 0.34 (1) 0.66 (0) 3 1.00 (0) 0 0.34 (1) 1 2 0.4 (1) 0.6 (0)
Huffman
coding 2 0.33 (00) 0.34 (1) 1 0.33 (00) 2 2 0.4 (00) 0.4 (1)
3 0.33 (01) 2 0.33 (01) 0 1 0.2 (01)
https://www.youtube.com/watch?v=EvjrxnzI63Y
Example 2: Lossless
Predictive Coding
https://www.youtube.com/watch?v=EvjrxnzI63Y
Lossless Compression
Approaches
Averagely, use
Variable-length coding shorter-length
Code code to
redundancy Huffman coding convey the
same amount of
information
Bit-plane coding
Run-length coding
Interpixel
LZW
redundancy
Predictive coding
Lossy Compression
• Spatial domain methods
– Lossy predictive coding
• Delta modulation (DM)
• Transform coding
– Operate on the transformed image
Lossy Predictive Coding
• Prediction + quantization
•
Predictor fˆn = a f n -1
Error eˆ = f - fˆ
n n n
Delta
• ìd if en > 0
Error quantization en = í
î- d
Modulation
otherwise
• •
Prediction f n = e n + fˆn
Lossy Predictive Coding
•
fˆn = a f n -1
eˆ = f - fˆ
n n n
• ìd if en > 0
en = í
î- d otherwise
• •
f n = e n + fˆn
𝛼=1
𝑒 = 𝑓 − 𝑓ˆ
Transform Coding
• Use discrete image transforms to transform the
image
• Discard those coefficients that are near zero
• Coarsely quantize those coefficients that are small
• When reconstructed later, little important content
will have been lost
• Example
– JPEG (image lossy compression)
– MPEG (video compression)
– Wavelet transform
JPEG
• Joint Photographics Expert Group
• An image compression standard
sanctioned by ISO
• can be very effectively applied to a 24-bit
color image, achieving compression
ratios of 10:1 to 20:1 without any image
degradation that is visible to the human
eye at normal magnification
• File is saved as .jpg or .jpeg
JPEG Compression Steps
• Convert RGB model to intensity and chrominance
(YIQ)
• Throw away half of the chrominance data
• Divide the pictures into blocks of 8x8 pixels
• Perform a discrete Cosine transform on each
block
• Quantize the DCT coefficients
• Run-length encoding
• Huffman encoding
Color model Downsample Divide picture DCT on Huffman
conversion chrominance content into 8x8 blocks each block RLC
coding
JPEG Compression: Step 1
Step 1: The input image is divided into a small block which is
having 8x8 dimensions. This dimension is sum up to 64 units.
Each unit of the image is called pixel.
https://www.javatpoint.com/jpeg-compression
JPEG Compression: Step 2
Step 2: JPEG uses [Y,Cb,Cr] model instead of using the [R,G,B]
model. So in the 2nd step, RGB is converted into YCbCr.
The YIQ Color Space
• Used in US commercial color television broadcasting
• Recoding of RGB for transmission efficiency and for
downward compatibility with b/w television
• Y component: illuminance (gets the majority of the b/w)
• I, Q: chrominance
é (2 x + 1)up ù é (2 y + 1)vp ù
g ( x, y, u, v) = a (u )a (v) cosê ú cosê ú
ë 2N û ë 2N û
N -1 N -1
• Inverse transform f ( x, y) = åå T (u, v)h( x, y, u, v)
x =0 y =0
g ( x, y, u, v) = h( x, y, u, v)
https://www.youtube.com/watch?v=h3u-lVDyHD4
https://www.geeksforgeeks.org/discrete-cosine-transform-algorithm-
program/
The 64 DCT Basis Functions
• Horizontal frequencies increase from left to right,
• and vertical frequencies increase from top to bottom.
v
0 1 2 3 4 5 6 7
0
u
1
https://www.mathworks.com/help/images/discrete-cosine-transform.html
JPEG Compression: Step 4
Step 4: Humans are unable to see important aspects of the
image because they are having high frequencies. The matrix
after DCT conversion can only preserve values at the lowest
frequency that to in certain point. Quantization is used to
reduce the number of bits per sample.
æ F (u, v) ö
Stqndard quantization formula: F ' (u, v) = round çç ÷÷
è q(u, v) ø
JPEG Compression: Step 5
Step 5: The zigzag scan is used to map the 8x8 matrix to a 1x64
vector. Zigzag scanning is used to group low-frequency
coefficients to the top level of the vector and the high coefficient
to the bottom. To remove the large number of zero in the
quantized matrix, the zigzag matrix is used.
More clearly Zig-zag Scan
JPEG Compression: Step 6
Step 6: Next step is vectoring, the different pulse code
modulation (DPCM) is applied to the DC component. DC
components are large and vary but they are usually close to the
previous value. DPCM encodes the difference between the
current block and the previous block..
JPEG Compression: Step 7
Step 7: In this step, Run Length Encoding (RLE) is applied to
AC components. This is done because AC components have a
lot of zeros in it. It encodes in pair of (skip, value) in which skip is
non zero value and value is the actual coded value of the non
zero components.
JPEG Compression: Step 8
Step 8: In this step, DC components are coded into Huffman.
JPEG Compression - 1
Input Image
16 11 10 16 24 40 51 61 17 18 24 47 99 99 99 99
12 12 14 19 26 58 60 55 18 21 26 66 99 99 99 99
14 13 16 24 40 57 69 56 24 26 56 99 99 99 99 99
14 17 22 29 51 87 80 62 47 66 99 99 99 99 99 99
18 22 37 56 68 109 103 77 99 99 99 99 99 99 99 99
24 35 55 64 81 104 113 92 99 99 99 99 99 99 99 99
49 64 78 87 103 121 120 101 99 99 99 99 99 99 99 99
72 92 95 98 112 100 103 99 99 99 99 99 99 99 99 99
JPEG Compression - 3
Ø Quantization Result
JPEG Compression -4
Restored Image
https://www.youtube.com/watch?v=Ky4CaKw7tdo
Motion Compensation
• Data processing:
• It is required to apply motion prediction at
every macroblock level
• Here predictive coding is applicable only that
part of image where motion is present
• There are 3 types of predictions are available
1. forward prediction :
2. backward prediction
3. bidirectional prediction.
Temporal Redundancy
Reduction
• Three frames
– I frame (intra picture)
– P frame (predicted picture)
– B frame (bidirectionally interpolated
picture)
Motion Compensation
Motion Compensation: DCT
• DCT: requires to remove High frequency
components
• We have to apply DCT on 8*8 data blocks
Motion Compensation: Quantization
B2-Code
• Divide symbols into blocks with
the size of 4
• Represent the symbols in each
group with 2bits
• Concatenate them with
continuation bit C
• a11 can be presented either
001010 or 101110 depending on
the bit assigned to C
Binary Shift
• Divide into blocks of 7 symbols
• Generate prefix code with 7
symbols
Huffman shift
http://site.iugaza.edu.ps/jroumy/files/Tru • Generate Huffman code for the 8
symbols(7 symbols+ sum of all
ncated-huffman.pdf others)
https://www.youtube.com/watch?v=lvhe
u2ElJ-E