Introducing a border/outline to objects in an image – follow up question
Show older comments
Based on the question in http://www.mathworks.com/matlabcentral/answers/27252 and the resulted script (below) I have two questions?
-The indexing and outline seems to be random (1 in the middle left while 10 is in the upper right), how does Matlab decide what will be the indexing (<http://i1196.photobucket.com/albums/aa410/nasa078/Mathworks/markup01.jpg)>?
-Furthermore, how can I “enforce” it that the outline and the index number will start from top to bottom, like in this example (<http://i39.tinypic.com/e839yt.jpg>)
Thanks.
Code:
Irgb = imread('ap78s9.jpg'); %http://i39.tinypic.com/ap78s9.jpg
Igray = rgb2gray(Irgb);
Ibw = im2bw(Igray,graythresh(Igray));
Ifill = imfill(Ibw,'holes');
B = bwboundaries(Ifill);
stat = regionprops(Ifill,'Centroid');
imshow(~Ibw); hold on
for k = 1 : length(B)
b = B{k};
c = stat(k).Centroid;
plot(b(:,2),b(:,1),'g','linewidth',2);
text(c(1),c(2),num2str(k),'backgroundcolor','g');
end
Accepted Answer
More Answers (0)
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!