Escolar Documentos
Profissional Documentos
Cultura Documentos
Lossy Compression
Spring 2015
Original
Quantization
Uniform
Non-uniform
Transform coding
DCT
Encoder
Entropy
Transform Quantization coding
channel
Decoder
Inverse Inverse Entropy
Transform Quantization decoding
Reconstruction Values
Input Values
Bin 4 Bin 4
index index
Bin 3 Bin 3
x Bin 2 Entropy Entropy
Coding Decoding Bin 2 x
Bin 1 Bin 1
Bin 0 Bin 0
Quantizer Dequantizer
(Inverse Quantizer)
Quantization is a function that maps an input interval to one integer
Can reduce the bits required to represent the source.
Reconstructed result is generally not the original input
Terminologies:
Decision boundaries bi: bin boundaries
Reconstruction levels yi: output value of each bin by the dequantizer.
yi
1
bi 1 bi for inner intervals.
2
Uniform Midrise Quantizer Uniform Midtread Quantizer
Reconstruction Reconstruction
3.5∆
3∆
2.5∆
2∆
1.5∆
-3∆ -2∆ -∆ 0.5 ∆ ∆
-2.5∆ -1.5∆ -0.5∆
-0.5∆ ∆ 2∆ 3∆ Input 0.5∆ 1.5∆ 2.5∆ Input
-1.5∆ -∆
-2.5∆ -2∆
-3.5∆ -3∆
-2∆
De-quantization mapping:
-3∆
xˆ B(q) q
x Q x̂ or x x̂
CMPT365 Multimedia Systems 8
Rate-Distortion Tradeoff
Things to be determined: Distortion
Number of bins A
Bin boundaries
Reconstruction levels B
Rate
A tradeoff between rate and distortion:
To reduce the size of the encoded bits, we need to reduce
the number of bins
Less bins More reconstruction errors
Number of bins: M
Decision boundaries: bi, i = 0, …, M
Reconstruction Levels: yi, i = 1, …, M
Reconstruction:
xˆ yi iff bi 1 x bi
bi
MSE:
M
MSEq x ˆ
x 2
f ( x ) dx x yi 2
f ( x)dx
i 1 bi1
Quantization
Uniform
Non-uniform
Vector quantization
Transform coding
DCT
y1 y2 y3 y4 y5 y6 y7 y8
-3.5∆ -2.5∆ -1.5∆ -0.5 ∆ 0. 5∆ 1.5∆ 2.5∆ 3.5∆ x
b0 b1 b2 b3 b4 b5 b6 b7 b8
-4∆ -3∆ -2∆ -∆ 0 ∆ 2∆ 3∆ 4∆
-Xmax Xmax
e(x) is uniformly distributed in [-∆/2, ∆/2].
0.5 ∆
∆ 2∆ 3∆ 4∆ x
-4∆ -3∆ -2∆ -∆
-0.5 ∆
CMPT365 Multimedia Systems 13
Uniform Quantization of a Uniformly Distributed
Source
M bi
MSE MSEq x ˆ
x 2
f ( x ) dx x y i 2
f ( x)dx
i 1 bi 1
2
1 M 1 3 1 2
M x dx
2 X max 0 2 2 X max 12
12
M increases, ∆ decreases, MSE decreases
1 / 122 X max
2
Signal Energy
SNR(dB) 10 log 10 10 log 10
Noise Energy 1 / 122
10 log 10
2 X max 2 10 log 10 M 2 10 log 10 2 2 n (20 log 10 2)n
2 X max / M 2
6.02n dB
If nn+1, ∆ is halved, noise variance reduces to 1/4,
and SNR increases by 6 dB.
Quantization
Uniform
Non-uniform
Transform coding
DCT
M bk
q2 x ˆ
x 2
f ( x ) dx x y k 2
f ( x)dx
k 1 bk 1
f(x)
0
CMPT365 Multimedia Systems 17
Lloyd-Max Quantizer
Also known as pdf-optimized quantizer
M bk
q2 x ˆ
x 2
f ( x ) dx x y k 2
f ( x)dx
k 1 bk 1
Given M, the optimal bi and yi that minimize MSE, satisfying
q2 q2
Lagrangian condition : 0, 0.
yi bi
bi
2 x f ( x)dx f(x)
0 yi
q bi 1
yi bi
f ( x)dx
bi 1
x
yi is the centroid of interval [bi-1, bi].
0 bi-1 bi
yi
CMPT365 Multimedia Systems 18
Lloyd-Max Quantizer
x f ( x)dx c x dx 1 2
(bi bi21 )
1
yi 2 (bi bi 1 )
bi 1 bi 1
bi
c(bi bi 1 ) bi bi 1 2
f ( x)dx
bi 1
f(x)
2
yi yi 1
0 bi
q
bi 2
bi is the midpoint of yi and yi+1
x
0 bi-1 bi bi+1
yi yi+1
CMPT365 Multimedia Systems 19
Lloyd-Max Quantizer
Summary of conditions for optimal quantizer:
bi
x f ( x)dx
yi
bi 1 yi yi 1
bi bi
f ( x)dx
bi 1
2
yi yi 1
2. Find all decision levels bi
2
M bk
Computer MSE:
3.
q2 x y k 2
f ( x)dx
k 1 bk 1
4. Stop if MSE changes little from last time.
x f ( x)dx
yi
bi 1
bi
bi 1
f ( x)dx
CMPT365 Multimedia Systems 21
Outline
Quantization
Uniform quantization
Non-uniform quantization
Transform coding
Discrete Cosine Transform (DCT)
Purpose of transform
Remove correlation between input samples
Transform most energy of an input block into a few
coefficients
Small coefficients can be discarded by quantization without too
much impact to reconstruction quality
Encoder
Entropy
Transform Quantization coding
www.sagebrush.com/mousing.htm
An electronic instrument that allows direct control of pitch and
amplitude
100
0
1 2 3 4 5 6 7 8 Sample Index
DFT Magnitudes
2000
1000
0
DC 1 2 3 4 5 6 7 8 High frequency
DCT Coefficients
500
-500
1 2 3 4 5 6 7 8
High frequency
DC
CMPT365 Multimedia Systems 27
2-D Example
Original Image Apply transform to each 8x8 block
Histograms of source and DCT coefficients
10000
8000
6000
4000
2000
0
0 50 100 150 200 250 300
0
-500 0 500 1000 1500 2000
y N 1 TN N x N 1 X T y
Inverse Transform:
1 y
xT y X T T
-1
x
y
1
T T T
X T T
T
x
0, i j
i j
Definition:
(2 j 1) i
Ci , j a cos , i, j 0, ..., N - 1.
2N
a 1 / N for i 0,
a 2 / N for i 1, ..., N - 1.
Matlab function:
dct(eye(N));
y0 x0 1 1 1 x0 1 x0 x1
y C2 x 1 1 x x x
1 1 2 1 2 1 1
y0 captures the mean of x0 and x1 (low-pass)
x0 = x1 = 1 y0 = sqrt(2) (DC), y1 = 0
y1 captures the difference of x0 and x1 (high-pass)
x0 = 1, x1 = -1 y0 = 0 (DC), y1 = sqrt(2).
DC Att. 403.0103, Mirr Att. 324.2604, Stopband 50, Coding Gain = 5.055 dB
5
Low pass 0
-5
High
Magnitude Response (dB)
-10
pass
1 1 1 -15
C2 1 1
2 -20
-25
-30
-35
-40
0 0.1 0.2 0.3 0.4 0.5
Normalized Frequency
DC x 2π
CMPT365 Multimedia Systems 33
4-point DCT
Four subbands
0.5000 0.5000 0.5000 0.5000
0.6533 0.2706 -0.2706 -0.6533
0.5000 -0.5000 -0.5000 0.5000
0.2706 -0.6533 0.6533 -0.2706
DC Att. 406.0206, Mirr Att. 324.2604, Stopband 8.3456, Coding Gain = 7.5701 dB
5
-5
-15
-20
-25
-30
-35
-40
0 0.1 0.2 0.3 0.4 0.5
Normalized Frequency
x 2π
CMPT365 Multimedia Systems 34
8-point DCT
Eight subbands
DC Att. 409.0309, Mirr Att. 320.1639, Stopband 9.9559, Coding Gain = 8.8259 dB
5
-5
-15
-20
-25
-30
-35
-40
0 0.1 0.2 0.3 0.4 0.5
Normalized Frequency
x 2π
CMPT365 Multimedia Systems 35
Example
x = [100 110 120 130 140 150 160 170]T;
8-point DCT:
[381.8377, -64.4232, 0.0, -6.7345, 0.0, -2.0090, 0.0, -0.5070]
Most energy are in the first 2 coefficients.
250
200
150
100
50
1 2 3 4 5 6 7 8
400
300
200
100
-100
1 2 3 4 5 6 7 8
X: N x N input block
T: N x N transform
A = TX: Apply T to each column of X
B=XTT: Apply T to each row of X
2-D Separable Transform:
Apply T to each row
Then apply T to each column
Y TXT T
Inverse Transform:
X TT YT
CMPT365 Multimedia Systems 39
2-D 8-point DCT Example
Original Data:
89 78 76 75 70 82 81 82
122 95 86 80 80 76 74 81
184 153 126 106 85 76 71 75
221 205 180 146 97 71 68 67
225 222 217 194 144 95 78 82
228 225 227 220 193 146 110 108
223 224 225 224 220 197 156 120
217 219 219 224 230 220 197 151
Inverse transform:
N 1
x TT y t T0 t1T t TN 1 y t Ti yi
i 0
t t ,
T
i j i, j 0, ..., N 1.
Outer products of basis vectors
Proof:
Define S i , j : The (i, j) - th entry is Y(i, j), all others are 0.
N 1 N 1 N 1 N 1
X TT YT TT Si , j T Y (i, j ) t Ti t j
i 0 j 0 i 0 j 0
Textbook 8.1-8.5
Other sources
Introduction to Data Compression by Khalid Sayood
Vector Quantization and Signal Compression by Allen Gersho
and Robert M. Gray
Digital Image Processing by Rafael C. Gonzales and Richard
E.Woods
Probability and Random Processes with Applications to Signal
Processing by Henry Stark and John W. Woods
A Wavelet Tour of Signal Processing by Stephane G. Mallat