Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
Linear
Li
C
Convolution
l ti
1D, Continuous vs. discrete signals (review)
2D
Filter Design
Computer Implementation
What is a transform?
Transforms are decompositions of a function f(x)
into some basis functions (x, u). u is typically
the freq. index.
Illustration of Decomposition
3
f
3
f = 11+22+33
o
1
1
Yao Wang, NYU-Poly
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
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
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
-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
-u0
u0
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
10
11
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 )
12
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
13
Example 1
f ( x, y ) sin 4x cos 6y
f(x,y)
( (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
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
15
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
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 )
F * (u ,v)
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)
18
Separable Signal
f(x,y) = fx(x)fy(y)
F(u,v)
( ) = Fx((u)F
) y((v),
)
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
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
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 2r cos( )
rdrd
Property
f (r , 0 )
F ( , 0 )
22
Example of Rotation
23
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
F (u )e j 2un du
24
F (u ) F * (u )
F (u ) F (u )
F (u ) is symmetric
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
26
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
27
Periodicity
F (u , v)
f (m, n)e j 2 ( mu nv )
m n
e j 2 ( m ( u k ) n ( v l ))
e j 2 ( mu nv ) e j 2 ( mk nl )
e j 2 ( mu nv )
28
Illustration of Periodicity
u
Low frequencies
1.0
High frequencies
0.5
-1.0
-0.5
0.5
1.0
29
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
30
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 )
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
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
f (m, n)
0 .5
0 .5
0 .5 0 .5
F (u , v) dudv
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
0.5
0.5
0 .5 0 .5
1 (u, v)
Yao Wang, NYU-Poly
33
Example
2
1
1
f (m, n) 0
0
0
1 2 1
f(m,n)
n
34
Graph of F(u,v)
20
40
60
80
00
20 40 60 80 100
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
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( , )dd
f ( , )h(x , y )dd
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
f()h(x-)
h(x-)
(1) 0 x < 1
h(x)
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
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
x
EL5123: Fourier Transform
38
f ( n) * h( n)
f ( n m) h( m)
f ( m) h( n m)
39
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
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
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
41
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
42
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
44
1
1
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
46
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.
48
Computation Cost
Separable:
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
Extended pixels
50
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
51
% 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
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)
g(m,n)
53
54
Convolution Theorem
Convolution Theorem
f *h F H, f h
Proof
F *H
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
k ,l
F (u , v) H (u , v)
Yao Wang, NYU-Poly
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/
-2/
2/
-1/
1/
56
Example
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
57
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
58
59
1 1 1
1
H1 0 0 0
3
1 1 1
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
61
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
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
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
1 2 1
1
H2
2
12
2
24
1 2 1
1 2 1
1
H3
2
12
2
24
1 2 1
64
Programming Assignment
1.
2.
3.
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
66