<<
Home , Pi

2-D Fourier Transforms

Yao Wang Polytechnic University, Brooklyn, NY 11201

With contribution from Zhu Liu, Onur Guleryuz, and Gonzalez/Woods, Digital Image Processing, 2ed Lecture Outline • Continuous (FT) – 1D FT (review) – 2D FT • Fourier Transform for Discrete Time (DTFT) – 1D DTFT (review) – 2D DTFT • Linear Convo lu tion – 1D, Continuous vs. discrete signals (review) – 2D • Filter Design • Computer Implementation

Yao Wang, NYU-Poly EL5123: Fourier Transform 2 What is a transform?

• Transforms are decompositions of a function f(x) into some basis functions Ø(x, u). u is typically the freq. index.

Yao Wang, NYU-Poly EL5123: Fourier Transform 3 Illustration of Decomposition

Φ3 f

α3 f = α1Φ1+α2Φ2+α3Φ3

o α2 Φ2 α1

Φ1

Yao Wang, NYU-Poly EL5123: Fourier Transform 4 Decomposition

• Ortho-normal basis function   1, u1  u2 (x,u1) *(x,u2 )dx   0, u1  u2 • Forward  * Projection of F(u)  f (x),(x,u)   f (x) (x,u)dx f(x) onto  (x,u) • Inverse  Representing f(x) as sum of f (x)   F(u)(x,u)du (x,u) for all u, with weight  F(u)

Yao Wang, NYU-Poly EL5123: Fourier Transform 5 Fourier Transform

• Basis function (x,u)  e j2ux , u  ,.

• Forward Transform

 F(u)  F{ f (x)}  f (x)e j2uxdx  • Inverse Transform  f (x)  F 1{F(u)}  F(u)e j2uxdu 

Yao Wang, NYU-Poly EL5123: Fourier Transform 6 Important Transform Pairs

 f (x) 1  F(u)   (u) f (x)  e j2f0x  F(u)   (u  f ) 0 1 f (x)  cos(2 f0x)  F(u)  (u  f0 )   (u  f0 ) 2  1 f (x)  sin(2 f x)  F(u)  (u  f )  (u  f ) 0 2 j 0 0

 1, x  x0 sin(2x0u) f (x)    F(u)   2x0 sinc(2x0u) 0, otherwise u sin(t) where, sinc(t)  t

Derive the last transform pair in class

Yao Wang, NYU-Poly EL5123: Fourier Transform 7 FT of the Rectangle Function

sin(2x u) sin(t) F(u)  0  2x sinc(2x u) where, sinc(t)  u 0 0 t

f(x) f(x) x =2 x0=1 0

-1 1 x -2 2 x

Note first zero occurs at u0=1/(2 x0)=1/pulse-width, other zeros are multiples of this.

Yao Wang, NYU-Poly EL5123: Fourier Transform 8 IFT of Ideal Low Pass Signal

• What is f(x)?

F(u)

-u0 u0 u

Yao Wang, NYU-Poly EL5123: Fourier Transform 9 Representation of FT • Generally, both f(x) and F(u) are complex • Two representations – Real and Imaginary F(u)  R(u)  jI(u) – Magnitude and Phase

j (u) F(u)  A(u)e , where I F(u) I(u) I(u) A(u)  R(u)2  I(u)2 , (u)  tan 1 R(u) Φ(u) R(u) R • Relationship R(u)  A(u)cos(u), I(u)  A(u)sin(u) • Power spectrum P(u)  A(u)2  F(u) F(u)*  F(u) 2

Yao Wang, NYU-Poly EL5123: Fourier Transform 10 What if f(x) is real?

• Real world signals f(x) are usually real • F(u) is still complex , but has special properties

F * (u)  F(u) R(u)  R(u), A(u)  A(u), P(u)  P(u) : even function I(u)  I(u),(u)  (u) :odd function

