Digital Image Processing_Chapter 4
Digital Image Processing_Chapter 4
Chapter 4:
Image Enhancement in the
Frequency Domain
Outline
Fourier series:
Any periodic signals can be
viewed as weighted sum
of sinusoidal signals with
different frequencies
Frequency Domain:
view frequency as an
independent variable
(Images from Rafael C. Gonzalez and Richard E.
Wood, Digital Image Processing, 2nd Edition.
Fourier Tr. and Frequency Domain
Fourier Tr.
Time, spatial Frequency
Domain Domain
Signals Signals
Inv Fourier Tr.
Magnitude spectrum: display the magnitude of Fourier coefficients among frequency components.
This spectrum can tell how much a frequency contribute to the input signal.
Phase spectrum: display the phase of Fourier coefficients among frequency components, tells
"where" the frequency component is in the input signal.
Fourier Tr. and Frequency Domain (cont.)
Fourier Tr. and Frequency Domain (cont.)
Fourier Tr. and Frequency Domain (cont.)
Fourier transform’s meaning
Consider a sinusoidal signal x that is a function of time t with frequency components of 15 Hz
and 20 Hz. Use a time vector sampled in increments of 1/50 seconds over a period of 10
seconds
n = length(x);
Ts = 1/50;
fshift = (-n/2:n/2-1)*(fs/n);
t = 0:Ts:10-Ts;
yshift = fftshift(y);
x = sin(2*pi*15*t) + sin(2*pi*20*t);
plot(fshift,abs(yshift))
plot(t,x)
xlabel('Frequency (Hz)')
xlabel('Time (seconds)')
ylabel('Magnitude')
ylabel('Amplitude')
Fourier Tr. and Frequency Domain (cont.)
Example: for a signal f(x) with sampling period 0.5 sec, 100 point,
we will get frequency resolution equal to
Matrix form
2-Dimensional Discrete Fourier Transform
2-D IDFT
x = 0 ,…, M-1
y = 0 ,…, N-1
2-Dimensional Discrete Fourier Transform (cont.)
1 1
u = v =
Mx Ny
where
x = spatial resolution in x direction
y = spatial resolution in y direction
1-D
DFT
f(x,y) by row F(u,y)
1-D DFT
by column
F(u,v)
How to Perform 2-D DFT by Using 1-D DFT (cont.)
Alternative method
f(x,y)
1-D DFT
by column
1-D
DFT
F(x,v) by row F(u,v)
Periodicity of 1-D DFT
From DFT:
-N 0 N 2N
F(u)
f(x)
DFT
0 N-1 0 N-1
0 N-1
-M
We display only
2M in this range
-N 0 N 2N (Images from Rafael C. Gonzalez and Richard E.
Wood, Digital Image Processing, 2nd Edition.
Conventional Display for 2-D DFT
2D FFTSHIFT
(Images from Rafael C. Gonzalez and Richard E. High frequency area Low frequency area
Wood, Digital Image Processing, 2nd Edition.
2-D FFT Shift (cont.) : How it works
-M
Display of 2D DFT
After FFT Shift
M
Original display
2M
of 2D DFT
-N 0 N 2N
2D DFT
Original image
2D FFT Shift
Example of 2-D DFT
2D DFT
Original image
2D FFT Shift
Relationship between Convolution and DFT
Basic Concept of Filtering in the Frequency Domain
From Fourier Transform Property:
H(u,v)
F(u,v) g(x,y)
(User defined)
FFT shift
X 2D IFFT
2D FFT
FFT shift
f(x,y) G(u,v)
In this case, F(u,v) and H(u,v) must have the same size and
have the zero frequency at the center.
Multiplication in Freq. Domain = Circular Convolution
Original H(u,v)
image Gaussian
Lowpass
Filter with
D0 = 5
Filtered image
(obtained using
circular convolution)
Failure to handle the periodicity issue properly will give incorrect results
if the convolution function is obtained using the Fourier transform.
The result will have erroneous data at the beginning and have missing
data at the end.
The solution to this problem is straightforward. Assume that f and h
consist of A and B points, respectively. We append zeros to both
functions so that they have identical periods, denoted by P.
Linear Convolution by using Circular Convolution and Zero Padding
Filtered image
The smaller D0, the more high frequency components are removed.
Results of Ideal Lowpass Filters
Ringing effect
can be obviously
seen!
which becomes
finer in texture as
the amount of
high frequency
content removed
decreases
How ringing effect happens
How ringing effect happens (cont.)
Surface Plot
-3
x 10
15
20
20
0
Ripples that cause ringing effect -20 -20
0
How ringing effect happens (cont.)
There is less
ringing effect
compared to
those of ideal
lowpass
filters!
Spatial Masks of the Butterworth Lowpass Filters
Note: the Gaussian filter is the only filter that has no ripple and
hence no ringing effect.
Gaussian Lowpass Filter (cont.)
− D 2(u,v ) / 2D 2
H (u, v) = e 0
0.8
0.6
Gaussian lowpass
0.4 filter with D0 = 5
0.2
20
20
0
0
-20 -20
0.03
with D0 = 5 0
20
20
0
0
-20 -20
Gaussian shape
Results of Gaussian Lowpass Filters
No ringing
effect!
Application of Gaussian Lowpass Filters
Original image
Softer-Looking
Homomorphic Filtering
Highpass Filters
Hhp = 1 - Hlp
Ideal Highpass Filters
Ideal HPF Filter Transfer function
0 D(u,v) D0
H (u, v) =
1 D(u,v) D0
where D(u,v) = Distance from (u,v) to the center of the mask.
− D 2(u,v ) / 2D 2
1 H (u, v) = 1 − e 0
0.8
0
60
60
40 50
40
20 30
20
10
3000
2000
with D0 = 5 60
60
40 50
40
20 30
20
10
Spatial Responses of Highpass Filters
Ripples
Results of Ideal Highpass Filters
Laplacian
2 f 2 f
2
f = 2 +
x y2
2 f = 4z −(z + z + z + z )
5 2 4 6 8
✓ Laplacian mask
Z1 Z2 Z3 0 1 0
Z4 Z5 Z6 1 -4 1
Z7 Z8 Z9 0 1 0
Laplacian Filter in the Frequency Domain
Laplacian Filter in the Frequency Domain (cont.)
Laplacian Filter in the Frequency Domain
H(u,v) = −(u2 + v2 )
The enhancement :
g(x, y) = f (x, y) − 2 f (x, y)
In freq. domain :
H (u,v ) = 1 + [( u − M /2) 2 + (v − N/2) 2 ]
By inverse transform
Unsharp masking
✓ Consists simply of generating a sharp image by
subtracting from an image a blurred version of itself.
Sharpening Filtering in the Frequency Domain
Spatial Domain
a = 0.5, b = 2
(Images from Rafael C. Gonzalez and Richard E.
Wood, Digital Image Processing, 2nd Edition.
High Frequency Emphasis Filtering
Homomorphic Filtering
An image can be expressed as
f (x, y) = i( x, y)r( x, y)
i(x,y) = illumination component
r(x,y) = reflectance component
✓ Constant c
To control the sharpness of the slope of the
filter function as it transitions between γL and
γH.
✓ This type of filter is similar to the high-
frequency emphasis filter.
Homomorphic Filtering
N −1 2 N −1
−j
F [n] = f [k ]e F [n] = f [k ]W
nk
N nk
Re-writing: as N
k =0 k =0
- The same values of WNnk (called a twiddle factor) are calculated many times
as the computational proceeds.
- First, the integer products nk repeats for different combinations of k and n.
- Secondly, WNnk is a periodic function with only N distinct values.
The Fast Fourier Transform
The Fast Fourier Transform
Decimation-in-time algorithm …
Let us begin by splitting the single summation over N samples into 2 summations, each
with N/2 samples, one for k even and the other for k odd.
Substitute m = k/2 for k even and m = (k-1)/2 for k odd and write:
N N
−1 −1
2 2
F [n] = f [2m]WN2 mn + f [2m + 1]WN( 2 m +1) n
m =0 m =0
2 2
−j ( 2 mn ) −j mn
Note that WN2 mn = e N
=e N 2
= WNmn2
N N
−1 −1
2 2
Therefore F [n] = f [2m]WNmn2 + WNn f [2m + 1]WNmn2
m =0 m =0
Thus, the N-point DFT F[n] can be obtained from two N/2-point transforms, one on even
input data, G[n] and the other one on odd input data, H[n].
Although the frequency index n ranges over N values, only N/2 values of G[n] and H[n]
need to be computed since G[n] and H[n] are periodic in n with period N/2.
For example: N = 8:
• Even input data: f[0], f[2], f[4], f[6]
• Odd input data: f[1], f[3], f[5], f[7]
For N=8, only one further stage is needed (i.e. there are stages, where N = 2 ), as
shown below.
Thus, the FFT is computed by dividing up, or decimating, the sample sequence f[k] into
sub-sequences until only 2-point DFT’s remain.
Since it is the input, or time, samples divided up, this algorithm is known as the
decimation-in-time (DIT) algorithm. (An equivalent algorithm exists for which the output,
or frequency, points are sub-divided --- the decimation-in- frequency algorithm.)
The basic computation at the heart of the FFT is known as the butterfly because of its
crisscross appearance. For the DIT FFT algorithm, the butterfly computation is of the form
shown:
where A and B are complex numbers. Thus, a
butterfly computation requires
1 complex multiplication and 2 complex
additions.
3/17/2023
The Fast Fourier Transform
A step-by-step FFT signal flow graph generation
F [0] = G[0] + W80 H [0]
F [1] = G[1] + W81 H [1]
F [2] = G[2] + W82 H [2]
F [3] = G[3] + W83 H [3]
F [4] = G[0] + W84 H [0] = G[0] − W80 H [0]
Note: the WNnk is the
F [5] = G[1] + W H [1] = G[1] − W H [1]
8
5
8
1
negative of the WNnk!
F [6] = G[2] + W H [2] = G[2] − W82 H [2]
8
6
These will be the inputs to the next stage which is the final stage, which we have
already done before.
Can you identify where the FFT butterflies are?
Computational Speed of FFT
For FFT, each stage (i.e. each halving), N/2 complex multiplications are required to
combine the results of the previous stage. Since there are (log2N) stages, the number of
complex multiplications required to evaluate an N-point DFT with the FFT is
approximately N/2xlog2N (and Nlog2N complex additions).
Remember: The Fast Fourier Transform is just a faster algorithm for computing the Discrete
Fourier Transform —it does not produce a different result
MATLAB CODE: FFT
https://www.mathworks.com/help/matlab/ref/fft.html