Detection de contours

Signaler
-
qlq un me corriger ce programme svp

I=imread('lena.jpg');
I=rgb2gray(I);
I=double(I)/255;
level=0.5;

%carte de gradient
MH= [1 2 1; 0 0 0;-1 -2 -1];
GH = conv2 (I, MH);
figure(1),imshow(GH), title('Contours horizontal');
MV= [-1 0 1; -2 0 2; -1 0 1];
GV = conv2 (I, MV);
figure(2),imshow(GV), title('Contours vertical');
G=sqrt(GH.*GH + GV.*GV);
G=im2bw(G,level);
figure(3),imshow(G), title('Contours global');

%direction du gradient
eq=imdivide(GH,GV);
eq=atan(eq);
eq= (eq*180)/pi;
figure(4),imshow(eq),title ('direction gradient');

%seuillage et suppression des non maximum locaux
for i = 1 : size(eq,1)
j = 1 : size(eq,2)
if level > eq(i,j)
eq(i,j) = 0;
if level < eq(i,j)
eq(i,j) = 255;
end
end
end
eq = im2bw(eq,level);
figure(5), imshow(eq)