Yao Wang, NYU-Poly EL5123: Fourier Transform 11 Property of Fourier Transform

• Duality f (t)  F(u) F(t)  f (u) • Linearity

Fa1 f1(x)  a2 f2 (x) a1F{ f1(x)} a2 F{ f2 (x)} • SliScaling Faf (x) aF{ f (x)}  • Translation

 j2 x0u j2u0 x f (x  x0 )  F(u)e , f (x)e  F(u  u0 ) • f (x)  g(x)   f (x )g()d f (x)  g(x)  F(u)G(u)

We will review convolution later!

Yao Wang, NYU-Poly EL5123: Fourier Transform 12 Two Dimension Fourier Transform

• Basis functions (x, y;u,v)  e j(2ux2vy)  e j2uxe j2vy , u,v   ,. • Forward – Transform   F(u,v)  F{ f (x, y)}  f (x, y)e j2 (uxvy)dxdy   • Inverse – Transform   f (x, y)  F 1{F(u,v)}  F(u,v)e j2 (uxvy)dudv   • PtProperty – All the properties of 1D FT apply to 2D FT

Yao Wang, NYU-Poly EL5123: Fourier Transform 13 Example 1

f (x, y) sin 4x  cos6y f(x,y)

 j2 (uxvy) F{sin 4 x}  sin 4xe dxdy   sin4 xe j2 uxdx e j2 vydy      sin4 xe j2uxdx (v)  1  ( (u  2)  (u  2)) (v) 2 j  1  ( (u  2,v)  (u  2,v)) 2 j u F(u,v) , x  y  0 where  (x, y)   (x) (y)   0, otherwise v 1 Likewise, F{cos6y}  ( (u,v  3)  (u,v  3)) 2

Yao Wang, NYU-Poly EL5123: Fourier Transform 14 Example 2

   1 j(2 x3 y)  j(2 x3 y) f (x, y)  sin(2 x  3y)  e   e   2 j     Fe j(2 x3 y)  e j(2 x3 y)e j2 (xu yv)dxdy     e j2 xe j2 uxdx e j3 ye j2yvdy 3 3   (u 1) (v  )   (u 1,v  ) [X, Y]=meshgrid(-2:1/16:2,-2:1/16:2); 2 2 f=sin(2**X+3*pi*Y);  3 imagesc(f); colormap(gray) Likewise, Fe j(2 x3y)   (u 1,v  ) Truesize, axis off;  2 Thfherefore,  1  3 3  u Fsin(2 x  3 y)   (u 1,v  )  (u 1,v  ) F(u,v) 2 j  2 2 

v

Yao Wang, NYU-Poly EL5123: Fourier Transform 15  Important Transform Pairs 

   1 sin(2 f x  2 f y)  (u  f ,v  f )  (u  f ,v  f ) x y 2 j x y x y 1 cos(2 f x  2 f y)  (u  f ,v  f )  (u  f ,v  f ) x y 2 x y x y

2D rectangular function  2D sinc function

Yao Wang, NYU-Poly EL5123: Fourier Transform 16 Properties of 2D FT (1)

• Linearity

Fa1 f1(x, y)  a2 f2 (x, y) a1F{ f1(x, y)} a2 F{ f2 (x, y)} • Translation

 j2 (x0u y0v) f (x  x0 , y  y0 )  F(u,v)e ,

j2 (u0 xv0y) f (x, y)e  F(u  u0 ,v  v0 ) • Conjugation f * (x, y)  F * (u,v)

Yao Wang, NYU-Poly EL5123: Fourier Transform 17 Properties of 2D FT (2)

• Symmetry f (x, y) is real  F(u,v)  F(u,v) • Convolution – Definition of convolution f (x, y)  g(x, y)   f (x , y   )g(,  )dd

– Convolution theory f (x, y)  g(x, y)  F(u,v)G(u,v)

We will describe 2D convolution later!

