0% found this document useful (0 votes)
23 views57 pages

CH 4 Fourier Transform I

The document provides an introduction to the Fourier Transform and its applications in digital image processing, including the Discrete Fourier Transform (DFT) and Fast Fourier Transform (FFT). It explains the mathematical definitions, properties, and significance of Fourier transforms in analyzing signals and images, emphasizing the importance of magnitude and phase. Additionally, it covers practical implementation in MATLAB and visual representation of the Fourier Transform results.

Uploaded by

duanhd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views57 pages

CH 4 Fourier Transform I

The document provides an introduction to the Fourier Transform and its applications in digital image processing, including the Discrete Fourier Transform (DFT) and Fast Fourier Transform (FFT). It explains the mathematical definitions, properties, and significance of Fourier transforms in analyzing signals and images, emphasizing the importance of magnitude and phase. Additionally, it covers practical implementation in MATLAB and visual representation of the Fourier Transform results.

Uploaded by

duanhd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 57

Introduction to Digital Image

Processing

Ho Dinh Duan
HCMC – 2020-21
1
Ch 4

Fourier Transform - basic

2
Contents

• Fourier transform of continuous functions


• Discrete Fourier Transform, Fast Fourier
Transform (DFT, FFT)
• The Fourier transform of some basic
functions
• A review in Math: Fourier series

3
What is Fourier transform?

• The Fourier Transform is a tool that breaks a


waveform (a function or signal) into an
alternate representation, characterized by
sines and cosines (sinusoidals).
• Fourier Transform maps a function into a
(complex-valued) function, which is
considered operating in the frequency
domain

4
What the Fourier transform does?

• It decomposes any function into a sum of


sinusoidal basis functions (Cosine and Sine);
• (Euler notation) Each of these basis functions
is a complex exponential of a different
frequency

(this function has period=1/ ; hence is the frequency;


i being the complex imaginary unit)

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)

• or, in terms of Cosine and Sine

6
The Inverse Fourier Transform

Which means

7
Example: The Fourier transform of the
Box function

g(t) has amplitude of A, and extends from t=-T/2 to t=T/2.


For |t|>T/2, g(t)=0. 8
The Fourier transform of the Box function -
calculation

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

And the phase of z is


tan-1(b/a)

For the Fourier Transform of an image (as a function g(x,y)), the


magnitude and the phase of G(f) (an array of complex numbers) are
useful to study the characteristics of this image, especially the
behaviour of frequency distribution, in addition to the other two
quantities, the Real part and the Imaginary part of a complex
number.

As an image is a discrete 2 dimensional array of numbers, we will


look deeper into the Discrete Fourier Transform – DFT 13
Homework 4.1 (CLO2)

Generalize the box function into two dimension?


Then compute the Fourier transform for this 2-D box function.

14
Discrete Fourier transform

• A signal is a one-dimensional array, an image


is a two-dimensional array of (real) numbers;
• So they can be considered as finite sets of
values of a function in one or two variables;
• The Fourier transform applies directly to
signals or images (the Discrete Fourier
Transform)

15
Discrete Fourier Transform (DFT) – one
variable

For simplicity, we first begin with one dimension.


Given a 1D function (or signal) uniformly sampled
The DFT of {} is defined as

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

is symmetric, and the Fourier transform {Fn}


can be expressed as F=f.W, here f is
considered as a row vector.
17
Furthermore, the coefficients can be computed by taking
the inner product of Fk and

Which can be verified using the orthonormality of the { }

The Inverse transform is given by

(so we can see the transform matrix here is similar to W,


except for )

18
Homework 4.2 CLO2&3

Use Python (or Matlab), compute the matrix W of the


forward one-dimensional Fourier transform and W -1 for
the backward, with N=5. Give your observations on these
matrices.

Is the fact that N being a prime or a composit integer


affects much on the matrix W?

19
Remarks

Even if the fk are real numbers, their discrete Fourier


transform is a sequence of complex numbers

Discrete Fourier transforms (DFTs) are extremely


useful because they reveal periodicities in input data as
well as the relative strengths of any periodic
components

Note that the computation complexity of DFT is o(N2)

20
Fourier in two variables
In continuous case, for a function g(x,y) of two
variables, the Fourier transform is

ℱ { 𝑔 ( 𝑥 , 𝑦 ) } =𝐺 ( 𝑢, 𝑣 )=∬ 𝑔(𝑠, 𝑡)𝑒 − 2 𝜋 𝑖(𝑢𝑠+ 𝑣𝑡)
𝑑𝑠𝑑𝑡
−∞

The inverse is,



𝑔 ( 𝑥 , 𝑦 )=∬ 𝑔 ( 𝑠 , 𝑡 )𝑒 2 𝜋 𝑖( 𝑥𝑠+ 𝑦𝑡)
𝑑𝑠𝑑𝑡
−∞

(in both equation, s and t are dummy variables)


We shall discretize these equations next

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 𝑀 𝑁

and the inverse DFT


𝑀 − 1 𝑁 −1
1 𝑥𝑢 + 𝑦𝑣
𝑓 (𝑥 , 𝑦 )=
𝑀𝑁
∑∑ 𝐹 ( 𝑢, 𝑣 ) exp ⁡{2 𝜋 𝑖( ¿
𝑀 𝑁
)}¿
0 0

