hold on
A=imread('example.tif');% A-b/w image, object - black color.
A=imcomplement(A);
R=9; %R=0.5* object distance - 18px
se=strel('disk', R, 0);
BW2 = imdilate(A, se);
X = bwlabel(BW2,4);
Y=X.*A;
stats = regionprops(Y, 'Centroid');
RGB = label2rgb(Y, @jet, 'k');
imshow(RGB)
for k = 1:length(stats)
    centroid = stats(k).Centroid;
    text(centroid(1),centroid(2),int2str(k),'Color','w','FontSize',8,'FontWeight','bold');
end
 


Hosted by uCoz