Yao Wang, NYU-Poly EL5123: Fourier Transform 18 Separability of 2D FT and Separable Signal • Separability of 2D FT

F2{ f (x, y)}  Fy{Fx{ f (x, y)}}  Fx{Fy{ f (x, y)}}

– where Fx, Fy are 1D FT along x and y. – one can do 1DFT for each row of original image, then 1D FT along each column of resulting image • Separable Signal

– f(x,y) = fx(x)fy(y) – F(()u,v) = Fx(()u)Fy(()v), • where Fx(u) = Fx{fx(x)}, Fy(u) = Fy{fy(y)} – For separable signal, one can simply compute two 1D transforms!

Yao Wang, NYU-Poly EL5123: Fourier Transform 19 Example 1

f (x, y)  sin(3x)cos(5y) 1 f x (x)  sin(3x)  Fx (u)   (u  3/ 2)  (u  3/ 2) 2 j  1 f (y)  cos(5 y)  F (v)  (v  5/ 2)  (v  5/ 2) y y 2 F(u,v)  Fx(u)Fy(v)  1  3 5 3 5 3 5 3 5    (u  ,v  )  (u  ,v  )  (u  ,v  )  (u  ,v  ) 4 j  2 2 2 2 2 2 2 2 

u

v

Yao Wang, NYU-Poly EL5123: Fourier Transform 20 Example 2

1, | x | x0 ,| y | y0 f (x, y)    0, otherwise

F(u,v)  4x0 y0 sinc(2x0u)sinc(2y0v)

x 2 u

x0 = 2 y0 = 1

v -1 1 y

-2

w/ logrithmic mapping Yao Wang, NYU-Poly EL5123: Fourier Transform 21

• Let x  r cos, y  r sin, u   cos, v   sin. • 2D FT in polar coordinate (r, θ) and (ρ, Ø)  2   j2 (r cos cos r sin sin ) F(,)  f (r, )e rdrd 00     j2 r cos(  )  f (r, )e rdrd        • Property

f (r, 0 )  F(, 0 )

Yao Wang, NYU-Poly EL5123: Fourier Transform 22 Example of Rotation

Yao Wang, NYU-Poly EL5123: Fourier Transform 23 Fourier Transform For Discrete Time Sequence (DTFT) • One Dimensional DTFT – f(n) is a 1D discrete time sequence – Forward Transform  F(u) i s peri odi c in u, w ith per io d  j2un F(u)   f (n)e of 1 n – ITfInverse Transform

1/ 2 f (n)  F(u)e j2undu 1/ 2

Yao Wang, NYU-Poly EL5123: Fourier Transform 24 Properties unique for DTFT

• Periodicity – F(u) = F(u+1) – The FT of a discrete time sequence is only considered for u є (-½ , ½) ½)andu=, and u = +½isthe½ is the highest discrete frequency • Symmetry for real f (n)  f * (n)  F(u)  F * (u)  F(u)  F(u)  F(u) is symmetric

Yao Wang, NYU-Poly EL5123: Fourier Transform 25 Example

1, n  0,1,..., N 1; f (n)     0, others  N 1 1 e j2 uN sin 2u(N / 2) F(u)  e j2 nu   e j (N 1)u   j2u sin 2u(1/ 2) n0 1 e

f(n)

0 N-1 n N=10

There are N/2 zeros in (0, ½], 1/N apart

Yao Wang, NYU-Poly EL5123: Fourier Transform 26 Two Dimensional DTFT

• Let f(m,n) represent a 2D sequence • Forward Transform   F(u,v)  f (m,n)e j2 (munv) m n • Inverse Transform

1/ 2 1/ 2 f (m,n)  F(u,v)e j2 (munv)dudv 1/ 2  1/ 2 • Properties – Periodicity, Shifting and Modulation, Conservation

