CH 4 Fourier Transform I
CH 4 Fourier Transform I
Processing
Ho Dinh Duan
HCMC – 2020-21
1
Ch 4
2
Contents
3
What is Fourier transform?
4
What the Fourier transform does?
5
The Fourier transform – definition
(continuous functions)
• The Fourier Transform of a function g(t) is define as
the following integral (f being the variable in the
frequency domain)
6
The Inverse Fourier Transform
Which means
7
Example: The Fourier transform of the
Box function
where
9
The Box function with T=10,
and its Fourier transform
10
Fourier transform in two variables
• For a function g(x,y) of two variables (as in
the case of a digital image), the Fourier
transform is
∞
ℱ { 𝑔 ( 𝑥 , 𝑦 ) } =𝐺 ( 𝑢, 𝑣 )=∬ 𝑔(𝑠, 𝑡)𝑒
− 2 𝜋 𝑖(𝑢𝑠+ 𝑣𝑡)
𝑑𝑠𝑑𝑡
−∞
The inverse,
∞
𝑔 ( 𝑥 , 𝑦 )=∬ 𝑔 ( 𝑠 , 𝑡 )𝑒
2 𝜋 𝑖( 𝑥𝑠+ 𝑦𝑡 )
𝑑𝑠𝑑𝑡
−∞
11
A remark on the Fourier transform and
the Fourier series
• We have defined the Fourier transform directly (ad
hoc) by formulating the F(f(x,y)) using the integral
operator and the basis functions; this has the merit
of being straight-forward and simple, but lack of a
reasoning for it;
• Another approach is, by passing thru the Fourier
series using sinusoidal expression, we know the
good properties of the transform and its motivation
(in fact, the sinusoidal representation is a special
case of a normal representation of functions in a
Hilbert space)
12
The Magnitude and Phase
Recall, if z is a complex number
z = a + b.i
Then the magnitude of z
|z| = (a2 + b2)1/2
14
Discrete Fourier transform
15
Discrete Fourier Transform (DFT) – one
variable
with n=0,1,…,N-1.
16
Discrete Fourier Transform (DFT) – one variable
We re-write Fn as
where
with , k,n=0,1,…,N-1.
The NxN matrix
18
Homework 4.2 CLO2&3
19
Remarks
20
Fourier in two variables
In continuous case, for a function g(x,y) of two
variables, the Fourier transform is
∞
ℱ { 𝑔 ( 𝑥 , 𝑦 ) } =𝐺 ( 𝑢, 𝑣 )=∬ 𝑔(𝑠, 𝑡)𝑒 − 2 𝜋 𝑖(𝑢𝑠+ 𝑣𝑡)
𝑑𝑠𝑑𝑡
−∞
21
Discrete Fourier transform
• The Discrete Fourier Transform (DFT) in two dimension takes
a matrix f(x,y) of size M x N as input (as in the case of a digital
image), and outputs a matrix F(u,v) of complex numbers, of
the same size
𝑀 −1 𝑁 −1
𝑥𝑢 +𝑦𝑣
𝐹 ( 𝑢,𝑣 )= ∑ ∑ 𝑓 ( 𝑥, 𝑦 ) exp {−2𝜋 𝑖( ¿ )}¿
0 0 𝑀 𝑁
23
Fast Fourier Transform
24
Fast Fourier Transform (FFT)
• The Fast Fourier Transform (FFT) is a Discrete
Fourier Transform (DFT) algorithm which reduces
the number of computations needed for N points from
o(N2) to o(Nlog2N); it is based on the following
algorithm
• The Cooley-Tukey FFT algorithm (idea):
– First, rearrange the input elements in bit-reversed order
– Then, build the output transform by breaking up the
transform of length N into two transform of length N/2
25
The following equations show the basic ideas of breaking a
sequence of length N into two sequences of length N/2, one
with only odd indices and the other with even indices
27
An example of a 16-element sequence
bit-reversal
29
The diagram for FFT. It has
3 steps:
(i) Decompose an N-point
time domain signal into
N signals each
containing a single point
(bit-reversal
decomposition)
(ii) Find the spectrum of
each of the N point
signals (which is just the
identity), and
(iii) Synthesize the N
frequency spectra into a
single frequency
spectrum
30
The FFT butterfly is the basic calculation in the FFT, taking two
complex points and converting them into two other complex
points; and it is repeated over the FFT
31
Fast Fourier Transform – Using
Matlab
MATLAB has three functions to compute the DFT:
1. fft -for one dimension (useful for audio)
2. fft2 -for two dimensions (useful for images)
3. fftn -for n dimensions
32
A remark for inspecting the FFT
33
To better view the FFT
The procedure is as follows:
1) Find the maximum value M of |F(u,v)| (this is indeed the absolute
value of the DC component), and use imshow() to display |F(u,v)|/M;
2) Use mat2gray() to view |F(u,v)| directly
3) Use angle() to show the phase angle of the transform.
34
How the FFT looks like?
35
Visualizing the FFT
50 50 50
50 50
100 100
150 150
200 200
250 250
50 100 150 200 250 50 100 150 200 250
Phase angle of FFT (shifted) Real part of FFT (shifted) Imag part of FFT (shifted)
50 50 50
100 100 100
150 150 150
200 200 200
250 250 250
100 200 300 400 100 200 300 400 100 200 300 400
Phase angle of FFT (shifted) Real part of FFT (shifted) Imag part of FFT (shifted)
50 50 50
100 100 100
150 150 150
200 200 200
250 250 250
100 200 300 400 100 200 300 400 100 200 300 400
(left to right, up to down) The original image (same as in the previous slide, but it was
binarized in thresholding), the Magnitude, Phase angle, Real part, and Imaginary
part of the FFT 38
Note the slight difference between the plots in this slide with the previous one
Why Fourier transform?
39
Spatial vs Frequency domain
• Image Processing can be considered as a special
case of a more general context – Signal Processing
• Most of the time, we are working with objects in the
spatial domain, i.e things relating to their positions
(or coordinates) and properties (e.g the gray scales)
• In some cases, the repeating of patterns or the rate
of changes in intensity is of importance, this involves
the frequencies of signals in certain directions
40
What the Fourier transform does…
• Help investigate the behaviour of the image as far as
frequency is concerned, for example, noise
reduction;
• Help enhance the image by modifying the
transformed image (in the frequency domain)
algorithmically, then transform back to the spatial
domain (frequency filtering)
• And some mathematical models work fairly easier in
the frequency domain, thanks to many usefulness of
the Complex number field etc.
41
A small demonstration
This demonstration
– reads an image, with noise
– transform into frequency domain (fft2),
– filter it, lowpass
– then transform back to spatial domain
42
Original image
50
100
150
200
250
300
350
400
450
43
Transformed back, display all values
50
100
150
200
250
300
350
400
450
44
Transformed back, display the magnitude
50
100
150
200
250
300
350
400
450
45
Transformed back, display the binarized image
50
100
150
200
250
300
350
400
450
46
A look back in Math:
the Fourier series
47
Fourier series
• First, begin with periodic functions
• A function g(t) is periodic, with period T, if
g(t+T)=g(t)
for all t.
Eg. The square waveform
48
Fourier series
• The sinusoids (linear combinations of Sines and
Cosines) are obviously the most common periodic
functions
• For an arbitrary periodic function g(t) - how closely can
we approximate this function with simple sinusoids?
• Answer: whenever g(t) is continuous and 'smooth’. (In
real life, almost all functions are continuous and
smooth!)
• Fourier Series: the realization of this approximation, i.e
a linear combination of simple sinusoids that best
approximate g(t)
49
A property of periodic functions
• A periodic function may be written as a sum of
sines and cosines, of varying amplitudes and
frequencies, at arbitrary precision
51
Matlab codes
Plot of sin(x)+sin(3x)/3+sin(5x)/5+... ; with length=9
1
0.8
0.6
-0.2
k=round(n/2)-1 -0.8
-1
L=4*pi, N=100; % can change these 0 2 4 6 8 10 12 14
t=linspace(0,L,N); N=9
s=0.0
for repeat=0:k Plot of sin(x)+sin(3x)/3+sin(5x)/5+... ; with length=199
s=s+(1/(2*repeat+1))*sin((2*repeat+1)*t); 0.8
end 0.6
figure; plot(t,s);
0.4
0.2
title('Plot of
0
sin(x)+sin(3x)/3+sin(5x)/5+... ; with
-0.2
length='+string(n)); -0.4
-0.6
-0.8
0 2 4 6 8 10 12 14
where 𝜋
1
𝑎 0=
𝜋
∫ 𝑓 ( 𝑥 ) 𝑑𝑥
−𝜋
𝜋
1
𝑎𝑛 =
𝜋
∫ 𝑓 ( 𝑥 ) cos (𝑛𝑥 ) 𝑑𝑥
−𝜋
𝜋
1
𝑏𝑛 =
𝜋
∫ 𝑓 ( 𝑥 ) sin (𝑛𝑥 ) 𝑑𝑥
−𝜋
53
Basic calculation for the Fourier coefficients
55
Exercise – Calculate the Fourier series of square waveform
56
End of Chapter
57