Image Compression
Image Compression
• Lossless
• Information preserving
• Low compression ratios
• Lossy
• Not information preserving
• High compression ratios
compression
Compression ratio:
Definitions: Data Redundancy
Example:
Types of Data Redundancy
(1) Coding Redundancy
(2) Interpixel Redundancy
(3) Psychovisual Redundancy
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)
• Case 1: l(rk) = constant length
Example:
Coding Redundancy (cont’d)
• Case 2: 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 redundancy, the data must be
transformed in another format (i.e., through a
transformation)
• e.g., thresholding, differences between adjacent pixels, DFT
thresholded
(1+10) bits/pair
Psychovisual redundancy
• The human eye does not respond with equal sensitivity to all visual
information.
units of information!
How much information does an image contain?
• Average information content of an image:
L 1
E I (rk ) Pr(rk )
k 0
using
Entropy units/pixel
• Redundancy:
where:
image
Entropy Estimation (cont’d)
• First order estimate of H:
Estimating Entropy (cont’d)
• Second order estimate of H:
• Use relative frequencies of pixel blocks :
image
Estimating Entropy (cont’d)
16
Estimating Entropy (cont’d)
• 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)
• Backward Pass
Assign code symbols going backwards
Huffman Coding (cont’d)
• Lavg using Huffman coding:
Encode message: a1 a2 a3 a3 a4
0 1
2) Subdivide [0, 1) based on the probability of αi
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.
Note: -finite
(3 x precision
0.2log10(0.2)+0.4log 10(0.4))=0.5786
arithmetic might digits/symbol
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.
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)
39 39 126 126
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
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
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
K << N
K-1 K-1
Transform Selection
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
DFT
i.e., n-point periodicity
gives rise to
discontinuities!
DCT
i.e., 2n-point periodicity
prevents
discontinuities!
DCT (cont’d)
• 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
(non-centered
spectrum)
JPEG Steps
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)
DC
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))
Quantized De-quantized
Example 1 (cont’d)
Reconstructed Error
Example 2: less homogeneous 8
x 8 block
Example 2 (cont’d)
Quantized De-quantized
Example 2 (cont’d)
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 90
YUV Color Space
In many applications, it is desirable to describe a color in terms
of its luminance and chrominance content separately, to enable
more efficient processing and transmission of color signals
One such coordinate is the YUV color space
Y is the components of luminance
Cb and Cr are the components of chrominance
The values in the YUV coordinate are related to the values in the RGB
coordinate by
Y 0.299 0.587 0.114 R 0
Cb
0.169 0.334 0.500 G
128
Cr 0.500 0.419 0.081 B 128
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 91
Luminance/Chrominance commonly used, with Chrominance
subsampled due to human vision insensitivity
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 92
Spatial Sampling of Color Component
The three different chrominance downsampling format
(a) 4 : 4 : 4 (b) 4 : 2 : 2 (c) 4 : 2 : 0
W W W
H Y H Y H Y
W W/2 W/2
H/2 Cb
H Cb H Cb
W W/2 W/2
H/2 Cr
H Cr H Cr
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 93
JPEG
B
The JPEG Encoder
G
R Chrominance
YVU color 8X8
Downsampling
Image coordinate FDCT
(4:2:2 or 4:2:0)
Huffman
zigzag
Encoding
Quantizer Bit-stream
Differential Huffman
Quantization Coding Encoding
Table
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 94
JPEG Modes
• JPEG supports several different modes
• Sequential Mode
• Progressive Mode
• Hierarchical Mode
• Lossless Mode
Sequential
Progressive
Progressive JPEG (cont’d)
• Each scan, codes a subset of DCT coefficients.
(1) Progressive spectral selection algorithm
(2) Progressive successive approximation
algorithm
(3) Combined progressive algorithm
Progressive JPEG (cont’d)
(1) Progressive spectral selection algorithm
• Group DCT coefficients into several spectral bands
• Send low-frequency DCT coefficients first
• Send higher-frequency DCT coefficients next
Progressive JPEG (cont’d)
(2) Progressive successive approximation algorithm
• Send all DCT coefficients but with lower precision.
• Refine DCT coefficients in later scans.
Progressive JPEG (cont’d)
(3) Combined progressive algorithm
• Combines spectral selection and successive approximation.
Results using spectral
selection
Results using successive
approximation
Example using successive
approximation
after 0.9s after 1.6s
N/4 x N/4
N/2 x N/2
NxN
Lossless JPEG
• Uses predictive coding (see next slides)
JPEG 2000
B
The JPEG 2000 Encoder
G
JPEG 2000
R Forward Bit-stream
Component 2D DWT Quantization EBCOT
Image
Transform
Rate-
Context Arithmetic
Distortion
Modeling Coding
Control
Tier-1
Tier-2
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 109
Original
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 110
JPEG
27:1
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 111
JPEG2000
27:1
NTU, GICE, MD531, DISP Lab An Introduction to Image Compression Wei-Yi Wei 112
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.
Block Truncation Coding
• Divide image in non-overlapping blocks of pixels.
• Derive a bitmap (0/1) for each block using thresholding.
• e.g., use mean pixel value in each block as threshold.
• For each group of 1s and 0s, determine reconstruction value
• e.g., average of corresponding pixel values in original block.
Subband Coding
• Analyze image to produce components containing frequencies in
well defined bands (i.e., subbands)
• e.g., use wavelet transform or steerable filters.
• Optimize quantization/coding in each subband.
Vector Quantization
• Develop a dictionary of fixed-size vectors (i.e., code vectors),
usually blocks of pixel values.
• Partition image in non-overlapping blocks (i.e., image vectors).
• Encode each image vector by the index of its closest code vector.
Fractal Coding
• Decompose image into segments (i.e., using standard
segmentations techniques based on edges, color, texture, etc.) and
look them up in a library of IFS codes.
• Best suited for textures and natural images, relying on the fact that
parts of an image often resemble other parts of the same image
(i.e., self-similarity).
Fingerprint Compression
• An image coding standard for digitized fingerprints, developed
and maintained by:
• FBI
• Los Alamos National Lab (LANL)
• National Institute for Standards and Technology (NIST).
NO blocking artifacts!
WSQ Algorithm
Varying compression ratio
• FBI’s target bit rate is around 0.75 bits per pixel (bpp)
• i.e., corresponds to a target compression ratio of 10.7
(assuming 8-bit images)
• This target bit rate is set via a ‘‘knob’’ on the WSQ algorithm.
• i.e., similar to the "quality" parameter in many JPEG
implementations.
Varying compression ratio
(cont’d)
• In practice, the WSQ algorithm yields a higher compression ratio than
the target because of unpredictable amounts of lossless entropy
coding gain.
• i.e., mostly due to variable amounts of blank space in the images.
WSQ image, file size 47619 bytes, JPEG image, file size 49658 bytes,
compression ratio 12.4 compression ratio 11.9
Varying compression ratio (cont’d)
0.75 bpp compression
WSQ image, file size 39270 bytes JPEG image, file size 40780 bytes,
compression ratio 15.0 compression ratio 14.5
Varying compression ratio (cont’d)
0.6 bpp compression
WSQ image, file size 30987 bytes, JPEG image, file size 30081 bytes,
compression ratio 19.0 compression ratio 19.6
Video Compression