You are on page 1of 73

Image processing

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

Any function can be written as the


sum of an even and an odd function

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

  

Here we suppose f(t) is over the interval (–π,π).

Fourier Sine Series


Because sin(mt) is an odd function, we can write any odd function, f(t) as:
 


1
  f (t)   Fmsin(mt)
m 0 

where the series F’m is computed as Fm 


 f (t ) sin(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

Let’s now allow f(t) 


 f (t )  F (u )   f (t ) exp( j 2ut )dt
range from – to , rewrite: 
Fourier Transform
Continuous Fourier Transform (CFT) Inverse Fourier Transform (IFT)


 f ( t )  F ( u )   f ( t ) e  j 2ut dt
   j 2ut
f ( t )  F -1 F ( u )   F ( u ) e du
F (u ) X (u ) j Y (u ) Frequency, [Hz] 

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)itsu·x
Fourier
 1/M
spectrum
d a

time domain frequency domain time domain frequency domain


d=a+b+c

c b

time domain frequency domain time domain frequency domain

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 2ux / M ) u=0,1,2,…,M-1
M x 0

M 1
f ( x )   F ( u ) exp( j 2ux / 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

u=0,1,2,…,M-1 and v=0,1,2,…,N-1


M 1 N 1
f ( x , y )    F ( u ,v ) exp( j 2 ( ux / M  vy / N ))
u 0 v 0 x=0,1,2,…,M-1 and y=0,1,2,…,N-1

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

• Rewrite F(u,v) as follows:

• Let’s set:

• Then:
Separability
• How can we compute F(x,v)? of row s o f f( x,y)
N x DFT

How can we compute F(u,v)?


DFT of cols of F(x,v)

To take the two-dimensional Fourier Transform, one can take a 1-


dimensional along one of the axis and take the second DFT on new results
along the other axis. The computation of the 2-D Fourier transform as a
series of 1-D transforms is shown next

In the same manner, a two-dimensional inverse Fourier transform can be


performed using series of 1-D inverse Fourier transforms.
Translation or Shifting
The FT of a shifted function is unaltered except for a linearly varying
phase factor.
Translating the original image by (x0,y0), the spectrum of the DFT of the
translated image will be same as the original image, but having its phase
changedf(x,y) F(u,v)
• Translation is spatial domain:
)
•Translation is frequency domain: N

Translating the original image by


(x0,y0), the spectrum of the DFT
of the translated image will be same
as the original image, but having its
phase changed:
 
Two important results of this property which will aid us in our future
developments are given next:

In most implementations the Fourier image is shifted in such a way that


the DC-value (the image mean) F(0,0) is displayed in the center of the
image. The further away from the center an image point is, the higher is
its corresponding frequency.
Thus, the origin of the Fourier transform of f(x,y) can be moved to the
center of its corresponding N x N frequency square simply by multiplying
f(x,y) by (-1)x+y .
also
 

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

The following is the simple proof of the above property:

If f(x,y) is real, the Fourier transform also exhibits conjugate symmetry:


,More interestingly

As mentioned before, these results are important, because displaying the


Magnitude of the Fourier transform for interpretive purposes often is of
interest.   
Rotation
Simply stated: if a function is rotated, then its Fourier transform
rotates an equal amount.

• Rotating f(x,y) by θ rotates F(u,v) by θ


Distributivity
The Fourier transform and its inverse are distributive over addition but not over
multiplication.

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

Frequency Domain (log


magnitude)
u

General appearance
Magnitude and Phase of DFT
• What is more important?

magnitude phase

• Hint: use inverse DFT to reconstruct the image using magnitude or


phase only information

Reconstructed image using


magnitude only
(i.e., magnitude determines the
contribution of each component)

Reconstructed image using


phase only
(i.e., phase determines
which components are present)
Fast Fourier Transform
• Cooly & Tukey – 1965
• A large amount of work has been devoted to reducing the computation
time of a DFT.
• This has led to efficient algorithms which are known as the Fast Fourier
Transform (FFT) algorithms.
• Example:
– Consider N=100
– Brute Force O(N2)=10000
– If we can break this into 2 (50 point) DFTs, then: O(502) + O(502)
=5000<10000 !
– If we can break this into 4 (25 point) DFTs, then: O(252) + O(252)
– O(252) + O(252)=2500
– Decompose further, gaining each time.
• Two basic classes
– Decimation in time (DIT) Ratio FFT DFT N
– Decimation in frequency (DIF) 32:1 256*8=2048 2562=65536 256

57:1 512*9=4608 5122=262144 512

