Frequency Domain Bandpass Filtering For Image Processing
Frequency Domain Bandpass Filtering For Image Processing
Home Work IV
PREPARED BY:
LEONARDO O. IHEME
(106054)
SUBMITTED TO:
Frequency filtering is based on the Fourier Transform. The operator usually takes an image
and a filter function in the Fourier domain. This image is then multiplied with the filter
( ) ( ) ( )
where ( ) is the input image in the Fourier domain, ( ) the filter function and G(k,l)
is the filtered image. To obtain the resulting image in the spatial domain, ( ) has to be re-
transformed using the inverse Fourier Transform. Since the multiplication in the Fourier
space is identical to convolution in the spatial domain, all frequency filters can in theory be
implemented as a spatial filter. However, in practice, the Fourier domain filter function can
A bandpass attenuates very low and very high frequencies, but retains a middle range band of
frequencies. Bandpass filtering can be used to enhance edges (suppressing low frequencies)
while reducing the noise at the same time (attenuating high frequencies). We obtain the filter
function of a bandpass by multiplying the filter functions of a low pass and of a high pass in
the frequency domain, where the cut-off frequency of the low pass is higher than that of the
high pass. Therefore in theory, one can derive a bandpass filter function if the low pass filter
function is available.
Bandpass filtering is attractive but there is always a trade-off between blurring and noise: low
pass reduces noise but accentuates blurring, high pass reduces blurring but accentuates noise
Ideal Bandpass Filter
The ideal bandpass filter passes only frequencies within the pass band and gives an output in
the spatial domain that is in most cases blurred and/or ringed. It is the easiest bandpass filter
to simulate but its vertical edges and sharp corners are not realizable in the physical world.
( )
( ) {
The following example demonstrates the effect of applying an ideal bandpass filter with cut
s = size(ima);
ma=max(max((imafft)));
maxr = 0.5*sqrt(s(1)^2+s(2)^2);
cutoff1 = maxr*30;
cutoff2 = maxr*120;
c=1;
for i = 1 : s(1)
for j = 1 : s(2)
r = sqrt((i-1-s(1)/2)^2+(j-1-s(2)/2)^2);
if ( r < 30)
z(i,j) = 0;
else
if ( r > 120)
z(i,j) = 0;
else
z(i,j) =255;
end
end
end
end
% Plots
subplot(222)
imafft=imafft.*z/255;
ima_out = fftshift(ifft2(fftshift(imafft)));
ima_out =ima_out-ima;
fftshow(ima_out,'abs');
title('Filtered image (Ideal)');
subplot(223)
fftshow(imafft3, 'log');
title('Fourier Spectrum of Image')
subplot(224)
fftshow(z,'log');
title('Filtered');
Butterworth Bandpass Filter
This filter can be derived mathematically by multiplying the transfer functions of a a low and
high pass filter. The low pass filter will have the higher cut off frequency.
( )
( )⁄
( )
( )⁄
( ) ( ) ( )
where are the cut frequencies of the low and high pass filters respectively; is
the order of the filter and ( ) is the distance from the origin.
The Butterworth filter has a “smooth” transfer function without any discontinuity or clear cut
off frequency. The range of frequencies that the filter allows is largely dependent on the order
of the filter. In the selection of there has to be a compromise between the demands of the
frequency domain (sharp cutoff) and the spatial domain (rapid decay).
The example presented in this section demonstrates the effect of applying a fourth order
Butterworth filter with cut off frequencies 30 and 120 to a 256×256 grey scale image.
The result shows that the ringing and blurring effect that was observed with the ideal banpass
filter does not exist for the Butterworth filter. The Matlab code is presented below:
subplot(2,2,1)
imshow(micro,[]);
subplot(2,2,2)
fftshow(fftu,'log')
% Initialize filter.
filter1 = ones(2*nx-1,2*ny-1);
filter2 = ones(2*nx-1,2*ny-1);
filter3 = ones(2*nx-1,2*ny-1);
n = 4;
for i = 1:2*nx-1
for j =1:2*ny-1
dist = ((i-(nx+1))^2 + (j-(ny+1))^2)^.5;
% Use Butterworth filter.
filter1(i,j)= 1/(1 + (dist/120)^(2*n));
filter2(i,j) = 1/(1 + (dist/30)^(2*n));
filter3(i,j)= 1.0 - filter2(i,j);
filter3(i,j) = filter1(i,j).*filter3(i,j);
end
end
% Update image with passed frequencies.
fil_micro = fftu + filter3.*fftu;
subplot(2,2,3)
fftshow(filter3,'log')
fil_micro = ifftshift(fil_micro);
fil_micro = ifft2(fil_micro,2*nx-1,2*ny-1);
fil_micro = real(fil_micro(1:nx,1:ny));
fil_micro = uint8(fil_micro);
subplot(2,2,4)
imshow(fil_micro,[])
The Gaussian filter out-performs the previously discussed filter types because when a
Gaussian is transformed between the frequency and spatial domains, it remains a Gaussian;
and therefore does not incur the ringing effect in the spatial domain of the filtered image.
Again the derivation of a Gaussian bandpass filter starts from the lowpass filter
( ) ( )
( ) ( )
( ) ( ) ( )
where are the cut frequencies of the low and high pass filters respectively;
The example below shows that the Gaussian bandpass filter is the best among the three
discussed filters
Figure 3a: Original Image Figure 3b: Filtered Image
subplot(2,2,1)
imshow(micro,[]);
subplot(2,2,2)
fftshow(fftu,'log')
% Initialize filter.
filter1 = ones(2*nx-1,2*ny-1);
filter2 = ones(2*nx-1,2*ny-1);
filter3 = ones(2*nx-1,2*ny-1);
n = 4;
for i = 1:2*nx-1
for j =1:2*ny-1
dist = ((i-(nx+1))^2 + (j-(ny+1))^2)^.5;
% Use Gaussian filter.
filter1(i,j) = exp(-dist^2/(2*120^2));
filter2(i,j) = exp(-dist^2/(2*30^2));
filter3(i,j) = 1.0 - filter2(i,j);
filter3(i,j) = filter1(i,j).*filter3(i,j);
end
end
% Update image with passed frequencies
fil_micro = fftu + filter3.*fftu;
subplot(2,2,3)
fftshow(filter3,'log')
fil_micro = ifftshift(fil_micro);
fil_micro = ifft2(fil_micro,2*nx-1,2*ny-1);
fil_micro = real(fil_micro(1:nx,1:ny));
fil_micro = uint8(fil_micro);
subplot(2,2,4)
imshow(fil_micro,[])
Conclusion
From the human perspective, the Gaussian filter would be the most appropriate filter for
filtering. Determining which filter to use is dependent on the application so desired. The
figure below shows the different filters and the result of their application to the grey scale
image.
Figure 4a: Ideal Bandpass Figure 4b: Butterworth Figure 4c: Gaussian
Filter Bandpass Filter Bandpass Filter
Figure 4d: Original Image
References
[1] McAndrew A., “An Introduction to Digital Image Processing with Matlab Notes for
SCM2511 Image Processing 1”, School of Computer Science and Mathematics,
Victoria University of Technology.
[2] Demirel H., “Digital Image Processing Notes (Lecture 4)” Electrical and Electronic
Engineering, Eastern Mediterranean University, Spring 2010-2011.
[3] Filters (Frequency). (n.d.). Medical Image Processing, Analysis and Visualization.
Retrieved March 26, 2011, from
http://mipav.cit.nih.gov/documentation/HTML%20Algorithms/FiltersFrequency.html
[5] Anbajafari S., “Bandpass Filter for Image Processing”, Mathworks file exchange, 30
Nov 2008.