1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| close all
clear
I=imread('image/frog.jpg'); %recuperation de l'image
I=rgb2gray(I);
I=double(I)/255.0;
%%%%%%%%%%%%%%%%%%% filtre de Prewitt %%%%%%%%%%%%%%%%%%%%%
h_prewitt=fspecial('prewitt'); % creation du filtre (filtre horizontal)
v_prewitt=-h_prewitt';
IderivPrewittH=filter2(h_prewitt,I);
IderivPrewittV=filter2(v_prewitt,I);
%%%%%%%%% approche gradient
Ideriv=sqrt(IderivPrewittH.*IderivPrewittH + IderivPrewittV.*IderivPrewittV); %norme du gradient
%%%%%%% seuillage + histerisis
%% extraction des extrema locaux dans la direction du gradient
dirGrad=atan(IderivPrewittV./IderivPrewittH); %calcul des directions
dirGrad=dirGrad*180/pi; % passage en degré
%arondir la matrice des directions par multiple de 45 degré
dirGrad=arrondiMultiple(dirGrad);
%detection des extrema
Icontour=Ideriv;
[row,col]=size(dirGrad); %nombre de lignes et de colones
for i1=2:row-1
for j1=2:col-1
switch dirGrad(i1,j1)
case 0
if Icontour(i1,j1)<Icontour(i1,j1-1) | Icontour(i1,j1)<Icontour(i1,j1+1)
Icontour(i1,j1)=0;
end;
case 45
if Icontour(i1,j1)<Icontour(i1-1,j1+1) | Icontour(i1,j1)<Icontour(i1+1,j1-1)
Icontour(i1,j1)=0;
end;
case -45
if Icontour(i1,j1)<Icontour(i1+1,j1+1) | Icontour(i1,j1)<Icontour(i1-1,j1-1)
Icontour(i1,j1)=0;
end;
case{-90,90}
if Icontour(i1,j1)<Icontour(i1-1,j1) | Icontour(i1,j1)<Icontour(i1+1,j1)
Icontour(i1,j1)=0;
end;
otherwise
Icontour(i1,j1)=Icontour(i1,j1);
end;
end;
end;
figure,
imshow(Icontour,'notruesize'); |
Partager