Sei sulla pagina 1di 66

2-D Fourier Transforms

Yao Wang
Polytechnic University
University, Brooklyn
Brooklyn, NY 11201
With contribution from Zhu Liu, Onur Guleryuz, and
Gonzalez/Woods, Digital Image Processing, 2ed

Lecture Outline
Continuous Fourier Transform (FT)
1D FT (review)
2D FT

Fourier Transform for Discrete Time Sequence


(DTFT)
1D DTFT (review)
2D DTFT

Linear
Li
C
Convolution
l ti
1D, Continuous vs. discrete signals (review)
2D

Filter Design
Computer Implementation

Yao Wang, NYU-Poly

EL5123: Fourier Transform

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

Illustration of Decomposition
3
f
3

f = 11+22+33

o
1

1
Yao Wang, NYU-Poly

EL5123: Fourier Transform

Decomposition
Ortho-normal basis function
1, u1 u2
( x, u1 ) * ( x, u2 )dx 0, u1 u2

Forward
F (u ) f ( x),
) ( x, u )

f ( x)

( x, u )dx
d

Projection of
f(x) onto
(x,u)

Inverse

f ( x)

F (u ) ( x, u )du

Yao Wang, NYU-Poly

Representing f(x) as sum of


(x,u) for all u, with weight
F(u)

EL5123: Fourier Transform

Fourier Transform
Basis function

( x, u ) e

j 2ux

, u , .

Forward Transform
F (u ) F{ f ( x)}

f ( x)e j 2ux dx
d

Inverse Transform

f ( x) F {F (u )} F (u )e j 2ux du
1

Yao Wang, NYU-Poly

EL5123: Fourier Transform

Important Transform Pairs


f ( x) 1
f ( x) e j 2f0 x

F (u ) (u )

F (u ) (u f 0 )
1
f ( x) cos(2f 0 x) F (u ) (u f 0 ) (u f 0 )
2
1
(u f 0 ) (u f 0 )
f ( x) sin( 2f 0 x) F (u )
2j

1, x x0
f ( x)

0, otherwise

F (u )

sin( 2x0u )
2 x0 sinc(2 x0u )
u

sin(t )
where, sinc(t )
t
Derive the last transform pair in class
Yao Wang, NYU-Poly

EL5123: Fourier Transform

FT of the Rectangle Function


sin( 2x0u )
sin(t )
F (u )
2 x0 sinc(2 x0u ) where, sinc(t )
u
t
f(x)

-1

f(x)

x0=1

-2

x0=2

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

IFT of Ideal Low Pass Signal


What is f(x)?
F(u)

-u0

Yao Wang, NYU-Poly

u0

EL5123: Fourier Transform

Representation of FT
Generally, both f(x) and F(u) are complex
Two representations
F (u ) R(u ) jI (u )
Real and Imaginary
Magnitude and Phase
F (u ) A(u )e j (u ) , where
A(u ) R(u ) 2 I (u ) 2 , (u ) tan 1

I (u )
R (u
(u )

I
I(u)

F(u)
(u)

Relationship

R(u) R

R (u ) A(u ) cos (u ),
) I (u ) A(u ) sin
i (u )
Power spectrum
P (u ) A(u ) 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,
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
Linearity

f (t )

F (u )

F (t )

f ( u )

F a1 f1 ( x) a2 f 2 ( x) a1 F{ f1 ( x)} a2 F{ f 2 ( x)}

Scaling
S li

F af ( x) aF{ f ( x)}

Translation
f ( x x0 )

Convolution

F (u )e j 2x0u ,

f ( x)e j 2u0 x

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 ( 2ux 2vyy ) e j 2ux e j 2vyy , u , v , .


Forward Transform

F (u, v) F { f ( x, y )}

f ( x, y )e j 2 (ux vy ) dxdy

Inverse Transform

f ( x, y ) F {F (u , v)}
1

F (u , v)e

