image thumbnail

Edge Detection

by

 

This is simple method of edge detection.

edgedetectionnormal.m
clc;
clear all;
close all;
a=uigetfile('*.*','Select the Image:-');
a=imread(a);
% s=isrgb(a);
% if (s==1)
    a=rgb2gray(a);
% end
b=double(a);
d=b;
mh=[1 0;-1 0];
mv=[1 -1;0 0];
[r1,c1]=size(a);
for i=1:r1
    for j=1:c1
        new(i,j)=a(i,j);
        nem(i,j)=a(i,j);
    end
end
new=double(new);
nem=double(nem);
for i=2:1:r1-1
    for j=2:1:c1-1
        new(i,j)=(mh(1)*d(i,j))+(mh(2)*d(i,j+1))......
                +(mh(3)*d(i+1,j))+(mh(4)*d(i+1,j+1));
    end
end
for i=2:1:r1-1
    for j=2:1:c1-1
        nem(i,j)=(mv(1)*d(i,j))+(mv(2)*d(i,j+1))......
                +(mv(3)*d(i+1,j))+(mv(4)*d(i+1,j+1));
    end
end
new2=new+nem;





subplot(221);imshow(uint8(a));title('Original Image');
subplot(222);imshow(uint8(new));title('X-Gradiant Image');
subplot(223);imshow(uint8(nem));title('Y-Gradiant Image');
subplot(224);imshow(uint8(new2));title('Resultant Gradiant Image');

Contact us