Edge Detection:
In most image processing applications we have to deal with the edges in an image. There are different algorithms for finding edges in the images every one has its own attributes and results. One of the edge detection algorithm is Marr-Hilderth Algorithm.
Marr-Hilderth Algorithm:
It is based on following steps.
1.Filter the input image with an nxn Gaussian lowpass filter. N is the smallest odd integer greater than or equal to 6
2.Compute the Laplacian of the image resulting from step1
3.Find the zero crossing of the image from step 2
The serious disadvantage of this algorithm is that it also detect some false edges.
Consider the input image:
Input Image:
Image may be NSFW.
Clik here to view.
Output:
For sigma=1
Image may be NSFW.
Clik here to view.
Matlab Code:
function marr
clc
clear all
close all
a=imread(‘cameraman.tif’);
a=im2double(a);
[r c]=size(a);
sigma=input(‘Enter the value of Sigma : ‘);
order=6*sigma;
order=round(order);
order
if(rem(order,2)==0)
order=order+1
end
%Gaussian Filter Design
for i=1:order
for j=1:order
g(i,j)=exp((-(((i-ceil(order/2))^2)+((j-ceil(order/2))^2))/(2*(sigma^2))));
end
end
[r c]=size(g);
g
sum=0;
for i=1:r
for j=1:c
sum=sum+g(i,j);
end
end
%Convolving with the image
[r c]=size(a);
[p q]=size(g)
for i=floor(p/2)+1:r-floor(p/2)
for j=floor(q/2+1):c-floor(q/2)
filt(i,j)=0;
for m=1:p
for n=1:q
filt(i,j)=filt(i,j)+(a(i+(m-(floor(p/2)+1)),j+(n-(floor(q/2)+1)))*g(m,n));
end
end
end
end
%Taking Laplace of filtered Image
w=[1 1 1;1 -8 1;1 1 1];
[r c]=size(filt);
for i=2:r-2
for j=2:c-2
result(i,j)=0;
for m=1:3
for n=1:3
result(i,j)=result(i,j)+(filt(i+(m-2),j+(n-2))*w(m,n));
end
end
end
end
%Finding zero-crossings
b=1-result;
[r c]=size(b);
a=double(zeros(r,c));
for i=2:r-1
for j=2:c-1
sum=0;
if((b(i-1,j)>0&&b(i+1,j)<0)||(b(i-1,j)<0&&b(i+1,j)>0))
sum=sum+1;
end
if((b(i,j-1)>0&&b(i,j+1)<0)||(b(i,j-1)<0&&b(i,j+1)>0))
sum=sum+1;
end
if((b(i+1,j-1)>0&&b(i-1,j+1)<0)||(b(i+1,j-1)<0&&b(i-1,j+1)>0))
sum=sum+1;
end
if((b(i-1,j-1)>0&&b(i+1,j+1)<0)||(b(i-1,j-1)<0&&b(i+1,j+1)>0))
sum=sum+1;
end
sum;
if(sum>2)
a(i,j)=1;
else
a(i,j)=0;
end
end
end
figure(1)
imshow(g)
title(‘Gaussian Filter’)
figure(2)
imshow(filt)
title(‘Filtered Image’)
figure(3)
imshow(result)
title(‘Laplace of Filtered Image’)
figure(4)
imshow(a)
title(‘Zero-Crossings’)