How do I find the topmost, bottomost, leftmost and rightmost endpoints of a skeleton of a binary image? Please help.

3 次查看(过去 30 天)
skltn = bwmorph(binaryImage, 'skel', Inf); %getting skeleton of binary image
endpts = bwmorph(skltn, 'endpoints'); %getting enpoints of 'skltn'
[node_x, node_y] = find(endpoints==1); %getting the x and y coordinates of the endpoints in
%node_x and node_y respectively
%Now, how do I find the topmost, bottomost, leftmost and rightmost endpoints? Please help.

采纳的回答

Image Analyst
Image Analyst 2016-3-20
You really messed on on find. find() does not return x and y in that order -- it returns row and column (y and x) in that order. After that, just use min and max
[node_y, node_x] = find(endpoints==1); %getting the x and y coordinates of the endpoints in
%node_x and node_y respectively
% Get top row which is the smallest y value
yTopRow = min(node_y);
% Get bottom row which is the largest y value
yBottomRow = max(node_y);
% Get left column which is the smallest x value
xLeftColumn = min(node_x);
% Get right column which is the largest x value
xRightColumn = max(node_x);
  3 个评论
Image Analyst
Image Analyst 2016-3-20
If you look at the help for min() and max(), you'll see that it returns a second argument, which is the index of where it found the element. So to get the x of the top most endpoint, you'd do
[yTopRow, index] = min(node_y);
xTopRow = node_x(index);
Similarly for the other 4 points.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by