Вы находитесь на странице: 1из 60

# DFT Domain Image Filtering

Yao Wang
Polytechnic Institute of NYU, Brooklyn, NY 11201
With contribution from Zhu Liu, Onur Guleryuz, and
Gonzalez/Woods, Digital Image Processing, 2ed
Lecture Outline
1D discrete Fourier transform (DFT)
2D discrete Fo rier transform (DFT) 2D discrete Fourier transform (DFT)
Fast Fourier transform (FFT)
DFT domain filtering
1D unitary transform 1D unitary transform
2D unitary transform
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
2
Discrete Fourier Transform (DFT):
DTFT for Finite Duration Signals DTFT for Finite Duration Signals
: becomes ansform Fourier tr
: 1 ,..., 1 , 0 for defined only is signal the If = N n
) 1 , 0 ( , ) 2 exp( ) ( '
1
0
e =

=
f fn j n f (f) F
N
n
t
: (DFT) transform Forward
: yields rescaling and , 1 1 0 at ' Sampling = = ,...,N- , k/N, k f (f) F
( ) f
1 ,..., 1 , 0 , ) 2 exp( ) (
1
' ) (
1
0
= = =

=
N k n
N
k
j n f
N
)
N
k
( F k F
N
n
t
1 ,..., 1 , 0 , ) 2 exp( ) (
1
: (IDFT) transform Inverse
1
= =

N n n
N
k
j k F
N
f(n)
N
t
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
3
0

=
N
N
k
Property of DFT (1)
Periodicity
. modulo represents )) (( where
. 0 ), )) ((( ) (
N k
N k or k k F k F
N
N
> < =
p )) ((
N
)
) (
2 exp( ) (
1
) (
1
1
0
n
N
mN k
j n f
N
mN k F
N
N
n
+
= +

=
t
Proof
A
G
A
G
A
G
F(k)
) ( ) 2 2 exp( ) (
1
1
0
k F mn j n
N
k
j n f
N
N
n
= =

=
t t
B
C
D
E
F
G
B
C
D
E
F
G
B
C
D
E
F
G
0 N-1
N
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
4
low low high
Note: Highest frequency is at k=[N/2]. k=0,1, N-1 represent low frequency.
Property of DFT (2)
Translation
)} / ( 2 { ) ( ) )) ((( N k j k F f
). )) ((( } / 2 exp{ ) (
)} / ( 2 exp{ ) ( ) )) (((
0 0 N
o N o
k k F N n k j n f
N kn j k F n n f

t
t
Special case p
N is even, k
0
= N/2.
) )) ((( ) 1 )( ( } exp{ ) (
n
N
k F n f n j n f = t ). ))
2
((( ) 1 )( ( } exp{ ) (
N
k F n f n j n f = t
Shifting the frequency up by N/2
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
5
g q y p y
Property of DFT (3)
Conjugate symmetry for real sequences
* *
| ) ( | | ) ( |
) ( ) ( ) (
* *
or k N F k F
k N F k F k F
=
= =
. |, )
2
( | | )
2
( | even is N when k
N
F k
N
F = +
0
1 2 3 4 5 6 7
0
1 2 3 4 5 6 7 8
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
6
N=8 N=9
2D Discrete Fourier Transform
Definition
Assuming f(m n) m = 0 1 M 1 n = 0 1 Assuming f(m, n), m = 0, 1, , M-1, n = 0, 1,
, N-1, is a finite length 2D sequence
; 1 1 0 1 1 0 ) (
1
) (
1 1
) ( 2

+
N l M k f l k F
M N
N
ln
M
km
j t
. 1 ,..., 1 , 0 , 1 ,..., 1 , 0 , ) , (
1
) , (
; 1 ,..., 1 , 0 , 1 ,..., 1 , 0 , ) , ( ) , (
1 1
) ( 2
0 0
= = =
= = =

+
= =
N n M m e l k F
MN
n m f
N l M k e n m f
MN
l k F
M N
N
ln
M
km
j
m n
N M
t
Comparing to DTFT
0 0

= =
MN
k l
l
v
k
u e n m f v u F
nv mu j
= = =

+
) ( ) (
) ( 2t
N
v
M
u e n m f v u F
m n
j
= = =

= =
, , ) , ( ) , (
) (
} }
+
=
2 / 1 2 / 1
) ( 2
) , ( ) , ( dudv e v u F n m f
nv mu j t
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
7
} }
2 / 1 2 / 1
) , ( ) , ( dudv e v u F n m f
Property of 2D DFT (1)
Periodicity
0 0 ) )) (( )) ((( ) ( N l or l M k or k l k F l k F > < > < = . 0 , 0 ), )) (( , )) ((( ) , ( N l or l M k or k l k F l k F
N M
> < > < =
A B A B
-M
Low
Frequency
A
C
B
D
A
C
B
D
-M/2
High
Frequency
A B A B
0
(0,0) (0,N-1)
Frequency
C D C D
M
M/2
(M-1,0) (M-1,N-1)
Displayed
area using
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
8
0 N
-N -N/2
N/2
k
l
area using
fftshift
Property of 2D DFT (2)
Translation
)}, / / ( 2 exp{ ) , ( ) )) (( , )) (((
0 0 0 0 N M
N ln M km j l k F n n m m f + t
Special Case: M,N=even, k
0
=M/2, l
0
=N/2
). )) (( , )) ((( )} / / ( 2 exp{ ) , (
0 0 0 0 N M
l l k k F N n l M m k j n m f + t
N M
). ))
2
(( , ))
2
((( ) 1 )( , ( )} ( exp{ ) , (
) (
N M
n m
N
l
M
k F n m f n m j n m f = +
+
t
A B A B
-M
D C D C
-M
A
C
B
D
A
C
B
D
0
-M/2
D
B
C
A
D
B
C
A
0
-M/2
f(m,n)
f(m,n)(-1)
(m+n)
A
C
B
D
A
C
B
D
M/2
D
B
C
A
D
B
C
A
M/2
F(k,l)
F(k-M/2,l-N/2)
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
9
0 N
-N
M
-N/2
N/2
0 N
-N
M
-N/2
N/2
Property of 2D DFT (3)
Conjugate symmetry for real sequences
l N k M F l k F l k F = = ) ( ) ( ) (
* *
even N M for l
N
k
M
F l
N
k
M
F
l N k M F l k F
l N k M F l k F l k F
= = + +
=
, |, )
2
,
2
( | | )
2
,
2
( |
|, ) , ( | ) , ( |
), , ( ) , ( ) , (
2 2 2 2
0
5
10
1
6
11
2
7
12
3
8
13
4
9
14
3
39
35
2
38
34
1
37
33
4
40
36
0
5
10
1
6
11
2
7
12
3
8
13
4
9
14
3
33
30
2
32
29
1
31
28
15
20
20
16
21
25
17
22
26
18
23
27
19
24
28
31
27
23
30
26
22
29
25
21
32
28
24
10
15
20
15
11
16
21
25
12
17
22
26
13
18
23
27
14
19
24
19
30
27
23
18
29
26
22
17
28
25
21
16
M N 8
real
C j t i
15
10
29
33
30
34
31
35
32
36
18
13
17
12
16
11
5 37 38 39 40 8 7 6
19
14
9
10
5
28
31
29
32
30
33
14
9
13
8
12
7
11
6
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
10
M=N=8=even, x x real
Conjugate pairs
M=N=9=odd
Property of 2D DFT (5)
Separabability
2D DFT can be accomplished by N-point 1D DFT of 2D DFT can be accomplished by N point 1D DFT of
each row, followed by M-point 1D DFT of each
column
How many 1D DFTs?
M rows: M N-pt DFTs
N l N M t DFT N columns: N M-pt DFTs
M=N: 2N N-pt DFTs
Each N-pt DFT requires N
2
operations total requiring Each N-pt DFT requires N operations, total requiring
2N
3
operations
Direct calculation
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
11
Requiring M
2
N
2
(N
4
if M=N) operations
Property of 2D DFT (6)
2D DFT of Separable Images
T T
: form matrix In
) ( ) ( ) , ( ) ( ) ( ) , (
F F F f f f
= =
y x y x
l F k F l k F n f m f n m f
T
y x
T
y x
) 1 1 ( ) 1 1 ( ) 0 1 (
) 1 , 0 ( ) 1 , 0 ( ) 0 , 0 (
F F F f f f
(
(
(

= =
N f f f
N f f f

) 1 , 1 ( ) 1 , 1 ( ) 0 , 1 (
) 1 , 1 ( ) 1 , 1 ( ) 0 , 1 (
f
(
(
(

=
N M f M f M f
N f f f

| |
| |
y
DFT 1D pt N
y
x
DFT 1D pt M
x
) 1 ( ) 1 ( ) 0 (
) 1 ( ) 1 ( ) 0 (
F f
F f
=
=

T
y y y
T
x x x
N f f f
M f f f

## Yao Wang, NYU-Poly EL5123: DFT and unitary transform

12
y y y y y
Real images are seldom separable. But many 2D filters are separable.
Computer Implementation of 2D DFT
Complex array structure
Implement comple m ltiplication and Implement complex multiplication and
j2 k /M
Pre-compute the constants: e
-j2km/M
for all
k,m=0, 1, , M-1, and e
-j2ln/N
for all l,n=0,
1, , N-1.
Use separable processing to speed up
For real square image, only need to
calculate half of the points
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
13
calculate half of the points
Display of the Magnitude of 2D DFT
Shifting the low frequency components
into the center into the center
). ))
2
(( , ))
2
((( ) , ( ) 1 )( , ( ) , (
) (
N M
n m
N
l
M
k F l k G n m f n m g = =
+
A B D C
A
B
C D B A
C
D
F(k,l)
G(k,l)
Low
Frequency
High
Frequency
D
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
14
Frequency
Frequency
Matlab command: fftshift
Display of the Magnitude of 2D DFT
Amplitude rescaling )) , ( 1 log( ) , ( l k F l k G + =
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
15
Sample Fourier pairs
Which Fourier transform in the second row is for each image in the first row?
(a) (b) (c) (d)
(e) (f) (g) (h) (e) (f) (g) (h)
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
16
Fast Fourier Transform (FFT)
Direct computation of N-point DFT takes N
2
operations operations
FFT is a fast algorithm for computing DFT,
reducing the computation from N
2
to N log
2
(N) g p g
2
( )
Complex conjugate symmetry of
N kn j
e
/ 2t
( )
*
/ 2 / ) ( 2 / 2 / ) ( 2 N kn j N n k j N kn j N n N k j
e e e e
t t t t
= = =
Periodicity in n and k of
N kn j
e
/ 2t
( ) e e e e = = =
N N k N N k N k / ) ( 2 / ) ( 2 / 2
Matlab function for N-point DFT: fft(A,N),
fft2(A M N)
N n N k j N N n k j N kn j
e e e
/ ) ( 2 / ) ( 2 / 2 + +
= =
t t t
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
17
fft2(A,M,N)
Computation of 2D DFT
2D (MxN) point DFT can be computed in a
separablemanner: separable manner:
First compute N-point FFT for each row (M N
log (N) ) log
2
(N) )
Then compute M-point FFT for each column (N M
log
2
(M) ) log
2
(M) )
Total computation if M=N: 2N
2
log
2
(N)
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
18
Convolution Theorem (1D)
Circular convolution

1 N
Circular convolution Circular convolution (N-pt)

=
=
0
) ( ) )) ((( ) ( ) (
k
N
k h k n f n h n f
f(((n-k))
N
)
f(n) h(n)
Convolution theorem
0
1 2 3 4 n
Convolution theorem Convolution theorem
0
1 2 3 4 n
n
n+1
n+2
n+3
n+4
k
n-1
0
Convolution theorem
) ( ) ( ) ( ) ( k H k F n h n f
Convolution theorem Convolution theorem
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
19
Linear Convolution vs. Circular
Convolution Convolution
f(n): N1 pt, h(n): N2 pt, assume N1>=N2
f(n)*h(n): N=N1+N2-1 pt
Equivalent to circular convolution of M-pt, if
M>=N
If we do N1 pt circular convolution, which parts
of the resulting output is equal to that of linear
convolution (assume N2 is much smaller than
N1)?
Illustrate on board Illustrate on board
If f(n) is from 0 to N1-1, h(n) is from 0 to N2-1
Circular conv. = linear conv. Over N2-1 to N1-1
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
20
Calculate Linear Convolution Using DFT
1D case
f(n) is length N h(n) is length N f(n) is length N
1
, h(n) is length N
2
g(n) = f(n)*h(h) is length N = N
1
+N
2
-1.
T DFT d t t d f( ) d h( ) t To use DFT, need to extend f(n) and h(n) to
f(n) h(n) g(n)
*
Convolution
F(k) H(k) G(k) x
N-point DFT DFT DFT
Multiplication
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
21
Calculate Linear Convolution Using DFT
f(n), N
1
=5 f
e
(n), N=8
F
e
(k)
n
n
k
h(n), N
2
=4 h
e
(n), N=8
H
e
(k)
n
n
k
F (k) H (k)
) ( ) ( ) ( * ) ( n h n f n h n f
e e
=
F
e
(k) H
e
(k)
) ( ) ( ) ( ) ( n h n f n h n f
e e

Yao Wang, NYU-Poly EL5123: DFT and unitary transform
22
k
n
Comparison of Complexity
Direct calculation
Each point N multiplications Each point, N
2
multiplications
Overall, N
2
* N O(N
2
)
Vi FFT Via FFT
N-point FFT for f(n) and h(n)
N multiplications in the DFT domain
N-point inverse FFT for F(k)*H(k)
Overall, 3NlogN + N O(NlogN)
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
23
Circular Convolution (2D)
Circular Convolution

1 1 M N

= =
=
0 0
) , ( ) )) (( , )) ((( ) , ( ) , (
k l
N M
l k h l n k m f n m h n m f
Convolution Theorem
) , ( ) , ( ) , ( ) , ( l k H l k F n m h n m f ) , ( ) , ( ) , ( ) , ( f
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
24
Circular vs. Linear Convolution
If f(m,n) is N1xM1 pt, h(m,n) is N2xm2 pt
f(m n)*h(m n) is NxM pt N=N1+N2- f(m,n) h(m,n) is N xM pt, N =N1+N2-
1,M=M1+M2-1
Equivalent to NxM pt circular convolution if Equivalent to NxM pt circular convolution if
N>=N,M>-M
Can be implemented by using NxM pt 2D Can be implemented by using NxM pt 2D
DFT!
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
25
Separable filter
If the filter is separable,
h(m n)=hx(m) hy(n) h(m,n)=hx(m) hy(n)
Row-by-row circular convolution with hy(n),
then column by column circulua convolution then column-by-column circulua convolution
with hx(m)
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
26
Filtering in DFT Domain
Relation between spatial and frequency domain operation:
)) ( ( ) ( )) ( ( ) (
) , ( ) , ( ) , ( ) , ( ) , ( ) , (
y x h DFT v u H v u H IDFT y x h
v u F v u H v u G y x f y x h y x g
= =
= =
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
27
)). , ( ( ) , ( )), , ( ( ) , ( y x h DFT v u H v u H IDFT y x h = =
Typically DFT size=image size. This corresponds to circular convolution.
Low-Pass Filter Using DFT Window
Filtering in DFT domain:
G(k,l)=H(k,l) F(k,l)
Ideal Low-Pass Filter
H(k,l)= 1 in low frequency range (the four corners!)
= 0 in high frequency range
Can think of H(k,l) as a mask in the DFT domain
The (k,l)th coefficient is unchanged if H(k,l)=1, and is set to zero if
H(k,l)=0.
More generally, H(k,l) can take on higher values in low-
frequency range, and lower values in high frequency
range
Note that equivalent spatial filter is truncated sinc. With
Circular convolution, it leads to ringing artifacts.
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
28
Low-Pass Filter in DFT Domain
The window size where
H(kl)=1is
The window can be implemented in matlab via
H(k,l)=1 is
(2 W1+1)x(2 W2+1)
Before
The window can be implemented in matlab via
R1=zeros(M,1);
R1(1:W1+1,M-W1+1:M)=1;
R2=zeros(N,1);
shifting: note
low frequency
are at four
corners!
( , );
R2(1:W2+1,N-W2+1:N)=1;
H=R1*R2;
Given G(k,l)=F(k,l)H(k,l), matlab may make small numerical errors in
corners!
the inverse transform leading to complex valued images. g(m,n) is
best reconstructed via:
g=real(ifft2(F.*H));
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
29
Example
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
30
Courtesy of Onur Guleyuz
Spatial Filter Corresponding
to Ideal LPF to Ideal LPF
10
20 20
30
40
50
10
20
10 20 30 40 50 60
60
20
30
40
50
IDFT
10 20 30 40 50 60
60
Ideal LPF with Ideal LPF with
W1=W2=10
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
31
To suppress the ringing artifacts, the window function should be smoothed
by an appropriately designed smoothing function.
High Pass Filtering
The high-pass filtered image can be
thought of as the original image minus the thought of as the original image minus the
low pass filtered image.
High pass filtering by DFT windows: High-pass filtering by DFT windows:
If w(k,l) (W1 W2) is a low-pass DFT window,
simply define a high-pass window h(k, l) by h(k, l) p y g p ( , ) y ( , )
= 1 w(k, l).
High-pass filtering in spatial domain:
If L is a low-pass filter of size W, simply define a
high pass filter H via H(m,n) = (m,n) - L(m,n).
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
32
Courtesy of Onur Guleyuz
High Pass Filtering in DFT Domain
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
33
DFT as Unitary Transform
We have so far explained DFT as sampled
version of DTFT for finite duration discrete time
signals
Finite duration discrete time signal = vector (1D)
or image (2D) or image (2D)
Transform = decomposition of vector or image
into a weighted sum of some basis vectors or into a weighted sum of some basis vectors or
images.
Unitary transform : basis functions are
orthonormal to each other
DFT uses a special type of basis functions
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
34
One Dimensional Linear Transform
Let C
N
represent the N dimensional
complex space complex space.
Let h
0
, h
1
, , h
N-1
represent N linearly
independent vectors in C
N
independent vectors in C
N
.
For any vector f C
N
,
1 N
) 0 (
, ) (
1
0
(
= =

=

t
k t
N
k
k
Bt h f
Af f B t = =
1
.
) 1 (
) (
], ,..., , [
1 1 0
(
(
(
(
(

= =

t
where
N

t h h h B
Af f B t = =
f and t form a transform pair
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
35
) 1 (
(

N t
Inner Product
Definition of inner product

1
*
) ( ) (
N
H
f f f f f f
Orthogonal

=
= >= <
0
2 1 2 1 2 1
) ( ) ( ,
n
H
n f n f f f f f
Norm of a vector
0 ,
2 1
>= < f f
Norm of a vector
Normalized: unit norm

=
= >= =<
1
0
2
2
| ) ( | ,
N
n
H
n f f f f f f
1
2
f
Normalized: unit norm
Orthonomal = orthogonal + normalized
1 = f
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
36
Orthonormal Basis Vectors (OBV)
{h
k
, k=0,N-1} are OBV if

= l k 1

=
= >= <
l k
l k
l k l k
0
1
,
,
o h h
f h h h h h f h
H
N N
l k k

) ( ) ( ) (
1 1
f h h h h h f h
H
l k l
k
k
k
l l
l t k t k t = >= < >= >=< <

= =
) ( , ) ( ) ( , ,
0 0
h
(
(

H
0
Af f B f
h
h
t = =
(
(
(
(
(

=
H
H
1
0

h
(
(

H
N 1
. ,
1
I BB B B B B = = =
H H H
or
B is unitary
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
37
. , I BB B B B B or
y
Definition of Unitary Transform
Basis vectors are orthonormal
For ard transform
f h

N
f h k
1
*
) ( ) ( ) (
Forward transform
h
f h
(
(

>= =<
=

H
n
k k
n f n h k t
0
0
*
, ) ( ) ( , ) (
Af f B f
h
h
t = =
(
(
(
(
(

=
H
H
H
1

Inverse transform
h
(

N 1
N
h k f

1
) ( ) ( ) (
Inverse transform
| | t A Bt t h h h h f
H
N
N
k
k
k
k t
n h k t n f
= = = =
=

1 1 0
1
0
) (
, ) ( ) ( ) (

## Yao Wang, NYU-Poly EL5123: DFT and unitary transform

38
| | t A Bt t h h h h f
N
k
k
k t

=
1 1 0
0
) (
Example of 1D Unitary Transform
(
(

(
(

(
(

(
(

2 / 1
2 / 1
2 / 1
2 / 1
2 / 1
2 / 1
2 / 1
2 / 1
(
(
(
(

=
(
(
(
(

=
(
(
(
(

=
(
(
(
(

= ,
2 / 1
2 / 1
,
2 / 1
2 / 1
,
2 / 1
2 / 1
,
2 / 1
2 / 1
3 2 1 0
h h h h

=
(
(

5 1
2 / 1 2 / 1 2 / 1 2 / 1
0
t

=
=

(
(
(
(

=
0
2
3
2
1
0
t
t
f

=
=
(
(

1
0
4
3
3
2
t
t
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
39
Property of Unitary Transform
Energy preservation: ||f||=||t||.
Proof:
t t t t AA t f f f = = = =
H H H H
Proof:
Mean vector relation:
t t t t AA t f f f = = = =
A A h
H
} { }, {
, ,
t f
A A
E and E
where
t f
t
H
f f t
= =
= =
Covariance relation:
, ,
H H
t
H
f
H
f t
where A C A C A AC C = =
Proof:
} ) )( {( }, ) )( {(
H
t t t
H
f f f
E E t t C f f C = =
H H H
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
40
. } ) )( ( { ) (
H
f
H H
f f t f t
E A AC A f f A C f A t = = =
1D DFT as a Unitary Transform
; 1 ..., , 1 , 0 , ) (
1
) (
1
0
2
= =

N k e n f
N
k F
N
n
N
kn
j t
. 1 ..., , 1 , 0 , ) (
1
) (
1
2
0
= =

=
N n e k F
N
n f
N
N
N
kn
j
n
t
,
1
) (
2
= or e
N
n h
N
kn
j
k
t
0 =
N
k
1
1
2
(
(
(

N
N
k
j t
. 1 ,..., 1 , 0 ,
1
) 1 (
2
=
(
(
(
(

N k
e
N
N
k N
j
N
k
t

h
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
41
(

e
N
Example: 1D DFT
( ( (
(

=
) 0 2 exp(
: vectors basis only two are there : case 2
k
j
N
t
h h h
(
(

=
(

=
(
(
(

=
1
1
2
1
,
1
1
2
1
:
) 1
2
2 exp(
) 0
2
2 exp(
2
1
1 0
k
j
j
k
t
t
f h
f
> =<
(

=
obtain we , , Using
, determine ,
2
1
if
1 0
t
t t
k k
( ) ( )
( ( (

= =
|
|
.
|

\
|
(

= = + =
|
|
.
|

\
|
(

=
1 1 1
2
1
2 * 1 1 * 1
2
1
2
1
,
1
1
2
1
,
2
3
2 * 1 1 * 1
2
1
2
1
,
1
1
2
1
1 0
t t
k k
f h h =
(

=
(

= +
2
1
1
1
2
1
1
1
2
3
: Verify
1 1 0 0
t t
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
42
Another Example: 1D DFT
(
(
(

(
(
(

(
(
(

(
(
(

(
(
(
(
(

1
1
1
1
1
1
1
1
1
1
) 1
4
2 exp(
) 0
4
2 exp(
1
j j
k
j
k
j
t
t
h h h h h
(
(
(

=
(
(
(

=
(
(
(

=
(
(
(

=
(
(
(
(
(

= =
1 2
1
;
1
1
1
2
1
;
1 2
1
;
1
1
1
2
1
: yields
) 3
4
2 exp(
) 2
4
2 exp(
4
2
1
using : case 4
3 2 1 0
j
j
j
j
k
j
k
j
N
k
t
t
( ) ( )
f
+ = + = = + + + =
(
(
(

); 3 (
2
1
3 5 4 2
2
1
; 7 3 5 4 2
2
1
4
2
4
1 0
j j j t t
( ) ( ) ( )
f
(
(

(
(

+
= + = = + =

(
(
(

=
8 ) 3 ( ) 3 ( 14
. 3
2
1
3 5 4 2
2
1
; 0 3 5 4 2
2
1
2 2 2
3
5
3 2
j j
j j j t t
f h h h h =
(
(
(
(

=
(
(
(
(

+ +
+ + +
+ +
= + + +
12
20
16
4
1
) 3 ( ) 3 ( 14
) 3 ( ) 3 ( 14
) 3 ( ) 3 ( 14
4
1
: Verify
3 3 2 2 1 1 0 0
j j j j
j j
j j j j
t t t t
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
43
Two Dimensional Decomposition
Decompose an MxN 2D matrix F=[F(m,n)]
into a linear combination of some basic into a linear combination of some basic
images, H
k,l
=[H
k,l
(m,n)], so that:

=
=
1
0
1
0
,
, ) , (
M
k
N
l
l k
l k T H F

= =
=
1 1
,
0 0
) , ( ) , ( ) , (
M N
l k
k l
n m H l k T n m F
= = 0 0 k l
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
44
Graphical Interpretation
+
t
1 t
2
t
3
t
4
t
1 t
2
t
3
t
4
Inverse transform: Represent a vector (e.g. a block of image samples) as the
superposition of some basis vectors (block patterns)
Forward transform: Determine the coefficients associated with each basis vector
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
45
Two Dimensional Inner Product
Inner Product

1 1
*
M N
Norm of a Matrix

= =
>= <
0 0
2
*
1 2 1
) , ( ) , ( ,
m n
n m F n m F F F
Norm of a Matrix

>= =<
1
0
1
0
2
) , ( ,
M N
n m F F F F
A set of basis images {H
k,l
, k=0,1,,M-1,
l=0 1 N-1} is orthonormal if
= = 0 0 m n
l=0,1,,N-1} is orthonormal if

= =
= >= <
otherwise
j l i k if
j l i k j i l k
0
, , 1
,
, , , ,
o o H H
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
46

otherwise , 0
Two Dimensional Unitary Transform
{H
k,l
} is an orthonormal set of basis images
For ard transform Forward transform

>= =<
1 1
*
) ( ) ( ) (
M N
n m F n m H l k T F H
Inverse transform

= =
>= =<
0 0
, ,
) , ( ) , ( , ) , (
m n
l k l k
n m F n m H l k T F H
Inverse transform

=
=
1
0
1
0
,
, ) , ( ) , ( ) , (
M
k
N
l
l k
or n m H l k T n m F

=
=
1
0
1
0
,
) , (
M
k
N
l
l k
l k T H F
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
47
Example of 2D Unitary Transform
=
(

=
(

=
(

=
(

=
5 ) 0 , 0 (
,
2 / 1 2 / 1
2 / 1 2 / 1
,
2 / 1 2 / 1
2 / 1 2 / 1
,
2 / 1 2 / 1
2 / 1 2 / 1
,
2 / 1 2 / 1
2 / 1 2 / 1
11 10 01 00
T
H H H H

=
=
=

=
0 ) 1 , 1 (
1 ) 0 , 1 (
2 ) 1 , 0 (
) , (
4 3
2 1
T
T
T
F

0 ) 1 , 1 ( T
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
48
2D DFT as a Unitary Transform
. 1 ,..., 1 , 0 , 1 ,..., 1 , 0 , ) , (
1
) , (
1
0
1
0
) ( 2
= = =

=
+
N n M m e l k F
MN
n m f
M
k
N
l
N
ln
M
km
j t
|
.
|

\
|
+
N
ln
M
km
j t 2
1
|
.

\
=
N M
j
l k
e
MN
n m H
,
1
) , (
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
49
Basis Images for 8x8 DFT (Real Part)
Basis Images for 8x8 DFT (Imaginary Part)
Notice how the frequency content of the basis images change !
Separable Unitary Transform
Let h
k
, k=0, 1, , M-1 represent
orthonormal basis vectors in C
M
orthonormal basis vectors in C ,
Let g
l
, l=0, 1, , N-1 represent
orthonormal basis vectors in C
N
orthonormal basis vectors in C
N
,
H
k,l
=h
k
g
l
T
, or H
k,l
(m,n)=h
k
(m)g
l
(n).
Then H
k,l
will form an orthonormal basis
set in C
MxN
.
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
50
Example of Separable Unitary Transform
Example 1
( (
2 / 1 2 / 1
(
(

(
(

=
(

=
2 / 1 2 / 1 2 / 1 2 / 1
.
2 / 1
2 / 1
,
2 / 1
2 / 1
1 0
T T
h h H h h H
h h
(

= =
(

= =
(

= =
(

= =
2 / 1 2 / 1
2 / 1 2 / 1
2 / 1 2 / 1
2 / 1 2 / 1
2 / 1 2 / 1 2 / 1 2 / 1
1 1 11 0 1 10
1 0 01 0 0 00
T T
h h H h h H
h h H h h H
2D DFT

2 / 1 2 / 1 2 / 1 2 / 1
N
ln
M
km
j
e n m H
t 2
1
) ( =
|
.
|

\
|
+
N
ln
j
l
M
km
j
k
l k
e
N
n g e
M
m h
e
MN
n m H
t t 2 2
,
1
) ( ,
1
) (
, ) , (
= =
=
. \
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
51
N M
Example: 4x4 DFT
(
(
(
(
(

=
(
(
(
(
(

=
(
(
(
(
(

=
(
(
(
(
(

=
1
1
2
1
;
1
1
1
2
1
;
1
1
2
1
;
1
1
1
2
1
: are basis DFT 1D the Recall
3 2 1 0
j j
h h h h
( )
(
(
(

(
(
(

(
(
(

(
(
(

=
(

1 1
1 1
1
1 1 1 1
1 1 1 1
1
1 1
1 1
1
1 1 1 1
1 1 1 1
1
: yields using
1 1
j j
j j
j j
j j
j j
T
l k k,l
h h H
(
(
(

(
(
(

(
(
(

(
(
(

(
(
(

=
(
(
(

=
(
(
(

=
(
(
(

=
1 1
1 1
1
1 1 1 1
1
1 1
1 1
1
1 1 1 1
1
1 1
1 1 4
1
,
1 1 1 1
1 1 1 1 4
1
,
1 1
1 1 4
1
,
1 1 1 1
1 1 1 1 4
1
3 , 0 2 , 0 1 , 0 0 , 0
j j
j j
j j j j j j
j j
j j j j
j j
j j
j j
j j
j j
j j
H H H H
H H H H
(
(
(
(

=
(
(
(
(

=
(
(
(
(

=
(
(
(
(

= H
(
(
(

=
(
(
(

=
(
(
(

=
(
(
(

=
1 1
1 1
1
1 1 1 1
1 1 1 1
1
1 1
1 1
1
1 1 1 1
1 1 1 1
1
1 1
1 1 4
,
1 1 1 1 4
,
1 1
1 1 4
,
1 1 1 1 4
3 , 1 2 , 1 1 , 1 0 , 1
j j
j j
j j
j j
j j
j j
j j j j j j
j j
j j j j
H H H
H H H H
(
(
(
(

=
(
(
(
(

=
(
(
(
(

=
(
(
(
(

=
(
(
(

=
(
(
(

=
(
(
(

=
(
(
(

= H
1 1
1 1
1
,
1 1 1 1
1
,
1 1
1 1
1
,
1 1 1 1
1
1 1
1 1 4
,
1 1 1 1
1 1 1 1 4
,
1 1
1 1 4
,
1 1 1 1
1 1 1 1 4
3 3 2 3 1 3 0 3
3 , 2 2 , 2 1 , 2 0 , 2
j j
j j
j j j j j j
j j
j j j j
j j
j j
j j
j j
H H H H
H H H
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
52
(
(

(
(

(
(

(
(

1 1
1 1 4
,
1 1 1 1 4
,
1 1
1 1 4
,
1 1 1 1 4
3 , 3 2 , 3 1 , 3 0 , 3
j j
j j
j j j j j j
j j
j j j j
Example: 4x4 DFT
comp te
1 3 1 0
0 2 2 1
For T
(
(
(

F
0 2 2 1 1 1 1 1
e.g, yields, , Using
compute ,
1 2 2 1
1 2 1 0
For
, ,
,
T
T
l k l k
l k
|
|

|
(
(

(
(

> =<
(
(
(

=
F H
F
( )
0 2 2 1 1 1
4
18
1 2 2 1 1 2 1 0 1 3 1 0 0 2 2 1
4
1
1 2 2 1
1 2 1 0
1 3 1 0
,
1 1 1 1
1 1 1 1
1 1 1 1
4
1
,
*
0 , 0 0 , 0
j j
T
|
|

|
(
(

(
(

= + + + + + + + + + + + + + + =
|
|
|
|
|
.

\
(
(
(
(

(
(
(
(

>= =< F H
( ) ) 1 (
4
1
2 2 1 2 3 2 2 1
4
1
1 2 2 1
1 2 1 0
1 3 1 0
,
1 1
1 1
1 1
4
1
,
3 , 2 3 , 2
j j j j j j j j
j j
j j
j j
T = + + + + + =
|
|
|
|
|
.

\
(
(
(
(

(
(
(
(

>= =< F H
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
53
Property of Separable Transform
When the transform is separable, we can
perform the 2D transform separately perform the 2D transform separately.
First, do 1D transform for each row using
basis vectors g basis vectors g
l
,
Second, do 1D transform for each column of
the intermediate image using basis vectors h
k
the intermediate image using basis vectors h
k
.
Proof:
1 1 1 1 1 M M N M N

= = = = =
= = =
0
*
0 0
* *
0 0
*
,
) , ( ) ( ) , ( ) ( ) ( ) , ( ) , ( ) , (
m m n
l
m n
l k
l m U m h n m F n g m h n m F n m H l k T
k k
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
54
Computational Savings of
Separable Transform Separable Transform
A MxN transform takes about MxN
calculations for each transform value, calculations for each transform value,
and the total number of calculation is
M
2
N
2
(N
4
if M=N) ( )
If the transform is separable
1. Calculate M N-point 1D transform, each p ,
requiring N
2
calculations
2. Calculate N M-point 1D transform, each
i i M
2
l l ti requiring M
2
calculations
3. Overall: MN
2
+NM
2
(2N
3
, if M=N)
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
55
Other Transforms
Discrete cosine transform (DCT)
Basis functions are real
Can be thought of as real version of DFT Can be thought of as real version of DFT
We will discuss DCT and its application in image compression
(JPEG) later
Discrete sine transform (DST) sc ete s e t a s o ( S )
Walsh transform
Haar transform Haar transform
Slant transform
Wavelet transform
Multi-resolution transform
We will discuss wavelet transform and its application in image
compression (JPEG2000) later
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
56
Homework
1. Find the NxN point DFT of the following 2D image f(m, n), 0 m, n N:
a) f(m, n) = 1, n = 0; f(m, n) = 0; n 0.
b) f( ) 1 0 f( ) 0 0 b) f(m, n) = 1, m = 0; f(m, n) = 0, m 0.
c) f(m, n) = 1, m = n; f(m, n) = 0, otherwise.
d) f(m, n) = 1, m = N 1- n; f(m, n) = 0, otherwise.
From the result, what can you say about the relation between the directionality of an
image with that of its DFT?
2. One can use the DFT algorithms to compute the linear convolution of an image F(m,
n) with a filter H(m n) Let the convolved image be denoted by Y(m n) n) with a filter H(m, n). Let the convolved image be denoted by Y(m, n).
i) Suppose the image size is 256x256 and the filter size is 11x11: What is the
required size of the DFT to obtain the convolution of these two? Explain the exact
steps to obtain the convolution result.
ii) Suppose we use a 256x256 point DFT algorithm for F(m, n) and H(m, n), and
obtain Z(m, n) as follows: Z = IDFT (DFT(X).*DFT(H)). The DFT and IDFT in the
above equation are both 256x256 points. For what values of (m, n) does Z(m, n)
equal Y(m, n) ?
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
57
Homework (cntd)
3. Show that the following vectors form an orthonormal basis set for any value of u:
(

=
(

=
u
u
u
u
cos
sin
,
sin
cos
1 0
h h
Determine the corresponding matrix A and B for the forward and inverse transform described by
4. Consider a zero mean random vector u with covariance matrix
( 1
. : transform Inverse ; : transform Forward Bt f Af t = =
From the class of unitary transforms given in Prob. 3, determine the value of for which the
components of transformed vector v will be uncorrelated (i.e., the covariance matrix of the
transformed vector is a diagonal matrix).
(

=
1
1

u
C
5. The basis images of the 2D-DCT are:
;
1 1
1 1
2
1
;
1 1
1 1
2
1
;
1 1
1 1
2
1
;
1 1
1 1
2
1
11 10 01 00 (

=
(

=
(

=
(

= H H H H
Calculate the transform of the image:
Find the reconstructed image obtained with the 2 largest coefficients (in magnitude). Calculate
the error between the original and reconstructed images defined by You
F

= n m F n m F E
2
)] , (

) , ( [
(

=
3 2
2 1
F
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
58
the error between the original and reconstructed images defined by You
should see that where t(k, l) represents the transform coefficient
associated with the basis image H
kl
.

n m,
)] , ( ) , ( [

=
omitted are l k t l k
l k t E
) , ( : ,
2
| ) , ( |
Computer Assignment
1. Perform 2D DFT (using the fft2 function in Matlab) on several test images of your choice
(sample images are available at the Matlab image toolbox directory). Display the magnitude of
the DFT image with and without shifting (using fftshift) and with and without logarithmic
mapping, to see the effect of shifting and logarithmic mapping. Include the printouts in your
submission Also examine in which frequency range the DFT coefficients have large submission. Also, examine in which frequency range the DFT coefficients have large
magnitudes and explain why. Note that you may want to work on a small portion of your image
(say 256x256 or less), to save computation time.
Note that if your image is an RGB image, you should convert it to a grayscale image using
"rgb2gray" function and apply the above operations on the grayscale image only. If the original
image is an index image, you should not apply DFT to the index image directly, rather you
should derive the grayscale image from it, using the "ind2gray" function.
2. Write a program (in Matlab or C) which filters an image by zeroing out certain DFT coefficients.
The program consists of 3 steps:
1) performing 2D DFT (you can use the fft2" function in Matlab);
2) zeroing out the coefficients at certain frequencies (see below); ) g ( )
3) performing inverse DFT to get back a filtered image. Truncate or scale the image properly
such that its range is between 0 and 255.
For part 2, try the following two types of filters:
(a) let F(k, l) = 0 for TN < {k, l} < (1 - T )N, T = 1/4, 1/8 (i.e., low-pass filtering);
(b) let F(k, l) = 0 for the following regions i) 0 {k and l} TN;ii) 0<= k <=TN, and (1 - T)N l (b) let F(k, l) 0 for the following regions i) 0 {k and l} TN;ii) 0 k TN, and (1 T)N l
N -1;iii) (1 - T)N k N -1 and 0 {l} TN; iv)(1 - T)N k and l N -1;T=1/4, 1/8
Compare the original and processed images. Comment on the function of the two types of
filters.
Yao Wang, NYU-Poly EL5123: DFT and unitary transform
59