Professional Documents
Culture Documents
and Applications
Introduction
Requirements on JPEG implementations
JPEG Image Preparation
Blocks, Minimum Coded Units (MCU)
JPEG Quantization
Quantization Tables
JPEG Compression
Variants of Image
Compression
Four different modes
Lossy Sequential DCT based mode
Baseline process that must be supported by every JPEG
implementation.
Lossless mode
low compression ratio
allows perfect reconstruction of original image
Hierarchical mode
accomodates images of different resolutions
JPEG Compression
Image
Preparation
Prediction
FDCT
Baseline
Sequential
Mode
Expanded
Lossy
Mode
Block, MCU
8bits/pixel
Transformation
Source Coding
lossy DCT
12 bits/pixel
Layered
coding
Lossless
Mode
Hierarchical
Mode
2-16 bits/pixel
Predictive
Entropy
coding
Switch
between
lossy DCT
and
lossless
technique
Quantization
Compressed
Image
Entropy
Encoding
Run-length
Huffman
Arithmetic
Run-length
Huffman
JPEG Compression
JPEG Compression
Image Preparation
Ci
Xi
Cn
...
Yi
C2
C1
Division of the source image into planes
JPEG Compression
JPEG Compression
A1 A2
X2
X3
B1 B2
C1 C2
Y2
X1 = X2 = X3
Y3
An
Y1 = Y2 = Y3
Bn
Cn
X3
B1 B2
Y1
Y2
An
C1 C2
Y1 = Y2 = Y3
Y3
Bn/2
X1 = 2X2 = 2X3
Cn/2
JPEG Compression
Image Preparation
JPEG Compression
10
* * *
* * *
* * *
*
*
*
*
* *
* *
C_0
C_2
C_1
*
Y_max = 4 pixels,
Level 2
H_2 = 1 (X = 6/2)
V_2 = 1 (Y = 4/2)
Level 0
H_0 = 2 (X = 6)
V_0 = 2 (Y = 4)
*
*
*
*
X_max = 6 pixels
JPEG Compression
11
JPEG Compression
12
Image Preparation
13
Image Preparation
(MCU Example)
4 components - C1, C2, C3, C4
C1:
C2:
C3:
C4:
H_1
H_2
H_3
H_4
=
=
=
=
2,
2,
1,
1,
V_1
V_2
V_3
V_4
=
=
=
=
2
1
2
1
...
2
C2: d00
...
3
C3: d00
4
C4: d00
...
...
d1
31
d2
11
d3
30
d4
10
JPEG Compression
14
Image Preparation
(MCU Example)
JPEG Compression
15
Image Preparation
After image preparation,
uncompressed image samples are grouped into data
units of 8x8 pixels and passed to the JPEG encoder
order of the data units is defined by the MCUs
precision 8 bits/pixel represents the baseline mode
values are in the range of [0,255];
JPEG Compression
16
Image Processing
First step:
pixel values are shifted (ZERO-SHIFT) into the range
[-128,127] with 0 in the center.
Values in the 8x8 pixel are defined by S_yx with y,x in the
range [0,7] and there are 64 sampled values S_yx in each
block.
JPEG Compression
17
S(u) = C(u)
2
x=0
S(x) cos
( )
(2x+1)u
16
S(v,u) =
C(u)C(v)
S(y,x) cos
x=0 y=0
( ) ( )
(2x+1)u
16
JPEG Compression
cos
(2y+1)v
16
18
Factoring
By computing the DCT coefficients, we can use factoring; the
problem will be reduced to a series of 1D FDCTs.
S(v,u) =
x=0
C(u) cos
( )(
(2x+1)u
16
y=0
JPEG Compression
C(v) cos
( )
(2y+1)v
16
S(y,x)
)
19
JPEG Compression
20
Quantization
GOAL: To throw out bits.
Example:
101101 = 45 (6 bits).
We can truncate this to 4 bits: 1011 - 11
or 3 bits 101 = 5 (original value - 40) or 110 = 6 (value = 48)
JPEG Compression
21
Quantization Tables
Quantization tables consist of 64 elements
Each value is 8 bits - Q_vu
JPEG Compression
22
Example:
16
13
26
29
56
87
95
121
11
14
24
40
55
69
98
112
12
18
22
58
64
55
103
100
14
17
22
51
72
56
104
120
12
16
24
61
92
80
103
92
10
19
49
60
78
109
62
101
16
24
35
57
64
81
77
103
14
40
37
51
68
87
113
99
Eye is most sensitive to low frequencies (upper left corner), less sensitive to high frequencies (lower right corner)
JPEG Compression
23
Entropy Encoding
After image processing we have quantized DC and AC
coefficients.
Initial step of entropy encoding is to map 8x8 plane
into 64 element vector
.
.
.
Zig zag scan
JPEG Compression
24
Entropy encoding
DC Coefficient Processing
Treat quantized DC coefficients separately from AC
coefficients.
DC coefficients determine the basic color of the data unit.
DC coefficient is large and varied, but often close to previous
value.
Use difference encoding.
DC0
DC1
DC2
DC0
Diff1
Diff2
DC3
DC4
DC5
Diff3
Diff4
Diff5
DC6
DC7
DC8
Diff6
Diff7
Diff8
JPEG Compression
25
Entropy Encoding
AC Coefficient Processing
DCT processing of AC coefficients
follows zig-zag sequence which means that the coefficients
with lower frequencies are encoded first, followed by higher
frequencies.
Implies that we can get a sequence of similar data bytes,
hence can apply entropy encoding.
JPEG standard specifies Huffman or Arithmetic encoding, in
baseline mode only Huffman Coding is used.
Arithmetic encoding is protected by patent.
JPEG Compression
26
JPEG Compression
27
Entropy Encoding
(DC Huffman Encoding)
Categorize DC values into DC code tables.
Get difference magnitude categories for DC coefficients (12
possible categories).
Handle SSSS as Huffman Symbols
consider symbols p(0)p(11). Create a Huffman tree and get a
Huffman code for SSSS.
For each category, additional bits field is appended to the code
word to uniquely identify which difference in that categories
actually occurred.
Send(Huffman code, actual value).
Example: If SSSS=2 has the Huffman code 001 and Diff= -3,
we send 00100, first 3 bits are Huffman code and last 2 bits
represent -3 in 2s complement.
JPEG Compression
28
Difference Magnitude
Categories
Difference Values
0 bit
1 bit
2 bits
3 bits
.
.
11 bits
-1,1
-3,-2,2,3
-7,-6,..,-4,4,..,7
.
.
-2047,..,-1024,1024,..,2047
JPEG Compression
29
Entropy Encoding
(AC - Huffman Encoding)
Each non-zero AC coefficient in zigzag scan is
described as a composite 8 bit value
RS = binary RRRRSSSS.
SSSS defines
category for the amplitude of the next non-zero coefficient in
zig-zag scan.
RRRR defines
position of the coefficient in the zigzag scan relative to previous
nonzero coefficient (run length coding of 0 coefficients b/w
nonzero coefficients).
JPEG Compression
30
AC Coefficient Categories
AC Coefficients
-1,1
1 bit
2 bits
3 bits
.
.
10 bits
-3,-2,2,3
-7,-6,..,-4,4,..,7
.
.
-1023,..,-512,512,..,1023
JPEG Compression
31
JPEG Comments
Applications do not have to include both an encoder and
decoder if the compression and decompression process agree
on a common table.
The encoded data stream has a fixed interchange format:
encoded image data, chosen parameters, tables of the coding
process.
JPEG Compression
32
Start-of-Image
Tables, etc.
Tables, etc.
header
header
block
End-of-Image
...
Scan
segment
block
Scan
Restart
...
JPEG Compression
segment
Restart
block
33
JPEG Headers
JPEG Headers:
Frame Header sample precision, width and height of image, number of
components, unique ID (for each component),
horizontal/vertical sampling factors (for each component),
quantization table to use (for each component)
Scan Header
number of components in scan, component ID for each
component, Huffman table for each component.
Misc
occurs b/w headers and includes quantization tables, Huffman
tables, Arithmetic coding tables, comments, application data.
JPEG Compression
34