j 2 ( ux vy )

dudv

Property
P
t
All the properties of 1D FT apply to 2D FT

Yao Wang, NYU-Poly

EL5123: Fourier Transform

13

Example 1
f ( x, y ) sin 4x cos 6y

f(x,y)

F {sin 4x} sin 4xe j 2 (ux vy ) dxdy


sin 4xe j 2ux dx e j 2vy dy
sin 4xe j 2ux dx (v)
1
( (u 2) (u 2)) (v)
2j
1

( (u 2, v) (u 2, v))
2j

, x y 0
where ( x, y ) ( x) ( y )
0, otherwise

u
F(u,v)
v

1
Likewise, F{cos 6y} ( (u, v 3) (u , v 3))
2
Yao Wang, NYU-Poly

EL5123: Fourier Transform

14

Example 2
f ( x, y ) sin( 2x 3y )

1 j ( 2x 3y ) j ( 2x 3y )
e
e
2j

F e j ( 2x 3y ) e j ( 2x 3y ) e j 2 ( xu yv ) dxdy
e j 2x e j 2ux dx e j 3y e j 2yv dy
3
3
(u 1) (v ) (u 1, v )
2
2
3
Likewise, F e j ( 2x 3y ) (u 1, v )
2
Therefore
h f ,

F sin( 2x 3y )

3
3
1
(u 1, v ) (u 1, v )
2
2
2j

[X,Y]=meshgrid(-2:1/16:2,-2:1/16:2);
[X
Y]=meshgrid( 2:1/16:2 2:1/16:2);
f=sin(2*pi*X+3*pi*Y);
imagesc(f); colormap(gray)
Truesize, axis off;

u
F(u,v)
v

Yao Wang, NYU-Poly

EL5123: Fourier Transform

15

Important Transform Pairs

1
(u f x , v f y ) (u f x , v f y )
sin( 2f x x 2f y y )
2j
1
(u f x , v f y ) (u f x , v f y )
cos(2f x x 2f y y )
2
2D rectangular
g
function 2D sinc function

Yao Wang, NYU-Poly

EL5123: Fourier Transform

16

Properties of 2D FT (1)
Linearity

F a1 f1 ( x, y ) a2 f 2 ( x, y ) a1 F{ f1 ( x, y )} a2 F{ f 2 ( x, y )}

Translation
f ( x x0 , y y0 )
f ( x , y ) e j 2 ( u 0 x v 0 y )

F (u , v)e

j 2 ( x0 u y 0 v )

F (u u0 , v v0 )

Conjugation
f * ( x, y )

Yao Wang, NYU-Poly

