18
2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing Lectures 11 & 12 M.R. Azimi, Professor Department of Electrical and Computer Engineering Colorado State University M.R. Azimi Digital Image Processing

Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

  • Upload
    trananh

  • View
    231

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

Digital Image ProcessingLectures 11 & 12

M.R. Azimi, Professor

Department of Electrical and Computer EngineeringColorado State University

M.R. Azimi Digital Image Processing

Page 2: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

Algorithm For Computing Linear Convolution using 2DDFT-Cont

Example 1 (circular convolution):

Consider 2-D arrays x(m,n) =1 02 1

,h(m,n) =1 01 1

. Find y(m,n)

and y(m,n).The 2× 2 DFT of these sequences give

X(k, l) =

1∑m=0

1∑n=0

x(m,n)e−j2πmk

2 e−j2πnl

2

X(0, 0) = x(0, 0) + x(0, 1) + x(1, 0) + x(1, 1) = 4

X(0, 1) = x(0, 0) + x(0, 1)e−jπ + x(1, 0) + x(1, 1)e−jπ

= x(0, 0)− x(0, 1) + x(1, 0)− x(1, 1)= 1− 0 + 2− 1 = 2

X(1, 0) = x(0, 0) + x(0, 1) + x(1, 0)e−jπ + x(1, 1)e−jπ

= x(0, 0) + x(0, 1)− x(1, 0)− x(1, 1) = −2

M.R. Azimi Digital Image Processing

Page 3: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

X(1, 1) = x(0, 0) + x(0, 1)e−jπ + x(1, 0)e−jπ + x(1, 1)e−j2π

= 0

Thus X(k, l) =4 2−2 0

, H(k, l) =3 1−1 1

. and

Y (k, l) = X(k, l)H(k, l) =12 22 0

. Taking IDFT we get

y(m,n) =4 33 2

. This result can alternatively be obtained using

the circular convolution in the spatial domain i.e.

y(m,n) =1∑p=0

1∑q=0

x(p, q)h(((m− p))2, ((n− q))2)

y(0, 0) = x(0, 0)h(0, 0) + x(0, 1)h(0, 1) + x(1, 0)h(1, 0)

+x(1, 1)h(1, 1) = 4

M.R. Azimi Digital Image Processing

Page 4: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

y(0, 1) = x(0, 0)h(0, 1) + x(0, 1)h(0, 0) + x(1, 0)h(1, 1)

+x(1, 1)h(1, 0) = 3

y(1, 0) = x(0, 0)h(1, 0) + x(0, 1)h(1, 1) + x(1, 0)h(0, 0)

+x(1, 1)h(0, 1) = 3

y(1, 1) = x(0, 0)h(1, 1) + x(0, 1)h(1, 0) + x(1, 0)h(0, 1)

+x(1, 1)h(0, 0) = 2

Now, let us find the result of the desired linear convolution firstusing the direct method and then using the DFT.

y(0, 0) = x(0, 0)h(0, 0) = 1

y(0, 1) = x(0, 0)h(0, 1) + x(0, 1)h(0, 0) = 0...

y(2, 1) = x(1, 1)h(1, 0) + x(1, 0)h(1, 1) = 3

y(2, 2) = x(1, 1)h(1, 1) = 1

M.R. Azimi Digital Image Processing

Page 5: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

y(m,n) =1 0 03 2 02 3 1

Note: y(m,n) is the aliased version of this array. Extend arrays tosize P = 4 ≥M1 +M2 − 1, Q = 4 ≥ N1 +N2 − 1 i.e.

x′(m,n) =

1 0 0 02 1 0 00 0 0 00 0 0 0

, h′(m,n) =

1 0 0 01 1 0 00 0 0 00 0 0 0

Taking 4× 4 DFT and IDFT of the product gives

y′(m,n) =

1 0 0 03 2 0 02 3 1 00 0 0 0

which is y(m,n) if the last row and column are removed.M.R. Azimi Digital Image Processing

Page 6: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

Matrix Representation of DFT

Consider an N-point finite-extent sequence x(n), n ∈ [0, N − 1] with DFT

