# Does bwboundaries always returned ordered, clockwise, boundaries?

36 ビュー (過去 30 日間)
David 2016 年 10 月 25 日
コメント済み: David 2016 年 10 月 27 日
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

#### 0 件のコメント

サインイン to comment.

### 採用された回答

Chaya N 2016 年 10 月 25 日

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 件のコメント

David 2016 年 10 月 26 日
Great, thanks! How come this same information isn't included at https://www.mathworks.com/help/images/ref/bwboundaries.html?
I often search documentation online instead of calling help within the program. I had assumed I was accessing the same information, but I guess this isn't the case?
Thanks again, Dave
Chaya N 2016 年 10 月 26 日
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 2016 年 10 月 27 日
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.

サインイン to comment.

### その他の回答 (1 件)

Amith Kamath 2016 年 10 月 25 日
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?

#### 1 件のコメント

David 2016 年 10 月 26 日
Yes exactly. Thanks!

サインイン to comment.

サインイン してこの質問に回答します。

Translated by