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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 20 Mär. 2016
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 Kommentare
Image Analyst
Image Analyst am 20 Mär. 2016
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by