X(k) =1√N

N−1∑n=0

x(n)WnkN k ∈ [0, N − 1]

where WN∆= e−2πj/N , then in matrix form

X(0)

...X(N − 1)

N×1

= 1√N

1 1 · · · 1

1 WN · · · WN−1N

......

...

1 WN−1N · · · WN

N×N

x(0)

...x(N − 1)

N×1

X = WNx

WN : DFT matrix with elements wkn = 1√NW knmodNN

The inverse is x = W−1N X.

M.R. Azimi Digital Image Processing

Page 7: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

Properties and Remarksa. Symmetry and UnitaryFor a 1-D DFT matrix

WtN = WN i.e. symmetry, W−1

N = W∗N i.e. unitary

Thus W∗NWN = I.

b. Energy ConservationFor a unitary transform the energy is preserved in both domains i.e.

‖X‖2 = ‖x‖2

To see this

‖X‖2 ∆=

N−1∑k=0

|X(k)|2 = X∗t

X = x∗t

W∗tNWNx

= x∗t

x = ‖x‖2

M.R. Azimi Digital Image Processing

Page 8: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

c. 2-D DFT in Matrix FormFor a 2-D finite-extent image, x(m,n) with ROS,RMN , the 2-DDFT is

X(k, l) =1√MN

M−1∑m=0

N−1∑n=0

x(m,n)WmkM Wnl

N k ∈ [0,M−1], l ∈ [0, N−1]

If x and X represent the original image matrix and its DFT image(complex) matrix (both of size M ×N), respectively, the separable2-D transform in matrix form can be written as

X = WMxWN

andx = W∗

MXW∗N

which shows the separability of the 2-D DFT. This is a unifiedmatrix representation since for other image transforms such assine, cosine, Hadamand, Haar and Slant transforms similarrepresentation hold.

M.R. Azimi Digital Image Processing

Page 9: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

Basis Images of 2-D DFTLet w∗k be the kth column of W∗

M and wHl be the lth row of W∗N ,

then the (k, l)th basis image is

W∗(k, l) = w∗kwHl

Using x = W∗MXW∗

N the image can be represented as

x =

M−1∑k=0

N−1∑l=0

X(k, l)W∗(k, l)

i.e. the image is decomposed onto a space spanned by these MNbasis images.The coefficients in this representation are given by

X(k, l) =< x,W∗(k, l) >

where inner product of two matrices is given by

< A,B >=

M−1∑m=0

N−1∑n=0

a(m,n)b∗(m,n)

.M.R. Azimi Digital Image Processing

Page 10: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

Discrete Cosine Transform (DCT)

Recall that the DFS of any real even symmetric signal contains only realcoefficients corresponding to the cosine terms. This can be extended tothe DFT of a symmetrically extended signal/image. There are many waysto symmetrically extend a signal or an image leading to variety of DCTtypes. Here, we present DCT-II which is the most common one (see Fig.).

The 1-D DCT-II of a finite-extent signal x(n) of size N is

X(k) =

1√N

N−1∑n=0

x(n) k = 0√2N

N−1∑n=0

x(n) cos[ (2n+1)kπ2N ] k ∈ [1, N − 1]

M.R. Azimi Digital Image Processing

Page 11: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

The inverse transform is

x(n) =1√NX(0)+

√2

N

N−1∑k=1

X(k)cos[(2n+ 1)kπ

2N] n ∈ [0, N−1]

In matrix form we get

X = Cx, C = [c(k, n)]

with forward kernel

c(k, n) =

