LAB 5

CONSTRUCTING FILTERS IN THE FREQUENCY DOMAIN

Source Code

bullet

    blackspot.m

bullet

    editspect.m

bullet

    wienfilt.m

bullet

    lowpassfilter.m

bullet

    highpassfilter.m

bullet

    highboostfilter.m

bullet

    psf2.m

|| Lab2 || Lab3 || Lab4 || Lab5 || Lab6 || Lab7 || Lab8 ||
 Back to Main Menu

________________________________________________________________________________________________________________________

Aim of this lab:


The aim of this laboratory session is to reinforce the concepts associated with the Fourier Transform. This will involve constructing filters directly in the frequency domain in order to implement some image enhancement techniques.
________________________________________________________________________________________________________________________

The Butterworth Filter

For the first task of this lab, we were ask to construct a few low-pass, high-pass and high boost Butterworth filters by using the function lowpassfilter.m, highpassfilter.m and highboostfilter.m provided to us. Experiment with different values of parameters have been carried out for these filters. The result is shown below:

Low-pass filter

MATLAB Command:

im = imread('me.jpg');
g = rgb2gray(im);
imfft = fft2(g);
low = lowpassfilter(size(im),0.3,1); 
%cutoff = 0.3 and n = 1
surfl(fftshift(low)),shading interp;
lowinv = real(ifft2(low));            
%inverse fft of the filter
surfl(fftshift(lowinv)),shading interp; 

newlow = imfft.*low;
newim = real(ifft2(newlow));
show(newim);


Figure1: My original grey scale image

       
Figure2: Low pass filter with                        Figure3: The inverse of low pass filter              Figure4: Result of myself after applying low pass filter
             cutoff = 0.3, n = 1


       
Figure5: Low pass filter with                        Figure6: The inverse of low pass filter            Figure7: Result of myself after applying low pass filter
             cutoff = 0.1, n = 2000

From the above result, we can see that by applying a low order low pass filter, we get a smoother image. This is because the low order filter has a more Gaussian profile which smoothen the image more. The image obtained from high order has a low smoothing effect compare to the low order filter.

High-pass filter

MATLAB Command:

high= highpassfilter(size(im),0.3,1);  %cutoff = 0.3 and n = 1
surfl(fftshift(low)),shading interp;
highinv = real(ifft2(low));            
%inverse fft of the filter
surfl(fftshift(highinv)),shading interp; 

newhigh = imfft.*high;
newim = real(ifft2(newhigh));
show(newim);

       
Figure8: High pass filter with                        Figure9: The inverse of high pass filter            Figure10: Result of myself after applying high pass filter
             cutoff = 0.3, n = 1

       
Figure11: High pass filter with                       Figure12: The inverse of high pass filter        Figure13: Result of myself after applying high pass filter
             cutoff = 0.1, n = 2000

When using the low order filter for the high pass filter, the image obtain is smoother compare to a high order high pass filter.

High-boost filter

MATLAB Command:

boost = highboostfilter(size(im),0.3,1,500);    %high boost filter with cutoff=3, n=1 and boost=500
surfl(fftshift(boost)), shading interp;
surfl(fftshift(boost)), shading interp;
boostinv = real(ifft2(boost));
surfl(fftshift(boostinv)), shading interp;     
%inverse fft of the filter
newboost = imfft.*boost;
newim = real(ifft2(newboost));
show(newim);


       
Figure14: High boost filter with                  Figure15: The inverse of high boost filter        Figure16: Result of myself after applying high boost filter
             cutoff = 0.3, n = 1, boost = 5

       
Figure17: High boost filter with                  Figure18: The inverse of high boost filter        Figure19: Result of myself after applying high boost filter
               cutoff = 0.3, n = 1, boost = 500

By applying a higher boost value, the image obtained has higher frequencies compare to the low order high boost filter. However, if the boost value is too large, then the resulting image will be very dark as the low frequencies of the image becomes very small and cannot be observed.

Black-spot Filtering

