Beruflich Dokumente
Kultur Dokumente
Image Compression
But life is short and information endless...
Abbreviation is a necessary evil and the
abbreviators business is to make the best of a job
which, although intrinsically bad, is still better than
nothing.
Aldous Huxley
M. Carli - 2005
Image Compression
M. Carli - 2005
Image Compression
Why Compression?
M. Carli - 2005
Image Compression
Digital image
A digital image is a two-dimensional
sequence of samples
M. Carli - 2005
Image Compression
M. Carli - 2005
Image Compression
Color
Color images: three values per sample
location, (red, green and blue)
xr [n1, n2], xg[n1, n2] xb[n1, n2]
M. Carli - 2005
Image Compression
M. Carli - 2005
Image Compression
lossless
Compression techniques
lossy
Image Compression
RD = 1
1
n
where C R = 1
CR M. Carli - 2005
n2
1
Examining RD = 1
CR
compression
ratio
Image Compression
Case 1: n2 = n1
CR = 1 and RD = 0
Case 2: n2
n1
CR and RD 1
Case 3: n2
n1
CR 0 and RD
M. Carli - 2005
(undesirable)
data expansion
Image Compression
Redundancy
M. Carli - 2005
Image Compression
Example
Suppose that:
CR = 10 (or 10 :1)
RD = 0.9
M. Carli - 2005
Image Compression
Coding Redundancy
k =0
Image Compression
Coding
The average lenght of the code words assigned to
the various gray-level values: the sum of the
product of the number of bits used to represent
each gray level and the probability that the gray
level occurs.
Total number of bits to code an MxN image is
MNLavg
Usually l(rk) = m bits (constant). Lavg = k mpr (rk)=m
M. Carli - 2005
Image Compression
Coding
It makes sense to assign
fewer bits to those rk for
which pr(rk) are large in
order to reduce the sum.
achieves data
compression and results in
a variable length code.
Lavg =
L 1
l (rk ) pr (rk )
k =0
Image Compression
natural
binary
code
Gray-level distribution
Code 1: Lavg = 3 bits
Code 2: Lavg = 2.7 bits
2(0.19)+2(0.25)+...
3
= 1.11
2.7
1
RD = 1
= 0.099
1.11
CR =
M. Carli - 2005
Image Compression
probability
codeword length
M. Carli - 2005
Image Compression
Interpixel Redundancy
Same2 histograms x
autocorrelation
coefficients along one
line of each image
A(n)
( n ) =
A(0)
trimodal
1 N 1n
f ( x, y) f ( x, y + n)
N n y =0
M. Carli - 2005
A( n) =
Image Compression
Interpixel Redundancy
Second image shows high correlation between
pixels 45 and 90 samples apart
Adjacent pixels of both images are highly correlated
Interpixel (or spatial) redundancy:
redundancy the value of any
given pixel can be reasonably predicted from the
values of its neighbors; as a consequence, any pixel
carries a small amount of information
Interpixel redundancy can be reduced through
mappings (e.g., differences between adjacent pixels)
M. Carli - 2005
Image Compression
CR =
1024 343 1
= 2.63
12,166 11
number of runs
11 bits are necessary to
represent each run-length pair
RD = 1
1
= 0.62
2.63
M. Carli - 2005
10
Image Compression
Psychovisual Redundancy
The eye does not respond with equal sensitivity to
all visual information
Certain information has less relative importance
than other information in normal visual processing
(psychovisually redundant)
It can be eliminated without significantly
impairing the quality of image perception
M. Carli - 2005
Image Compression
M. Carli - 2005
11
Compression by Quantization
8 bits
Image Compression
M. Carli - 2005
Image Compression
e( x, y ) = f ( x, y ) f ( x, y )
erms
1
=
MN
M 1 N 1
f ( x, y) f ( x, y)
x =0 y =0
M. Carli - 2005
1/ 2
2
12
Image Compression
f ( x, y ) 2
SNRms =
x =0 y =0
M 1 N 1
f ( x, y ) f ( x, y ) 2
x =0 y =0
M. Carli - 2005
Image Compression
M. Carli - 2005
13
Image Compression
Source encoder:
encoder removes input redundancies
Channel encoder: increases the noise
immunity of the source encoders output
M. Carli - 2005
Image Compression
M. Carli - 2005
14
Image Compression
M. Carli - 2005
Image Compression
Source Encoder
Mapper:
Mapper designed to reduce interpixel redundancy;
redundancy
e.g.:
Run-length encoding
Transform encoding (e.g., DCT in JPEG standard)
Quantizer:
Quantizer reduces psychovisual redundancies (it
cannot be used in lossless compression)
Symbol Encoder:
Encoder creates a fixed/variable length code;
it reduces coding redundancies
M. Carli - 2005
15
Image Compression
Quantizer
Goal: reduce the number of possible amplitude values for
coding
Simple scalar quantizerwith four output indices
M. Carli - 2005
Image Compression
16
Image Compression
Measuring Information
I ( E ) = log
1
= log P ( E )
P( E )
units of information
I(E) is often called self-information
M. Carli - 2005
Image Compression
Self-Information
If P ( E ) = 1, I ( E ) = 0 (no information)
If the base of the logarithm is 2, the unit of
information is called a bit
17
Image Compression
Entropy
Source alphabet
{a1, a2 ,, aL }
information
source
M. Carli - 2005
Image Compression
4
4
12
1/ 8
1/ 8
3/ 8
H = 1.81 bits/pixel
(first-order estimate)
M. Carli - 2005
18
Image Compression
H = 1.41 bits/pixel
(first-order estimate)
Image Compression
19
Image Compression
M. Carli - 2005
Image Compression
Huffman Coding
20
Image Compression
Image Compression
21
Huffman Coding
Image Compression
010100111 1 00
a3
a a a a6
2 2
1
M. Carli - 2005
Image Compression
Arithmetic Coding
22
Image Compression
Arithmetic Coding
Image Compression
M. Carli - 2005
any number in
this subinterval,
e.g. 0.068, can
be used to
represent the
message
23
Image Compression
Uses a dictionary
Dictionary is adapted to the data
It assigns fixed-length codewords to
variable-length sequences of source symbols
Decoder builds the matching dictionary
based on the codewords received
Used in GIF, TIFF, and PDF formats
M. Carli - 2005
Image Compression
39
39
39
39
126
126
126
126
126
126
126
126
M. Carli - 2005
24
Image Compression
M. Carli - 2005
Image Compression
variable-length code
prediction error
en = f n fn
Decoder
f n = en + fn
M. Carli - 2005
25
Image Compression
The Predictor
Example:
Example
fn = round i f n i
i =1
Example:
Example
m=order of predictor
f ( x, y ) = round i f ( x, y i )
i =1
M. Carli - 2005
m
f ( x, y )
Image Compression
f ( x, y ) = round [ f ( x, y 1)]
f ( x, y )
previous pixel
predictor
e( x, y ) = f ( x, y ) f ( x, y )
=1
histograms of original
and error image
Laplacian PDF
M. Carli - 2005
26
Image Compression
f n = en + fn
Feedback loop prevents error
buildup at the decoders output
Decoder
f n = en + fn
M. Carli - 2005
Image Compression
fn = f n 1
M. Carli - 2005
27
Image Compression
Optimal Predictors
{ }
E en2 = E f n fn
f n = en + fn en + fn = f n
and to
(quantization error is
assumed to be negligible)
fn = i f n i
Image Compression
Optimal predictor
M. Carli - 2005
28
Image Compression
is = R r where
E { f n 1 f n1}
R=
E { f n m f n 1}
E { f n1 f nm }
autocorrelation
matrix
E { f n m f nm }
E { f n f n 1}
1
=
r=
m M. Carli - 2005 E { f n f n m }
Image Compression
f ( x, y ) = 0.5 f ( x, y 1) + 0.5 f ( x 1, y )
f ( x, y ) = 0.75 f ( x, y 1) + 0.75 f ( x 1, y ) 0.5 f ( x 1, y 1)
0.97 f ( x, y 1) if h v
f ( x, y ) =
0.97 f ( x 1, y ) otherwise
where:
h = f ( x 1, y ) f ( x 1, y 1)
v = f ( x, y 1) f ( x 1, y 1)
M. Carli - 2005
29
Image Compression
original image
M. Carli - 2005
Image Compression
Transform Coding
Encoder
Decoder
M. Carli - 2005
30
Image Compression
Transform Selection
T (u , v) =
N 1 N 1
f ( x, y ) g ( x, y , u , v )
x =0 y =0
u , v = 0,1,, N 1
The inverse discrete transform is defined as
f ( x, y ) =
N 1 N 1
T (u, v)h( x, y, u, v)
u =0 v =0
x, y = 0,1,, N 1
M. Carli - 2005
Image Compression
g ( x, y , u , v ) = e
2
(ux + vy )
N
h ( x, y , u , v ) =
1
N
2
(ux + vy )
N
M. Carli - 2005
31
Image Compression
2 N
2N
where
N
(u ) =
2
N
for u = 0
for u = 1, 2,, N 1
Image Compression
M. Carli - 2005
32
Image Compression
DFT
rms = 1.28
DCT
rms = 0.68
M. Carli - 2005
Image Compression
Why DCT?
Blocking artifacts are less pronounced in the DCT
than in the DFT
The DCT is a good approximation of the
Karhunen-Loeve Transform (KLT) which is
optimal in terms of energy compaction
However, unlike the KLT, the DCT has imageindependent basis functions
The DCT is used in JPEG compression standards
M. Carli - 2005
33
Image Compression
M. Carli - 2005
Image Compression
M. Carli - 2005
34
Image Compression
2 2
original
4 4
88
M. Carli - 2005
Image Compression
Bit Allocation
35
Image Compression
Threshold Coding
M. Carli - 2005
Image Compression
Zonal Coding
M. Carli - 2005
36
Image Compression
Typical Masks
zonal mask
1:= keep
0:=discard
zonal bit
allocation
threshold coding is
adaptive: the locations
of the coefficients to
keep depend on
threshold mask
subimages
thresholded
coefficients
ordering
M. Carli - 2005
Image Compression
Approximations
obtained by using
12.5% of the 8x8
DCT coefficients
Zonal
Coding
Threshold
Coding
M. Carli - 2005
37
Image Compression
Image Compression
M. Carli - 2005
38
Image Compression
M. Carli - 2005
Image Compression
2.
3.
39
Image Compression
f =
183 160
183 153
179 168
177 177
178 178
179 180
179 179
180 179
Image Compression
fs = f 128 =
55 32 -34
25
66 35
55 25 -12
48
59 38
51 40
49 49
43
51
54 51
49 51
42
37
3
3
50 50
51 52
51
52
48 54
51 55
36
36
2
2
51 51
52 51
52
53
54 55
51 53
42
42
1
2
37
41
39
39
43
43
45
41
M. Carli - 2005
40
Image Compression
-20 -18 10
-11 -7 9
dcts = round (dct2( fs )) =
-6 1
6
3 3 0
3 5 0
3 1 -1
17 79 -60
26
45
31
-1
-24
33
21
-6
-16
15
10
-11
-13
-4
-7
-5
-2
-7
-4
-4
-8
-1
-2
-3
-1
-26
-10
-9
1
2
4
M. Carli - 2005
Image Compression
qmat =
16
12
14
14
18
24
49
72
11
12
13
17
22
35
64
92
10
14
16
22
37
55
78
95
16
19
24
29
56
64
87
98
24
26
40
51
68
81
103
112
40
58
57
87
109
104
121
100
51 61
60 55
69 56
80 62
103 77
113 92
120 101
103 99
M. Carli - 2005
41
Image Compression
M. Carli - 2005
Image Compression
Example: Thresholding
20
-3
-1
-1
t = round (dcts./ qmat ) =
0
0
0
-3
-2
-2
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
M. Carli - 2005
42
Image Compression
-1
-1
t = round (dcts./ qmat ) =
0
0
0
DC coefficient
0
-3
-2
-2
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
end-of-block
Image Compression
43
Image Compression
0
0
0
0
0
0
26
-14 -13 16 24
-14 0
0 29
40
0
0
0
0
0
M. Carli - 2005
Image Compression
67
58
12
25
-9
15
20
30
69
65
43
40
-8
-4
46
41
44
49
53
41
52
54
52
50
44
59
58
53
53
40
43
40
40
46
59
57
58
61
63
38
42
47
47
41
0
3
3
1
0
55
50
56
53
64
34
-1
42
47
49
42
33
33
45
57
M. Carli - 2005
44
to be compared to
f =
Image Compression
183 160
183
179
177
178
179
179
180
Image Compression
Decompressed
M. Carli - 2005
45
Image Compression
CR = 34 :1
CR = 67 :1
rms = 3.42
rms = 6.33
M. Carli - 2005
Image Compression
M. Carli - 2005
46
Image Compression
M. Carli - 2005
47