You are on page 1of 6

ROBERT EDGE DETECTION

Clc;
clear all;
close all;
A= imread('cameraman.tif');
F=im2double(A);
H=F;
I=F;
K=F;
[r c]=size(F);
GX=[1 -1;0 0];
GY=[1 0;-1 0];
GXY=GX+GY;
G1=zeros(2,2);
G2=zeros(2,2);
G3=zeros(2,2);
H=F;I=F;K=F;

for i=1:(r-1)
for j=1:(c-1)
for k=1:2
for l=1:2
G1(k,l)=F(i+k-1,j+l-1).*GX(3-k,3-l);
G2(k,l)=F(i+k-1,j+l-1).*GY(3-k,3-l);
G3(k,l)=F(i+k-1,j+l-1).*GXY(3-k,3-l);
end
end
sumG1=sum(sum(G1));
H(i,j)=sumG1;
sumG2=sum(sum(G2));
I(i,j)=sumG2;
sumG3=sum(sum(G3));
K(i,j)=sumG3;
end
end

subplot(2,2,1);
imshow(uint8(A));
title('Input Image ');
subplot(2,2,2);
imshow(H);
title('Output Image for GX');
subplot(2,2,3);
imshow(I);
title('Output Image for GY');
subplot(2,2,4);
imshow(K);
title('Output Image for GXY');
SOBEL EDGE DETECTION
F= double(imread('cameraman.tif'));
H=F;
I=F;
K=F;
[rows cols]=size(F);
GX=[-1 -2 -1;0 0 0;1 2 1];
GY=[-1 0 1;-2 0 2;-1 0 1];
GXY=GX+GY;
G1=zeros(3,3);
G2=zeros(3,3);
G3=zeros(3,3);

for i=2:(rows-1)
for j=2:(cols-1)
for k=-1:1
for l=-1:1
G1(k+2,l+2)=F(i+k,j+l).*GX(k+2,l+2);
G2(k+2,l+2)=F(i+k,j+l).*GY(k+2,l+2);
G3(k+2,l+2)=F(i+k,j+l).*GXY(k+2,l+2);
end
end
sumG1=sum(sum(G1));
H(i,j)=sumG1;
sumG2=sum(sum(G2));
I(i,j)=sumG2;
sumG3=sum(sum(G3));
K(i,j)=sumG3;
end
end
H=uint8(round(H));
I=uint8(round(I));
K=uint8(round(K));
subplot(3,2,[1 2]);
imshow(uint8(F));
title('Input Image ');
subplot(3,2,3);
imshow(H);
title('Output Image for GX');
subplot(3,2,4);
imshow(I);
title('Output Image for GY');
subplot(3,2,5);
imshow(K);
title('Output Image for GXY');
BW = edge(F,'sobel');
subplot(3,2,6);
imshow(BW);
title('Output Image for GXY using inbuilt function');
figure;
PREWITT EDGE DETECTION

F= double(imread('cameraman.tif'));
H=F;
I=F;
K=F;
[rows cols]=size(F);
GX=[-1 -1 -1;0 0 0;1 1 1];
GY=[-1 0 1;-1 0 1;-1 0 1];
GXY=GX+GY;
G1=zeros(3,3);
G2=zeros(3,3);
G3=zeros(3,3);

for i=2:(rows-1)
for j=2:(cols-1)
for k=-1:1
for l=-1:1
G1(k+2,l+2)=F(i+k,j+l).*GX(k+2,l+2);
G2(k+2,l+2)=F(i+k,j+l).*GY(k+2,l+2);
G3(k+2,l+2)=F(i+k,j+l).*GXY(k+2,l+2);
end
end
sumG1=sum(sum(G1));
H(i,j)=sumG1;
sumG2=sum(sum(G2));
I(i,j)=sumG2;
sumG3=sum(sum(G3));
K(i,j)=sumG3;
end
end
H=uint8(round(H));
I=uint8(round(I));
K=uint8(round(K));
subplot(3,2,[1 2]);
imshow(uint8(F));
title('Input Image ');
subplot(3,2,3);
imshow(H);
title('Output Image for GX');
subplot(3,2,4);
imshow(I);
title('Output Image for GY');
subplot(3,2,5);
imshow(K);
title('Output Image for GXY');
BW = edge(F,'sobel');
subplot(3,2,6);
imshow(BW);
title('Output Image for GXY using inbuilt function');
figure;

You might also like