Yao Wang, NYU-Poly EL5123: Fourier Transform 27 Periodicity

 F(u,v)  f (m,n)e j2 (munv) mn  • F(u,v) is periodic in u, v with period 1, i.e., for all integers k, l: – F(u+k, v+l) = F(u, v) • To see this consider e j2 (m(uk )n(vl))  e j2 (munv)e j2 (mk nl)  e j2 (munv) In MATLAB, frequency scaling is such that 1 represents maximum freq u,v=1/2.

Yao Wang, NYU-Poly EL5123: Fourier Transform 28 Illustration of Periodicity

u

Low frequencies 1.0

High frequencies

0.5

-1.0-0.5 0 0.5 1.0 v

Yao Wang, NYU-Poly EL5123: Fourier Transform 29 Fourier Transform Types

Low Pass High Pass Band Pass u u u 0.5 0.5 0.5

v v v -0.5 0.5 -0.5 0.5 -0.5 0.5

-0.5 -0.5 -0.5

Non-zero frequency components

Yao Wang, NYU-Poly EL5123: Fourier Transform 30 Shifting and Modulation

• Shifting

   j2 (munv) F{ f (m  m0 ,n  n0 )}    f (m  m0 ,n  n0 )e mn    j2 ((k m0 )u(ln0 )v) k  m  m0 ,l  n n0    f (k,l)e kl    e j2 (m0un0v)   f (k,l)e j2 (kulv) kl 

 j2 (m0un0v) f (m  m0 ,n  n0 )  e F(u,v)

• Modulation

j2 (mu0 nv0 ) e f (m,n)  F(u  u0 ,v  v0 )

Yao Wang, NYU-Poly EL5123: Fourier Transform 31 Energy Conservation

• Inner Product   f , g    f (m,n)g * (m,n) mn 

 05.5 0.  f (m,n) G* (u,v)e j2 (munv)dudv   05.5 0.  mn    0.5 0.5     f (m,n)e j2 (munv) G* (u,v)dudv 0.5 0.5    mn   0.5 0.5  F(u,v)G* (u,v)dudv  F,G  0.5 0.5 • Energy Conservation  2 0.5 0.5 2 f (m,n)  F(u,v) dudv  0.5 0.5 mn 

Yao Wang, NYU-Poly EL5123: Fourier Transform 32 Function

• Fourier transform of a delta function

  F(u,v)   (m,n)e j2 (munv)  1 mn   (m,n)  1

• Inverse Fourier transform of a delta function

0.5 0.5 f (m,n)   (u,v)e j2 (munv)dudv 1 0.5  0.5 1   (u,v)

Yao Wang, NYU-Poly EL5123: Fourier Transform 33 Example

m  1 2 1  f(m,n)  f (m,n)   0 0 0    n 1  2 1      F(u,v) 1e j2 (1*u1*v)  2e j2 (1*u0*v) 1e j2 (1*u1*v) 1e j2 (1*u1*v)  2e j2 (1*u0*v) 1e j2 (1*u1*v) j2 v  j2v  j2sin 2ue  j4sin 2 u  j2sin 2ue  j4sin 2 u(cos2v 1)

Note: This siggpnal is low pass in the horizontal direction , and band pass in the vertical direction.

Yao Wang, NYU-Poly EL5123: Fourier Transform 34 Graph of F(u,v)

du = [-0.5:0.01:0.5]; 20 d[dv = [-0500105]0.5:0.01:0.5]; Fu = abs(sin(2 * pi * du)); 40 Fv = cos(2 * pi * dv); 60 F = 4 * Fu' * (Fv + 1); Using MATLAB freqz2: mesh((,du, dv, ,); F); 80 colorbar; f=[1,2,1;0,0,0;-1,-2,-1]; Imagesc(F); freqz2(f) 00 colormap(gray); truesize; 20 40 60 80 100 Yao Wang, NYU-Poly EL5123: Fourier Transform 35 Linear Convolution  • Convolution of Continuous Signals  – 1D convolution     f (x)h(x)  f (x  )h( )d  f ( )h(x  )d   • Equalities