F * (u ,v)

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 ( , )dd

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)F
) y((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(3x) cos(5y )
f x ( x) sin((3x)
f y ( y ) cos(5y )

1
(u 3 / 2) (u 3 / 2)
2j
1
Fy (v) (v 5 / 2) (v 5 / 2)
2

Fx (u )

F (u , v) Fx(u ) Fy (v)

5
3
5
1
3
5
3
5
3
(u , v ) (u , v ) (u , v ) (u , v )
4j
2
2
2
2
2
2
2
2

Yao Wang, NYU-Poly

EL5123: Fourier Transform

20

Example 2
1, | x | x0 , | y | y0
f ( x, y )

0, otherwise
F (u , v) 4 x0 y0 sinc(2 x0u ) sinc(2 y0 v)
x
2

u
x0 = 2
y0 = 1

-1
1

-2
2
w/ logrithmic mapping
Yao Wang, NYU-Poly

EL5123: Fourier Transform

21

Rotation
Let x r cos , y r sin , u cos , v sin .
2D FT in polar coordinate (r
(r, ) and (
(, )
F ( , )

f (r , )e j 2 ( r cos cos r sin sin ) rdrd

f (r , )e

j 2r cos( )

rdrd

Property
f (r , 0 )

Yao Wang, NYU-Poly

F ( , 0 )

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 )

f ( n )e

j 2un

F(u)) is
F(
i periodic
i di iin u, with
ith period
i d
of 1

Inverse
I
Transform
T
f
1/ 2

f ( n)

1 / 2

Yao Wang, NYU-Poly

F (u )e j 2un du

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 (-
( , ),
) and u = + is the
highest discrete frequency

Symmetry for real sequences


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

F (u )

N 1

j 2nu

n 0

1 e j 2uN
1 e

j 2u

j ( N 1)u

sin 2u ( N / 2)
sin 2u (1 / 2)

f(n)

N-1

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 j 2 ( mu nv )

m
n

Inverse Transform
1/ 2

f (m, n)

1/ 2

1 / 2 1 / 2

F (u , v)e j 2 ( mu nv ) dudv

Properties
Periodicity, Shifting and Modulation, Energy
Conservation

Yao Wang, NYU-Poly

EL5123: Fourier Transform

27

Periodicity
F (u , v)

f (m, n)e j 2 ( mu nv )

m n

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 j 2 ( m ( u k ) n ( v l ))
e j 2 ( mu nv ) e j 2 ( mk nl )
e j 2 ( 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

Yao Wang, NYU-Poly

-0.5

0.5

EL5123: Fourier Transform

1.0

29

Fourier Transform Types


Band Pass

Low Pass

High Pass

0.5

0.5

0.5

v
0.5

-0.5

-0.5

v
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
F{ f (m m0 , n n0 )}
k m m0 , l n n 0

m n

f (m m0 , n n0 )e j 2 ( mu nv )

f (k , l )e j 2 (( k m0 )u (l n0 ) v )

k l

e j 2 ( m0u n0v )

f (k , l )e j 2 ( ku lv )

k l

f (m m0 , n n0 ) e j 2 ( m0u n0v ) F (u , v)

Modulation

j 2 ( mu0 nv0 )

Yao Wang, NYU-Poly

f (m, n)
EL5123: Fourier Transform

F (u u0 , v v0 )
31

Energy Conservation
Inner Product

f , g

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

m n

m n

0.5 0.5

f (m, n) G * (u , v)e j 2 ( mu nv ) dudv


0.5 0.5

f (m, n)e j 2 ( mu nv ) G * (u , v)dudv


0.5 0.5
m n

0.5

0.5

0.5

0.5

Energy Conservation
0.5 0.5

F (u , v)G * (u , v)dudv F , G

m n

Yao Wang, NYU-Poly

f (m, n)

0 .5

0 .5

0 .5 0 .5

F (u , v) dudv

EL5123: Fourier Transform

32

Delta Function
Fourier transform of a delta function

F (u , v)

(m, n)e j 2 ( mu nv ) 1

m n

(m, n) 1

Inverse Fourier transform of a delta


function
f (m, n)

0.5

0.5

0 .5 0 .5

(u, v)e j 2 ( mu nv ) dudv 1

1 (u, v)
Yao Wang, NYU-Poly

EL5123: Fourier Transform

33

Example
2
1
1
f (m, n) 0
0
0
1 2 1

f(m,n)
n

F (u , v) 1e j 2 ( 1*u 1*v ) 2e j 2 ( 1*u 0*v ) 1e j 2 ( 1*u 1*v )


1e j 2 (1*u 1*v ) 2e j 2 (1*u 0*v ) 1e j 2 (1*u 1*v )
j 2 sin 2ue j 2v j 4 sin 2u j 2 sin 2ue j 2v
j 4 sin 2u (cos 2v 1)
Note: This signal
g
is low p
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)

20
40
60
80
00

20 40 60 80 100

Yao Wang, NYU-Poly

du = [-0.5:0.01:0.5];
d = [[-0.5:0.01:0.5];
dv
0 5 0 01 0 5]
Fu = abs(sin(2 * pi * du));
Fv = cos(2 * pi * dv);
F = 4 * Fu' * (Fv + 1);
mesh(du,
( , dv,, F);
);
colorbar;
Imagesc(F);
colormap(gray); truesize;
EL5123: Fourier Transform

Using MATLAB freqz2:


f=[1,2,1;0,0,0;-1,-2,-1];
freqz2(f)
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 )

Yao Wang, NYU-Poly

f ( x , y )h( , )dd

f ( , )h(x , y )dd

EL5123: Fourier Transform

36

Examples of 1D Convolution
f(x)
1
0

f()h(x-)

h(x-)
x

x-1

x-1
1

x-1 1

(2) 1 x < 2

h(-)
1
1

f(x)*h(x)
1
x
1

Yao Wang, NYU-Poly

f()h(x-)

h(x-)

(1) 0 x < 1

h(x)

EL5123: Fourier Transform

37

Example of 2D Convolution
y
1

h(x-,y-) 1
y

f(x,y)
1

x
(1) 0<x1,
0<x1 0<y1
g(x,y)=x*y

y
1

h(x,y)
1

y
2

f(x,y)*h(x,y)

x-1

(3) 1<x2, 0<y1


g(x,y)=(2-x)*y
( ) (2 )*
2
Yao Wang, NYU-Poly

x 1

(2) 0<x1,
0<x1 1<y2
g(x,y)=x*(2-y)

h(x-,y-)

h(x-,y-)
y 1
y-1
1

h(x-,y-)

y-1
1
x-1 x

(4) 1<x2, 1<y2


g(x y)=(2 x)*(2
g(x,y)=(2-x)
(2-y)
y)

x
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)

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 impulse
p
response
p
((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)
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)
0

n-5

n
0
(a) n < 0, g(n) = 0

h(n)
0

h(n-m)

h(-m)

0 n

n-5

(b) 0 n 8, g(n) > 0


-5

h(n-m)

f(n)*h(n)

n-5

(c) n > 8,
8 g(n) = 0
8

0
Yao Wang, NYU-Poly

n
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 )

k l

f ( k , l ) h( m k , n l )

k l

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

Range
If the range of f(m
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

f(m,n)

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

n
m
h(m,n)

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

k
1

n
f(m,n)*h(m,n) k

h(-k,-l)
1

2
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).
h(m,
(n)
Matrix representation
T
H hx hy
Where hx and hy are column vectors

Example
1 0 1 1
H 2 0 2 21 0 1 hx hTy
1 0 1 1
Yao Wang, NYU-Poly

EL5123: Fourier Transform

44

DTFT of Separable Filter


Previous example
1 0 1 1
H 2 0 2 21 0 1 hx hTy
1 0 1 1

Recognizing that the filter is separable

1
1

0 1 Fy (v) 1e j 2v 0 (1)e j 2v 2 j sin 2v


2 1 Fx(u ) 1e j 2u 2 e j 2u 2 2 cos 2u

F (u, v) Fx(u ) Fy (v) 4 j (1 cos 2u ) sin 2v

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 )
k

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
The size of the image is M*N
M N.
The size of the filter is K*L.

Non-separable
N
bl filt
filtering
i
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


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
M=N,
N K
K=L:
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
adversely
For
F better
b tt results,
lt use
symmetric extension
((mirror image)
g ) to fill the
outside image values

200

200 205

203

203

200

200 205

203

203

195

195 200

200

200

200

200 205

195

195

200

200 205

195

195

Actual image pixels


Yao Wang, NYU-Poly

EL5123: Fourier Transform

Extended pixels
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)

