DIP Exp - 6 [ Edge DETECTION ]
%EDGE DETECTION USING PREWITT OPERATOR/MASK.
clear all;
clc;
aa=imread('sample.jpg');
a=double(rgb2gray(aa));
% ab=imnoise(aa);
% a=double(ab);
w=[-2 -1 0;-1 0 1;0 1 2]
[row col]=size(a);
for x=2:1:row-1
for y=2:1:col-1
a1(x,y)=(a(x-1,y-1)*w(1)+a(x-1,y)*w(2)+a(x-1,y+1)*w(3)+a(x,y-1)*w(4)+a(x,y)*w(5)+a(x,y+1)*w(6)+a(x+1,y-1)*w(7)+a(x+1,y)*w(8)+a(x+1,y+1)*w(9));
end
end
subplot(221)
figure(1)
imshow(uint8(a))
title('ORIGINAL IMAGE')
subplot(222)
imshow(uint8(a1))
title('PREWITT OPERATED IMAGE')
%EDGE DETECTION USING SOBEL OPERATOR/MASK.
w=[-2 -2 0;-2 0 2;0 2 2]
[row col]=size(a);
for x=2:1:row-1
for y=2:1:col-1
a1(x,y)=(a(x-1,y-1)*w(1)+a(x-1,y)*w(2)+a(x-1,y+1)*w(3)+a(x,y-1)*w(4)+a(x,y)*w(5)+a(x,y+1)*w(6)+a(x+1,y-1)*w(7)+a(x+1,y)*w(8)+a(x+1,y+1)*w(9));
end
end
subplot(223)
imshow(uint8(a1))
title('SOBEL OPERATED IMAGE')
%EDGE DETECTION USING ROBERT OPERATOR/MASK.
w=[1 1;-1 -1]
[row col]=size(a);
for x=2:1:row-1
for y=2:1:col-1
a1(x,y)=(a(x,y)*w(1)+a(x,y+1)*w(2)+a(x+1,y)*w(3)+a(x+1,y+1)*w(4));
end
end
subplot(224)
imshow(uint8(a1))
title('ROBERT OPERATED IMAGE')