Cette détection de coins utilise un cercle pour trouver la variation d'intensité entre les pixels. Prenons le cercle suivant :
Grâce à ce cercle nous faisons le calcul suivant :
où
et
Les coordonnées x et y correspondent au centre du cercle pc. Ce calcul a pour effet de calculer les coins potentiels de l'image. Les pixels possédant une valeur assez importante sont considérés comme coins potentiels. Pour chaque coin potentiel, nous effectuons le calcul de la variation minimum dans toutes les directions grâce à l'algorithme suivant :
avec
Nous supprimons ensuite tous les points de la matrice m inférieurs à un seuil T
Puis une détection des maxima locaux est appliquée.
clear all;
close all;
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
'*.*','All Files' },'mytitle',...
'C:\Work\myfile.jpg')
img = imread(filename);
img=mean(img,3);
[ligneorigine colonneorigine]=size(img);
taille=1;
%effet de bord
img = wextend(2,'zpd',img,1);
[ligne colonne]=size(img);
d=zeros(ligne,colonne);
for i = taille+1 : ligne-(taille+1)
for j = taille+1 : colonne -(taille+1)
d(i,j)=min( (img(i,j-1)-img(i,j))^2+(img(i,j+1)-img(i,j))^2 ,...
(img(i-1,j)-img(i,j))^2+(img(i+1,j)-img(i,j))^2 );
end
i
end
threshold = 50;
d(d<=threshold)=0;
d(d>threshold)=1;
m=zeros(ligne,colonne);
%threshold = 35000;
for i = taille+1 : ligne-(taille+1)
for j = taille+1 : colonne -(taille+1)
if d(i,j)~=0
c=min( (img(i,j-1)-img(i,j))^2+(img(i,j+1)-img(i,j))^2 ,...
(img(i-1,j)-img(i,j))^2+(img(i+1,j)-img(i,j))^2 );
B1= (img(i-1,j)-img(i,j-1))*(img(i,j-1)-img(i,j))+(img(i+1,j)-img(i,j+1))*(img(i,j+1)-img(i,j));
B2= (img(i-1,j)-img(i,j+1))*(img(i,j+1)-img(i,j))+(img(i+1,j)-img(i,j-1))*(img(i,j-1)-img(i,j));
RA=(img(i,j-1)-img(i,j))^2+(img(i,j+1)-img(i,j))^2;
RB=(img(i-1,j)-img(i,j))^2+(img(i+1,j)-img(i,j))^2;
C= RA;
B=min(B1,B2);
A= RB-RA-2*B;
if B<0 && (A+B)>0
m(i,j)=C-(B^2/A);
else
m(i,j)=c;
end
else
m(i,j)=0;
end
end
i
end
m = m(taille:end-taille-1,taille:end-taille-1);
threshold = 1000;
m(m<=threshold)=0;
[imax,vmax]= maxlocaux(m,10);
figure( 'name','détection de coin Trajkovic 4 voisins',...
'NumberTitle','off',...
'MenuBar','none',...
'color',[0.3137 0.3137 0.5098]);
imshow(uint8(img))
hold on
nb=200;
if length(imax)>nb
nbcorner = nb;
else
nbcorner=length(imax);
end
for i = 1 : nbcorner %length(imax)
plot([vmax(i,2)-2 vmax(i,2)-2 vmax(i,2)+2 vmax(i,2)+2 vmax(i,2)-2],...
[vmax(i,1)-2 vmax(i,1)+2 vmax(i,1)+2 vmax(i,1)-2 vmax(i,1)-2] ,'r','LineWidth',1)
end
Une amélioration de la première version est de prendre 8 voisins au lieu de 4. Cette augmentation du nombre de variations sur le cercle
permet de supprimer les erreurs dues aux bruits. Prenons le cercle suivant :
Les equations deviennent alors :
avec
Grâce à ce calcul nous déterminons les coins potentiels de l'image. Pour chaque coin potentiel, nous effectuons le calcul de la variation minimum dans les 8 directions grâce à l'agorythme suivant :
avec
Puis nous seuillons la matrice m avec un seuil T:
Et enfin une détection de maxima locaux.
clear all;
close all;
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
'*.*','All Files' },'mytitle',...
'C:\Work\myfile.jpg')
img = imread(filename);
img=mean(img,3);
[ligneorigine colonneorigine]=size(img);
taille=2;
%effet de bord
img = wextend(2,'zpd',img,1);
[ligne colonne]=size(img);
d=zeros(ligne,colonne);
for i = taille+1 : ligne-(taille+1)
for j = taille+1 : colonne -(taille+1)
A=img(i-1,j);
Ap=img(i+1,j);
B=img(i,j-1);
Bp=img(i,j+1);
C=img(i,j);
D=img(i-1,j-1);
Dp=img(i+1,j+1);
E=img(i-1,j+1);
Ep=img(i+1,j-1);
RA=(A-C)^2+(Ap-C)^2;
RB=(B-C)^2+(Bp-C)^2;
RD=(D-C)^2+(Dp-C)^2;
RE=(E-C)^2+(Ep-C)^2;
d(i,j)=min([RA,RB,RD,RE]);
end
i
end
threshold = 50;
d(d<=threshold)=0;
m=zeros(ligne,colonne);
for i = taille+1 : ligne-(taille+1)
for j = taille+1 : colonne -(taille+1)
if d(i,j)~=0
A=img(i-1,j);
Ap=img(i+1,j);
B=img(i,j-1);
Bp=img(i,j+1);
C=img(i,j);
D=img(i-1,j-1);
Dp=img(i+1,j+1);
E=img(i-1,j+1);
Ep=img(i+1,j-1);
B1= (B-A)*(A-C)+(Bp-Ap)*(Ap-C);
B2= (D-B)*(B-C)+(Dp-Bp)*(Bp-C);
B3= (E-D)*(E-C)+(Ep-Dp)*(Ep-C);
B4= (Ap-E)*(E-C)+(A-Ep)*(Ep-C);
RA=(A-C)^2+(Ap-C)^2;
RB=(B-C)^2+(Bp-C)^2;
RD=(D-C)^2+(Dp-C)^2;
RE=(E-C)^2+(Ep-C)^2;
A1=RB-RA-2*B1;
A2=RD-RB-2*B2;
A3=RE-RD-2*B3;
A4=RA-RE-2*B4;
if max([B1,B2,B3,B4])<0 && min([(A1+B1),(A2+B2),(A3+B3),(A4+B4)])>0
D1=RA - (B1^2/A1);
D2=RB - (B2^2/A2);
D3=RD - (B3^2/A3);
D4=RE - (B4^2/A4);
m(i,j)=min([D1,D2,D3,D4]);
else
m(i,j)=min([RA,RB,RD,RE]);
end
else
m(i,j)=0;
end
end
i
end
m = m(taille:end-taille-1,taille:end-taille-1);
[ligne colonne]=size(img);
radius=10;
[imax,vmax]= maxlocaux(m,radius);
figure( 'name','détection de coin Trajkovic 4 voisins',...
'NumberTitle','off',...
'color',[0.3137 0.3137 0.5098]);
imshow(uint8(img))
hold on
nb=200;
if length(imax)>nb
nbcorner = nb;
else
nbcorner=length(imax);
end
for i = 1 : nbcorner %length(imax)
plot([vmax(i,2)-2 vmax(i,2)-2 vmax(i,2)+2 vmax(i,2)+2 vmax(i,2)-2],...
[vmax(i,1)-2 vmax(i,1)+2 vmax(i,1)+2 vmax(i,1)-2 vmax(i,1)-2] ,'r','LineWidth',1)
end
Copyright © 2010-2014, tous droits réservés, contact : operationpixel@free.fr