SK-ITCImage Compression Case Study9
SK-ITCImage Compression Case Study9
1
JPEG Coding
Cr
Cb Steps Involved:
Y
f(i, j) F(u, v) Quantiz Fq(u, v)
DCT 1. Discrete Cosine
ation
Transform of each 8x8
8x8 8x8
pixel array
f(x,y) 🡪T F(u,v)
Quant
2. Quantization using a
… table or using a constant
Tables
Coding 3. Zig-Zag scan to exploit
Tables Zig Zag redundancy
Heade Scan 4. Differential Pulse Code
Modulation(DPCM) on
r
Tables the DC component and
Entro Run length Coding of the
DPCM
py AC components
Data
Codin 5. Entropy coding
g RLC (Huffman) of the final
output
2
Color
• RGB planes
• Transform RGB into YUV
• Y – luminance
• U,V – chrominance
• UV have lower spatial resolutions
• Down sampled to take advantage of lower resolution
• Each image is encoded in a single left-to-right, top-to-bottom scan.
• The technique we have been discussing so far is an example of such a mode, also referred to
as the Baseline Sequential Mode
Four main steps in the JPEG encoding scheme.
• 1. Picture Preparation
• Separate the Y,U, and V components (planes)
• Subsample both U & V by 4x4 pixel regions (i.e. each 4x4 region becomes 1 mega-pixel)
• Split each plane into 8x8 blocks (64 pixels for Y, 64 mega-pixels for U/V)
• 3. Quantization
• Non-uniform quantization applied to the DCT coefficients (higher resolution given to DC and low frequency coefficients)
• Usually results in most of the higher frequency coefficients quantizing to a value of 0.
• 4. Entropy Encoding
• Used to further reduce the amount of space required to store the JPEG image
• Run length coding can be used on the long sequences of zeroes produced by the DCT
Overview of JPEG
• RGB YUV
• Down sample UV
• Original data is 8 bits per pixel, all positive [0,255]. Shift to
[-128, 127].
• Divide image into 8x8 blocks
• DCT on each block
• Use quantization table to quantize values in each block
{Reducing high freq content}
• Use zig-zag scanning to order values in each block
• Organize data into bands {DC, low f, mid f, high f}
• Run length encoding
• Huffman encoding
• Each number in the matrix represents a pixel in the 88
image. The darker pixels are represented by a lower
number, and the lighter pixels have a higher number.
• Each number falls between 0 and 255, with the midpoint
being 128.
• Before computing the DCT of each 88 block, each value in
the matrix must be recentered around zero. I.e., the
midpoint must be 0.
• Each number must, therefore, have 128 subtracted so that
the range is between 128 and 127.
• The reason for recentering around 0 is to reduce the
dynamic range after DCT
• DC coefficient - This is the top left-hand corner DCT
coefficient, otherwise known as the constant component.
This defines the basic hue for the entire 88 pixel block.
• AC coefficients - These are the remaining 63 DCT
coefficients, otherwise known as the alternating
components.
Quantization
• The eye is more sensitive to the lower frequencies.
• Divide each frequency component by a constant
• Divide higher frequency components with a larger value
• Truncate, and this will reduce the non-zero values
• Four quantization matrices are available in JPEG
• Non-uniform Quantization -- Quantization Tables
• Eye is most sensitive to low frequencies (upper left corner in frequency
matrix), less sensitive to high frequencies (lower right corner)
RLE on AC Components
• The 1x64 vectors have a lot of zeros in them, more so towards the end of
the vector.
• Higher up entries in the vector capture higher frequency (DCT) components
which tend to be capture less of the content.
• Could have been as a result of using a quantization table
• Encode a series of 0s as a (skip,value) pair, where skip is the number of
zeros and value is the next non-zero component.
• Send (0,0) as end-of-block sentinel value.
... 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 2 ...
5, 7, 1x64
1 2
11
• 26 3 6 2 2 1 0 0 0 0 0 1 1 4 2 0 3 1 5 1 1 0 0 0 0 0 0 0 1 2 1 3 1 0 0 0 0
000000000000000000000000000
• 26 3 0 3 2 6 2 4 1 3 1 1 5 1 2 1 1 1 2 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0
000000000000000000000000000000
Run Length Encoding
• 26 3 0 3 2 6 2 4 1 3 1 1 5 1 2 1 1 1 2 0 0 0 0 0 1 10
0000000000000000000000000000000000
000
4 4
5 1x64 5 1x64
5
4 9
1x64 1x64
4 -
8 1x64 6 1x64
. .
. .
3 . .
1
2 1x64 2 1x64
3
6 4
1x64 1x64
14
Entropy Coding: DC Components
• DC components are differentially coded as (SIZE,Value)
• The code for a Value is derived from the following table
Size_and_Value Table
15
Entropy Coding: DC Components (Contd..)
• DC components are differentially coded as (SIZE,Value)
• The code for a SIZE is derived from the following table
SIZE Code Code Example: If a DC component is 40
Length and the previous DC
component is 48. The
0 2 00
difference is -8. Therefore it
1 3 010 is coded as:
2 3 011 1010111
3 3 100 0111: The value for representing –8
(see Size_and_Value table)
4 3 101
101: The size from the same table
5 3 110 reads 4. The corresponding
6 4 1110 code from the table at left is
7 5 11110 101.
8 6 111110
9 7 1111110
10 8 11111110
11 9 111111110
Huffman Table for DC component SIZE field 16
Entropy Coding: AC Components
• AC components (range –1023..1023) are coded as (S1,S2 pairs):
• S1: (RunLength/SIZE)
• RunLength: The length of the consecutive zero values [0..15]
• SIZE: The number of bits needed to code the next nonzero AC component’s value. [0-A]
• (0,0) is the End_Of_Block for the 8x8 block.
• S1 is Huffman coded (see AC code table below)
• S2: (Value)
Partial Huffman Table for AC Run/Size
17
2,2 11111001
2,3 1111110111
2,4 111111110100
2,5 1111111110001001
2,6 1111111110001010
2,7 1111111110001011
2,8 1111111110001100
2,9 1111111110001101
2,10 1111111110001110
3,1 111010
3,2 111110111
3,3 111111110101
3,4 1111111110001111
3,5 1111111110010000
3,6 1111111110010001
3,7 1111111110010010
3,8 1111111110010011
3,9 1111111110010100
3,10 1111111110010101
Entropy Coding: Example
Example: Consider encoding the AC components by
4 1 arranging them in a zig-zag order -> 12,10, 1, -7
1 -2 0
- 0 0 0 0 0
0 0 0 0 0 0 2 0s, -4, 56 zeros
0
1 7
0 4
0 0 0 0 0 0 12: read as zero 0s,12: (0/4)12 🡪 10111100
0 0 0 0 0 0 0 0
1011: The code for (0/4 from AC code table)
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1100: The code for 12 from the
0 0 0 0 0 0 0 0 Size_and_Value table.
0 0 0 0 0 0 0 0 10: (0/4)10 🡪 10111010
1: (0/1)1 🡪 001
-7: (0/3)-7 🡪 100000
2 0s, -4: (2/3)-4 🡪 1111110111011
1111110111: The 10-bit code for 2/3
011: representation of –4 from Size_and_Value
table.
56 0s: (0,0) 🡪 1010 (Rest of the components are
zeros therefore we simply put the EOB to
signify this fact)
19