DIP-Lab 8

CPEG540 Image Processing
Spring 2014
Lab 8
Date: 11:00 AM ~ 12:15 PM on April 10, 2014
Where: Tech 163
Objective: To Understand the usage of Filtering in Frequency domain.(Ideal, Butterworth, band reject,
notch and motion de-blurring filter )
Theory:
Ideal Filtering: For a shifted Fourier transformed image a low pass filter can be applied in order to
maintain the values at the center and remove or minimize the values away from the center. When the
low frequency part of the image is desired a high pass filter is applied.
Butterworth filtering: To overcome the introduction of unwanted artifacts in Ideal Filtering a
Butterworth filter is used.
To get rid of periodic noise band reject and notch filtering are used after a clear observation of the
Fourier transforms of the image.
Procedures:
Open your Matlab and type the Following codes and observe the output and draw your conclusions.
>> cm=imread('cameraman.tif');
>> cf=fftshift(fft2(cm));
>> figure,fftshow(cf,'log')
>> cfl=cf.*c;
>> figure,fftshow(cfl,'log')
>> cfli=ifft2(cfl);
>> figure,fftshow(cfli,'abs')
Where c is the circle used in Lab7.
>>
>>
>>
>>
>>
>>
>>
[x,y]=meshgrid(-128:127,-128:127);
z=sqrt(x.^2+y.^2);
c=(z>15);
cfh=cf.*c;
figure,fftshow(cfh,'log')
cfhi=ifft2(cfh);
figure,fftshow(cfhi,'abs')
To apply low pass and high pass Butterworth filters the following commands are used:
>> bl=lbutter(c,15,1);
>> cfbl=cf.*bl;
>> figure,fftshow(cfbl,'log')
>>
>>
>>
>>
>>
>>
>>
cfbli=ifft2(cfbl);
figure,fftshow(cfbli,'abs')
bh=hbutter(cm,15,1);
cfbh=cf.*bh;
figure,fftshow(cfbh,'log')
cfbhi=ifft2(cfbh);
figure,fftshow(cfbhi,'abs')
The same way we used Gaussian spatial filtering in time domain, it can also be used in Frequency
domain as shown below. For different standard deviation different results are obtained.
Low Pass Gaussian Filtering
>> g1=mat2gray(fspecial('gaussian',256,10));
>> cg1=cf.*g1;
>> fftshow(cg1,'log')
>> g2=mat2gray(fspecial('gaussian',256,30));
>> cg2=cf.*g2;
>> figure,fftshow(cg2,'log')
>> cgi1=ifft2(cg1);
>> cgi2=ifft2(cg2);
>> fftshow(cgi1,'abs');
>> fftshow(cgi2,'abs');
High Pass Gaussian Filtering
>> h1=1-g1;
>> h2=1-g2;
>> ch1=cf.*h1;
>> ch2=cf.*h2;
>> ch1i=ifft2(ch1);
>> chi1=ifft2(ch1);
>> chi2=ifft2(ch2);
>> fftshow(chi1,'abs')
>> figure,fftshow(chi2,'abs')
To Understand how the periodic noise removal filter works, first a noise is added to the cameraman
image as follows.
>> [x,y]=meshgrid(1:256,1:256);
>> s=1+sin(x+y/1.5);
>> cp=(double(cm)/128+s)/4;
>> cpf=fftshift(fft2(cp));
>> figure,fftshow(cpf,'abs')
Then the band-reject filter is applied to get rid of the noise and observe the results to draw your
conclusions.
>> br=(z < 47 | z > 51);
>> cpfbr=cpf.*br
Using Notch filter the noise could be get rid of as follows.
>> cpf(156,:)=0;
>> cpf(102,:)=0;
>> cpf(:,170)=0;
>> cpf(:,88)=0;
To Understand how motion deblurring filter works, try the following given commands.
To make it blurry:
>> bg=imread('board.tif');
>> b=bg(100:355,50:305);
>> imshow(b)
>> m=fspecial('motion',7,0);
>> bm=imfilter(b,m);
>> imshow(bm)%% blurry image is created
To de-blur the image, we need to divide its transform by the transform corresponding to the blur filter.
>>
>>
>>
>>
>>
>>
>>
m2=zeros(256,256);
m2(1,1:7)=m;
mf=fft2(m2);
d=0.02;
mf=fft2(m2);mf(find(abs(mf)<d))=1;
bmi=ifft2(fft2(bm)./mf);
imshow(mat2gray(abs(bmi))*2)