102:1 1024*10=10240 10242=1048576 1024

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 n0
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 nWNnk ; 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  nW 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  nW Nnk  WNk  x2  nW Nnk
 2  n 0 n0
]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-

• Decimation in time FFT:


– Number of stages = log2N
– Number of blocks/stage = N/2stage
– Number of butterflies/block = 2stage-1
FFT Implementation
FFT Implementation
Example: 8 point FFT
(1) Number of stages:
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-

• 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
Example: 8 point FFT
(1) Number of stages:
W0 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-

• 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
Example: 8 point FFT
(1) Number of stages:
W0 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-

• 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
:Number of stages)1(
W0 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-

• 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-

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-

• 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
Block 1 (1) Number of
stages:
W0 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-

• 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
Block 1 (1) Number of stages:
W0 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-

• 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
Block 1 (1) Number of stages:
W0 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-

• 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
Block 1 (1) Number of stages:
W0 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-

• 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
Block 1 (1) Number of
stages:
W0 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-

• 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-
Block 1
W0 1-
 Nstages = 3
W0 1- W2 1-
(2) Blocks/stage:
W0 1-  Stage 1: Nblocks = 4
W0 1-
W1 1-
Stage 2: Nblocks = 1
W0

W0 1- W2 1-

W0 1- W2 1- W3 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-
Block 1
W0 1-
 Nstages = 3
W0 1- W2 1-
(2) Blocks/stage:
W0 1-  Stage 1: Nblocks = 4
W0 1-
W1 1-
Block 2
Stage 2: Nblocks = 2
W0

W0 1- W2 1-

W0 1- W2 1- W3 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-

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 

• 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:
 Nstages = 3
W0 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-

• 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

• 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 = 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

2D FFT[(1D FFT to columns),(1D FFT to columns)


Bit Reversing
Bit Reversing
• Note that the inputs have been shuffled
so that the outputs are produced in the
correct order.
• This can be represented as a bit-
reversing process:

Order Reversed-Bit Binary Time Point


Word Word (n)
x[0] 000 000 0

x[4] 100 001 1

x[2] 010 010 2

x[6] 110 011 3

x[1] 001 100 4

x[5] 101 101 5

x[3] 011 110 6

x[7] 111 111 7


Fft2
2-D discrete Fourier transform
Y = fft2(X)
returns the two-dimensional discrete Fourier
transform (DFT) of X, computed with a fast Fourier
transform (FFT) algorithm. The result Y is the same
size as X.

Y = fft2(X,m,n)

truncates X, or pads X with zeros to create an m-


by-n array before doing the transform. The result is
m-by-n
f = ones(10,20);
F = fft2(f, 500,500);
f1 = zeros(500,500);
f1(240:260,230:270) = 1;
subplot(2,2,1);imshow(f1,[]);
S = abs(F);
subplot(2,2,2); imshow(S,[]);
Fc = fftshift(F);
S1 = abs(Fc);
subplot(2,2,3); imshow(S1,[]);
S2 = log(1+S1);
subplot(2,2,4);imshow(S2,[]);
Frequency Domain
Frequency Domain Filtering
Filtering
i o n
n c t
F u
ea d
p r
t S
Po in
SF
P

Send a Point of light through the system and


.see what comes out
– Send a point of light through the system.
– The output is the PSF, which is h(r,c).
• However, it is not always practical to implement a point of light.
• A more reliable method is to use sinusoidal inputs at many different
frequencies to determine the overall frequency response H(u,v).
PSF actually measures the amount and direction of blurring that can occur
to one pixel. The blur can be:
Linear in one direction (horizontal, vertical, diagonal).
Circularly symmetric (blur in all direction).
This blurring is modeled using a PSF mask.
The PSF mask is then used to model h(r,c).
,,,,,Blur can be linear in one direction only horizontal ,verttical

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)

• To get the original image, we take the inverse Fourier transform of


I(u,v):
 D(u, v)  1  1 
I (r , c)  F  I (u, v)  F 
1 1
  F  D(u, v) 
 H (u , v )   H (u , v ) 
• The inverse filter is the term 1/H(u,v).
– Note that the inversion is point-by-point inversion, and not a matrix
inversion.
Inverse Filter
• To find 1/H(u,v), we take each term separately and divide it into 1.
1 1 1 
50 50 25  1  50
1
50
1
25
1 
H (u , v ) 
 20 20 20
 H ( u ,v )

 20 20 20 
 20 35 22 
 20
1 1 1

35 22

In practice, a number of complications can arise when this technique is


applied.
If any points in H(u,v) are zero, then we have a division by zero, 1/0.
With the assumption of no noise, D(u,v) can also contain zeros, and this
can lead to an indeterminate ratio, 0/0.
If the assumption of no noise is not correct, the restored image would
really be distorted by the additive noise.
• One method to deal with this problem is to limit the restoration to a
specific radius about the origin in the spectrum, called the restoration
cutoff frequency.
• For spectral component beyond this radius, we can set the filter gain to
0 (Î(u,v) = 0) or 1.
• This is equivalent to an ideal lowpass filter, which results in blurring and
ringing (waves around the edges).
Inverse Filter
• Setting the cut-off frequency too low may provide poor result (blurred).
• Setting it too high may result in the restored image being overshadowed
by noise.
• In practice, the cut-off frequency must be experimentally determined
and highly application specific.

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 )

