Professional Documents
Culture Documents
3-2020-? Lecture 4
Spatial domain
Fourier Transform
Fourier Transform
• Basic ideas:
A periodic function can be
represented by the sum of
sines/cosines functions of different
frequencies, multiplied by a
different coefficient.
Non-periodic functions can also be
represented as the integral of
sines/cosines multiplied by weighing
function.
Joseph Fourier (1768-1830)
Fourier was obsessed with the physics of heat and
developed the Fourier transform theory to model
heat-flow problems. Fourier was born in
Auxerre, France
E ( x) [ f ( x) f ( x)] / 2
E(-x) = E(x)
O( x) [ f ( x) f ( x)] / 2
O(-x) = -O(x)
f ( x) E ( x) O( x)
Approximating a square wave
as the sum of sine waves.
Fourier Cosine Series
Because cos(mt) is an even function, we can write an even function, f(t) as:
F
1
f(t) m cos(mt)
m 0
where series Fm is computed as Fm f (t ) cos(mt ) dt
Fourier Series
So if f(t) is a general function, neither even nor odd, it can be written:
1 1
f (t )
m 0
Fm cos(mt )
m 0
Fm sin(mt )
Even component Odd component
where the Fourier series is
Fm
f (t) cos(mt) dt Fm
f (t) sin(mt) dt
Fourier Transform
Let F(m) incorporates both cosine and sine series coefficients, with the
sine series distinguished by making it the imaginary component:
F (m) Fm jFm' f (t ) cos(mt )dt j f (t ) sin(mt )dt
j ( u )
F (u ) F (u ) e
Phase Spectrum
Amplitude Spectrum
(a) A discrete
function of M
points ,
(b)its Fourier
spectrum.
(c) A discrete
function with twice
number of nonzero
points ,
(d)itsu·x
Fourier
1/M
spectrum
d a
c b
8
Discrete Fourier Transform(DFT)
• A continuous function f(x) is discretized as:
f(t)
{ f ( t0 ), f ( t0 t ), f ( t0 2 t ),..., f ( t0 ( M 1) t )}
f(t0+∆t)
f(t0+2∆t)
f(t0)
f(t0+3∆t) F[t0+(N-1)∆t]
∆t
t
t0 t1 t2 t3 tN-1
• The discrete Fourier transform pair that applies to sampled functions
is given by: M 1 1
F (u ) f ( x ) exp( j 2ux / M ) u=0,1,2,…,M-1
M x 0
M 1
f ( x ) F ( u ) exp( j 2ux / M ) x=0,1,2,…,M-1
u 0 9
2D-Discrete Fourier Transform(DFT)
M 1 N 1
• In 2-D case, the DFT pair is: F ( u ,v ) 1 f ( x , y ) exp( j 2 ( ux / M vy / N ))
MN x 0 y 0
Separability
Translation or Shifting
DFT Properties
Periodicity and Conjugate Symmetry
Rotation
Distributivity
Scalling
Convolution
10
Correlation
Separability
• The 2D DFT can be computed using 1D transforms only:
:Forward DFT
:Inverse DFT
ux vy ux vy
j 2 ( ) j 2 ( ) j 2 ( )
e N
e N
e N
• Let’s set:
• Then:
Separability
• How can we compute F(x,v)? of row s o f f( x,y)
N x DFT
It implies that shift in f(x,y) does not affect the magnitude of its Fourier
transform. This is important because the visual examination of transform
is usually limited to a display of its magnitude.
Periodicity and Conjugate Symmetry
The DFT and IDFT are periodic with period N ; that is
Scaling
This property is best summarized by "a contraction in one domain produces
corresponding expansion in the Fourier domain".
Convolution
The convolution of two functions f(x) and g(x) is defined by the integral:
The Convolution Theorem tells us that convolution in the spatial domain corresponds
to multiplication in the frequency domain, and vice versa.
Correlation
One of the principal applications of correlation in image processing is in
the area of template or prototype matching i.e. finding the closest match
between an unknown image and a set of known images
Image
v Detail
General appearance
Magnitude and Phase of DFT
• What is more important?
magnitude phase
2048
DFT FFT
N 1
X k x n W Nnk ; 0 k N 1 x[n] = x[0], x[1], …, x[N-1]
n 0
Lets divide the sequence x[n] into even and odd sequences:
x[2n] = x[0], x[2], …, x[N-2]
x[2n+1] = x[1], x[3], …, x[N-1]
N N
1 1
• Equation 1 can be rewritten as:
2 2 2 n 1 k
X k x 2 n WN2 nk x 2 n 1 W N
n 0 n 0
2 2
j nk
2 nk
j
N
2 nk
N 2 2 n 1 k W k W nk
WN
WN e e N N
• Since 2
nk
WN
2
N N
• Then: 2
1
2
1
X k nk W k
x 2 n W N N
x 2 n 1 W nk
N
n 0 n0
2 2
Y k
k
WN Z k
DFT FFT
• The result is that an N-point DFT can be divided into two N/2 point
DFT’s: N 1
X k x nWNnk ; 0 k N 1 N-point DFT
n 0
Where Y(k) and Z(k) are the two N/2 point DFTs operating on even
and odd samples respectively:
N N
1 1
2 2
X k x
1 N N
n W nk
W k
x
2 Nn W nk Two N/2-point DFTs
n 0 2 n 0 2
Y k WNk Z k
DFT FFT
• Periodicity and symmetry of W can be exploited to simplify the DFT
further: N
1
N
1
2 2
X k
n 0
x1 n W Nnk W Nk
n 0
x2 nW Nnk
2 2
N N
1 N 1 N
2 n k 2 n k
N N
X k
2
n 0
x1 n W N 2 k
WN 2 x2
n 0
n W N 2
2 2
:Or
N 2 2 N 2 2
k j k j j k j k
WN 2
e N
e N 2
e N
e j e N
W Nk : Symmetry
N 2 2 N 2
k j k j j k
e e WNk Periodicity :
:And
N 2 N 22 N 2
W N
2
e
2 2
DFT →FFT
DFT →FFT
• Symmetry and periodicity:
W86
W85 W87
WNk+N/2 = -WNk
W8 4 WN/2k+N/2 = WN/2k
W80 = W88
W8k+4 = -W8k
W83 W81 = W89 W8k+8 = W8k
W82
• Finally by exploiting the symmetry and periodicity,
Equation 3 can be written as:
N N
1 1
N 2 2
X k x1 nW Nnk WNk x2 nW Nnk
2 n 0 n0
]4[
2 2
Y k WNk Z k
DFT FFT
N
X k Y k W Nk Z k ; k 0, 1
2
N N
X k Y k WNk Z k ; k 0, 1
2 2
Y(k) and WNk Z(k) only need to be calculated once and used for both
equations.
Note: the calculation is reduced from 0 to N-1 to 0 to (N/2 - 1).
X k
Y k
k
WN Z k ; k 0 ,
N
2
1
X k
N
2
Y k k
WN Z k ; k 0 ,
N
2
1
Y(k) and Z(k) can also be divided into N/4 point DFTs using the same
process shown above:
The process continues Y k U k W Nk V k Z k P k W Nk Q k
until we reach 2 point 2 2
DFTs N
N
Z k P k W Nk Q k
Y k U k W Nk V k
4 2 4 2
FFT Implementation
FFT Implementation
Example: 8 point FFT
W0 1-
W0 1-
W0 1- W2 1-
W0 1-
W0 1-
W1 1-
W0
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
W0 1- W2 1-
W0 1-
W0 1-
W1 1-
W0
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
Nstages = 1
W0 1- W2 1-
W0 1-
W0 1-
W1 1-
W0
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
Nstages = 2
W0 1- W2 1-
W0 1-
W0 1-
W1 1-
W0
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
Nstages = 3
W0 1- W2 1-
W0 1-
W0 1-
W1 1-
W0
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
W0 1- W2 1-
Nstages = 3
W0 1-
(2) Blocks/stage:
W0 1-
W0
W1 1- Stage 1:
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
W0 1- W2 1-
Nstages = 3
W0 1-
(2) Blocks/stage:
W0 1-
W0
W1 1- Stage 1: Nblocks
W0 1- W2 1-
=1
W0 1- W2 1- W3 1-
W0 1-
Nstages = 3
Block 2
W0 1- W2 1-
(2) Blocks/stage:
W0 1- Stage 1: Nblocks
=2
W0 1-
W1 1-
W0
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
Nstages = 3
Block 2
W0 1- W2 1-
(2) Blocks/stage:
Block 3 W0 1- Stage 1: Nblocks = 3
W0 1-
W1 1-
W0
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
Nstages = 3
Block 2
W0 1- W2 1-
(2) Blocks/stage:
Block 3 W0 1- Stage 1: Nblocks = 4
W0 1-
W1 1-
W0
W0 1- W2 1-
Block 4
W0 1- W2 1- W3 1-
W0 1-
W0 1- W2 1-
Nstages = 3
W0 1-
(2) Blocks/stage:
W0 1-
W0
W1 1- Stage 1: Nblocks
W0 1- W2 1-
=1
W0 1- W2 1- W3 1-
W0 1- W2 1- W3 1-
W0 1- W2 1- W3 1-
W0 1-
Nstages = 3
Block 1
W0 1- W2 1-
(2) Blocks/stage:
W0 1- Stage 1: Nblocks = 4
W0 1-
W1 1-
Stage 2: Nblocks = 2
W0
W0 1- W2 1-
W0 1- W2 1- W3 1- Stage 3: Nblocks = 1
W0 1-
(2) Blocks/stage:
Stage 1: Nblocks = 4
W0 1- W2 1-
Stage 2: Nblocks = 2
Stage 3: Nblocks = 1
W0 1-
W0 1-
1-
(3) B’flies/block:
W1
W0
Stage 1:
W0 1- W2 1-
W0 1- W2 1- W3 1-
W0 1-
W1 1-
Stage 3: Nblocks = 1
W0
W0 1- W2 1- (3) B’flies/block:
W0 1- W2 1- W3 1-
Stage 1: Nbtf = 1
W0 1-
W1 1-
Stage 3: Nblocks = 1
W0
W0 1- W2 1- (3) B’flies/block:
W0 1- W2 1- W3 1-
Stage 1: Nbtf = 1
Stage 2: Nbtf = 1
• Decimation in time FFT:
– Number of stages = log2N
– Number of blocks/stage = N/2stage
– Number of butterflies/block = 2stage-1
FFT Implementation
FFT Implementation
Stage 1 Stage 2 Stage 3
Example: 8 point FFT
(1) Number of stages:
W0 1- Nstages = 3
W0 1- (2) Blocks/stage:
W0 1- W2 1- Stage 1: Nblocks = 4
Stage 2: Nblocks = 2
W0 1-
W0 1-
W1 1-
Stage 3: Nblocks = 1
W0
W0 1- W2 1- (3) B’flies/block:
W0 1- W2 1- W3 1-
Stage 1: Nbtf = 1
Stage 2: Nbtf = 2
• Decimation in time FFT:
– Number of stages = log2N
– Number of blocks/stage = N/2stage
– Number of butterflies/block = 2stage-1
FFT Implementation
FFT Implementation
Stage 1 Stage 2 Stage 3
Example: 8 point FFT
(1) Number of stages:
W0 1- Nstages = 3
W0 1- (2) Blocks/stage:
W0 1- W2 1- Stage 1: Nblocks = 4
Stage 2: Nblocks = 2
W0 1-
W0 1-
W1 1-
Stage 3: Nblocks = 1
W0
W0 1- W2 1- (3) B’flies/block:
W0 1- W2 1- W3 1-
Stage 1: Nbtf = 1
Stage 2: Nbtf = 2
• Decimation in time FFT: Stage 3: Nbtf = 1
– Number of stages = log2N
– Number of blocks/stage = N/2stage
– Number of butterflies/block = 2stage-1
FFT Implementation
FFT Implementation
Stage 1 Stage 2 Stage 3
Example: 8 point FFT
(1) Number of stages:
W0 1- Nstages = 3
W0 1- (2) Blocks/stage:
W0 1- W2 1- Stage 1: Nblocks = 4
Stage 2: Nblocks = 2
W0 1-
W0 1-
W1 1-
Stage 3: Nblocks = 1
W0
W0 1- W2 1- (3) B’flies/block:
W0 1- W2 1- W3 1-
Stage 1: Nbtf = 1
Stage 2: Nbtf = 2
• Decimation in time FFT: Stage 3: Nbtf = 2
– Number of stages = log2N
– Number of blocks/stage = N/2stage
– Number of butterflies/block = 2stage-1
FFT Implementation
FFT Implementation
Stage 1 Stage 2 Stage 3
Example: 8 point FFT
(1) Number of stages:
W0 1- Nstages = 3
W0 1- (2) Blocks/stage:
W0 1- W2 1- Stage 1: Nblocks = 4
Stage 2: Nblocks = 2
W0 1-
W0 1-
W1 1-
Stage 3: Nblocks = 1
W0
W0 1- W2 1- (3) B’flies/block:
W0 1- W2 1- W3 1-
Stage 1: Nbtf = 1
Stage 2: Nbtf = 2
• Decimation in time FFT:
Stage 3: Nbtf = 3
– Number of stages = log2N
– Number of blocks/stage = N/2stage
– Number of butterflies/block = 2stage-1
FFT Implementation
FFT Implementation
Stage 1 Stage 2 Stage 3
Example: 8 point FFT
(1) Number of stages:
W0 1- Nstages = 3
W0 1- (2) Blocks/stage:
W0 1- W2 1- Stage 1: Nblocks = 4
Stage 2: Nblocks = 2
W0 1-
W0 1-
W1 1-
Stage 3: Nblocks = 1
W0
W0 1- W2 1- (3) B’flies/block:
W0 1- W2 1- W3 1-
Stage 1: Nbtf = 1
Stage 2: Nbtf = 2
• Decimation in time FFT: Stage 3: Nbtf = 4
– Number of stages = log2N
– Number of blocks/stage = N/2stage
– Number of butterflies/block = 2stage-1
8-Point FFT
8-Point FFT Diagram
Diagram
WN0 1
WN0 1
WN0 1 WN2 1
WN0 1
WN0 1 WN1 1
WN0 1 WN2 1
WN0 1 WN2 WN3
1 1
Y = fft2(X,m,n)
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0 0
1 1 1 1 1 0 0 4 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0 0
Horizontal PSF mask with uniform blur Vertical PSF mask with center-weighting
0 0 0 0 1 0 1 1 1 0
0 0 0 2 0 1 2 4 2 1
0 0 4 0 0 1 4 8 4 1
0 2 0 0 0 1 2 4 2 1
0 1 1 1 0
1 0 0 0 0
Diagonal PSF mask Circular PSF mask with
with gaussian distribution Gaussian distribution
After the PSF mask has been selected, the mask must be padded with
zeros up to the size of the image.
Then the zero-padded mask must be shifted, with wrap-around, so that the
center of the original mask is at the point (0,0) in the image (at the upper
left corner).
Then Fourier transform is performed
• The frequency domain filters incorporate information regarding the
noise and the PSF into their model.
– D(u,v) = H(u,v)I(u,v) + N(u,v)
• To obtain the restored image, the general form is as follows:
-1 -
– Î(r,c) = F [Î(u,v)] = F 1[Rtype(u,v)D(u,v)]
– Rtype(u,v) is the frequency domain filter.
Inverse Filter
• The inverse filter uses the typical model with the assumption of no
noise (N(u,v) = 0).
– D(u,v) = H(u,v)I(u,v) + 0
• The fourier transform of the original image can be found as follows:
D(u, v) 1
I (u, v) D(u, v)
H (u, v) H (u , v)
2
cy = 3 4
Original Image Image blurred with 11x11
f f fre q u e n
e ta i ls e ncy=6 s
to d u l
Gaussian convolution mask
e fil ter, cu ed to show ff freq w detai
s o o
Inver am stretch l t e
t
r, cu ed to s
h
g r i h
Histo nv e rse f stretc
I m
ogra
Hist
5
re q u e ncy = 9
f details
t e r, cutoff s h o w
e fil d to
Invers m stretche
ra
Histog Inverse filter, cutoff frequency = 120
Histogram stretched to show details
Wiener Filter
• The Wiener filter is also called the minimum mean-square estimator.
• It can solve some of the weaknesses of the inverse filter.
– This is done by attempting to model the error in the restored image
using statistical methods.
– After the error is modeled, the average error is mathematically
minimized.
H * (u , v)
RW (u , v)
2 S n (u , v )
H (u , v)
S I (u , v)
H*(u,v) = complex conjugate of H(u,v)
Sn(u,v) = |N(u,v)|2 = power spectrum of the noise
SI (u,v) = |I(u,v)|2= power spectrum of the original image
Wiener Filter
• If the noise power spectrum is zero, the Wiener filter becomes an
H * ( u ,v )
inverse filter. RW ( u , v )
0
H ( u ,v ) 2
S I ( u ,v )
H * ( u ,v ) H * ( u ,v ) 1
H ( u ,v ) 2 H ( u ,v ) H * ( u ,v ) H ( u ,v )
0 1 0
1 4 1
0 1 0
• However, before P(u,v) is calculated, the p(r,c) function must be zero-
padded to the same size as the image.
• P(u,v) is then obtained by applying Fourier transform on p(r,c).
• Once P(u,v) is obtained, then it can be incorporated into RCLS(u,v).
Restored Image
The end