<<

Image Quantization Lloyd-Max Quantizer Image Transforms

Digital Image Processing Lectures 7 & 8

M.R. Azimi, Professor

Department of Electrical and Engineering Colorado State University

February 2011

M.R. Azimi Processing Image Quantization Lloyd-Max Quantizer Image Transforms Quantization Process

A quantizer maps the continuous variable x into a discrete xq which takes values from a finite set {r1, . . . , rL} of numbers. This mapping is generally a staircase function as shown below.

Quantization Rule:

Define {tk, k = 1,...,L + 1} as a set of transition or decision levels with t1 and tL+1 as the Min. and Max. values of x, respectively. If x lies in the interval [tk, tk+1), then xq = rk, where rk is called the kth reconstruction level.

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

Properties: Quantization mapping is irreversible, i.e. for a given quantizer output, the input value cannot be determined uniquely. Quantization incurs . The design is a trade-off between simplicity and performance (minimum distortion). Quantization is a ”zero-memory” operation, i.e. output depends on only one input. Uniform Quantizer: Simplest and most commonly used (e.g., PCM, differential PCM and transform coding) quantizer. Let the output of an takes values between 0 to A. If samples are quantized uniformly to L (e.g. L = 256) levels, then transition and reconstruction levels are

A(k−1) tk = L k = 1,...,L + 1 A/2 rk = tk + L k = 1,...,L

∆ The interval q == tk − tk−1 = rk − rk−1 is constant for different values of k and is called ”quantization interval”.

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms Minimum Mean Squared or Lloyd-Max Quantizer

This quantizer minimizes the mean squared error for a given number of quantization levels. Let x, with 0 ≤ x ≤ A be a real scalar random variable with a continuous PDF pX (x). It is desired to find optimum the decision levels tk and the reconstruction levels rk for an L-level quantizer such that the mean square error (MSE) (or quantization distortion)

Z tL+1 2 2  = E[(x − xq) ] = (x − xq) pX (x)dx t1

is minimized. Note that pX (x) is the PDF of the amplitude of x i.e. R A 0 pX (x)dx = 1. The MSE can be rewritten as

L Z ti+1 X 2  = (x − ri) pX (x)dx i=1 ti

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

To minimize  w.r.t. tk and rk

∂ 2 2 = 0 ⇒ (tk − rk−1) pX (tk) − (tk − rk) pX (tk) = 0 ∂tk ∂ Z tk+1 = 0 ⇒ 2 (x − rk)pX (x)dx = 0, k ∈ [1,L] ∂rk tk where the first derivative is obtained using the fact that tk ≤ x < tk+1 ⇒ xq = rk, simplification of the above equations gives r + r t = k k−1 (1) k 2 R tk+1 xpX (x)dx tk rk = (2) R tk+1 pX (x)dx tk i.e. the optimum transition levels lie halfway between the optimum reconstruction levels, which in turn lie at the center of mass of the PDF in between the optimum transition levels.

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

These non-linear equations must be solved simultaneously given the bounding values t1 and tL+1. In practice, these equations can be solved by an iterative scheme such as the Newton method. When the No. of quantization levels is large, an approximate solution can be obtained by modeling the PDF pX (x) as a piecewise constant function i.e., t + t p (x) ' p (tˆ ), tˆ =∆ j j+1 , t ≤ x ≤ t X X j j 2 j j+1

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

Using this approximation and performing the required minimization, the equation for optimum transition level becomes

(t − t ) R ak [p (x)]−1/3dx L+1 1 t1 X tk+1 ≈ + t1 R tL+1 [p (x)]−1/3dx t1 X with k(t − t ) a = L+1 1 + t , k ∈ [0,L] k L 1 Thus, this together with optimum reconstruction level in (2) i.e. tk+tk+1 rk = 2 are now de-coupled. The quantizer MS distortion is

t 1 Z L+1 1 3 3  ≈ 2 { [pX (x)] dx} 12L t1

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

Properties of Lloyd-Max Quantizers

1 Unbiased in the mean i.e. E[X] = E[Xq].

Proof: Since Xq is a discrete r.v. we have L X E[Xq] = rkpXq (xq = rk) k=1

Using the staircase mapping of quantizer, the PMF at rk is

Z tk+1

pXq (xq = rk) = pX (x)dx tk Thus, using Eq. (2) of Llyod-Max quantizer we get

L L X Z tk+1 X Z tk+1 E[Xq] = rk pX (x)dx = xpX (x)dx k=1 tk k=1 tk which can be reduced to Z tL+1 E[Xq] = xpX (x)dx = E[X] t1

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

2 Orthogonality of error with output i.e. E[(X − Xq)Xq] = 0. 2 Proof: To prove we show E[XXq] = E[Xq ]. Using the correlation definition L X Z tk+1 E[XXq] = xxqpX,Xq (x, xq = rk)dx k=1 tk

When x ∈ Ωk i.e. segment k, joint PDF pX,Xq (x, xq = rk) can be

expressed as pXq (xq = rk|x ∈ Ωk)pX (x ∈ Ωk) = pX (x ∈ Ωk). Thus, L X Z tk+1 E[XXq] = rk xpX (x)dx k=1 tk Using Eq. (2) of Llyod-Max quantizer and result in property 1, L L Z tk+1 X X 2 2 E[XXq] = rk xpX (x)dx = rkpXq (xq = rk) = E[Xq ] k=1 tk k=1 Byproduct: Eq. (2) can be expressed as conditional mean estimator

Z tk+1

rk = xpXq (xq|x ∈ Ωk)dx = E[Xq|X ∈ Ωk] tk M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

Remarks

