Does bwboundaries always returned ordered, clockwise, boundaries?

9 visualizaciones (últimos 30 días)
David
David el 25 de Oct. de 2016
Comentada: David el 27 de Oct. de 2016
I am using bwboundaries to get the boundaries of an arbitrary assortment of objects. Because of some line integral calculations I plan to perform on the results, I need to know the handedness of the boundaries returned by bwboundaries. When I test bwboundaries with the following simple code, I find that it faithfully returns boundaries in an ordered clockwise manner, but I can't find any guarantee of this behavior in the documentation. To be clear, I don't care about the overall order of the boundary arraylist returned by bwboundaries, but the ordering and direction of each individual boundary in that list.
a = rand(401) > 0.992;
a = imdilate(a,strel('disk',5));
imtool(a)
b = bwboundaries(a);
figure;hold on;
for j=1:length(b)
bb = b{j};
for i = 1:length(bb)-1
plot(bb(i:i+1,1),bb(i:i+1,2))
pause(.02)
end
end
Can anyone confirm that bwboundaries does indeed returned ordered, clockwise boundaries, and provide a firm proof that this is so? If it is, I strongly recommend to Mathworks that this useful behavior be communicated in the documentation.
Thanks, David

Respuesta aceptada

Chaya N
Chaya N el 25 de Oct. de 2016
Editada: Chaya N el 25 de Oct. de 2016
Hello David, Please look up " help bwboundaries " at the command line if you would like an explicit mention of this particular property (specifically, the last line of the first paragraph!)
The confirmation that you seek is also provided as a reference in the 'Algorithms' subsection of the documentation here, but not in as many words.
A part of this reference goes : "This function is based on the boundaries function presented in the first edition of Digital Image Processing Using MATLAB..."
The information in the book says that the boundaries are traced in the clockwise direction by default. I suppose you could verify this firmly enough by looking up page 434 (Chapter 11, Subsection 11.1.3 - Some Basic Utility M-Functions) in the book!
  3 comentarios
Chaya N
Chaya N el 26 de Oct. de 2016
Ah! That I wouldn't know for sure. I can only guess that the original file has been updated since its first version so the wrapper inside the file has been changed too (it is statistically quite probable that somebody has already asked your question before). The essential functionality however, still remains the same so I suppose the documentation has not been changed (unless more examples and illustrations were added). I would therefore suggest that if you ever come across a similar situation again, it would be prudent to check both places.
I will also leave you with my favorite answer that every academic I've ever met has always told me when I've asked similar questions in the past: Have you checked the References for the original source?
DISCLAIMER: All opinions and guesses mentioned here are my very own.
David
David el 27 de Oct. de 2016
No haha you are totally right, I deserved that :). I even thought of trying to look at the references before posting here but was too lazy I suppose.

Iniciar sesión para comentar.

Más respuestas (1)

Amith Kamath
Amith Kamath el 25 de Oct. de 2016
David,
Thanks for the detailed question, and sharing the cool demo with us. Here is what the help text for bwboundaries says:
>> help bwboundaries
B = bwboundaries(BW) traces the exterior boundary of objects, as well
as boundaries of holes inside these objects. It also descends into the
outermost objects (parents) and traces their children (objects
completely enclosed by the parents). BW must be a binary image where
nonzero pixels belong to an object and 0-pixels constitute the
background. B is a P-by-1 cell array, where P is the number of objects
and holes. Each cell contains a Q-by-2 matrix, where Q is the number of
boundary pixels for the corresponding region. Each row of these Q-by-2
matrices contains the row and column coordinates of a boundary pixel.
*The coordinates are ordered in a clockwise direction.*
The last line indicates that it is expected behavior that the coordinates are ordered clockwise. Is this the information you were looking for?

Community Treasure Hunt

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

Start Hunting!

Translated by