R
Renormalization:
li ti
The filtered value may not be in the range of (0,255) and may not be
integers
Use two-pass
p
operation
p
First pass: save directly filtered value in an intermediate floating-point 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
T display
di l th
the unnormalized
li d iimage di
directly,
tl use i
imagesc(( ) function
f
ti

Yao Wang, NYU-Poly

EL5123: Fourier Transform

51

Sample Matlab Program


% readin bmp file
x = imread('lena.bmp');
[xh xw] = size(x);
y = double(x);

% define 2D filter
h = ones(5,5)/25;
[hh hw] = size(h);
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
z=zeros(xh,xw)
xw) if not low
low-pass
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
%h(0,0)
h(hhh+1,hhw+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
h
25
1
1

1 1 1 1
1 1 1 1
1 1 1 1

1 1 1 1
1 1 1 1

f(m,n)

Yao Wang, NYU-Poly

g(m,n)

EL5123: Fourier Transform

53

What if the filter is symmetric? Can you


write a different MATLAB code that has
reduced computation time?
MATLAB built
built-in
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
Proof

F *H

g (m, n) f (m, n) * h(m, n) f (m k , n l )h(k , l )


k

FT on both sides
G (u , v) f (m k , n l )h(k , l )e j 2 ( mu nv )
m , n k ,l

f (m k , n l )e j 2 (( m k )u ( n l ) v ) h(k , l )e j 2 ( ku lv )
m , n k ,l

f (m k , n l )e j 2 (( m k )u ( n l ) v ) h(k , l )e j 2 ( ku lv )
m,n

k ,l

f (m' , n' )e j 2 ( m 'u n 'v ) h(k , l )e j 2 ( ku lv )


m ', n '

k ,l

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)

