Professional Documents
Culture Documents
Digital Image Processing - Filtering in Frequency Domain
Digital Image Processing - Filtering in Frequency Domain
THINKING IN FREQUENCY
10/25/2022 Le Thanh Ha 2
Frequency Spectra
• example : g(t) = sin(2πf t) + (1/3)sin(2π(3f) t)
= +
Slides: Efros
Frequency Spectra
Frequency Spectra
= +
=
Frequency Spectra
= +
=
Frequency Spectra
= +
=
Frequency Spectra
= +
=
Frequency Spectra
= +
=
Frequency Spectra
1
= A sin(2 kt )
k =1 k
1D Discrete Fourier transform
N −1 2 i
−
X k = xn e
kn
N
k = 0,..., N − 1
n =0
N −1 2 i
1
X e
kn
xn = k
N
n = 0,..., N − 1
N k =0
10/25/2022 Le Thanh Ha 11
2D Discrete Fourier transform
• Discrete domain:
M N
F ( wx , wy ) = f ( x, y )e
− i ( wx x + wy y )
x =1 y =1
M N
1
F (wx , wy )e
i ( wx x + wy y )
f ( x, y ) =
MN x =1 y =1
10/25/2022 Le Thanh Ha 12
2D Fourier transform
Intensity Image
Fourier Image
http://sharp.bu.edu/~slehar/fourier/fourier.html#filtering
Signals can be composed
+ =
http://sharp.bu.edu/~slehar/fourier/fourier.html#filtering
More: http://www.cs.unm.edu/~brayer/vision/fourier.html
10/25/2022 Le Thanh Ha 16
2D Fourier transform
FT of each character
symbol is different
from others,
especially at the
low frequencies.
10/25/2022 Le Thanh Ha 18
2D Fourier transform
• 2 real images
10/25/2022 Le Thanh Ha 19
2D Fourier transform
10/25/2022 Le Thanh Ha 20
2D Fourier transform
10/25/2022 Le Thanh Ha 21
2D Fourier transform - IP
10/25/2022 Le Thanh Ha 22
Demonstration using MATLAB
• Operator order:
– Read an Image
– Transform using fft2
– Shift frequency coefs to center using fftshift
– Create filters (ideal, gaussian, …)
– Filter in frequency domain
– Shift frequency coefs back using ifftshift
– Invert transform using ifft2
10/25/2022 Le Thanh Ha 23
Practice question
Match the spatial domain image to the Fourier magnitude image
1 2 3 4 5
A C E
D
Sampling
Why does a lower resolution image still make
sense to us? What do we lose?
Image: http://www.flickr.com/photos/igorms/136916757/
Subsampling by a factor of 2
Source: S. Marschner
Aliasing problem
• 1D example (sinewave):
Source: S. Marschner
Aliasing problem
• Sub-sampling may be dangerous….
• Characteristic errors may appear:
– “Wagon wheels rolling the wrong way in
movies”
– “Checkerboards disintegrate in ray tracing”
– “Striped shirts look funny on color television”
Source: D. Forsyth
Aliasing in video
Source: A. Efros
Sampling and aliasing
Nyquist-Shannon Sampling Theorem
• When sampling a signal at discrete intervals, the
sampling frequency must be 2 fmax
• fmax = max frequency of the input signal
• This will allows to reconstruct the original
perfectly from the sampled version
v v v good
bad
Anti-aliasing
Solutions:
• Sample more often
• Get rid of all frequencies that are greater than half the new
sampling frequency
– Will lose information
– But it’s better than aliasing
– Apply a smoothing filter
Algorithm for downsampling by factor of 2
1. Start with image(h, w)
2. Apply low-pass filter
im_blur = imfilter(image, fspecial(‘gaussian’, 7, 1))
3. Sample every other pixel
im_small = im_blur(1:2:end, 1:2:end);
With and without anti-aliasing
10/25/2022 Le Thanh Ha 36
Why does a lower resolution image still make
sense to us? What do we lose?
Image: http://www.flickr.com/photos/igorms/136916757/
What do you see?
10/25/2022 Le Thanh Ha 38
Why do we get different, distance-dependent interpretations of
hybrid images?
Come closer
Go further
Hybrid Images
10/25/2022 Le Thanh Ha 42
Subband filter
50 50 50
10/25/2022 Le Thanh Ha 43
Ideal Lowpass filter
10/25/2022 Le Thanh Ha 45
Ideal Lowpass filter
10/25/2022 Le Thanh Ha 46
Butterworth Filter
1
H (u, v) =
1 + D(u, v) / D0
n
10/25/2022 Le Thanh Ha 47
Butterworth Filter
10/25/2022 Le Thanh Ha 48
Butterworth Filter
10/25/2022 Le Thanh Ha 49
Gaussian Filter
10/25/2022 Le Thanh Ha 50
Gaussian Filter
10/25/2022 Le Thanh Ha 51
10/25/2022 Le Thanh Ha 52
Demonstration using MATLAB
• Operator order:
– Read an Image
– Transform using fft2
– Shift frequency coefs to center using fftshift
– Create filters (ideal, butterworth, …)
– Filter in frequency domain
– Shift frequency coefs back using ifftshift
– Invert transform using ifft2
10/25/2022 Le Thanh Ha 53