• When the noise spectrum gets larger, the denominators of Wiener


filter increases, thus decreasing the value of RW(u,v) .
• This leads to a desired behavior:
– In portions of the spectrum where there is no noise, we have an
inverse filter.
– In portions of the spectrum heavily corrupted by noise, the filter
attenuates the signal.
Wiener Filter
• In practical applications the original, uncorrupted image is typically
not available.
– Therefore, the power spectrum ratio is replaced by a parameter K
whose optimal value must be experimentally determined.
H * ( u ,v )
RW ( u ,v ) 
H ( u ,v ) 2  K

K can just be a constant.


However, making K a function of the frequency domain variables (u,v) may
give some extra benefits.
Noise typically dominates at high frequencies.
Making the value K increases as the frequency increases will cause the
filter to attenuates at high frequency, thus reducing the noise.
Wiener Filter

Original Image Blurred image with added


gaussian noise

Result of Wiener filter Result of inverse filter


with cut-off frequency=80 with cut-off frequency=80
Constrained Least-Squares Filter
• This filter can eliminate some of the artifacts caused by other
frequency domain filters.
– Some of the other frequency domain filters cause “waves” to appear
in the image.
– This filter includes a smoothing criterion in the filter derivative that
can eliminate this effect.
H * ( u ,v )  = the adjustment factor
RCLS ( u ,v ) 
P(u,v) = the Fourier Transform of the
H ( u ,v ) 2  P ( u ,v ) 2
smoothness criterion function.

• The adjustment factor’s value is experimentally determined and is


application dependent.
• A standard function used for p(r,c) is the laplacian filter mask:

 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).

Blurred image with


Original Image added gaussian noise

Result of CLS filter with Result of Wiener filter


cut-off frequency = 128  = 23000 with cut-off frequency=80
Geometric Mean Filters
• The geometric filter equation provides a general form for
many of the frequency domain restoration filters.
1
 
RGM ( u ,v )  
H ( u ,v )  *

  
H ( u ,v )
 H (u ,v )   H (u ,v )  n
2 2 S ( u , v )

 S I ( u , v ) 
• The terms are as previously defined, with γ and α being positive real
constants.
• If α = ½ and γ = 1, then this filter is called a power spectrum
equalization filter (homomorphic filter).
– It is an average between the inverse filter and the Wiener filter
(hence the term geometric mean).
• If α = 0, this filter is called a parametric Wiener filter.
Geometric Mean Filters
– When γ = 1, this filter becomes a standard Wiener filter.
– When γ = 0, this filter becomes an inverse filter.
– As γ is adjusted, the results vary between these two filters, with
larger values providing more of the Wiener effect.
• In general, the frequency domain filters work well for small amount of
blurring and moderate amount of additive noise
• The inverse filter is inadequate with too much noise.
• The Wiener filter has the tendency to cause undesirable artifacts in
the resultant image.
• The constrained least-squares filter helps to minimize the Wiener-
type artifact.
• The parametric Wiener and geometric mean provide additional
parameters for application-specific needs.
Notch Filter
• The filter “notches” out selected frequencies.
• It is useful to restore images that have been corrupted with a
sinusoidal interference pattern.
– Can be seen in poor broadcast television images.
– It is also a common artifact in images that have been obtained where
the imaging device reside on some type of vibrating mechanical
system such as a ship or a satellite.
• The interference pattern appears as high peak in frequency domain.
• Therefore, it can easily be identified and eliminated using notch filter.
• Usually, when high peak is notched out, the image lost some amount of
energy which results in lost of contrast.
– Need to enhance using histogram stretch.
Image corrupted with
Original Image sinusoidal noise

Restored Image
The end

You might also like