# bwboundaries: Explanation of a example

14 visualizaciones (últimos 30 días)
Zynk el 5 de Feb. de 2015
Comentada: Image Analyst el 7 de Sept. de 2021
This simple example is given in the Matlab Documentation:
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
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

Image Analyst el 5 de Feb. de 2015
If you have 10 blobs, you would get 10 boundaries. It gets the k'th boundary with this line
boundary = B{k};
And then it gets the x and y coordinates. Think of it like this
for k = 1 : length(B)
thisBoundary = B{k}; % Get k'th boundary
x = thisBoundary(:, 2);
y = thisBoundary(:, 1);
plot(x, y, 'w', 'LineWidth', 2);
end
The 'w' means to plot in white color, and the line width is the thickness of the line it's using to plot the boundary in the overlay above the image.
##### 1 comentarioMostrar NingunoOcultar Ninguno
Zynk el 5 de Feb. de 2015
Thanks, I understood why I needed the loop in order to plot,but not exactly how it was getting the boundary or why. Now it is clear.

Iniciar sesión para comentar.

### Más respuestas (2)

Anand el 5 de Feb. de 2015
I assume you are talking about Example 1 in the documentation.
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 comentariosMostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos
Image Analyst el 7 de Sept. de 2021
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.

Iniciar sesión para comentar.

Babu Sankhi el 22 de Jul. de 2020
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 comentariosMostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos
Babu Sankhi el 26 de Jul. de 2020
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.
thank you

Iniciar sesión para comentar.

### Categorías

Más información sobre Blocked Images en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by