Documente Academic
Documente Profesional
Documente Cultură
Conclusions
2 / 56
Resources
Image compression =
minimizing the number of bits to represent an image.
Reasons to compress
Quantization
Lossy compression
Entropy coding
Lossless compression
u
q
takes values from a discrete set
Uniform quantization
Adaptive/optimal quantization
15 / 56
Quantization
u
q
takes values from a discrete set
Uniform quantization
Adaptive/optimal quantization
15 / 56
Quantization
u
q
takes values from a discrete set
Uniform quantization
Adaptive/optimal quantization
15 / 56
Quantization
u
q
takes values from a discrete set
Uniform quantization
Adaptive/optimal quantization
Note: Color quantization leads to vector quantization
15 / 56
Quantization example
PNG, 813 897 pixels, 256 levels, 315 kB
16 / 56
Quantization example
PNG, 813 897 pixels, 128 levels, 256 kB
16 / 56
Quantization example
PNG, 813 897 pixels, 64 levels, 202 kB
16 / 56
Quantization example
PNG, 813 897 pixels, 32 levels, 147 kB
16 / 56
Quantization example
PNG, 813 897 pixels, 16 levels, 89 kB
16 / 56
Quantization example
PNG, 813 897 pixels, 8 levels, 53 kB
16 / 56
Quantization example
PNG, 813 897 pixels, 4 levels, 36 kB
16 / 56
Quantization example
PNG, 813 897 pixels, 2 levels, 20 kB
16 / 56
Optimal quantization
Lloyd-Max
i
_
i +1
i
(u r
i
)
2
p(u) du
u u
q
: t
k
u < t
k+1
u
q
(u) = r
k
Optimality conditions:
t
k
= (r
k
+ r
k+1
)/2
r
k
= E
_
u|t
k
u < t
k+1
_
=
_
t
k
u<t
k+1
u p(u) du
_
t
k
u<t
k+1
p(u) du
Lloyd-Max
i
_
i +1
i
(u r
i
)
2
p(u) du
u u
q
: t
k
u < t
k+1
u
q
(u) = r
k
Optimality conditions:
t
k
= (r
k
+ r
k+1
)/2
r
k
= E
_
u|t
k
u < t
k+1
_
=
_
t
k
u<t
k+1
u p(u) du
_
t
k
u<t
k+1
p(u) du
Lloyd-Max
i
_
i +1
i
(u r
i
)
2
p(u) du
u u
q
: t
k
u < t
k+1
u
q
(u) = r
k
Optimality conditions:
t
k
= (r
k
+ r
k+1
)/2
r
k
= E
_
u|t
k
u < t
k+1
_
=
_
t
k
u<t
k+1
u p(u) du
_
t
k
u<t
k+1
p(u) du
Lloyd-Max
i
_
i +1
i
(u r
i
)
2
p(u) du
u u
q
: t
k
u < t
k+1
u
q
(u) = r
k
Optimality conditions:
t
k
= (r
k
+ r
k+1
)/2
r
k
= E
_
u|t
k
u < t
k+1
_
=
_
t
k
u<t
k+1
u p(u) du
_
t
k
u<t
k+1
p(u) du
=
L
k=1
p
k
log
2
p
k
Maximum entropy is H = log
2
L for p
k
=
1
L
Notes:
Probabilities p
k
can be estimated from a histogram
Human coding
Arithmetic coding
Input: Symbols a
1
, . . . , a
L
with probabilities p
1
, p
2
, . . . , p
L
Output: Prex-free binary code c
1
, c
2
, . . . , c
L
with minimum
expected codeword length
L
k=1
p
k
length(c
k
).
Algorithm:
While there are more than two orphan nodes, merge the two
orphan nodes with the smallest p
i
, p
j
, creating a new parent
node with probability p
i
+ p
j
. The new edges are labeled 0
and 1.
Encode symbols a
1
, a
2
, a
3
, a
4
with probabilities
p
1
= 0.4, p
2
= 0.35, p
3
= 0.2, p
4
= 0.05.
Entropy is H =
4
k=1
p
k
log
2
p
k
1.74 bits/symbol
23 / 56
Human coding example
Encode symbols a
1
, a
2
, a
3
, a
4
with probabilities
p
1
= 0.4, p
2
= 0.35, p
3
= 0.2, p
4
= 0.05.
Entropy is H =
4
k=1
p
k
log
2
p
k
1.74 bits/symbol
a1: 0.4
a2: 0.35
a3: 0.2
a4: 0.05
110
111
0.25
11
10
0.6
1
0
1
The code is c
1
= 0, c
2
= 10, c
3
= 110, c
4
= 111.
Average length is
4
k=1
p
k
length(c
k
)a 1.85 bits/symbol
Lossless
Causal ordering
36 / 56
DPCM
+
+
+
Quantizer
Predictor
im(i)
p_im(i)
e(i) diffs(i)
Encoding Decoding
Predictor
+
+
im(i) diffs(i)
no quantization
f (i , j ) = a
1
f (i , j 1) + a
2
f (i 1, j 1) + a
3
f (i 1, j )
= a
T
f(i , j )
with a = [a
1
a
2
a
3
]
T
f(i , j ) = [f (i , j 1) f (i 1, j 1) f (i 1, j )]
T
minimizing the expected quadratic prediction error
J = E
_
(
f (i , j ) f (i , j ))
2
39 / 56
Optimal linear predictor
= E
_
a
T
f f
T
a + f
2
2f a
T
f
= a
T
Ca 2a
T
b + R(0, 0)
with C = E
_
f f
T
=
_
_
R(0, 0) R(0, 1) R(1, 1)
R(0, 1) R(0, 0) R(1, 0)
R(1, 1) R(1, 0) R(0, 0)
_
_
b = E
_
f f
=
_
R(1, 0) R(1, 1) R(0, 1)
T
The optimal a must satisfy
b = Ca
39 / 56
Predictive compression example
Input image
0 50 100 150 200 250
0
500
1000
1500
2000
Histogram of the input image, entropy 7.66
40 / 56
Predictive compression example
0 50 100 150 200 250
0
500
1000
1500
2000
Histogram of the input image, entropy 7.66
Image histogram
300 200 100 0 100 200 300
0
0.5
1
1.5
2
2.5
x 10
4
prediction error
f
r
e
q
u
e
n
c
y
histogram of the errors, entropy: 5.95
Prediction error histogram
Linear 1D predictor (columnwise) of order 3.
40 / 56
Predictive compression example
300 200 100 0 100 200 300
0
0.5
1
1.5
2
2.5
x 10
4
prediction error
f
r
e
q
u
e
n
c
y
histogram of the errors, entropy: 5.95
Prediction error histogram
200 100 0 100 200
25
20
15
10
5
0
5
10
15
20
25
zero mean prediction error
q
u
a
n
t
i
z
e
d
p
r
e
d
i
c
t
i
o
n
e
r
r
o
r
quantization function
Quantization function,
Lloyd-Max
40 / 56
Predictive compression example
300 200 100 0 100 200 300
0
0.5
1
1.5
2
2.5
x 10
4
prediction error
f
r
e
q
u
e
n
c
y
histogram of the errors, entropy: 5.95
Prediction error histogram
300 200 100 0 100 200 300
0
1
2
3
4
5
6
7
8
x 10
4
prediction error
f
r
e
q
u
e
n
c
y
histogram of quantized errors, entropy: 1.93
Quantized prediction error
histogram
40 / 56
Predictive compression example
Input image
Original image
Compressed to 25% of the original size.
40 / 56
Predictive compression example
Reconstructed image
Reconstructed image
Compressed to 25% of the original size.
40 / 56
Introduction
Simple methods
Vector image formats
Pixel coding
Entropy coding
Dictionary coding
Image specic methods
Transform coding
Performance, examples, conclusions
41 / 56
Transform coding
= 0 and R = E
_
xx
T
Eigenvalue decomposition
Rv
i
=
i
v
i
or RV = V with V = [v
1
. . . v
N
]
Karhunen-Lo`eve transform:
y = V
T
x
Properties
Diagonalization: E
_
yy
T
= V
T
RV = V
T
V =
Variance maximization: If
1
> . . .
N
, then
E
__
M
k=1
y
k
_
2
M
k=1
2
k
is maximized over V
43 / 56
Principal component analysis
Discrete Karhunen-Lo`eve transform
Disadvantages:
No fast algorithm.
n=0
x
n
cos
_
N
_
n +
1
2
_
k
_
k = 0, . . . , N 1
X
k
= DCT
_
x
n
)
44 / 56
Discrete cosine transform
DCT
1D DCT basis functions
44 / 56
2D DCT
2D DCT is separable:
X
jk
= DCT
mn
(x
mn
) = DCT
m
_
DCT
n
(x
mn
)
_
Basis functions are:
jk
= cos
_
N
_
n +
1
2
_
j
_
cos
_
N
_
n +
1
2
_
k
_
45 / 56
2D DCT
Basis functions are:
45 / 56
JPEG compression
1992
DCT of 8 8 blocks.
DPCM on DC components.
Human encoding.
46 / 56
JPEG: Step 1 Divide to blocks
Usually 8 8, can be 16 16
47 / 56
JPEG: Step 1 Divide to blocks
Usually 8 8, can be 16 16
47 / 56
JPEG: Step 1 Divide to blocks
Usually 8 8, can be 16 16
47 / 56
JPEG: Step 2 Color conversion
Optional
Calculate
=
_
50/q if 1 q 50
2 q/50 if 50 q 100
50 / 56
JPEG: Step 4 Quantization
of DCT coecients
Calculate
=
_
50/q if 1 q 50
2 q/50 if 50 q 100
jk
= round
_
F
jk
Q
jk
_
50 / 56
JPEG: Step 4 Quantization
of DCT coecients
jk
= round
_
F
jk
Q
jk
_
_
16 11 10 16 24 40 51 61
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99
_
_
It can be dierent for chrominance.
50 / 56
JPEG: Step 4 Quantization
of DCT coecients
275 663 231 77 34 54 37 16 14 2 2 2 6 7 5 4
882 343301116 5 55 51 22 7 11 2 1 1 1 12 11
154 294 70 101 77 13 28 32 28 8 2 1 9 8 9 6
90 16 160 19 77 77 21 33 38 39 5 15 13 13 0 5
153 101 1 43 25 56 43 2 41 36 16 10 19 8 2 4
4 137 103 39 3 4 11 6 18 14 16 8 8 6 7 3
1 35 64 77 39 2 15 6 13 7 8 7 6 9 7 9
29 61 46 44 34 29 10 1 0 2 11 10 7 2 11 12
34 36 56 50 40 17 34 24 8 4 9 14 5 1 9 4
5 13 21 33 33 19 20 22 24 7 16 12 9 5 3 0
16 28 25 8 28 13 18 15 20 9 2 10 8 9 3 2
22 32 38 27 5 16 7 10 5 21 13 2 9 15 3 0
9 12 15 29 30 2 22 10 0 1 11 9 6 4 15 7
1 14 9 1 12 17 7 13 6 3 2 9 12 5 22 18
14 23 24 20 18 3 21 5 1 10 7 2 0 12 9 8
20 13 10 27 16 9 9 25 2 11 15 2 15 5 3 2
DCT2 coefficients
2 4 6 8 10 12 14 16
2
4
6
8
10
12
14
16
10 10 10 10 50 50 50 50 100 100 100 100 100 100 100 100
10 10 10 10 50 50 50 50 100 100 100 100 100 100 100 100
10 10 10 10 50 50 50 50 100 100 100 100 100 100 100 100
10 10 10 10 50 50 50 50 100 100 100 100 100 100 100 100
50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100
50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100
50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100
50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
Quantization matrix
10 10 10 10 50 50 50 50 100 100 100 100 100 100 100 100
10 10 10 10 50 50 50 50 100 100 100 100 100 100 100 100
10 10 10 10 50 50 50 50 100 100 100 100 100 100 100 100
10 10 10 10 50 50 50 50 100 100 100 100 100 100 100 100
50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100
50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100
50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100
50 50 50 50 50 50 50 50 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
2 4 6 8 10 12 14 16
2
4
6
8
10
12
14
16
DCT coecients (16 16) Quantization matrix Q
jk
50 / 56
JPEG: Step 4 Quantization
of DCT coecients
275 663 231 77 34 54 37 16 14 2 2 2 6 7 5 4
882 343301116 5 55 51 22 7 11 2 1 1 1 12 11
154 294 70 101 77 13 28 32 28 8 2 1 9 8 9 6
90 16 160 19 77 77 21 33 38 39 5 15 13 13 0 5
153 101 1 43 25 56 43 2 41 36 16 10 19 8 2 4
4 137 103 39 3 4 11 6 18 14 16 8 8 6 7 3
1 35 64 77 39 2 15 6 13 7 8 7 6 9 7 9
29 61 46 44 34 29 10 1 0 2 11 10 7 2 11 12
34 36 56 50 40 17 34 24 8 4 9 14 5 1 9 4
5 13 21 33 33 19 20 22 24 7 16 12 9 5 3 0
16 28 25 8 28 13 18 15 20 9 2 10 8 9 3 2
22 32 38 27 5 16 7 10 5 21 13 2 9 15 3 0
9 12 15 29 30 2 22 10 0 1 11 9 6 4 15 7
1 14 9 1 12 17 7 13 6 3 2 9 12 5 22 18
14 23 24 20 18 3 21 5 1 10 7 2 0 12 9 8
20 13 10 27 16 9 9 25 2 11 15 2 15 5 3 2
DCT2 coefficients
2 4 6 8 10 12 14 16
2
4
6
8
10
12
14
16
28 66 23 8 1 1 1 0 0 0 0 0 0 0 0 0
88 34 30 12 0 1 1 0 0 0 0 0 0 0 0 0
15 29 7 10 2 0 1 1 0 0 0 0 0 0 0 0
9 2 16 2 2 2 0 1 0 0 0 0 0 0 0 0
3 2 0 1 1 1 1 0 0 0 0 0 0 0 0 0
0 3 2 1 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 2 1 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Quantized DCT2 coefficients
2 4 6 8 10 12 14 16
2
4
6
8
10
12
14
16
DCT coecients Quantized coecients F
jk
50 / 56
JPEG: Step 4 Quantization
of DCT coecients
275 663 231 77 34 54 37 16 14 2 2 2 6 7 5 4
882 343301116 5 55 51 22 7 11 2 1 1 1 12 11
154 294 70 101 77 13 28 32 28 8 2 1 9 8 9 6
90 16 160 19 77 77 21 33 38 39 5 15 13 13 0 5
153 101 1 43 25 56 43 2 41 36 16 10 19 8 2 4
4 137 103 39 3 4 11 6 18 14 16 8 8 6 7 3
1 35 64 77 39 2 15 6 13 7 8 7 6 9 7 9
29 61 46 44 34 29 10 1 0 2 11 10 7 2 11 12
34 36 56 50 40 17 34 24 8 4 9 14 5 1 9 4
5 13 21 33 33 19 20 22 24 7 16 12 9 5 3 0
16 28 25 8 28 13 18 15 20 9 2 10 8 9 3 2
22 32 38 27 5 16 7 10 5 21 13 2 9 15 3 0
9 12 15 29 30 2 22 10 0 1 11 9 6 4 15 7
1 14 9 1 12 17 7 13 6 3 2 9 12 5 22 18
14 23 24 20 18 3 21 5 1 10 7 2 0 12 9 8
20 13 10 27 16 9 9 25 2 11 15 2 15 5 3 2
DCT2 coefficients
2 4 6 8 10 12 14 16
2
4
6
8
10
12
14
16
280 660 230 80 50 50 50 0 0 0 0 0 0 0 0 0
880 340300120 0 50 50 0 0 0 0 0 0 0 0 0
150 290 70 100 100 0 50 50 0 0 0 0 0 0 0 0
90 20 160 20 100100 0 50 0 0 0 0 0 0 0 0
150 100 0 50 50 50 50 0 0 0 0 0 0 0 0 0
0 150 100 50 0 0 0 0 0 0 0 0 0 0 0 0
0 50 50 100 50 0 0 0 0 0 0 0 0 0 0 0
50 50 50 50 50 50 0 0 0 0 0 0 0 0 0 0
0 0 100 100 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
dct2 coefficients from the quantized data
2 4 6 8 10 12 14 16
2
4
6
8
10
12
14
16
DCT coecients Reconstructed coecients F
jk
Q
jk
50 / 56
JPEG: Step 4 Entropy coding
Predictive coding of F
00
(from previous block)
Error resilience
Unlimited scalability
Excellent compressibility
55 / 56
Conclusions
What to take home
Quantization
Predictive coding
Video coding
56 / 56
Conclusions
What to take home
Quantization
Predictive coding
Video coding
56 / 56