The coefficient (1/MN) is a scaling factor.


22
Remark

As , we can perform the Fourier transform of an MxN


matrix A by first apply a linear transform by an MxM
matrix on the left, and then another NxN matrix on the
right of A:
₣(A)=UAV,
and here for the Fourier transform, U and V are Unitary
matrices, with entries of the form or

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

And the bit reversal algorithm follows from this arrangement


26
Note that

+ This algorithm is best-performed when N is a power of 2

+ when N=2n, the number of required ALU operations is


2Nlog2N = 2Nn

+ In practice, generally N is not a power of 2, most programs


will zero-pad the image to the nearest size of power 2

27
An example of a 16-element sequence
bit-reversal

Each stage uses an interlace decomposition, separating the even


and odd numbered samples 28
The bit-reversal sorting algorithm for 16 sample points

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

MATLAB has three related functions that compute the


inverse DFT:
0. ifft
1. ifft2
2. ifftn

32
A remark for inspecting the FFT

For the Fourier Transform G(f) of an image (as a function in two


variables), the magnitude and phase of G(f), which is a complex
function, are very useful to study the characteristics of this
image and can reveal a lot of image information

The Matlab function for calculating the magnitude is abs(), and


the phase is angle()

The function fftshift() is used to adjust the transformed image for


convenient subsequent processing; while the log(1+abs()) is
useful to scale the transformed image in visualization

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?

As the FFT of a digital image is an array of complex numbers, we


cannot display it right away;
But there are features of the FFT that can be visualize, and they
do in some cases reveal the characyeristics of the original image;
Those features are the Magnitude, Phase angle, the Real part
and Imaginary part, which are real array of numbers, and hence
can be display; (another feature is the F(0,0) – the so called DC
coefficient of the FFT);
The following slides will illustrate these aspects.

35
Visualizing the FFT

original image Magnitude of FFT (shifted) Phase angle of FFT (shifted)

50 50 50

100 100 100

150 150 150

200 200 200

250 250 250


50 100 150 200 250 50 100 150 200 250 50 100 150 200 250

Real part of FFT (shifted) Imag part of FFT (shifted)

50 50

100 100

150 150

200 200

250 250
50 100 150 200 250 50 100 150 200 250

(left to right, up to down) The original image, the Magnitude, Phase


angle, Real part, and Imaginary part of the FFT
36
Visualizing the FFT (cont’d)
Original image Magnitude of FFT (shifted) 1+log(abs())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, the Magnitude, 1+log(abs()),


Phase angle, Real part, and Imaginary part of the FFT
37
Visualizing the FFT (cont’d)
Original image (binarized) Magnitude of FFT (shifted) 1+log(abs())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

100 200 300 400 500 600

43
Transformed back, display all values

frequency filtered (complex)

50

100

150

200

250

300

350

400

450

100 200 300 400 500 600

44
Transformed back, display the magnitude

freq filtered (magnitude)

50

100

150

200

250

300

350

400

450

100 200 300 400 500 600

45
Transformed back, display the binarized image

freq filtered (binarized)

50

100

150

200

250

300

350

400

450

100 200 300 400 500 600

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

A square waveform and its sinusoidal approximation 50


Exercise

• Write Matlab codes that plot the Sine


series resembling the one in the previous
slide, at any given length?

(an answer in the next slide)

51
Matlab codes
Plot of sin(x)+sin(3x)/3+sin(5x)/5+... ; with length=9
1

0.8

0.6

% Plot of sin(x)+sin(3x)/3+sin(5x)/5+... 0.4

% as the length tends to infinity, it 0.2

appxoximates the impulse funct


0

-0.2

n=input('Length of the Sin series (odd -0.4

number): ') -0.6

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

In fact this Sine series is the Fourier expression of N=199 52


a square wave form
The Fourier Series of a function f(x)

If f(x) is a continuous and smooth function in one variable x, then

where 𝜋
1
𝑎 0=
𝜋
∫ 𝑓 ( 𝑥 ) 𝑑𝑥
−𝜋

𝜋
1
𝑎𝑛 =
𝜋
∫ 𝑓 ( 𝑥 ) cos ⁡(𝑛𝑥 ) 𝑑𝑥
−𝜋

𝜋
1
𝑏𝑛 =
𝜋
∫ 𝑓 ( 𝑥 ) sin ⁡(𝑛𝑥 ) 𝑑𝑥
−𝜋
53
Basic calculation for the Fourier coefficients

𝑓𝑜𝑟 𝑚 , 𝑛 ≠ 0 , 𝑤𝑖𝑡h 𝛿𝑚 ,𝑛 𝑡h𝑒 𝐾𝑟𝑜𝑛𝑒𝑐𝑘𝑒𝑟 𝐷𝑒𝑙𝑡𝑎


54
In forms of Complex numbers
In some cases, it is necessary to express the Fourier series in terms of
complex numbers; let g(t) be a function with fundamental period T (i.e with
frequency 2π/T), then

where the Euler notation is used

The coefficients can be computed by

55
Exercise – Calculate the Fourier series of square waveform

Calculation the Fourier


series of the waveform given
by the figure on the left
using the formula in previous
slide.

56
End of Chapter

57

You might also like