MATLAB: How to find the topmost, bottomost, leftmost and rightmost endpoints of a skeleton of a binary image? Please help.

bwmorphendpointsImage Processing Toolboxskelskeletonskeletonization

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.

Best Answer

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);