No Slide Title

Download Report

Transcript No Slide Title

Quantization
Heejune AHN
Embedded Communications Laboratory
Seoul National Univ. of Technology
Fall 2013
Last updated 2013. 9. 24
Outline





Quantization Concept
Quantizer Design
Quantizer in Video Coding
Vector Quantizer
Rate-distortion optimization Concept


Lagrangian Method
Appendix

Detail for Lloyd-max Quantization Algorithm
Heejune AHN: Image and Video Compression
p. 2
1. Quantization

Reduce representation set



Nlarge points ([0 ~ Nlarge]) to Nsmall points ([0, … Nsmall])
Inevitable when Analog to Digital Conversion
Not Reversible !
ReScale
ADC/Quant
Original
Quanitzed
(digital/analog)
Levels
Heejune AHN: Image and Video Compression
p. 3
Scalar Quantizer
x

q
Quantize a single value (single input & single output)


Q
Mapping function


-1
In contrast to VQ (Vector Quantizer, to be discussed later)
{[xi-1, xi) => yi}
Decision levels to
reconstruction level
q
Quantizer
output
Q
xˆ
yi
xi-1
xi
Output : {yi}
Quantizer
input
Input : x
Heejune AHN: Image and Video Compression
p. 4
Quantizer’s Effects

+ Bit Rate Reduction

Bits required to represent the values: (E1bits=> E2 bits)
• Nlarge (= 2E1)points ([0 ~ N]) to Nsmall (= 2E2)points ([0, … Nsmall])
• Bit reduction = E2 - E1 = log2 (NLarge/Nsmall)

- Distortion


e = yi - x (in [xi-1, xi))
MSE (mean squared error)
1
MSE=
N1 N2

N1 1 N2 1
   x n , n   xˆ n , n 
n1 0 n2 0
1
2
1
2
2
Trade-off problem
Heejune AHN: Image and Video Compression
p. 5
2. Quantization Design

Distortion


Quantization error = difference original (x) and quantized (yi)
Distortion Measure
N
xi
i 1
xi 1
D  

Quantizer design parameters





( x  yi ) 2 f X ( x) dx
Step size (N)
decision level (xi)
reconstruction level (yi)
Distortion depends on Input signal distribution (f(x))
Optimization Problem

How to set the ranges and reconstruction values, i.e., {yi & [xi-1,
xi)} for i =0, … N, so that the resulting MSE is minimized.
Heejune AHN: Image and Video Compression
p. 6
Optimal Quantizer

Solutions

Note performance depends on the input statistics.

Simpler design
• Uniform (Fixed quant step) quantizer
• With/Without dead-zone near zero

Lloyd-Max algorithm
• a optimal quantizer design algorithm
• More levels for dense region, Less levels for sparse region.
(non-linear quantizer)
Heejune AHN: Image and Video Compression
p. 7
Uniform Quantizers

Properties