{1/√N k = 0, n ∈ [0, N − 1]√

2N cos[ (2n+1)kπ

2N ] k ∈ [1, N − 1], n ∈ [0, N − 1]

where x is the signal vector X is the DCT vector.The inverse transform in matrix form is

x = C−1X = CtX

Remarks

1 DCT is real and orthogonal i.e.

C = C∗, C−1 = Ct

M.R. Azimi Digital Image Processing

Page 12: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

2 2-DCT can be performed using 1-D DCT’s along columns androw, i.e. separable.

3 DCT is NOT the real part of the DFT rather it is related tothe DFT of a symmetrically extended signal/image.

4 The energy of signal/image is packed mostly in only a fewDCT coefficients (i.e. only a few significant X(k)’s), hencemaking DCT very useful for data compression applications.

2-D DCT of ImagesThe 2-D DCT of a finite-extent image x(m,n) of size N ×N is

X(k,l)=

1N

N−1∑m=0

N−1∑n=0

x(m,n)k,l=0,0

m,n∈[0,N−1]

2N

N−1∑m=0

N−1∑n=0

x(m,n) cos[(2m+1)kπ

2N] cos[

(2n+1)lπ2N

]

k,l 6=0,0

k,l∈[0,N−1],m,n∈[0,N−1]

M.R. Azimi Digital Image Processing

Page 13: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

The inverse 2-D IDCT is

x(m,n)= 1NX(0,0)+ 2

N

∑ N−1∑k=0,l=0

k,l 6=(0,0)

X(k,l) cos[(2m+1)kπ

2N] cos[

(2n+1)lπ2N

]

The 2-D DCT of an image x in matrix form becomes

X = CxCt

with forward kernel defined by

C(k,l;m,n)=

1N

k,l=0,m,n∈[0,N−1]2N

cos[(2m+1)kπ

2N] cos[

(2n+1)lπ2N

] k,l 6=0,0 k,l∈[0,N−1],m,n∈[0,N−1]

The inverse 2-D IDCT in matrix form is

x = CtXC

M.R. Azimi Digital Image Processing

Page 14: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

Figure below shows basis images C(k, l) = ckctl , k, l ∈ [0, N − 1] of

2-D DCT for N = 8 where ck is kth column of C. Image x isdecomposed as a linear combination of these basis images with theDCT coefficients, X(k, l)s, i.e. x =

∑M−1k=0

∑N−1l=0 X(k, l)C(k, l).

ExampleTo show the usefulness of the DCT for data reduction and compression

applications, we reconstructed the Peppers image based upon only

64× 64 DCT coefficients. The following figures show the DCT

coefficients of the Peppers image and the reconstructed result, which

exhibits some smearing and ringing artifacts. Why?

M.R. Azimi Digital Image Processing

Page 15: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

In real applications, however, the original image is typicallypartitioned into blocks (e.g., 16× 16) and DCT coefficients aretaken from each block. If a portion of these coefficients is kept foreach block and then reconstruction is done block-by-block thefollowing reconstructed image will be obtained, which shows amuch better reconstruction.

M.R. Azimi Digital Image Processing

Page 16: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

M.R. Azimi Digital Image Processing

Page 17: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

Example 1Show that the N ×N cosine transform matrix C is orthogonal, i.e. proveCCt = IN .Consider the k, lth (for k, l 6= 0) element of CCt,

[CCt]k,l =2

N

N−1∑n=0

cos[(2n+ 1)kπ

2N] cos[

(2n+ 1)lπ

2N]

=1

2N

N−1∑n=0

[e−j(2n+1)(k+l)π

2N +ej(2n+1)(k+l)π

2N +e−j(2n+1)(k−l)π

2N +ej(2n+1)(k−l)π

2N ]

which simplifies to

[CCt]k,l = cos[(k + l)π

2N]δ(k + l −N) + cos[

(k − l)π2N

]δ(k − l)

where the first term is always zero and the second term is also zeroexcept when k = l. Thus,

[CCt]k,l ==

{1 for k = l0 otherwise

M.R. Azimi Digital Image Processing

Page 18: Digital Image Processing Lectures 11 & 12 · 2-D Discrete Fourier Transform Uni ed Matrix RepresentationOther Image Transforms Discrete Cosine Transform (DCT) Digital Image Processing

2-D Discrete Fourier Transform Unified Matrix Representation Other Image Transforms Discrete Cosine Transform (DCT)

For k, l = 0, [CCt]0,0 =N−1∑n=0

1N = 1. Hence, CCt = IN i.e.

orthogonal transformation matrix.

M.R. Azimi Digital Image Processing