eleg404/604: digital imaging & photography€¦ · eleg404/604: digital imaging &...

89
ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware Chapter VI

Upload: others

Post on 05-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

ELEG404/604: Digital Imaging &Photography

Gonzalo R. ArceDepartment of Electrical and Computer Engineering

University of Delaware

Chapter VI

Page 2: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

1/84

ELEG404/604

The Discrete Fourier TransformThe DFT is

G(u) = ΣM−1x=0 g(x)e−2jπux/M u= 0,1, ...M −1.

g(x) = 1M

ΣM−1u=0 G(u)e2jπux/M x= 0,1, ...M −1.

Page 3: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

1/84

ELEG404/604

The Discrete Fourier TransformThe DFT is

G(u) = ΣM−1x=0 g(x)e−2jπux/M u= 0,1, ...M −1.

g(x) = 1M

ΣM−1u=0 G(u)e2jπux/M x= 0,1, ...M −1.

Page 4: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

2/84

ELEG404/604

In 2-dimensions the DFT is

G(u,v) = ΣM−1x=0 ΣN−1

y=0 g(x,y)e−2jπ(ux/M+vy/N) u= 0,1, ...M−1;v= 0,1, ...N−1.

g(x,y) = 1MN

ΣM−1u=0 ΣN−1

u=0 G(u,v)e2jπ(ux/M+vy/N) x= 0,1, ...M−1;y= 0,1, ...N−1.

Page 5: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

3/84

ELEG404/604

Two Dimensional cosine functions

Page 6: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

4/84

ELEG404/604

Two Dimensional cosine functions

Page 7: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

5/84

ELEG404/604

Two Dimensional cosine functions

Page 8: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

6/84

ELEG404/604

Two Dimensional cosine functions

Page 9: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

7/84

ELEG404/604

Some Properties

I Translation

g(x,y)ej2πu0x/M ↔ G(u−u0)

Example: for u0 =M/2

g(x,y)(−1)x ↔ G(u−M/2)

Example in 2D: for u0 =M/2,v0 =M/2

g(x,y)(−1)(x+y) ↔ G(u−M/2,v−M/2)

Page 10: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

8/84

ELEG404/604

I Translation

g(x−x0,y−y0)

↔ G(u,v)e−j2π(x0u/M+y0v/M)

I Magnitude and Phase: Since the DFT is complexG(u,v) = |G(u,v)|ejϕ(u,v)

where:

|G(u,v)|= [(Re(u,v))2 + (Im(u,v))2]1/2 , Fourier spectrum

ϕ(u,v) = arctan(Im(u,v)Re(u,v)

), Phase angle

I Power spectrumP (u,v) = |G(u,v)|2 = [(Re(u,v))2 + (Im(u,v))2]

Page 11: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

8/84

ELEG404/604

I Translation

g(x−x0,y−y0) ↔ G(u,v)e−j2π(x0u/M+y0v/M)

I Magnitude and Phase: Since the DFT is complexG(u,v) = |G(u,v)|ejϕ(u,v)

where:

|G(u,v)|= [(Re(u,v))2 + (Im(u,v))2]1/2 , Fourier spectrum

ϕ(u,v) = arctan(Im(u,v)Re(u,v)

), Phase angle

I Power spectrumP (u,v) = |G(u,v)|2 = [(Re(u,v))2 + (Im(u,v))2]

Page 12: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

8/84

ELEG404/604

I Translation

g(x−x0,y−y0) ↔ G(u,v)e−j2π(x0u/M+y0v/M)

I Magnitude and Phase: Since the DFT is complexG(u,v) = |G(u,v)|ejϕ(u,v)

where:

|G(u,v)|= [(Re(u,v))2 + (Im(u,v))2]1/2 , Fourier spectrum

ϕ(u,v) = arctan(Im(u,v)Re(u,v)

), Phase angle

I Power spectrumP (u,v) = |G(u,v)|2 = [(Re(u,v))2 + (Im(u,v))2]

Page 13: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

9/84

ELEG404/604

Centering the 2D SpectrumOriginal Swapped

