bwboundaries: Explanation of a example
이전 댓글 표시
This simple example is given in the Matlab Documentation:
I = imread('rice.png');
BW = im2bw(I, graythresh(I));
B = bwboundaries(BW,'noholes');
for k = 1:length(B)
boundary = B{k};
end
Even if I can see the result and why we need the loop, I don't fully get to understand what exactly is doing the "for" loop, I wouldn't know how to explain how it works. Can someone help me? Thank you
채택된 답변
추가 답변 (2개)
Anand
2015년 2월 5일
I assume you are talking about Example 1 in the documentation.
I = imread('rice.png');
BW = im2bw(I, graythresh(I));
[B,L] = bwboundaries(BW,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end
The for loop here is used in order to plot a white outline displaying the boundaries on the image.
댓글 수: 4
MashalS
2021년 8월 22일
what does noholes mean? what if its replaced by holes in 3rd line ?
Image Analyst
2021년 8월 22일
noholes means that there are no nested boundaries. So a donut shaped region would return only the larger outer boundary, not the inner boundary between the donut and the hole.
if you did not use noholes, for a donut region, it will return both the outer boundary and the inner boundary between the region and the hole. In other words, it will return the boundary of the hole (same as inner boundary of the donut) as well as the outer boundary of the donut.
Suresh D
2021년 9월 7일
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
Please explain this line
Image Analyst
2021년 9월 7일
boundary is an n-by-2 array of the row, column coordinates, in other words
[row1, col1;
row2, col2;
...
rown, coln];
which is
[y1, x1;
y2, x2;
...
yn, xn]
so boundary(:,2) is a column vector of all the x values and boundary(:,1) is a column vector of all the y values. So the plot command is essentially
plot(x, y, 'w', 'LineWidth', 2);
which will draw a white line between all the boundary points.
Babu Sankhi
2020년 7월 22일
0 개 추천
For my images I got the boundaries only for the very good contrast png images not for the less contrast images. Is there any way to get boundary even for the images with less contrast? In addition to that I want to find the distance between center and boundary(left/right) for several images. Is there any helpful codes/function so that I can find those distances more precisely?
Thank you
댓글 수: 4
Image Analyst
2020년 7월 24일
Depends on the image. You can try adapthisteq().
Babu Sankhi
2020년 7월 24일
Thank you analyst,
I am still gettting difficulty on findig the codes so that I can measure the distance between rightmost edges of green and red boundaries ( I mean the distance between A and B points) of the attached png image? Can You please help me on this regard? I have several images to do that .
Thank you
Image Analyst
2020년 7월 25일
You can use bwdist(). Attach your original image in a new question if you still need help.
Babu Sankhi
2020년 7월 26일
Thank you analyst for your help. But bwdist() did not give any difinite value in my case so I am still stucked with that . I have attached my original microscopy image and the code I used to get the boudaries of desired region of image . After that my problem is to find the distance between right most points of innner(green) and outer(Red) boundaries . It means I have to find the distance between A and B in in resulting png.
Can you please share more ideas about it ?
thank you
카테고리
도움말 센터 및 File Exchange에서 Blocked Images에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!