xi and yi are spaced evenly (so, uniform), with space Δ (step size)
Mid-tread (odd # of recon. levels) vs Mid-rise (no zero recon. )
mid-tread is more popular than mid-rise.
Uniform Midrise Quantizer
3.5∆
2.5∆
1.5∆
-3∆ -2∆ -∆
-0.5∆
Uniform Midtread Quantizer
Reconstruction
Reconstruction
3∆
0.5 ∆
∆ 2∆ 3∆ Input
-1.5∆
-2.5∆
-3.5∆
2∆
∆
-2.5∆ -1.5∆ -0.5∆
0.5∆ 1.5∆ 2.5∆ Input
-∆
-2∆
-3∆
What will be the mathematical representation for quant/inverse?
Heejune AHN: Image and Video Compression
p. 8
Heejune AHN: Image and Video Compression
p. 9
Uniform Quantizer Performance

For Uniform dist. Input, Uniform quantizer is optimal


Can you prove this?
Uniform Input X ~ U(-A,A)
f X (x)
1
A

2A
A
x
Error signal e = y – x ~ U(-Δ/2, Δ/2)
Heejune AHN: Image and Video Compression
p. 10

Signal Power (variance)
A2
 
3
2
x


MSE
2
1  2A 
1 A2
2 r
2
D


2



 
x ,
r 2
12 12  N 
3 (2 )
SNR
SNR(dB)  10 log
2
 x2
D
N  2r
 10 log (2 2 r )  6.02r (dB)
  6dB / bit

Note


If one bit added, Δ is halved, noise variance reduces to 1/4, SNR
increases by 6 dB.
SNR does not depends on input range, MSE does.
Heejune AHN: Image and Video Compression
p. 11
Non-uniform Quantizer

Issue


Many data are non-uniformly distributed and even unbounded
Concept



General Intuition: Dense Levels for Dense Input region
Boundness: Use saturation Post filter for unbounded input
Generally no closed-form expression for MSE.
• Range and Reconstruction Level is cross-related
Heejune AHN: Image and Video Compression
p. 12
Lloyd-Max Algorithm

Algorithm



Iteration algorithm with decision level (xi) and recon. level (yi)
Run until code book does not change any more
Step 1: find Near Region Ri((xi-1 , xi])
• Ri = {x | d(x,yi) <= d(x,yj), for all j =\= I }

Step 2: find level yi
• yi = E[X| x in Ri ]
Cm
range
최근린
분할
update
{Ri}m centroid
무게중심 계산
calculation
Heejune AHN: Image and Video Compression
Cm+1
p. 13

Lloyd-Max Algorithm

Minimize mean squared error.
L
  E[(x  y' ) ]   
2



0
t k yk
tk 
yk
k 1
t k 1
tk
( x  yk ) 2 f x ( x)dx
( yk  yk 1 )
2



t k 1
tk
t k 1
tk
xf x (u )dx
 E[ x | x  k ]  depending on the input pdf
f x ( x)dx
where Tk is the k th interval [tk,tk+1)
Heejune AHN: Image and Video Compression
p. 14
Example


Quantization and Quality (Lloyd-Max applied)
Original (8bpp) vs 6 bpp (spatial domain)
Heejune AHN: Image and Video Compression
p. 15

Original (8bpp) vs 4 bpp (spatial domain)
Heejune AHN: Image and Video Compression
p. 16

Original (8bpp) vs 2 bpp (spatial domain)
Heejune AHN: Image and Video Compression
p. 17
High Density Quantization

High Quality


Condition    x ,
Observation
• Slow change (Constant) over the quantization region
• Approximate with Uniform distribution
Pr [ R1 ]  Pr [ RN ]  0
conditional pdf of ( x  y ) in R  1  R
i
i
i

in the interval   ,  
 2 2 
f X (x)

Ri
x


 D  E[( X  Xˆ ) 2 ]  E E[( X  Xˆ ) 2 R ]   P ( Ri ) E[( X  yi ) 2 Ri ]
i
1 /2 2
2 2
  P ( Ri )   e de   P ( Ri ) 

  / 2
12 12
i
i
Heejune AHN: Image and Video Compression
p. 18
Quantization in Video Coding

UTQ (uniform Threshold Quantization) often is used



Difficult in adaptive design (a LM quantizer design)
Video quantizers are high quality ones
Quantization in VC


Input signal: quantize the (DCT) coefficients
Parameters
• q (Δ): quantization scale factor ( 2 ~ 62, usu. q = 2QUANT, 1 ~31 )
• Index (Level) : index for the reconstruction values
• Note: index, not reconstruction values are transmitted

E.g.
• Index: I (n,m) = floor(F(n,m)/q) = floor(F(n,m)/2QUANT)
– i.e. [i-1, i) *q => i
• Reconstruction: F’(n.m) = (I(n,m) + ½) x q = (2*I(n,m) +1)xQUANT
– i.e. i => (i +1/2) q (i.e, middle of range [i -1, i)*q)
• Note: with QUANT, no 1/2 in expression.
Heejune AHN: Image and Video Compression
p. 19
Uniform Threshold Quantizer



Threshold (dead zone) for reducing dct coeff.
Intra DC (zero threshold), Intra AC, inter DC, AC (non-zero)
2*Q(UANT) = q
AC (With Threshold)
DC (without Threshold, q = 8 )
3q
Quantizer
output
Quantizer
output
5Q
2q
3Q
q
-3q -2q
q
-q -q/2
-5Q
q/2 q
-q
2q
3q Quantizer
input
-3Q
-2Q
dead zone
-Q
2Q
-2q
-3Q
-3q
-5Q
Heejune AHN: Image and Video Compression
3Q
5Q
Quantizer
input
p. 20
3. Quantization in Video Coding


Applied on the Transform Coefficients
Key Throttle for Bit-Rate and Quality

Xorig
Very Important Trade-off in Video coding
Estimation
Transform
(MC, IntraP)
(e.g. DCT)
e = Xorig - Xest
Quantizati
on
Y = T(e)
Heejune AHN: Image and Video Compression
Entrophy
Coding
Yq = Q(Y)
VLC(Yq)
p. 21

Example #1
1480 26.0
9.5
8.9
-26.4 15.1
-8.1
0.3
185
3
1
1
-3
2
-1
0
11.0
8.3
-8.2
3.8
-8.4
-6.0
-2.8
10.6
1
1
-1
0
-1
0
0
1
-5.5
10.7
4.5
9.8
9.0
4.9
5.3
-8.3
-8.0
-2.1
4.0
-1.9
-5.1
2.8
4.9
-8.1
0
1
0
1
1
0
0
-1
-1
0
0
0
0
0
0
-1
1.6
1.4
8.2
4.3
3.4
4.1
-7.9
1.0
0
0
1
0
0
0
-1
0
-4.5
-5.0
-6.4
4.1
-4.4
1.8
-3.2
2.1
0
0
0
0
0
0
0
0
5.9
5.8
2.4
2.8
-2.0
5.9
3.2
1.1
0
0
0
0
0
0
0
0
-3.0
2.5
-1.0
0.7
4.1
-6.1
6.0
5.7
0
0
0
0
0
0
0
0
Transformed 8x8 block

Q(8)
Zig-zag scan
Example #2: Comparison with Coarse and Fine Quant

See Textbook Table 7.4
Heejune AHN: Image and Video Compression
p. 22
DCT Coef. Quantization

Human visual weight



coarse quant to High frequency components
NDZ-UTQ to Intra DC, DZ-UTQ to all others
Intra block Case
• I (n,m) = round(F(n,m)/(q*W(n,n))/8 )
• F’(n.m) = (I(n,m) + ½) x q x W(n,m)/8
8
16
19
22
26
27
29
34
16
16
16
16
16
16
16
16
16
16
22
24
27
29
34
37
16
16
16
16
16
16
16
16
19
22
26
27
29
34
34
38
16
16
16
16
16
16
16
16
22
22
26
27
29
34
37
40
16
16
16
16
16
16
16
16
22
26
27
29
32
35
40
48
16
16
16
16
16
16
16
16
26
27
29
32
35
40
48
58
16
16
16
16
16
16
16
16
26
27
29
34
38
46
56
69
16
16
16
16
16
16
16
16
27
29
35
38
46
56
69
83
16
16
16
16
16
16
16
16
intra
Heejune AHN: Image and Video Compression
inter
p. 23
Quantizer Example

MPEG-4 example

Inverse Quantization only Defined
if LEVEL = 0, REC = 0
Else If QUANT is ODD
|REC| = QUANT *(2 |LEVEL| +1)
Else
|REC| = QUANT *(2|LEVEL| +1) -1
• + 1 : Dead-zone
• (sorry, I cannot explain why odd/even)

31
27
23
19
15
7
3
Examples
• Q= 4
Len = 14 > 8
0
-7
-15
-11
-23
-31
Un-biased
Heejune AHN: Image and Video Compression
18
27
19
11
10
-19

26
11
Quantization is not defined
• Why?
34
-27
Len = 14 > 8
-10
-18
-26
-34
0
-11
-19
-27
biased
p. 24
4. Vector Quantizater

Vector Quantizer

Use statistical correlation of N dimension Input
Heejune AHN: Image and Video Compression
p. 25

Vector Quantizer Design


Generalized Loyd-Max Algorithm
Why Not Vector Quantization in Video Standards

Transform Coding utilizes the “Correlation”, the remaining signal does
not has Correlation much.
Heejune AHN: Image and Video Compression
p. 26
Heejune AHN: Image and Video Compression
p. 27

Performance of VQ
Heejune AHN: Image and Video Compression
p. 28
Embedded quantizers


Motivation: “scalability” – decoding of compressed
bitstreams at different rates (with different qualities)
Nested quantization intervals
Q0
x
Q1
Q2

In general, only one quantizer can be optimum
(exception: uniform quantizers)
Heejune AHN: Image and Video Compression
p. 29
Rate Distortion Theory

Rate vs Distortion


Inverse relation between Information/Data Rate and Distortion
Revisit to a uniform distributed r.v. with a uniform quantizer
2
1  2A 
1 A2
2 r
2
D


2



 
x ,
r 2
12 12  N 
3 (2 )
2
N  2r
Exponential decreasing
Proportional to Complexity of
source in statistics

Plot it !
Heejune AHN: Image and Video Compression
p. 30
Rate Distortion Theory

Rate-distortion Function and Theroy


Inverse relation between Information/Data Rate and Distortion
Example with Gaussian R.V.


(I)
R ( D)  


R
(I)
1
2
2
log
, 0 D
2
D
D2
0,
(D)
D
(I )

3.0
(R)
2
2.0
1.0
0.1
0.2 0.4
1
D /
Heejune AHN: Image and Video Compression
2
0.1
0.5 1.0
R
p. 31
Rate-Distortion Optimization

Motivation

Image coding
• Condition: we can use 10KBytes for a
whole picture
• Each part has different complexity (i.e,
simpler and complex, variance)
• Which parts I have to assign more bits?

simpler blocks
Analogy to school score
• Students are evaluated sum of Math and
English grade.
• I gets 90pts in Math, 50pts in Eng.
• Which subject I have to study?
• (natural assumption: 90 to 100 is much
harder than 50 to 60)
Heejune AHN: Image and Video Compression
More complex blocks
p. 32
Lagrange multiplier

Constrained Optimization Problem

Minimize distortion with bits no larger than max bits
min{D( R)}subject toR  R max


Cannot use partial differential for minima and maxima
Lagrange Multiplier technique


Insert one more imaginary variable (called Lagrange)
We have multivariable minimization problem
min{J  D( R)  R}
Heejune AHN: Image and Video Compression
p. 33
Side note: why not partial differential

Simple example


min f ( x, y)  x 2  y 2
1
subject to
 ( x, y)  x  y  1
Solution
• By substitution
• minimum ½ at x = y = 1/sqrt(2)

x2  y 2
1
Wrong Solution


With complex constraints, we cannot use substitution of variable
method
We cannot change partial different with ordinary difference
• If we check,
( x2  y2 )
x
 2x  0
( x2  y2 )
y
 2y  0
• x=y=0 ?
Heejune AHN: Image and Video Compression
p. 34
An Example: Lagrange Multiplier

Optimization Problem

multiple independent Gaussian variables
M
D( B)   Di (bi ), Di (bi )  hi i2 2  2bi  h i2 2 2bi ,
h 1
i 1
M
( bi )  B
i 1

Lagrange multiplier optimization
M
J   D(bi )   ( bi  B)
i
i 1
J
 0  λ  2 (ln 2) h i2 22bi
bi
i
  i2 22bi   [(2 ln 2)  h]1  C for i
Heejune AHN: Image and Video Compression
p. 35

Solution

Multiplying M equations, and take M-square

2
  i 
 i

1
M
 i bi 
 2





 2     i2 
 i


2
1
M
M
, b
Lagrange value
  2h ln 2    2
2

1
 2b

 2 2

bi 

2 
 M 
  2  2  2b  C
b
i
M

2
 2h ln 2     i 
 i

1
M
 2  2b
Bit-allocation
  i2 
1
bi0  b  log2  2 
2
 
• Large variance, then more bit allocation
• But the increment is logarithmic (not linear)
Heejune AHN: Image and Video Compression
p. 36
Appendix
Lloyd-Max Algorithm Details
Lloyd-Max scalar quantizer

Problem : For a signal x with given PDF f X ( x) find a quantizer with
M representative levels such that


2

d  MSE  E X  Xˆ   min .



Solution : Lloyd-Max quantizer
[Lloyd,1957] [Max,1960]

M-1 decision thresholds exactly
half-way between representative
levels.


M representative levels in the
1
tq   xˆq 1  xˆq  q  1, 2,, M -1
2
centroid of the PDF between two xˆq 
successive decision thresholds.
Necessary (but not sufficient)
conditions
Heejune AHN: Image and Video Compression
tq1
 x f
X
( x)dx
tq
tq1

q  0,1,, M -1
f X ( x)dx
tq
p. 38
Iterative Lloyd-Max quantizer design
1.
2.
Guess initial set of representative levels xˆq q  0,1, 2,, M -1
Calculate decision thresholds
1
tq   xˆq 1  xˆq  q  1, 2,, M -1
2
3.
Calculate new representative levels
tq 1
 x f
xˆq 
X
( x)dx
q  0,1, , M -1
tq
tq 1

f X ( x)dx
tq
4.
Repeat 2. and 3. until no further distortion reduction
Heejune AHN: Image and Video Compression
p. 39
Example of use of the Lloyd algorithm (I)



X zero-mean, unit-variance Gaussian r.v.
Design scalar quantizer with 4 quantization indices with
minimum expected distortion D*
Optimum quantizer, obtained with the Lloyd algorithm



Decision thresholds -0.98, 0, 0.98
Representative levels –1.51, -0.45, 0.45, 1.51
D*=0.12=9.30 dB
Boundary
Reconstruction
Heejune AHN: Image and Video Compression
p. 40
Example of use of the Lloyd algorithm (II)
Convergence
Initial quantizer A:
decision thresholds –3, 0 3
Quantization Function


Initial quantizer B:
decision thresholds –½, 0, ½
Quantization Function

6
4
2
0
-2
-4
-6
5
10
15
6
4
2
0
-2
-4
-6
0.2
0.2
0.15
SNROUT [dB]
D
0.4
0
0
5
10
10
SNROUT final = 9.2978
0
5
10
15
Iteration Number

0.1
15
5
0
5
10
15
Iteration Number
SNROUT [dB]
D
Iteration Number
0
10
5
SNROUT10final = 9.298
15
8
6
0
5
10
15
Iteration Number
After 6 iterations, in both cases, (D-D*)/D*<1%
Heejune AHN: Image and Video Compression
p. 41
Example of use of the Lloyd algorithm (III)



X zero-mean, unit-variance Laplacian r.v.
Design scalar quantizer with 4 quantization indices with
minimum expected distortion D*
Optimum quantizer, obtained with the Lloyd algorithm



Decision thresholds -1.13, 0, 1.13
Representative levels -1.83, -0.42, 0.42, 1.83
D*=0.18=7.54 dB
Threshold
Representative
Heejune AHN: Image and Video Compression
p. 42
Example of use of the Lloyd algorithm (IV)
Convergence
Initial quantizer A,
decision thresholds –3, 0 3
10
5
0
-5
-10
Initial quantizer B,
decision thresholds –½, 0, ½
Quantization Function

2
4
6
8
10
Iteration Number
12
14
10
5
0
-5
-10
0.2
D
0.2
5
6
4
10
15
SNRfinal = 7.5415
0

5
10
Iteration Number
4
6
8
10
12
14
16
Iteration Number
0.4
0
0
8
2
16
0.4
SNR [dB]
D
Quantization Function

15
SNR [dB]

0
0
8
5
6
4
10
15
SNRfinal = 7.5415
0
5
Iteration Number10
15
After 6 iterations, in both cases, (D-D*)/D*<1%
Heejune AHN: Image and Video Compression
p. 43
Lloyd algorithm with training data
xˆq ; q  0,1,2,, M -1
1.
Guess initial set of representative levels
2.
Assign each sample xi in training set T to closest representative
Bq  x T : Q  x   q
3.
q  0,1,2,, M -1
Calculate new representative levels
xˆq 
4.
xˆq
1
Bq
x
q  0,1,, M -1
xBq
Repeat 2. and 3. until no further distortion reduction
Heejune AHN: Image and Video Compression
p. 44
Lloyd-Max quantizer properties

Zero-mean quantization error
E  X  Xˆ   0

Quantization error and reconstruction decorrelated


E  X  Xˆ Xˆ   0



Variance subtraction property

    E  X  Xˆ

2
Xˆ
2
X
Heejune AHN: Image and Video Compression

2


p. 45