bwboundaries : missing coordinates of one of the two borders of my image

1 次查看(过去 30 天)
HI,
I have a problem with the function bwboundaries. When I use it with a black and white image (containing 2 pores), I can extract only the coordinates of a single border (whereas I have two). The plot gives me two disctinct border.
How can I have the coordinates for both borders?
I put the short code and the picture below.
Thank you
Image = imread('GDgeoRE2.bmp');
I = im2bw(Image);
Ifill = imfill(I,'holes');
B = bwboundaries(Ifill);
for k = 1:length(B)
b = B{k};
plot(b(:,1),b(:,2),'r','linewidth',2);
end
c1 = downsample(b(:,1),1);
c2 = downsample(b(:,2),1);
disp(b)
disp(c1)
disp(c2)

回答(1 个)

Guillaume
Guillaume 2019-9-18
编辑:Guillaume 2019-9-18
The problem has nothing to do with bwboundary. The problem is with you calling plot in a loop without hold on, so each time you call plot it erases the previous plot. Hence you're left with just the last boundary plot.
figure;
hold on;
for k = 1:length(B)
b = B{k};
plot(b(:,1),b(:,2),'r','linewidth',2);
end
would fix that.
  3 个评论
Guillaume
Guillaume 2019-9-18
I don't really understand what you are saying.
You could indeed concatenate all the boundaries into one array and plot it all at once but you'll get a line linking all the boundaries.
The concatenation can be done more efficiently without a loop:
v = [B{:}];

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by