CH 5 Fourier Transform II
CH 5 Fourier Transform II
Processing
Ho Dinh Duan
HCMC – 2020/22
Ch 5
Fourier Transform II
Contents
𝑀 −1 𝑁 −1
𝑥𝑢 +𝑦𝑣
𝐹 ( 𝑢,𝑣 )= ∑ ∑ 𝑓 ( 𝑥, 𝑦 ) exp {−2𝜋 𝑖( ¿ )}¿
0 0 𝑀 𝑁
Convolution
Another process that relates the spatial and frequency domains, that is
correlation.
By definition, the correlation of two function f(x,y) and g(x,y) is defined
as the product of the conjugate of Fourier transform of f(x,y) and the
Fourier transform of g(x,y):
F*(u,v) G(u,v),
where F(u,v) and G(u,v) are the Fourier transforms of f and g, respectively.
An important application of the correlation is for template matching,
where the problem is to find the the closest match between an unknown
image and a set of known images. One way to obtain this is by finding the
correlation between the unknown and each of the known image, where the
image that gives largest correlation value is the solution. (this is also
related to the problem of pattern recognition).
Filtering in the Frequency Domain - the Ideas
Filtering in the frequency domain involves the
relationship between convolution (in the spatial
domain) and multiplication (in the frequency domain)
• The following Convolution Theorem shows an
interesting relationship between the spatial domain
and frequency domain:
where
Conversely
Solving spatial problems in the
Frequency Domain
To get the results shown in the last image of the table, you can
also combine MATLAB calls as in:
f=zeros(30,30);
f(5:24,13:17)=1;
F=fft2(f, 256,256);
F2=fftshift(F);
figure,imshow(log(1+abs(F2)),[])
Notice in these calls to imshow(), the second argument is empty
square brackets. This maps the minimum value in the image to
black and the maximum value in the image to white.
Filtering with Frequencies
Frequency domain filters
• From the previous materials, it means we can
perform linear spatial filters as a simple
component-wise multiply in the frequency
domain.
• This suggests that we could use Fourier
transforms to speed up spatial filters. This only
works for large images that are correctly padded,
where multiple transformations are applied in the
frequency domain before moving back to the
spatial domain.
Padding an image
• When applying Fourier transforms padding is
very important. Note that, because images are
infinitely tiled in the frequency domain, filtering
produces wraparound artefacts if you don't zero
pad the image to a larger size.
• The paddedsize() function calculates a correct
padding size to avoid this problem. The
paddedsize function can also help optimize the
performance of the DFT by providing power of 2
padding sizes.
Basic steps in Frequency
filtering using Matlab
1. Obtain the padding parameters using function paddedsize:
PQ=paddedsize(size(f));
2. Obtain the Fourier transform of the image with padding:
F=fft2(f, PQ(1), PQ(2));
3. Generate a filter function, H, the same size as the image(*)
4. Multiply the transformed image by the filter:
G=H.*F;
5. Obtain the real part of the inverse FFT of G:
g=real(ifft2(G));
6. Crop the top, left rectangle to the original size:
g=g(1:size(f, 1), 1:size(f, 2));
This step is the topic of Filter Design; you can either use the Matlab built-in
(*)
You will notice that both approaches result in a similar looking, but usually the
frequency filtering got a finer/slimmer result (see next slide)
Original image Spatial Sobel filtered frequency filtered (complex)
50 50 50
100 100 100
150 150 150
200 200 200
250 250 250
300 300 300
350 350 350
400 400 400
450 450 450
100 200 300 400 500 600 100 200 300 400 500 600 100 200 300 400 500 600
50 50
100 100
150 150
200 200
250 250
300 300
350 350
400 400
450 450
100 200 300 400 500 600 100 200 300 400 500 600
Common frequency
domain filters
Frequency Domain specific
filters
You can also create filters directly in the
frequency domain. There are three
commonly discussed filters in the frequency
domain:
– Lowpass filters, sometimes known as
smoothing filters
– Highpass filters, sometimes known as
sharpening filters
– Notch filters, sometimes known as band-stop
filters
Lowpass filters
• Lowpass filters:
– create a blurred (or smoothed) image
– attenuate the high frequencies and leave the low frequencies
of the Fourier transform relatively unchanged
50
100
150
300
350
a=double(zeros(L,L)); 400
500
for l=1:L 50 100 150 200 250 300 350 400 450 500
if (k-L/2)^2+(l-L/2)^2<R^2
a(k,l)=1;
end
end
end
imshow(a); title('Ideal filter in
the frequency domain (disk)’);
mesh(a)
Butterworth filter
Matlab codes for the Butterworth filter
% create a Butterworth filter, zero's Butterworth filter in the frequency domain (n=1)
250
350
them as you wish
400
D=64; % disk radius 450
N=1; % the power of Butterworth filter, can 50 100 150 200 250 300 350 400 450 500
be any integer>0
H=double(zeros(L,L));
for k=1:L
for l=1:L
H(k,l)=1/(1+(sqrt((k-L/2)^2+(l-L/2)^2)/D))^
(2*N);
end
end
imshow(H); title(‘Butterworth filter in the
frequency domain (n=1)');
figure; mesh(H)
Gaussian filter
Highpass filters
• Highpass filters:
– sharpen (or shows the edges of) an image
– attenuate the low frequencies and leave the high
frequencies of the Fourier transform relatively
unchanged
• So far the filters mentioned here take values in the [0,1]
• The highpass filter (Hhp) is often represented by its
relationship to the lowpass filter (Hlp):
Note: an alternative is to take the inverse of the lowpass, but then there will be no
cut-off frequencies
An example of making highpass filter from
lowpass in the previous slide
50
100
150
200
250
300
350
400
450
500