DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9...

24
DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov

Transcript of DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9...

Page 1: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND

Image Compression

Lecture 9

Optimal Scalar QuantizationAlexander Kolesnikov

Page 2: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Quantization error for discrete data X

C2C1CM

...

M

j Cxjii

ji

yxp1

22 )(

Quantization error for the data X with M

cells:

Cell’s centroids:

ji

ji

Cxi

Cxii

j p

xp

y

Page 3: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Optimal scalar quantization: History

1

• J.D.Bruce [1963]: O(MN2) DP

• X. Wu [1991]: O(MN2) O(MN) DP+Monge

• X,Y,Z [2001]: O(NM) O(NM-1) Exhaustive search

in paper ”A fast algorithm for multilevel thresholding”

• Some researchers still believe that complexity of the optimal algorithm is exponential,

• … and some researchers are still re-inventing the optimal DP algorithm of O(MN2) complexity.

Page 4: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Problem formulation

• Let X={x1, x2, …, xN} be a finite ordered set of real numbers (intensity values).

• Let P={p1, p2, …, pN} be the correspondent set of a probabilities for the values X (histogram).

• Let {r0,r1,r2, …,rM+1} be an ordered set of integers

such that defines a partition of the set X into M

parts:

r0= 0 < r1 < ... < rj < rj+1 <... < rM = N.

x1 x2xN

p1

p2

Page 5: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Sequence partition problem

jj rkr

jkkjj yxprre1

21

2 )(],(

],( 11

22jj

M

j

rre

• Quantization error for one (part) cell:

jj

jj

rkrk

rkrkk

j p

xp

y

1

1

• Cell’s centroid yj:

• Partition indices: r0= 0 < r1 <... < rj < ... < rM =N.

We introduced r0= 0 for x0= .

• The total quantization error:

Page 6: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Scheme of partition into cells

104

22

2221

2 )()(],(21 k

kirkr

kk yxpyxprre

• Quantization error for the cell #2 (j=2):

• Data: x 0= < x1 <... < xj < ... < xN

• Partition indices: r0= 0 < r1 <... < rj < ... < rM =N.

• Cells:

• • • • •• • • •• •• • • •• ... ]( ]( ](#1 #2 #3

(x0=) x1 x2 x3 x4 x5 x6 x7x8 x9 x10 x11 x12 x13 x14 xN

(r0=0) r1=4 r2=10 rM =N=15

• N=15, the number of cells M=3

Page 7: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Optimization task

],( 1

1

2

}{

2 min jj

M

jr

rrej

• For a given data X, probabilities P and number of cells M find such a partition {ro,r1, r2, …, rM} that the total

quantization error is minimal:

jj rkr

jkkjj yxprre1

21

2 )(],(

jj

jj

rkrk

rkrkk

j p

xp

y

1

1

where

and

Page 8: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Cost function DM(0,N]

1

Let us introduce cost function Dm(0,n] that is minimum

quantization error for quantization of data sub-set

Xn={x1, x2, …, xn} with m cells:

Then DM(0,N] gives us solution of the problem in

question.

.where,],(],0( 11

2

}{min nrrrenD jjj

m

jrm

j

Page 9: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Dynamic programming approach

• In other words:

• Let’s rewrite the cost function:

.],(],(minmin

],(min],0(

12

1

1

1

2

,...,,

11

2

,...,,

2211

121

nrerre

rrenD

mjj

m

jrrrr

jj

m

jrrr

m

mm

m

],(],0(min],0( 12

111 1

nrerDnD mmmnrm

mm

],(],0(min],0( 12

111 1

nrerDnD mmmnrm

mm

Page 10: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Reccurent equations

1

],(],0(min],0( 21

1njejDnD m

njmm

],(],0(min],0( 21

1njejDnD m

njmm

Initialization:

],0(],0( 21 nenD ],0(],0( 2

1 nenD

Recursion:

Page 11: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Calculation of quantization error for a cell

1

jj rkr

jkkjj yxprre1

21

2 )(],(

jj rkr

jkkjj yxprre1

21

2 )(],(

jj

jj

rkrk

rkrkk

j p

xp

y

1

1

jj

jj

rkrk

rkrkk

j p

xp

y

1

1

• Complexity of the quantization error calculation is O(N)

Can we calculate it faster?

Page 12: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Calculation of quantization error for a cell

1

jj jjjj

jjjjjj

jj

jj

rkr rkrk

rkrkkkk

rkrkj

rkrkkj

rkrkk

rkrjijkkkk

rkrjkkjj

pxpxp

pyxpyxp

ypyxpxp

yxprre

1 11

111

1

1

2

2

22

22

21

2

2

)2(

)(],(

jj jjjj

jjjjjj

jj

jj

rkr rkrk

rkrkkkk

rkrkj

rkrkkj

rkrkk

rkrjijkkkk

rkrjkkjj

pxpxp

pyxpyxp

ypyxpxp

yxprre

1 11

111

1

1

2

2

22

22

21

2

2

)2(

)(],(

jj

jj

rkrk

rkrkk

j p

xp

y

1

1

jj

jj

rkrk

rkrkk

j p

xp

y

1

1

Page 13: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Calculation of quantization error for a cell

)]()(/[)]()([)]()([ 1002

111122 jjjjjj rSrSrSrSrSrS

where cumulants S0(n), S1(n), S2(n) are defined as follows:

.2,1,0;)(1

in

i

ikki xpnS

• Complexity of quantization error calculation for one cell is O(1).

j jj j j j r k rr k r

kr k r

k k k k j jp x p x p r r e11 1

2

21

2] , (

Page 14: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

DP search in the state space

M

N10

b

n

m

j

State space

C(n,m)

C(j,m-1)

C(N,M)

Start state

e2(j,n)

C(n,m) = min {C(m, m-1) + e2(m, n], C(m+1,m-1) + e2(m+1,n], . . . C(j,m-1) + e2(j, n]*),

. . . C(n-1, m-1) + e2(n, n]}

m-1 *

A(n,m)=jopt

Page 15: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Scheme of the DP algorithm// InitializationFOR n = 1 TO N DO C(n,1)=

e2(j,n]// Minimum searchFOR m = 2 TO M DO FOR n = m TO N DO

dmin FOR j= m-1 TO n-1 DO c C(j, m1) + e2(j,n] IF(c < cmin) cmin c; jmin j ENDIF ENDFOR C(n, m) dmin

A(n, m) jmin

ENDFORENDFOR

Complexity: O(MN2)Complexity: O(MN2)

C(n,m)=Dm(0,n]

Page 16: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Backtrack in the state space

M

N10

b

n

m

j

State space

A(N,M)

Start state

m-1

S(M+1)= NFOR m = M+1 TO 2 DO S(m1) = A(S(m), m))E2 C(N,M)