f (x) (x)  f (x), f (x) (x  x0 )  f (x  x0 ) – 2D convolution   f (x, y)h(x, y)  f (x , y   )h(,  )dd     f (,  )h(x , y   )dd  

Yao Wang, NYU-Poly EL5123: Fourier Transform 36 Examples of 1D Convolution

f(x) f(α)h(x-α) h(x-α) 1 x α α 0 1 x-1 x 0 x h(x) (1) 0 ≤ x < 1 f(α)h(x-α) 1 h(x-α)

0 x α α 1 x-1 x 0 x-1 1 (2) 1 ≤ x < 2 h(-α)

1 f(x)*h(x) 1 0 1 α x x 1 2

Yao Wang, NYU-Poly EL5123: Fourier Transform 37 Example of 2D Convolution y β β f(x,y) h(x-α,y-β) 1 h(x-α,y-β) 1 y 1 y y-1 α α 1x 1 x 1 x y (1) 0

1x β β h(x-α,y-β) h(x-α,y-β) 1 y 1 y f(x,y)*h(x,y) y-1 y α α 2 1 1 x-1 x x-1 x (3) 1

Yao Wang, NYU-Poly EL5123: Fourier Transform 38 Convolution of 1D Discrete Signals

• Definition of convolution  f (n)*h(n)   f (n  m)h(m)   f (m)h(n  m) mm 

• The convolution can be considered as the weighted average: – sample n-m is multiplied by h(m) • Filtering: f(n) is the signal, and h(n) is the filter – Finite imppp()ulse response (FIR) filter – Infinite impulse response (IIR) filter

• If the range of f(n) is (n0, n1), and the range of h(n) is (m0, m1), then the range of f(n)* h(n) is (n0+m0, n1+m1)

Yao Wang, NYU-Poly EL5123: Fourier Transform 39 Example of 1D Discrete Convolution

h(n-m) f(n) n-5 n 0 03n m (a) n < 0, g(n) = 0

h(n) h(n-m) 0 5 n h(-m) n-5 0 n m (b) 0 ≤ n ≤ 8, g(n) > 0 -50 m h(n-m)

f(n)*h(n) n n-5 0 m (c) n > 8 , g(n) = 0 0 8n

Yao Wang, NYU-Poly EL5123: Fourier Transform 40 Convolution of 2D Discrete Signals

• Definition of convolution

 f (m,n)*h(m,n)    f (m  k,n  l)h(k,l) kl      f (k,l)h(m  k,n  l) kl 

• Weighted average: – Pixel (m-k,n-l) is weighted by h(k,l) • Range

– If the range of f(m, n) is m0 ≤ m ≤ m1, n0 ≤ n ≤ n1 – If the range of h(m, n) is k0 ≤ m ≤ k1, l0 ≤ n ≤ l1, – Then the range of f(m, n)*h(m, n) is

m0 + k0 ≤ m ≤ m1 + k1, n0 + l0 ≤ n ≤ n1 + l1

Yao Wang, NYU-Poly EL5123: Fourier Transform 41 Example of 2D Discrete Convolution

m k f(m,n) f(k,l)h(-1-k, -2-l) 1 1

n l

k m f(k,l)h(2 -k1k,1-l) h(m,n) 1 1

l n

f(m,n)*h(m,n) k k h(-k,-l) 1 1 2 3 l l

Yao Wang, NYU-Poly EL5123: Fourier Transform 42 • Go through an example in class for an arbitrary 3x3 (non-symmetric) filter

Yao Wang, NYU-Poly EL5123: Fourier Transform 43 Separable Filtering

• A filter is separable if h(x, y)=hx(x)hy(y) or h(m, n)=hx(m)hy(n). • Matrix representation T H  hxhy

– Where hx and hy are column vectors • Example 1 0 1 1 H  2 0  2  21 0 1 h hT     x y 1 0 1 1