-/2

/2

-/4
/

F(u)
( )

-1/

g(x)=f(x)*h(x)

/4

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

H(u)

1/

Yao Wang, NYU-Poly

-2/

2/

EL5123: Fourier Transform

-1/

1/

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
h
25
1
1

Yao Wang, NYU-Poly

1 1 1 1
1 1 1 1
1 1 1 1

1 1 1 1
1 1 1 1

EL5123: Fourier Transform

57

1
1
1
1
h
25
1
1

Yao Wang, NYU-Poly

1 1 1 1
1 1 1 1
1 1 1 1

1 1 1 1
1 1 1 1

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
H1 0 0 0
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(m,n)
(m n) to yield a realizable h(m
h(m,n)
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


Hd(u)

H (u)

hd(x)

Hw(u)

window
function
w(x)

h (x)

hw (x)

x
Hamming window w( x) 0.54 0.46 cos(2

Yao Wang, NYU-Poly

EL5123: Fourier Transform

x
x
), 0 x X
X
62

Homework
1. Let

f ( x, y ) sin 2f 0 ( x y ), h( x, y )

sin(2f c x) sin(2f c y )
2 xy

Find
Fi
d the
h convolved
l d signal
i
l g(x,
( y)) = f(x,
f( y)) * h(x,
h( y)) ffor the
h ffollowing
ll i
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
2
{x, y}
fc ,
h ( x, y )
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 origin is at the center):
a) find their Fourier transforms (2D DTFT);
b) sketch the magnitudes of the Fourier transforms
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, using
g Matlab p
plotting
g 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
H1 1 1 1
9
1 1 1

Yao Wang, NYU-Poly

1 2 1
1

H2

2
12
2

24
1 2 1

EL5123: Fourier Transform

1 2 1
1

H3

2
12
2

24
1 2 1

64

Programming Assignment
1.

2.

3.

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
file. For simplicity
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
right
g most N/2 columns. You should p
properly
p y normalize the filtered image
g
so that the resulting image values can be saved as 8-bit 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
code,
filters. Write down your observation of the effect of the filters.
Optional: Now write a convolution program assuming the filter is
separable. Your program should allow you to specify the horizontal and
vertical filters,
filters and call a 1D convolution sub-program
sub program to accomplish the
2D convolution. Note: you cannot use the MATLAB conv( ) function.
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 3
4.,
3.4,
4 3
3.5,
5 3
3.5
5

Yao Wang, NYU-Poly

EL5123: Fourier Transform

66

Potrebbero piacerti anche