In Spatial Domain: %% %low Pass Filter

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

In spatial domain

clc;clear all;close all;


I=imread('C:\Users\Ripan\Desktop\sam.tif');
imshow(I)
title('Original image')
%%
%Low Pass Filter
mask1=[1 1 1;1 1 1;1 1 1]/9;
If1=imfilter(I,mask1);
figure;
imshow(If1)
title('Low Pass Filtered image')
%%
%Gaussian Filter
Ig=imnoise(I,'gaussian');
figure;
imshow(Ig)
title('Image with Gaussian noise')
mask2=zeros(3,3);
p=1;
for x=-1:1
for y=-1:1
mask2(x+2,y+2)=exp(-( x.^2+ y.^2 )/2*p^2);
end
end
If2=imfilter(I,mask2);
figure;
imshow(If2)
title('Gaussian Filtered image')
%%
%Weighted Low Pass Filter
mask3=[1 2 1;2 4 2;1 2 1]/16;
If3=imfilter(I,mask3);
figure;
imshow(If3)
title('Weighted Low Pass Filtered image')
%%
%High Pass Filter
mask4=[0 0 0;0 1 0;0 0 0]-[1 1 1;1 1 1;1 1 1]/9;
If4=imfilter(I,mask4);
figure;
imshow(If4)
title('High Pass Filtered image')
%%
%High Boost Filter
mask5=3*[0 0 0;0 1 0;0 0 0]-[1 1 1;1 1 1;1 1 1]/9;
If5=imfilter(I,mask5);
figure;
imshow(If5)
title('High Boost Filtered image')
%%
%Unsharp Masking
mask6=[0 0 0;0 1 0;0 0 0]+3*([0 0 0;0 1 0;0 0 0]-[1 1 1;1 1 1;1 1 1]/9);
If6=imfilter(I,mask6);
figure;
imshow(If6)
title('Unsharp Masking image')
%%
%Laplacian Filter
mask7=[0 1 0;1 -4 1;0 1 0];

If7=imfilter(I,mask7);
figure;
imshow(If7)
title('Laplacian Filtered image')
%%
%Band Pass Filter
mask8=[0 1 0;1 1 1;0 1 0]/5-[1 1 1;1 1 1;1 1 1]/9;
If8=imfilter(I,mask8);
figure;
imshow(If8,[])
title('Band Pass Filterd image')








Original image
Low Pass Filtered image
Image with Gaussian noise Gaussian Filtered image




Weighted Low Pass Filtered image
High Pass Filtered image
High Boost Filtered image
Unsharp Masking image
Laplacian Filtered image
Band Pass Filterd image
In frequency domain:

clc;clear all;close all;
I=imread('C:\Users\Girish\Desktop\sam.tif');
figure;
imshow(I)
title('original image')
%%
%Low Pass Filtered image
[r c]=size(I);
rx=round(r/2);
cx=round(c/2);
If=fft2(I);
H=zeros(r,c);
h=[1 1 1;1 1 1;1 1 1]/9;
for i=rx-1:rx+1
for j=cx-1:cx+1
H(i,j)=h(i-126,j-126);
end
end
Hf=fft2(H);
Imf=If.*Hf;
Im=ifftshift(ifft2(Imf)/256);
figure;
imshow(Im)
title('Low Pass Filtered image')
%%
%Gaussian Filter
Ig=imnoise(I,'gaussian');
figure;
imshow(Ig)
title('Image with Gaussian noise')
Igf=fft2(Ig);
h=zeros(3,3);
p=1;
for x=-1:1
for y=-1:1
h(x+2,y+2)=exp(-( x.^2+ y.^2 )/2*p^2);
end
end
for i=rx-1:rx+1
for j=cx-1:cx+1
H(i,j)=h(i-126,j-126);
end
end
Hf=fft2(H);
Imf=Igf.*Hf;
%Im=ifftshift(ifft2(Imf)/256);
Im=ifftshift(ifft2(Imf)/256);
figure;
imshow(Im,[])
title('Gaussian filtered image')
%%
%Weighted Low Pass Filtered image
h=[1 2 1;2 4 2;1 2 1]/16;
for i=rx-1:rx+1
for j=cx-1:cx+1
H(i,j)=h(i-126,j-126);
end
end
Hf=fft2(H);
Imf=If.*Hf;
Im=ifftshift(ifft2(Imf)/256);
figure;
imshow(Im)
title('Weighted Low Pass Filtered image')
%%
%High Pass Filtered image
h=[0 0 0;0 1 0;0 0 0]-[1 1 1;1 1 1;1 1 1]/9;
%h=h*9;
for i=rx-1:rx+1
for j=cx-1:cx+1
H(i,j)=h(i-126,j-126);
end
end
Hf=fft2(H);
Imf=If.*Hf;
Im=ifftshift(ifft2(Imf)/256);
figure;
imshow(Im)
title('High Pass Filtered image')
%%
%High Boost Filtered image
h=3*[0 0 0;0 1 0;0 0 0]-[1 1 1;1 1 1;1 1 1]/9;
for i=rx-1:rx+1
for j=cx-1:cx+1
H(i,j)=h(i-126,j-126);
end
end
Hf=fft2(H);
Imf=If.*Hf;
Im=ifftshift(ifft2(Imf)/256);
figure;
imshow(Im)
title('High Boost Filtered image')
%%
%Unsharp masking
h=[0 0 0;0 1 0;0 0 0]+3*([0 0 0;0 1 0;0 0 0]-[1 1 1;1 1 1;1 1 1]/9);
for i=rx-1:rx+1
for j=cx-1:cx+1
H(i,j)=h(i-126,j-126);
end
end
Hf=fft2(H);
Imf=If.*Hf;
Im=ifftshift(ifft2(Imf)/256);
figure;
imshow(Im)
title('Unsharp masking image')
%%
%Laplacian Filtered image
h=[0 1 0;1 -4 1;0 1 0];
for i=rx-1:rx+1
for j=cx-1:cx+1
H(i,j)=h(i-126,j-126);
end
end
Hf=fft2(H);
Imf=If.*Hf;
Im=ifftshift(ifft2(Imf)/256);
figure;
imshow(Im)
title('Laplacian Fileredimage')
%%
%Band Pass Filtered image
h=[0 1 0;1 1 1;0 1 0]/5-[1 1 1;1 1 1;1 1 1]/9;
for i=rx-1:rx+1
for j=cx-1:cx+1
H(i,j)=h(i-126,j-126);
end
end
Hf=fft2(H);
Imf=If.*Hf;
Im=ifftshift(ifft2(Imf)/64);
figure;
imshow(Im)
title('Band Pass Filtered image')






original image
Low Pass Filtered image
Image with Gaussian noise
Gaussian filtered image



Weighted Low Pass Filtered image
High Pass Filtered image
High Boost Filtered image
Unsharp masking image
Laplacian Fileredimage
Band Pass Filtered image

You might also like