% Expt 4: To Perform Spatial Filtering (Low Pass Filter) : Clear CLC

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

%***********************************************************************************

*
%Name: Shubham Patil
%Division: A Roll no.:439
%***********************************************************************************
*
% Expt 4: To Perform Spatial Filtering (Low Pass Filter)

clear ;
close;
clc;

//Read the image


I=imread('cameraman.tif')
subplot(1,2,1);imshow(I);title('Input Gray Image');

//Define fileter mask


Mask=[1/9 1/9 1/9 ;1/9 1/9 1/9 ;1/9 1/9 1/9 ];

//size of image
[m n]=size(I);

I=double(I)

//============================================================================
//Perfom Spational filter
for row=2:m-1
for col=2:n-1

//get the sub image


Isub=I(row-1:row+1,col-1:col+1);

//fiiter operation
Iout(row,col)=sum(Isub.*Mask);

//Iout(row,col)=I(row-1,col-1)*Mask(1,1)+I(row-1,col)*Mask(1,2)+I(row-1,col+1)*Mask(1,3)+I(row,col-1)*Mask(2,1)
+I(row,col)*Mask(2,2)+I(row,col+1)*Mask(2,3)+ I(row+1,col-1)*Mask(3,1)
//+I(row+1,col)*Mask(3,2)+I(row+1,col+1)*Mask(3,3)
end//col
end//row

//typecast
//Iout=mat2gray(Iout);
Iout=uint8(Iout);
subplot(1,2,2);imshow(Iout);title('Low pass filter output');

%*************************************OUTPUT**************************************

You might also like