Yao Wang, NYU-Poly EL5123: Fourier Transform 44 DTFT of Separable Filter

• Previous example

1 0 1 1     T H  2 0  2  21 0 1  hxhy 1 0 1 1 • Recognizing that the filter is separable 

1 0 1    Fy(v)  1e j2 v 0  (1)e j2v  2 j sin 2v j2u  j2u 1 2 1   Fx(u)  1e 2 e  2  2cos 2u F(u,v)  Fx(u)Fy(v)  4 j(1 cos 2 u)sin 2v

Yao Wang, NYU-Poly EL5123: Fourier Transform 45 Separable Filtering

• If H(m,n) is separable, the 2D convolution can be accomplished by first applying 1D filtering

along each row using hy(n), and then applying 1D filtering to the intermediate result along each

column using the filter hx(n) • Proof f (m,n)*h(m,n)   f (m  k,n  l)hx (k)hy (l) kl     f (m  k,n  l)hy (l)hx (k) k  l 

  g y (m  k,n)hx (k) k

 ( f (m,n)*hy (n))*hx (m)

Yao Wang, NYU-Poly EL5123: Fourier Transform 46 • Go through an example of filtering using separable filter in class

Yao Wang, NYU-Poly EL5123: Fourier Transform 47 Computation Cost

• Suppose – ThesizeoftheimageisMThe size of the image is MN*N. – The size of the filter is K*L. • Non-separable filter ing – Each pixel: K*L mul; K*L – 1 add. – Total: M*N*K*L mul; M*N*(K*L-1) add. – When M=N, K=L • M2K2 mul + M2(K2-1) add.

Yao Wang, NYU-Poly EL5123: Fourier Transform 48 Computation Cost

• Separable: – Each pixel in a row: L mul; L-1 add. – Each row: N*L mul; N*(L-1) add. – M rows: M*N*L mul; M*N*(L-1) add. – Each pixel in a column: K mul; K-1 add. – Each column: M*K mul; M*(K-1) add. – N columns: N*M*K mul; N*M*(K-1) add. – Total: M*N*(K+L) mul; M*N*(K+L-2) add. – When M= N, K= L: • 2M2K mul; 2M2(K-1) add. • Significant savings if K (and L) is large!

Yao Wang, NYU-Poly EL5123: Fourier Transform 49 Boundary Treatment

• When assuming the image values outside a given image are zero, the filtered values in the boundary are affected by assumed zero values 200 200 205 203 203 adversely 200 200 205 203 203 • FbttFor better result s, use symmetric extension 195 195 200 200 200 ((g)mirror image) to fill the 200 200 205 195 195 outside image values 200 200 205 195 195

Actual image pixels Extended pixels

Yao Wang, NYU-Poly EL5123: Fourier Transform 50 Computer implementation of convolution

• Boundary treatment – An image of size MxN convolving with a filter of size KxL will yield an image of size (M+K-1,N+L-1) – If the filter is symmetric, the convolved image should have extra boundary of thickness K/2 on each side – Filtered values in the outer boundary of K/2 pixels depend on the extended pixel values – For simplicity, we can ignore the boundary problem, and process only the inner rows and columns of the image, leaving the outer K/2 rows and L/2 columns unchanged (if filter is low-pass) or as zero (if filter is high-pass) • RlitiRenormalization: – The filtered value may not be in the range of (0,255) and may not be integers – Use two-pppass operation • First pass: save directly filtered value in an intermediate floating- array • Second pass: find minimum and maximum values of the intermediate image, renormalize to (0,255) and rounding to integers – F= round((F1-fmin)*255/(fmax-fmin)) • To di sp lay the unnorma lize d image direc tly, use “i()”imagesc( )” ftifunction

Yao Wang, NYU-Poly EL5123: Fourier Transform 51 Sample Matlab Program

