% Expt 5: To Perform Edge Detection Using Various Masks (Prewitt)

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 5: To perform edge detection using various masks (Prewitt)

clear ;
close;
clc;

//Read the image


//I=imread('A.bmp')
I=imread('ImageA.bmp')
subplot(2,2,1);imshow(I);title('Input Gray Image');

//Define Prewitt X mask


PrewittX=[-1 0 1;-1 0 1;-1 0 1];

//Define Prewitt y mask


PrewittY=[-1 -1 -1;0 0 0;1 1 1];

//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
Gx(row,col)=sum(Isub.*PrewittX);
Gy(row,col)=sum(Isub.*PrewittY);

//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

//==========================================================
Iout=abs(Gx)+abs(Gy);

//typecast
Gx=mat2gray(Gx);
//Iout=uint8(Iout);
subplot(2,2,2);imshow(Gx);title('Gx output');

//typecast
Gy=mat2gray(Gy);
//Iout=uint8(Iout);
subplot(2,2,3);imshow(Gy);title('Gy output');

//typecast
Iout=mat2gray(Iout);
//Iout=uint8(Iout);
subplot(2,2,4);imshow(Iout);title('Prewitt output');

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

You might also like