1 Two commonly used PDF’s for quantization of image related data are: 1 (x − µ)2 pX (x) = exp(− ) Gaussian p 2 2 2πσx 2σx α p (x) = exp(−α|x − µ|) Laplacian X 2 2 µ is the mean, σx is the variance (variance of the Laplacian PDF is 2 2 σx = α ). 2 For uniform distribution, the Lloyd-Max quantizer become a linear quantizer. Let  1 t1 ≤ x ≤ tL+1 p (x) = tL+1−t1 X 0 otherwise

2 2 (tk+1−tk) tk+1+tk Then from (2) we get rk = = . Now combining 2(tk+1−tk) 2 tk+1+tk−1 this result with (1) yields tk = 2 . Thus, ∆ tk − tk−1 = tk+1 − tk = constant = q.

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

Also t − t q = L+1 1 , t = t + q, r = t + q/2 L k k−1 k k and we have rk − rk−1 = tk − tk−1 = q. i.e. all transition and reconstruction levels are equally spaced. The ∆ quantization error e = x − xq is uniformly distributed over the interval (−q/2, q/2); hence MSE is

1 Z q/2 q2  = α2dα = q −q/2 12

2 The variance σx of a uniform random variable (original image) whose range is A is A2/12. For a uniform quantizer having B bits L = 2B, we have q = A/2B. This gives

σ2 x = 22B ⇒ SNR = 10log 22B = 6B dB  dB 10 i.e. in this special case the SNR achieved is 6dB/bit.

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms Image Transforms

2-D unitary transforms have found numerous applications in DIP. The followings are some examples.

1 Data compression using transform coding: reduce the bandwidth by discarding or grossly quantizing low magnitude transform coefficients.

2 : extract salient features of a pattern e.g. in FT high frequency components correspond to the edge information in the image.

3 to principal components: reduce the dimensionality of the image space by discarding the small components.

4 Image filtering: Wiener filter and standard 2-D filters.

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms Discrete Space Fourier Transform

The discovery of FFT for computing the FT of sampled made it possible for the of signals to be performed efficiently using digital . The computational saving made possible by FFT are even more important in the 2-D case when a large amount of data is involved. In what follows we start with 2-D DSFT and then show the relation between 2-D DSFT and 2-D DFT. Spatial Sampling of Band-limited Images and DSFT We saw that the 2-D FT of a continuous space image x(u, v) is ZZ ∞ −jω1u −jω2v X(ω1, ω2) = x(u, v)e e dudv −∞ and the inverse FT is 1 ZZ ∞ j(ω1u+ω2v) x(u, v) = 2 X(ω1, ω2)e dω1dω2 4π −∞

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

For the sampled image i.e. x(m∆u, n∆v) or simply x(m, n) the FT becomes ∞ ∞ X X −jω1m∆u −jω2n∆v X(ω1, ω2) = x(m, n)e e m=−∞ n=−∞ ∆u, ∆v are sampling intervals. Alternatively, ∞ X X −j(Ω1m+Ω2n) X(Ω1, Ω2) = x(m, n)e m,n=−∞ ∆ ∆ or 2DDSFT {x(m, n)} where Ω1 = ω1∆u,Ω2 = ω2∆v, are discrete frequency variables. Note that since ejΩn = ej(Ω+2kπ)n, we have X(Ω1, Ω2) = X(Ω1 + 2kπ, Ω2 + 2lπ), i.e. the 2-D DSFT is doubly periodic with periods 2π owing to spatial sampling at spacing ∆u and ∆v. The inverse DSFT considering this periodic behavior becomes 1 ZZ π j(Ω1m+Ω2n) x(m, n) = 2 X(Ω1, Ω2)e dΩ1dΩ2 4π −π

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

Example 1 Determine the frequency response of a 2-D system for which the impulse response is  1 |m| < M, |n| < N h(m, n) = 0 otherwise

∞ X X −j(Ω1m+Ω2n) H(Ω1, Ω2) = h(m, n)e m,n=−∞ M−1 N−1 X X = e−jΩ1me−jΩ2n m=−M+1 n=−N+1 e−jΩ1(−M+1) − e−jΩ1M = ( ) 1 − e−jΩ1 e−jΩ2(−N+1) − e−jΩ2N ×( ) 1 − e−jΩ2

M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

Then jΩ (M− 1 ) −jΩ (M− 1 ) e 1 2 − e 1 2 = ( ) ejΩ1/2 − e−jΩ1/2 jΩ (N− 1 ) −jΩ (N− 1 ) e 2 2 − e 2 2 ×( ) ejΩ2/2 − e−jΩ2/2 sin(Ω (M − 1/2)) sin(Ω (N − 1/2)) = 1 × 2 sin(Ω1/2) sin(Ω2/2) Note that this is the aliased version of the 2-D sinc function due to the sampling in the spatial domain (see Fig. M = 32 and N = 16).

Aliased 2−D Sinc

1500 )

2 1000 Ω , 1

Ω 500 H( 0

2

0 2 0 −2 Ω −2 2 Ω 1 M.R. Azimi Digital Image Processing Image Quantization Lloyd-Max Quantizer Image Transforms

Example 2 Determine the 2D DSFT of the image x(m, n) = amu(m)v(n) where u(m) is a 1D unit step function and

 1 0 ≤ n ≤ N − 1 v(n) = 0 elsewhere

∞ X X −j(Ω1m+Ω2n) X(Ω1, Ω2) = x(m, n)e m,n=−∞ ∞ ∞ X X = amu(m)e−jΩ1m e−jΩ2nv(n) m=−∞ n=−∞ ∞ N−1 X X = ame−jΩ1m e−jΩ2n m=0 n=0

1 N−1 sin(NΩ2/2) −jΩ2( 2 ) = ( −jΩ ) × e 1 − ae 1 sin(Ω2/2)

M.R. Azimi Digital Image Processing