% readin bmp file % define 2D filter x = imread('lena.bmp'); h = ones(5,5)/25; [xh xw] = size(x); [hh hw] = size(h); y = double(x); hhh = (hh - 1) / 2; hhw = (hw- 1) / 2;

% linear convolution, assuming the filter is non-separable (although this example filter is separable) z = y; %or z=zeros(xh, xw) if not low-pass filter for m = hhh + 1:xh - hhh, %skip first and last hhh rows to avoid boundary problems for n = hhw + 1:xw - hhw, %skip first and last hhw columns to avoid boundary problems tmpy = 0; for k = -hhh:hhh, for l = -hhw:hhw, tmpv = tmpv + y(m - k,n – l)* h(k + hhh + 1, l + hhw + 1); %h(0, 0) is stored in h(hhh+1, hhw+1) end end z(m, n) = tmpv; %for more efficient matlab coding, you can replace the above loop with z(m,n)=sum(sum(y(m-hhh:m+hhh,n-hhw:n+hhw).*h)) end end

Yao Wang, NYU-Poly EL5123: Fourier Transform 52 Results

1 1 1 1 1 1 1 1 1 1 1   h  1 1 1 1 1 25   1 1 1 1 1 1 1 1 1 1

f(m,n) g(m,n)

Yao Wang, NYU-Poly EL5123: Fourier Transform 53 • What if the filter is symmetric? Can you write a different MATLAB code that has reduced computation time? • MATLAB built-in functions – 1D filtering: conv – 2D filtering: conv2 – Computing DTFT: freqz, freqz2

Yao Wang, NYU-Poly EL5123: Fourier Transform 54 Convolution Theorem

• Convolution Theorem f *h  F  H, f  h  F * H

• Proof g(m,n)  f (m,n)*h(m,n)   f (m  k,n  l)h(k,l) k l

FT on both sides  G(u,v)   f (m  k,n  l)h(k,l)e j2 (munv) m,,n k l     f (m  k,n  l)e j2 ((mk )u(nl)v)h(k,l)e j2 (kulv) m,n k,l    f (m  k,n  l)e j2 ((mk )u(nl)v)  h(k,l)e j2 (kulv) ml,,n k  f (m',n')e j2 (m'un'v) h(k,l)e j2 (kulv) ml',,n' k  F(u,v) H (u,v)

Yao Wang, NYU-Poly EL5123: Fourier Transform 55 Explanation of Convolution in the Frequency Domain h(x) f(x) g(x)=f(x)*h(x)

-∆/2 ∆/2 x x -∆/4 ∆/4 x

F(()u) G(u)=F(u)H(u) H(u)

u -2/∆ 2/∆ u u -1/∆ 1/∆ -1/∆ 1/∆

Yao Wang, NYU-Poly EL5123: Fourier Transform 56 Example

• Given a 2D filter, show the frequency response. Apply to a given image, show original image and filtered image in pixel and freq. domain

1 1 1 1 1 1 1 1 1 1 1   h  1 1 1 1 1 25   1 1 1 1 1 1 1 1 1 1

Yao Wang, NYU-Poly EL5123: Fourier Transform 57 1 1 1 1 1 1 1 1 1 1 1   h  1 1 1 1 1 25   1 1 1 1 1 1 1 1 1 1

Yao Wang, NYU-Poly EL5123: Fourier Transform 58 Matlab Program Used

x = imread('lena256.bmp'); figure(1); imshow(x); f = double(x); ff=abs(fft2(f)); figure(2); imagesc(fftshift(log(ff+1))); colormap(gray);truesize;axis off; h = ones(5,5)/9; hf=abs(freqz2(h)); figure(3);imagesc((log(hf+1)));colormap(gray);truesize;axis off; y = conv2(f, h); figure(4);imagesc(y);colormap(gray);truesize;axis off; yf=abs(fft2(y)); figure(5);imagesc(fftshift(log(yf+1)));colormap(gray);truesize;axis off;