Page 14: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

10/84

ELEG404/604

Page 15: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

11/84

ELEG404/604

Intensity plot of 2D power spectrum

OriginalNon-centered

Spectrum

Centered

Spectrum

Page 16: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

12/84

ELEG404/604

Page 17: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

13/84

ELEG404/604

Page 18: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

14/84

ELEG404/604

Page 19: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

15/84

ELEG404/604

DFT- image scalingStretching the image causes the spectrum to contract and vice versa

Rectangular

Pulse

Spectrum

Page 20: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

16/84

ELEG404/604

DFT- oriented, repetitive patternsEnlarging the image causes the spectrum to contract.

Image

Spectrum

Page 21: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

17/84

ELEG404/604

DFT- image rotationThe spectrum turns in the same direction and the same amount as the image.

Image

Spectrum

OriginalRotated

15°

Rotated

30°

Page 22: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

18/84

ELEG404/604

DFT- superposition of image patternsBroadband effects caused by straight structures, e.g. dark beam on the wall.

Image

Spectrum

Page 23: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

19/84

ELEG404/604

DFT- natural image patterns

Image

Spectrum

Page 24: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

20/84

ELEG404/604

DFT- natural image patterns

Image

Spectrum

Page 25: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

21/84

ELEG404/604

Example of Image DFT (I)

Page 26: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

22/84

ELEG404/604

Example of Image DFT (II)

I Scanning Electron Microscope (SEM)image of IC board

I Edges correspond to high frequenciesI Note directionality of edges

Page 27: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

23/84

ELEG404/604

DFT of a print patternPossible to remove the raster pattern by erasing the peaks in the Fourierspectrum and reconstructing the smoothed image from the modified spectrumusing the inverse DFT.

Image

SpectrumZoom

Page 28: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

24/84

ELEG404/604

The DFT can be redefined as

X[n] = 1√N

N−1∑m=0

x[m]e−mnj2π/N =N−1∑m=0

wmnN x[m],

x[m] = 1√N

N−1∑n=0

X[n]emnj2π/N =N−1∑n=0

w−mnN X[n]

m,n= 0,1, · · · ,N −1

where wN4= e−j2π/N/

√N . The time function and its spectrum are periodic:

x[m+kN ] = x[m] and X[n+kN ] =X[n].

Page 29: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

25/84

ELEG404/604

The forward and inverse DFT can be written as:

X[n] = 1√N

N−1∑m=0

x[m]e−mnj2π/N =N−1∑m=0

wmnN x[m],

x[m] = 1√N

N−1∑n=0

X[n]emnj2π/N =N−1∑n=0

w−mnN X[n]

m,n= 0,1, · · · ,N −1Here we have defined

wmn4= 1√

N(e−j2π/N )mn, w∗mn = 1√

N(ej2π/N )mn

and w∗mn is its complex conjugate of wmn. We further define an N ×Nmatrix

W =

. . .. wmn .. . .

N×N

where wmn is the element in the mth row and nth column of W.

Page 30: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

26/84

ELEG404/604

W is symmetric (wmn = wnm)WT = W

and the rows (or columns) of W are orthogonal:

〈wm,wn〉=N−1∑k=0

w∗kmwkn = 1N

N−1∑k=0

(ej2π/N )mk(e−j2π/N )nk

= 1N

N−1∑k=0