S(M+1)= NFOR m = M+1 TO 2 DO S(m1) = A(S(m), m))E2 C(N,M)

N=22, M=8: S={22,18,14,12,9,6,4,3,1}

(x0,x3], (x3,x4], (x4,x6], (x6,x9], (x9,x12],

(x12,x14], (x14,x18], (x18,x22]

Page 17: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Optimal scalar quantization

• DP algorithm a) Time complexity: O(MN2)b) Space complexity: O(MN)

• Error balance property: e2(rj-1,rj]Const

• Optimal scalar quantizer as weighted k-link

shortest

path in directed acyclic graph (DAG)

• Wu [1991] reduced time complexity of optimal DP algorithm to O(MN) using Monge property of quantization error with L2 metrics.

• Space complexity: O(N2).

Page 18: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Can we do it faster?

• Wu [1991] reduced time complexity of optimal DP algorithm to O(MN) using Monge property (monotonicity property) of quantization error with L2

metrics.

• Space complexity: O(N2).

Page 19: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Example 1: M=3

Input imageInput image

UniformUniform

OptimalOptimal

Page 20: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Example 1: M=3

UniformUniform OptimalOptimal

Page 21: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Example 2: M=5

OptimalOptimal

UniformUniform

Page 22: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Example: M=5

UniformUniform OptimalOptimal

Page 23: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Example: M=12

Centroid dencity is higher when probability dencity is also higher...

Centroid dencity is higher when probability dencity is also higher...

Page 24: DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.

Summary

1) Optimal scalar quantization