% Find edges using the Canny operator with hysteresis thresholds of 0.1
% and 0.2 with smoothing parameter sigma set to 1.
% Explain: The Canny method finds edges by looking for local maxima of the
% gradient of I. The gradient is calculated using the derivative of a
% Gaussian filter. The method uses two thresholds, to detect strong
% and weak edges, and includes the weak edges in the output only if
% they are connected to strong edges. This method is therefore less
% likely than the others to be "fooled" by noise, and more likely to
% detect true weak edges.
edgeim = edge(im,'canny', T_edge, 1);
% figure(1), imshow(edgeim);
% Link edge pixels together into lists of sequential edge points, one
% list for each edge contour. Discard contours less than 10 pixels long.
[edgelist, labelededgeim] = edgelink(edgeim, 10);
% Display the labeled edge image with separate colours for each
% distinct edge (choose your favorite colourmap!)
%figure(2), imagesc(labelededgeim); colormap(vga), axis image, axis off
%figure(1); imshow(imo);
h = waitbar(0,'Please wait...Analysis can be time consuming for High Resolution image');
Nmax=max(max(labelededgeim));
%taille memoire resultat!
SC=zeros(1000,2,100);
for uu=1:Nmax
waitbar(uu/Nmax,h)
[r,c] = find(labelededgeim==uu);
rc = [r c];
[sx sy]=size(rc);
[imx,imy]=size(labelededgeim);
n1=zeros(imx,imy);
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end % Storing the extracted image in an array
Cn1=ait_imneg(n1);
%!!!attention x et y permutation
[y,x]=find(Cn1==0);
cerne=[y,x];
delta_sq = diff(cerne).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
P(uu)=perimeter/length(cerne);
if P(uu) > threshold
Pu(uu)=uu;
compt=compt+1;
SC(1:length(cerne),:,compt)=cerne;
disp('good');
%perimeter/length(cerne)
metric_string = [sprintf('R %d ', compt)];%,sprintf('\n'), sprintf('P %d', P(uu))];
figure(1);hold on;plot(x,y,'g.');hold on;
text(mean(x)-5,min(y)+5,metric_string,'Color','y',...
'FontSize',11,'FontWeight','bold');
else
disp('NOT A RING');
end
end
close(h);