Yao Wang, NYU-Poly EL5123: Fourier Transform 59  1 1 1  1 H   0 0 0  1 3   1 1 1

Yao Wang, NYU-Poly EL5123: Fourier Transform 60 Filter Design

• Given desired frequency response of the filter Hd(u,v) • Perform an inverse transform to obtain the desired impulse response hd(m,n). • When Hd(u,v) is band limited, hd(m,n) is infinitely long

• Truncate hd(mnm,n) to yield a realizable h(mnm,n) • Will distort the original frequency response • Better approach is to apply a well designed window function over the specified frequency response.

Yao Wang, NYU-Poly EL5123: Fourier Transform 61 Use of Window Function in Filter Design

H (u) d H(u) Hw(u)

u u u

hd(x) window h(x) hw (x) function w(x)

…… x x x x Hamming window w(x)  0.54  0.46cos(2 ), 0  x  X X

Yao Wang, NYU-Poly EL5123: Fourier Transform 62 Homework

sin(2f x)sin(2f y) 1. Let f (x, y)  sin 2f (x  y), h(x, y)  c c 0  2 xy

Find t he convo lve d s igna l g(x, y) = f(x, y)*) * h(x, y)f) for th e foll ow ing two cases:

a) f0/2 < fc < f0; and b) f0 < fc < 2f0. Hint: do the filtering in the frequency domain. Explain what happened by sketching the original signal, the filter, the convolution process and the convolved signal in the frequency domain. 2. Repeat the previous problem for

 1 1  f 2 ,   {x, y}  h(x, y) c   2 fc 2 fc  0, otherwise

Yao Wang, NYU-Poly EL5123: Fourier Transform 63 Homework (cntd)

3. For the three filters given below (assuming the is at the center): a) find their Fourier transforms (2D DTFT); b) sketch the magnitudes of the Fourier transforms. You should sketch by hand the DTFT as a function of u, when v=0 and when v=1/2; also as a function of v, when u=0 or ½. Also please plot the DTFT as a function of both u and v, usinggpg Matlab plotting function. c) Compare the functions of the three filters. In your calculation, you should make use of the separable property of the filter whenever appropriate. If necessary, split the filter into several additive terms such that each term can be calculated more efficiently.

1 1 1  1  2 1  1  2 1 1 1 1 H  1 1 1 H   2 12  2 H   2 12  2 1 9   2 24   3 24   1 1 1  1  2 1  1  2 1

Yao Wang, NYU-Poly EL5123: Fourier Transform 64 Programming Assignment

1. Write a Matlab or C-program for implementing filtering of a gray scale image. Your program should allow you to specify the filter with an arbitrary size (in the range of k0->k1, l0->l1), read in a gray scale image, and save the filtered image into another file. For simplicity, ignore the boundary effect. That is, do not compute the filtered values for pixels residing on the image boundary. If the filter has a size of M x N, the boundary pixels are those in the top and bottom M/2 rows, and left and riggppyght most N/2 columns. You should properly normalize the filtered image so that the resulting image values can be saved as 8- unsigned characters. Apply the filters given in the previous problem to a test image. Observe on the effect of these filters on your image. Note: you cannot use the MATLAB conv2( ) function. In your report, include your MATLAB code, the original test image and the images obtained with the three filters. Write down your observation of the effect of the filters. 2. Optional: Now write a convolution program assuming the filter is separable. Your program should allow you to specify the horizontal and vertical filters , and call a 1D convolution sub-program to accomplish the 2D convolution. Note: you cannot use the MATLAB conv( ) function. 3. Learn the various options of conv2( ) function in MATLAB using online help manual.

Yao Wang, NYU-Poly EL5123: Fourier Transform 65 Reading

• Gonzalez and Woods, Sec. 4.1 and 4.2, 4., 3435353.4, 3.5, 3.5

Yao Wang, NYU-Poly EL5123: Fourier Transform 66