Digital Image Representation
Image Compression
11/5/2010 CENG 460 By: Roya Choupani 1
Introduction to Multimedia
Computing
Topics
11/5/2010 CENG 460 By: Roya Choupani 2
Image Representation (Review)
Need for compression
Compression types (Review)
Lossless compression
Lossy compression
Image Compression Basics (Review)
Redundancy/redundancy types
Lossy image compression methods
JPEG
Cosine Transform and Quantization
Entropy Encoding
Image Representation
11/5/2010 CENG 460 By: Roya Choupani 3
An image is a 2D matrix of pixels
Each pixel consists of RGB components
Sample dimension:
1024 rows
2048 columns
3 bytes per pixel
Image size = 1024 * 2048 * 3 = 6 Mbytes
Compressed size of this image is about 600KBytes (about 10%
of its uncompressed size)
Data Redundancy
11/5/2010 CENG 460 By: Roya Choupani 4
Definition: If some parts of data are stored repeatedly, or can
be derived from other parts, the data is said to be redundant
e.g. If the pixels of a region in an image have the same color,
we do not need to store the color value for all of them.
Redundancy Types
11/5/2010 CENG 460 By: Roya Choupani 5
Visual Redundancy
Spatial Redundancy
Temporal Redundancy
Stochastic Redundancy
Visual Redundancy
11/5/2010 CENG 460 By: Roya Choupani 6
Our visual system is more sensitive to brightness than color.
Therefore less color information can be stored for each pixel.
Spatial Redundancy
11/5/2010 CENG 460 By: Roya Choupani 7
Pixels that are near to each other with similar colors have
spatial redundancy. This property can be used to reduce the
stored data size.
Stochastic Redundancy
11/5/2010 CENG 460 By: Roya Choupani 8
If a pixel color is used more than other colors, we can use
less bits for it.
Stochastic redundancy is present in all media data types
Lossy Image Compression
3/19/2010 CENG 460 By: Roya Choupani 9
Motivation: Compression rates of the lossless algorithms are about 30%.
This rate is not enough for large images
Solution: Using lossy image compression.
In lossy compression, decompressed image and the original image are different
but generally the difference is not noticeable
Lossy JPEG
3/19/2010 CENG 460 By: Roya Choupani 10
Jpeg is a standard for image compression
Jpeg has lossless and lossy versions
Lossy Jpeg standard uses:
Visual redundancy
Spatial redundancy
Stochastic redundancy
To compress an image
Visual Redundancy
3/19/2010 CENG 460 By: Roya Choupani 11
Human visual system is less sensitive to color than brightness.
JPEG standard stores less color information than brightness
To separate color information from brightness, RGB data is
converted into YCbCr
Color space transformation
11/5/2010 CENG 460 By: Roya Choupani 1
2
RGB values of the pixels are converted to YCbCr
Dividing Image into Blocks
11/5/2010 CENG 460 By: Roya Choupani 1
3
The image is divided into blocks of 16x16 pixels called macro-
blocks
Color transformation from RGB to YCbCr is done for each
macro-block
Y component is divided into four 8x8 blocks
Cb and Cr components are down-sampled
Down Sampling (1)
11/5/2010 CENG 460 By: Roya Choupani 1
4
Cb and Cr components are down-sampled as shown below.
Effect of Removing Visual Redundancy
3/19/2010 CENG 460 By: Roya Choupani 16
Each macro-block consists of three components (Y, Cb, Cr)
Each component has 4 blocks
Each macro-block contains 3x4=12 blocks
After down-sampling (4:1:1), a macro-block has 4 (Y) + 1 (Cb)
+ 1 (Cr) = 6 blocks
This is equal to 50% compression
Spatial Redundancy
3/19/2010 CENG 460 By: Roya Choupani 17
If neighboring pixels are close in color, the signal has low
frequency
If neighboring pixels are very different, the image contains
high frequency
Discrete Cosine Transform is used to separate low frequency
from high frequency data
Discrete cosine transform
3/19/2010 CENG 460 By: Roya Choupani 1
8
Cosine transform is applied to each block after down-
sampling.
where
Example DCT Transform (1)
3/19/2010 CENG 460 By: Roya Choupani 19
208 244 108 173 71 112 181 245
231 246 234 193 12 97 192 87
32 40 202 189 25 195 70 149
233 248 245 100 210 203 173 57
161 244 167 167 177 48 167 192
25 124 9 44 81 125 41 65
71 204 217 180 242 114 30 129
139 36 238 8 9 165 127 178
1116 102 45 -99 -95 -25 40 -26
135 59 80 -21 -10 109 -71 -86
-18 -31 99 -58 3 53 64 -31
-20 10 44 22 90 -104 -189 -46
142 2 136 35 1 5 -16 81
60 0 -112 43 29 -102 8 4
-211 -169 24 22 0 15 97 -80
37 -65 -47 -135 94 -16 0 -26
Example DCT Transform (2)
3/19/2010 CENG 460 By: Roya Choupani 20
149 149 147 147 148 146 146 146
150 146 149 148 147 148 150 150
148 150 148 145 145 146 146 145
146 147 148 145 147 148 149 149
146 146 150 148 146 148 148 149
146 146 146 149 149 149 150 149
149 148 149 150 147 147 145 145
146 147 149 146 148 145 147 147
1180 1 1 -2 -1 1 1 1
1 1 3 1 0 0 0 0
0 4 -1 1 2 0 -1 1
2 -2 -2 1 2 1 0 -2
-2 -1 0 -1 -1 -2 0 2
-2 4 -1 1 0 -2 -1 -1
-2 0 0 1 -1 -2 -2 0
-2 5 -1 -1 -1 0 1 -1
Quantization
3/19/2010 CENG 460 By: Roya Choupani 2
1
DCT coefficients are rounded to some integer number.
Quantization is done using a quantization table.
B is the quantized value, G is the coefficient and Q is
quantization table value.
Zig-zag coding
3/19/2010 CENG 460 By: Roya Choupani 23
The quantized coefficients are listed after a zig-zag tracing.
The list has many zeros in it
Effect of Removing Spatial Redundancy
3/19/2010 CENG 460 By: Roya Choupani 24
The quantized coefficients at the right bottom corner
correspond to high frequency content
After zig-zag scanning, high frequency coefficients are at the
end of the list.
The zeros at the end of the list are not stored.
Removing Stochastic Redundancy
3/19/2010 CENG 460 By: Roya Choupani 25
Some of the quantized coefficients are repeated more than
others.
These coefficients can be sent using less bits
This is called removing stochastic redundancy
Code Blocks
3/19/2010 CENG 460 By: Roya Choupani 26
Code blocks: After zig-zag scanning, code blocks are
created by the number of zeros and the non-zero value
coming after them.
<number of zeros, nonzero value>
e.g. 304000500000006
(0,3), (1,4), (3,5), (7,6)
Entropy coding
3/19/2010 CENG 460 By: Roya Choupani 2
7
The code blocks after zig-zag scaning are coded using a
stochastic or entropy coding method to store less number of
bits.
In entropy coding less number of bits are assigned to the
codes that are repeated more. (variable length codes)
The Huffman method is used for variable length coding.
Image Quality
3/19/2010 CENG 460 By: Roya Choupani 28
JPEG image quality depends on
Down sampling type (4:4:4, 4:2:2, 4:1:1)
Quantization matrix (If values of the quantization matrix is
large, more zeros are resulted, and more data is lost. )
Higher compression rate causes lower quality of the image
JPEG Coding Algorithm
11/5/2010 CENG 460 By: Roya Choupani 3
1
The encoding process steps of JPEG:
The color of the pixels in the image is converted from RGB to
YCbCr
The resolution of the Cb and Cr data is reduced, usually by a factor
of 2. (Down-sampling)
The image is split into blocks of 8×8 pixels, and each block of Y, Cb,
and Cr undergoes a discrete cosine transform (DCT).
The DCT coefficients are quantized and zig-zag scanned.
The resulting data for all 8×8 blocks is further compressed with a
loss-less stochastic algorithm.
Assignment
3/19/2010 CENG 460 By: Roya Choupani 3
2
Read and summarize the JPEG algorithm from the paper given at
the assignment part of the course web page.