Image and Multidimensional Signal Processing Colorado School of Mines

advertisement
Colorado School of Mines
Image and Multidimensional
Signal Processing
Professor William Hoff
Dept of Electrical Engineering &Computer Science
Colorado School of Mines
Department of Electrical Engineering and Computer Science
http://inside.mines.edu/~whoff/
Fourier Transform
Part 1: 1D discrete transforms
2
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Overview
• This topic is about
– Representing images in the “frequency” domain
– Understanding the operation of filters in this domain
• Topics:
– Fourier transform – definition and properties
– The 2D discrete Fourier transform
– Convolution theorem
• multiplication in the frequency domain is equivalent to convolution in the
spatial domain
– Filters and applications
• smoothing, sharpening, enhancement
3
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Fourier
•
Invented Fourier analysis to solve
the “heat equation”
– Original application was to
understand the flow of heat when
boring a cannon barrel
•
Jean Baptiste Joseph Fourier
(1768-1830)
Main idea
– Any periodic function can be
expressed as a sum of sines and
cosines of different frequencies,
each multiplied by a different
coefficient
•
This is called a “Fourier series”
– Other ideas
•
•
Given enough terms, the function can
be represented exactly
The function can be recovered from the
“frequency domain” representation
First five terms of the Fourier series representing a sawtooth
function (from http://en.wikipedia.org/wiki/Fourier_series)
4
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Complex Numbers
imag
•
•
A Fourier series is a sum of sines and
cosines
We can simplify its representation by
using complex numbers
q
R
•
Let j be the imaginary number
j  1
•
A complex number is defined as
C  R  jI
•
In polar coordinates
C  C  cos q  j sin q 
Euler’s formula
•
•
•
jq
e  cos q  j sin q , so C  C e
C
I
real
Complex conjugate
C *  R  jI
Matlab functions
–
•
jq
complex, conj, abs, angle
Fourier series
f (t ) 

c e
n  
j 2n / T
n
5
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Impulse function
• The “impulse” function is helpful to
understanding Fourier transforms
• It is defined as
 if t  0
 (t )  
 0 if t  0


1 if x  0
0 if x  0
 ( x)  

  ( x)  1
x 
– where we constrain it such that

Discrete equivalents:


 (t )dt  1
x 
f ( x) ( x  x0 )  f ( x0 )
• Sifting property



f (t ) (t )dt  f (0), also



f (t ) (t  t0 )dt  f (t0 )
6
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Fourier Transform
• The 1D Fourier transform (continuous)

F (u)   f ( x)e j 2uxdx

x: spatial
domain
• Inverse Fourier transform

f ( x)   F (u)e j 2uxdu

u: frequency
domain
• We often write
F  f ( x)  F (u )
F 1 F (u )  f ( x)
• f(x) and F(u) are called Fourier transform pairs
f ( x)  F (u)
7
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Example
• Find the Fourier transform of the “box” or
“rectangle” function
• Solution
F ( )  


W /2

W / 2
f (t )e  j 2t dt
Ae  j 2t dt


 A  j 2t W / 2
e
W / 2
j 2
 A  jtW

e
 e jtW
j 2
A

e jtW  e  jtW
j 2
sin W 
 AW
W 





•
This is known as the “sinc” function
sinc( m ) 
sin m 
m 
8
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Discrete Fourier Transform
•
Discrete Fourier transform and inverse
M 1
F (u )   f ( x)e j 2 ux / M
for u  0,1,..., M  1
x 0
1
f ( x) 
M
•
M 1
j 2ux / M
F
(
u
)
e

for x  0,1,, M  1
u 0
We consider f(x) and F(u) to be periodic in the discrete domain
-M
M
2M
What is F(0)?
9
Colorado School of Mines
Department of Electrical Engineering and Computer Science
A Note on Units
• Units
– Spatial units (x): length (e.g., x has units of meters)
– Frequency (u): 1 / length (e.g., u has units of meters-1)
• We have M samples of f(x) taken at integer spacing:
0, 1, … , M-1
• We can consider the samples to be taken at intervals
of Dx:
f(0), f(Dx), f(2Dx), …, f( (M-1)Dx)
1
0.8
0.6
• Similarly F(u) is sampled at:
F(0), F(Du), F(2Du), … , F( (M-1) Du)
0.4
0.2
0
-0.2
-0.4
• The longest possible wavelength is MDx
=> corresponds to min freq of Du = 1/(MDx)
-0.6
-0.8
-1
0
1000
2000
3000
4000
5000
6000
7000
10
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Example - Matlab
• 1D discrete Fourier transform
x = 0:M-1;
u = 0:M-1;
% Create an input series f(1), … ,f(M)
% :
for n=1:M
F(n) = 0;
for m = 1:M
F(n) = F(n) + f(m) * exp(-j*2*pi*u(n)*x(m)/M);
end
end
7
6
5
4
3
2
1
0
-1
-2
0
5
10
15
20
• Example of the rectangle function
Output series:
Input
series:
f = zeros(1,M);
f(1:4) = 1.0;
f(M-2:M) = 1.0;
Colorado School of Mines
F =
Columns 1 through 4
7.0000
5.6957 + 0.0000i
2.6180 + 0.0000i
Columns 5 through 8
-1.6180 - 0.0000i -1.0000 - 0.0000i
0.3820 + 0.0000i
Columns 9 through 12
0.6180 - 0.0000i -0.4596 + 0.0000i -1.0000 + 0.0000i
Columns 13 through 16
0.6180 - 0.0000i
1.1085 - 0.0000i
0.3820 + 0.0000i
Columns 17 through 20
-1.6180 Department
- 0.0000i
-0.3446
+ 0.0000i
2.6180
+ 0.0000i
of Electrical
Engineering
and Computer
Science
-0.3446 - 0.0000i
1.1085 + 0.0000i
-0.4596 - 0.0000i
-1.0000 - 0.0000i
11
5.6957 + 0.0000i
Fast Fourier Transform
• Reduces cost from O(M2) to O(M log M)
• Recursively divides problem into 2, and computes transform of each
• Requires #samples to be a power of 2 (if not, can pad with zeros)
– F(µ) = Feven (µ) + Fodd (µ)*e-j2pi µ /2K for 0 ≤µ < K
– F(µ) = Feven(µ) – Fodd(µ)*e-j2pi µ /2K for K ≤ µ < 2K
• Matlab’s fft function
12
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Important Fourier Transform Pairs
•
Rectangle
–
1.4
1
1.2
A rectangle transforms to a sinc function
0.8
1
0.6
0.8
0.4
0.6
0.2
rect (t )  sinc(  )
•
0.4
0
0.2
-0.2
0
-0.4
-0.2
-1
-0.5
0
0.5
1
-4
-3
-2
-1
0
1
2
3
4
-1.5
-1
-0.5
0
0.5
1
1.5
2
-1.5
-1
-0.5
0
0.5
1
1.5
2
-1.5
-1
-0.5
0
0.5
1
Cos
–
A cosine transforms to two impulses
1.2
1
1
0.8
0.6
•
1
cos(2 u0 x)   (u  u0 )   (u  u0 )
2
Sin
–
•
0.2
0.6
0
0.4
-0.2
-0.4
0.2
-0.6
-0.8
0
-1
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
-0.2
-2
A sine transforms to two (imaginary) impulses
1
sin(2 u0 x)  j  (u  u0 )   (u  u0 )
2
1
1
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
0
-0.2
-0.2
-0.4
-0.4
-0.6
-0.6
-0.8
-0.8
-1
Gaussian
–
0.8
0.4
-2
-1
-1.5
-1
-0.5
0
0.5
1
1.5
2
-2
A Gaussian transforms to a Gaussian
e
 x2 /2 2
 2 e
2 2 2u 2
0.4
0.4
0.3
0.3
0.2
0.2
0.1
0.1
0
-0.1
-2
Colorado School of Mines
0
-1.5
-1
-0.5
0
0.5
Department of Electrical Engineering and Computer Science
1
1.5
2
-0.1
-2
13
1.5
2
Important Fourier Transform Pairs
•
Impulse
 ( x)  1




F (u )   f ( x)e j 2 ux dx    ( x)e j 2 ux dx
 e  j 2 u 0  e 0  1
•
Shifted impulse
 ( x  a)  e j 2 au
e j 2 ax   (u  a)
14
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Important Fourier Transform Pairs
•
Periodic impulse train (comb)

1 
n

(
x

n
D
x
)


(
u

)


D
x
D
x
n 
n 
•
x
Dx
Proof
– Let
sDx ( x) 

  ( x  nDx)
n 
u
– By definition of Fourier series, we can write as
sDx ( x) 
– where

ce
n 
j
2 n
x
Dx
Du 
1/Dx
n
2 n
j
x
1 Dx /2
Dx
cn 
sDx ( x)e
dx

D
x
/2
Dx
– Since integral covers only the single impulse at the origin,
2 n
j
x
1 Dx /2
1 0 1
Dx
cn 

(
x
)
e
dx

e 

D
x
/2
Dx
Dx
Dx
Colorado School of Mines
Department of Electrical Engineering and Computer Science
15
Periodic impulse train (continued)
•
Proof (continued)
– The Fourier series expansion of the pulse train is thus
1  j 2Dxn x
sDx ( x) 
e

Dx n 
– Now we take Fourier transform
 1  j 2Dxn x  1   j 2Dxn x 
F sDx ( x)  F 
e
F e




D
x
D
x
n  
 n 


– By the translation property
e j 2 ax   (u  a)
– This becomes
1  
n 


u

  Dx 
Dx n  
16
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Convolution Theorem
•
Convolution in one domain is equivalent to multiplication in the other domain
h( x) * f ( x)  H (u ) F (u )
convolution
point-by-point multiplication
h( x) f ( x)  H (u ) * F (u )
point-by-point multiplication
•
convolution
Similarly for correlation, except that we have complex conjugate
h( x)  f ( x)  H * (u ) F (u )
h* ( x) f ( x)  H (u )  F (u )
•
As we will see a little later, this is very useful for implementing large filters
17
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Proof
• Convolution in 1D

h( x )  f ( x ) 
 h(t ) f ( x  t )dt

• Fourier transform of the convolution


  j 2 ut


 j 2 ut
F h(t )  f (t )     h(t ) f (t  t )dt  e
dt   h(t )   f (t  t )e
dt  dt
  


 


– The term in brackets is the Fourier transform of f(t-t)
• From the translation property, we know that
• So
F  f (t  t )  F (u)e j 2 ut
F h(t )  f (t ) 



h(t )  F (u )e
F h(t )  f (t )  H (u) F (u)
 j 2 ut

 dt  F (u )  h(t )e  j 2 ut dt

18
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Understanding Sampling and Aliasing
• We often subsample a signal
– When we originally digitize it
– When we shrink it
• We can reconstruct the signal exactly from the samples
if the samples are “dense” enough
• The sampling theorem says that the sampling rate must
be more than twice the maximum frequency of the input
signal (this is the “Nyquist rate”)
• If the sampling rate is lower, we can get errors in the
reconstructed signal (called “aliasing”)
19
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Sampling
• Sampling of a
continuous function
f(t) can be modeled
by multiplying it with
an impulse train
sDT (t ) 

  (t  nDT )
n 
f (t )  f (t ) sDT (t )



f (t ) (t  nDT )
n 
20
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Sampling
• Recall that multiplication in the spatial domain ↔ convolution in the
frequency domain
f (t ) sDT (t )  F (u)  S (u)
• We know that the Fourier transform of a “comb” function is
1  
n 
S (u ) 

u

  DT 
DT n   
• So

F (u )  S (u )   F (t ) S (u  t )dt
Copies of F(u) at
intervals of 1/DT


n 

  u t 
 dt
 F (t )n
D
T

 
1  
n 
1


F
(
t
)

u

t

d
t




DT n  
DT 
DT

1

DT


n 

F
u

  DT 
n 
21
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Sampling
Fourier transform of the
sampling function
2Dx
S(u)
1/Dx
1/Dx
2Dx
u
F(u)
Fourier transform of the
original function
u
Convolving the two results
in periodic copies of F(u)
2Dx
1/Dx
S(u)*F(u)
1/2Dx
1/2Dx
1/Dx
2Dx
u
22
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Reconstruction
•
•
We can reconstruct the original continuous function from the samples
We just need to eliminate the extra copies by multiplying by an ideal low
pass filter
Fs(u) = S(u)*F(u)
2Dx
1/Dx
1/Dx
2Dx
u
2Dx
u
H(u)
Ideal low pass filter
2Dx
1/Dx
1/2Dx
1/2Dx
1/Dx
H(u) Fs(u)
Multiplication - gets back the original F(u)
2Dx
Colorado School of Mines
1/Dx
1/Dx
Department of Electrical Engineering and Computer Science
2Dx
u
23
Reconstruction
• Recall that multiplication in frequency domain is equivalent to
convolution in the spatial domain
Fs(u)
u
1/2Dx
1/2Dx
H(u)
u
1/2Dx
1/2Dx
H(u) Fs(u)
u
1/2Dx
Colorado School of Mines
1/2Dx
Department of Electrical Engineering and Computer Science
24
Under Sampling
Fourier transform of the
sampling function
2Dx
S(u)
1/Dx
1/Dx
F(u)
•
Fourier transform of the
original function
1/2Dx
2Dx
u
If frequency range of original
function exceeds ±1/2Dx, we
have aliasing
u
1/2Dx
S(u)*F(u)
2Dx
1/Dx
1/2Dx
1/2Dx
1/Dx
2Dx
u
25
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Under Sampling
S(u)*F(u)
2Dx
1/Dx
1/2Dx
1/2Dx
1/Dx
2Dx
u
2Dx
u
2Dx
u
Ideal low pass filter
2Dx
1/Dx
1/Dx
H(u) Fs(u)
Multiplication
2Dx
1/Dx
1/2Dx
1/2Dx
1/Dx
26
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Example of aliasing
27
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Summary / Questions
• Any periodic function can be expressed as a sum of
sines and cosines of different frequencies, each
multiplied by a different coefficient.
• The Fourier transform expresses this concisely using
complex numbers.
• What is
– the “impulse function”?
– the “convolution theorem”?
– “aliasing”?
28
Colorado School of Mines
Department of Electrical Engineering and Computer Science
Download