Introducing a border/outline to objects in an image – follow up question

1 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2013-10-15
It's not random once you know how it operates. It doesn't go across columns and then down line by line like you'd think. It goes down lines first. First it goes down column 1 until it finds something then it labels it #1. Then it goes down columns 2, 3, 4, 5, etc. until it finds another object that is not labeled yet, and it assigns it the next label number. So if you follow that logic, it's perfectly understandable how it got the numbers. Basically the same as what you think except going down columns and moving left to right, instead of going across rows and going down from top to bottom like you were expecting. Does that make sense now?
To get it numbered the way you want, you'd have to transpose your image, label it, then transpose the labeled image.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by