How do I find the topmost, bottomost, leftmost and rightmost endpoints of a skeleton of a binary image? Please help.
조회 수: 1 (최근 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.
댓글 수: 0
채택된 답변
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
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!