(ej2π/N )(m−n)k ∗= δmn ={

1 m= n0 m 6= n

asI If m= n, (ej2π/N )(n−m)k = 1 and 〈wm,wn〉= 1,I If m 6= n, the summation becomes:

N−1∑k=0

(ej2π(n−m)/N )k = 1− (ej2π(n−m)/N )N

1− ej2π(n−m)/N = 0

We see that W is a unitary matrix (and symmetric):W∗T = W∗ = W−1

Page 31: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

27/84

ELEG404/604

Matrix Form of the 1-D DFTDefine the two N -long vectors:

X 4=

X[0]..

X[N −1]

N×1

, x 4=

x[0]..

x[N −1]

N×1

The DFT can then be written more conveniently as a matrix-vectormultiplication:

X =

X[0]..

X[N −1]

= 1√N

. . .

. (e−j2π/N )mn .

. . .

x[0]..

x[N −1]

= Wx

Page 32: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

28/84

ELEG404/604

Matrix Form of the 1-D DFT

and

x =

x[0]..

x[N −1]

= 1√N

. . .

. (ej2π/N )mn .

. . .

X[0]..

X[N −1]

= W∗X = W−1X

The computational complexity of the 1-D DFT is O(N2), which, as we willsee later, can be reduced to O(N log2N) by the Fast Fourier Transform(FFT) algorithm.

Page 33: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

29/84

ELEG404/604

Matrix Form of the 2D DFTReconsider the 2D DFT:

X[k, l] = 1√N

N−1∑n=0

[ 1√M

M−1∑m=0

x[m,n]e−j2πmkM ]︸ ︷︷ ︸

X′[k,n]

e−j2πnlN

= 1√N

N−1∑n=0

X ′[k,n]e−j2πnlN for 0≤m,k≤N−1, 0≤n, l≤N−1

X ′[k,n] 4= 1√M

N−1∑m=0

x[m,n]e−j2πmkM (n= 0,1, · · · ,N −1)

The summation above is with respect to the row index m and the columnindex n is a fixed parameter, this expression is a one-dimensional Fouriertransform of the nth column of [x], which can be written in column vector(vertical) form as:

X′n = W∗xnfor all columns n= 0, · · · ,N −1.

Page 34: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

30/84

ELEG404/604

Matrix Form of the 2D DFT

Putting all these N columns together, we can write[X′0, · · · ,X′N−1

]= W [x0, · · · ,xN−1]

or more conciselyX′ = Wx

where W is a M by N Fourier transform matrix.

Page 35: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

31/84

ELEG404/604

Matrix Form of the 2D DFTX[k, l] = 1√

N

∑N−1n=0 X

′[k,n]e−j2πnlN The sum is with respect to the columnindex n and the row index number k is fixed, this is a one-dimensional Fouriertransform of the kth row of X′, which can be written in row vector(horizontal) form as

XTk = X′TkWT , (k = 0, · · · ,N −1)

Putting all these N rows together, we can writeXT

0..

XTN−1

=

X′T0..

X′TN−1

W

(W is symmetric: WT = W), or more concisely

X = X′W

Page 36: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

32/84

ELEG404/604

Matrix Form of the 2D DFTBut since X′ = Wx, we have

X = WxW

Hence the 2D DFT can be implemented by transforming all the rows of x andthen transforming all the columns of the resulting matrix. The order of therow and column transforms is not important.Similarly, the inverse 2D DFT can be written as

x = W∗XW∗

Again note that W is a symmetric Unitary matrix:

W−1 = W∗T = W∗

The complexity of 2D DFT is O(N3) which can be reduced to O(N2log2N) ifFFT is used.

Page 37: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

33/84

ELEG404/604

The Fast Fourier Transform - FFT (1D)The DFT pair is given by

X(k) =N−1∑n=0

x(n)e−j2πN nk k = 0, . . . ,N −1 (1)

x(n) = 1N

N−1∑k=0

X(k)ej2πN nk n= 0, . . . ,N −1 (2)

The computational complexity for each point of the DFT is:I (N −1) Complex multiplicationsI (N −1) Complex additions

Hence for N points in the sequence we have:I O[N(N −1)] Complex multiplicationsI O[N(N −1)] Complex additions

Consider the decimation in time FFT algorithm.

Page 38: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

34/84

ELEG404/604

Divide the DFT in even and odd terms:

X(k) =(N/2)−1∑r=0

x(2r)W 2rkN +

(N/2)−1∑r=0

x(2r+ 1)W (2r+1)kN

=(N/2)−1∑r=0

x(2r)W 2rkN +W k

N

(N/2)−1∑r=0

x(2r+ 1)W 2rkN

(3)

Notice W 2rkN = e−j

2πN 2rk = e

−j(

2πN/2

)rk =W rk

N/2Hence

X(k) =(N/2)−1∑r=0

x(2r)W rkN/2︸ ︷︷ ︸

N2 −pointDFT

+W kN

(N/2)−1∑r=0

x(2r+ 1)W rkN/2︸ ︷︷ ︸

N2 −pointDFT

k= 0,1, · · · ,N−1

(4)

X(k) =G(k) +W kNH(k) k = 0,1, · · · ,N −1 (5)

But G(k) and H(k) are periodic in N2 .

Page 39: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

35/84

ELEG404/604

Page 40: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

36/84

ELEG404/604

For instanceX(1) =G(1) +W 1

NH(1) (N = 8)X(5) =G(5) +W 5

NH(5)=G(1) +W 5

NH(1)(6)

Each of the G(k) and H(k) are N/2 DFT’s; however, these can be computedusing N/4 point DFT’s and so on.For instance the N/2 point DFT:

Can be found as:

Page 41: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

37/84

ELEG404/604

Page 42: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

38/84

ELEG404/604

It self each 2 point DFT:

If N = 2b (a power of 2), then we have log2N = b decompositions. At eachstage we have N complex multiplications and additions. Hence the totalnumber of complexity operations is:I O(Nlog2N) multiplications.I O(Nlog2N) additions

Page 43: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

39/84

ELEG404/604

Page 44: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

40/84

ELEG404/604

CALCULATION OF THE 2-D DFT

1. Direct Calculation

The direct calculation of the 2-D DFT is the double sum:

X(k1,k2) =N1−1∑n1=0

N2−1∑n2=0

x(n1,n2)wn1k1N1

wn2k2N2

0≤ k1 ≤N1−10≤ k2 ≤N2−1

(7)

where wN = e−j2πN The evaluation of one sample of X(k1,k2) requires N1N2

complex multiplications and N1N2 complex additions.Thus, since there are N1N2 points. The complexity is in the order of [N2

1N22 ].

Page 45: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

41/84

ELEG404/604

2. Row-Column Decomposition

The 2-D DFT can be written as:

X(k1,k2) =N1−1∑n1=0

N2−1∑n2=0

x(n1,n2)wn2k2N2

︸ ︷︷ ︸

G(n1,k2)

wn1k1N1

(8)

X(k1,k2) =N1−1∑n1=0

G(n1,k2)wn1k1N1

(9)

Page 46: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

42/84

ELEG404/604

Hence

Page 47: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

43/84

ELEG404/604

The complexity here is as follow:

N1(1DN2 pt.DFTs) +N2(1DN1 pt.DFT ) =N1N22 +N2N

21

or N1N2(N1 +N2)

3. Row column FFTIf N1 and N2 are powers of 2 then each 1DDFT can be computed with a1DFFT . Recall they each N pt1DFFT has a complexity N logN .

Hence, the complexity is reduced to:

N1N2 logN2 +N2N1 logN1 =N1N2 log(N2N1) (10)

Page 48: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

44/84

ELEG404/604

To get a feeling for a numerical savings involved consider a1024×1024 2D DFT .

Cdirect = 240 ≈ 1012 complex multiplicationsCr/cdirect = 231 ≈ 109 complex multiplications

Cr/cFFT = 10×220 ≈ 107 complex multiplications

If it would take 1 day to process a 2D direct, then it would take 1 sec with ther/c FFT!!

Page 49: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

45/84

ELEG404/604

Linear Convolution Via DFTI Recall in one dimension

X(k) =N−1∑n=0

x(n)e−j2πkn/N , k = 0,1, . . . ,N −1.

I The N ×N unitary DFT matrix W is given by

W =

. . .. wmn .. . .

N×N

I Circular convolution Theorem: If

x2(n) =N−1∑k=0

h(n−k)cx1(k), 0≤ n≤N −1

thenDFT{x2(n)}N =DFT{h(n)}NDFT{x1(n)}N

Page 50: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

46/84

ELEG404/604

Linear Convolution via DFT (I)

Page 51: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

47/84

ELEG404/604

Linear Convolution via DFT (II)

Page 52: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

48/84

ELEG404/604

Linear Convolution via DFT Algorithm

The linear convolution of two sequences {h(n)}P−1n=0 and {x(n)}N−1

n=0 can beobtained by the following algorithm:1. Define M ≥ P +N

2. Define h(n) and x(n) as the M zero extended sequences of h(n) andx(n) respectively

3. Compute Y (k) = H(k)X(k), where H(k) =DFT{h(n)}M andX(k) =DFT{x(n)}M

4. Take the inverse DFT of Y (k) to obtain y(n)

Page 53: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

49/84

ELEG404/604

Two Dimensional DFT

The two dimensional DFT of an N ×N image is a separable transform definedas

X(u,v) =N−1∑m=0

N−1∑n=0

f(m,n)wkmN wlnN , 0≤ k, l ≤N −1

and the inverse transform is defined as

x(m,n) = 1N2

N−1∑k=0

N−1∑l=0

X(u,v)w−kmN w−lnN , 0≤m,n≤N −1.

Page 54: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

50/84

ELEG404/604

Two Dimensional Linear Convolution

I The DFT of the two dimensional circular convolution of two arrays is theproduct of their DFTs, i.e., if

y(m,n) =N−1∑m′=0

N−1∑n′=0

h(m−m′,n−n′)cu(m′,n′), 0≤m,n≤N −1

thenDFT{y(m,n)}N =DFT{h(m,n)}NDFT{u(m,n)}N

I Extensions to linear filtering can be done using zero padding

Page 55: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

50/84

ELEG404/604

Two Dimensional Linear Convolution

I The DFT of the two dimensional circular convolution of two arrays is theproduct of their DFTs, i.e., if

y(m,n) =N−1∑m′=0

N−1∑n′=0

h(m−m′,n−n′)cu(m′,n′), 0≤m,n≤N −1

thenDFT{y(m,n)}N =DFT{h(m,n)}NDFT{u(m,n)}N

I Extensions to linear filtering can be done using zero padding

Page 56: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

51/84

ELEG404/604

Two dimensional Example of Zero Padding

Page 57: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

52/84

ELEG404/604

Example of Image DFT (II)

We can center the DFT by premultiplying image U by the array (−1)m+n

x(k+N/2, l+N/2) = 1N

N−1∑m=0

N−1∑n=0

x(m,n)(−1)m+nwkmN wlnN

Page 58: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

53/84

ELEG404/604

Ideal Low Pass Filters (I)

Page 59: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

54/84

ELEG404/604

Ideal Low Pass Filters (II)

Page 60: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

55/84

ELEG404/604

ILPF Example

I Isolated spatial domain pointsrepresent fine details

I Convolution simply replicates sincs

I Width of sinc controls blurringI Positive and negative values of sinc

cause ringingI One dimensional signals are scan lines

Page 61: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

56/84

ELEG404/604

Energy Compaction (I)

Page 62: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

57/84

ELEG404/604

Energy Compaction (II)

Page 63: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

58/84

ELEG404/604

Filtering in the Frequency Domain

Page 64: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

59/84

ELEG404/604

Low Pass and High Filtering Example

Page 65: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

60/84

ELEG404/604

Low Pass Filters

I D(u,v) is the distance from point (u,v) to the originI Ideal filter can be implemented digitally but has undesired effectsI Butterworth filter is a smooth approximation to ideal filterI Gaussian filter is a smooth function both in space and frequency domains

Page 66: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

61/84

ELEG404/604

Butterworth Low Pass FilterFrequency response:

H(u,v) = 11 + [D(u,v)/D0]2n

I Order: n, Cutoff frequency: D0I Smooth transfer function

I Minimizes ringingI Order controls transition bandwidth

Page 67: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

62/84

ELEG404/604

Butterworth Filter Example

I Size 500×500I Filter order:2I D0 = 5,15,30,80

and 230I Significantly

reduced ringingcompared to ILPF

Page 68: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

63/84

ELEG404/604

Spatial Domain Representation of Butterworth Filter

I Cutoff frequency:5I Increasing filter order: 1,2,5 and 20

I Impulse response spreads, oscillations introducedI Smoothing and ringing introduced

Page 69: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

64/84

ELEG404/604

Gaussian Low Pass Filter

Frequency response:

H(u,v) = exp−D2(u,v)/2D20

I Spatial domain also a gaussian functionI No ringingI Less cutoof/transition control

Page 70: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

65/84

ELEG404/604

Gaussian Low Pass Filter Example

I D0 = 5,15,30,80and 230

I Not as muchsmoothing

I More gradualtransition band

I No ringing

Page 71: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

66/84

ELEG404/604

Application Example

I Poor resolution sampled textI Scanned material, faxesI Broken text

I Result of Gaussian low pass filtering: broken character segments are joined

Page 72: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

67/84

ELEG404/604

Enhancement of Poorly Acquired Images

Page 73: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

68/84

ELEG404/604

Gaussian Filter with Zero Padding Example

Page 74: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

69/84

ELEG404/604

Spectral Representations of Sharpening Filters

I Simple highpassrepresentation

Hhp(u,v) = 1−Hlp(u,v)

I Spectrally centeredexamplesI IdealI ButterworthI Gaussian

Page 75: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

70/84

ELEG404/604

High Pass Filters

Page 76: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

71/84

ELEG404/604

High Pass Filtering Example

Page 77: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

72/84

ELEG404/604

Application Example

I Thumb printI Result of highpass filteringI Result of thresholding

Page 78: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

73/84

ELEG404/604

Laplacian OperatorI Recall that

F{∇2f(x,y)

}=−(u2 +v2)F (u,v)

I Then, the Laplacian operator is a filter with frequency response

H(u,v) =−(u2 +v2)

I If spectral centering is used then

∇2f(x,y)↔−[(u−N/2)2 + (v−N/2)2

]F (u,v)

I A sharpened image is given by:

g(x,y) = f(x,y)−∇2f(x,y)= F−1

{[1−

((u−N/2)2 + (v−N/2)2

)]F (u,v)

}

Page 79: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

74/84

ELEG404/604

Laplacian in the Frequency and Spatial Domain

I Highpass filterI Spatial response

I Restricted to axisI Rotation invariant

responseI diagonals can be

added

Page 80: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

75/84

ELEG404/604

Laplacian Example

I ShownI OriginalI LaplacianI Scaled LaplacianI Enhanced result

Page 81: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

76/84

ELEG404/604

Unsharp Masking

I High-boost filtering

fhb(x,y) = Af(x,y)−flp(x,y)

I Rearrangingfhb(x,y) = (A−1)f(x,y) +fhp(x,y)

I Composite frequency response

Hhb(u,v) = (A−1)−Hhp(u,v)

I High frequency emphasis

Hhfe(u,v) = a+ bHhp(u,v)

Page 82: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

77/84

ELEG404/604

High-Boost Filtering Example

Page 83: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

78/84

ELEG404/604

High Frequency Emphasis ExampleHigh frequency emphasis, a= 0.5, b= 2.0

Page 84: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

79/84

ELEG404/604

Bandreject/Bandpass Filters

Page 85: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

80/84

ELEG404/604

Bandreject Example (I)

Page 86: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

81/84

ELEG404/604

Bandreject Example (II)

I Image example with nearlyperiodic interference

I Spectrum: energy in the verticalaxis represents the interferencepattern

I Notch vertical filterI Result of filtering

Page 87: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

82/84

ELEG404/604

Bandpass Example

I Same image as beforeI Result: interference pattern

Page 88: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

83/84

ELEG404/604

Implementation Examples

Page 89: ELEG404/604: Digital Imaging & Photography€¦ · ELEG404/604: Digital Imaging & Photography Gonzalo R. Arce Department of Electrical and Computer Engineering University of Delaware

84/84

ELEG404/604

Correlation Example

I Correlation measures statisticalsimilarity

I Common application: templatematching

I Zero pad image and templateI Multiply DFTs (conjugate image

DFTs)I Invert resultsI Find peaks location