The next task for this lab involved the black-spot filtering. We are asked to write a blackspot.m function in order to black out small spots within a Fourier spectrum. A finger print image (Figure20) and a pigeon image (Figure24) was taken as an experiment. Figure15 is the Fourier Transform of the image and we can see the repeated pattern of the underlying half-tone pattern appear as a series of bright dots in the FFT spectrum, these points represent all the harmonics of the repetitive half-tone pattern, each bright dot has a very strong frequency component. If the spots in the spectrum can be 'black out' and invert the Fourier Transform, we can get rid of this half-tone pattern. Result of the finger print image after applying black-spot filter is shown below:

MATLAB Command:

finger = imread('finger3.png');
finger_new = editspec(finger,0.01, 1);

pidgie = imread('pidgie.jpg');
pidgie_new = editspec(pidgie,0.01,1);


   
Figure20: finger3.png                                            Figure21: The Fourier Transform of finger3.png

  
Figure22: The Fourier Transform of finger3.png      Figure23: Result of finger3.png after applying black-spot filtering
               after blacken     


  
Figure24: pidgie.jpg                           Figure25: The Fourier Transform of pidgie.jpg 

   
Figure26: The Fourier Transform of     Figure27: Result of finger3.png after applying black-spot filtering
               pidgie.jpg after blacken   

Inverse Filtering

In this section of the lab, we were asked to use the write a function of Weiner filter and then apply it to the image blur.png(Figure28) and motion.png. The results obtained are:

The Blur Image (blur.jpg)

MATLAB Command:
blur = imread('blur.png');
ps = psf2(size(blur),4,0,5,5,2);
H = fft2(fftshift(ps));                            
%get the Fourier Transform of point spread and shift
wiener = (1./H) .* (abs(H).^2 ./ (abs(H).^2 + 0.01 ));                                  
wienerfft = fft2(wiener);
new = H.*wiener;                                   
%the product of Wiener Filter and FFT of point spread  
imagesc(fftshift(abs(new))), colormap(gray); %get the psfft.*wiener
improfile                                           
   %get the profile of the product

   
Figure28: blur.png                                                                          Figure29: The image of the point spread function   
 

   
Figure30: The profile of the point spread function                           Figure31: The Fourier Transform of the point spread function

   
Figure32: The profile of  point spread function FFT                         Figure33: The FFT of Wiener Filter

   
Figure34: The product of Wiener Filter and point spread                 Figure35: The profile of the product Wiener Filter and point spread
                 function FFT                                                                                    function FFT   

 
The best effort at enhancing the blur image are the both image below with different value of squareness:

   
Figure36: wienfilt(blur,8,8,0,10,0.01);               Figure37: wienfilt(blur,8,8,0,10,0.01); 

The Motion Blurred image (motion.jpg)

Matlab Command:
motion = imread('motion_blurred.png');
ps = psf2(size(motion),10,0.4,33,2,2);
H = fft2(fftshift(ps));
wiener = (1./H) .* (abs(H).^2 ./ (abs(H).^2 + 0.01 ));

psfft = fft2(ps);                                       %get the Fourier Transform of point spread
wienerfft = fft2(wiener);
new = H.*wiener;                                   
%the product of Wiener Filter and FFT of point spread  
imagesc(fftshift(abs(new))), colormap(gray); %get the psfft.*wiener
improfile      

   
Figure38: motion_blurred.png                                                        Figure39: The image of the point spread function   


   
Figure40: The profile of the point spread function                           Figure41: The Fourier Transform of the point spread function

   
Figure42: The profile of  point spread function FFT                         Figure43: The FFT of Wiener Filter

   
Figure44: The product of Wiener Filter and point spread                 Figure45: The profile of the product Wiener Filter and point spread
                 function FFT                                                                                    function FFT   


The two figures below are the best efforts of enhancing the motion_blurred images. Notice that the number plate can be seen after applying the wiener filter. The number plate of the car is "N 443 JJ0".

   
Figure46: wienfilt(motion,33,2,0.4,10,0.01);          Figure47: wienfilt(motion,33,2,0.4,10,0.0001);  

Written by Geoffrey Liau
Last updated: 30th April 2005
liauc01@student.uwa.edu.au