필터 지우기
필터 지우기

How to find the endpoint?

조회 수: 12 (최근 30일)
ZWY
ZWY 2022년 6월 8일
댓글: ZWY 2022년 6월 10일
Hi, i have an image and wanted to find the location of endpoints as shown in red circle.
I am using the
bw=bwmorph(bw,'endpoints')
however, it returns "0" instead of the location of endpoints.
How can I do with this? Thank you.
  댓글 수: 2
Rik
Rik 2022년 6월 8일
From what I recall, you need to skeletonize your image first.
ZWY
ZWY 2022년 6월 10일
Thanks Rik.

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
DGM 2022년 6월 8일
편집: DGM 2022년 6월 8일
% image recovered from screenshot
A = imread('vessel.png');
A = A>128; % binarize
% skeletonize
B = bwskel(A,'minbranchlength',50);
% fill loops
B = imfill(B,'holes');
% skeletonize to get rid of filled loops
B = bwskel(B,'minbranchlength',50);
imshow(B) % display interpolation makes fine lines look spotty
% get endpoints as a logical image
endpts = bwmorph(B,'endpoints');
imshow(endpts) % again, display interpolation hides most of the dots
That result can be used for logical indexing if needed. If for some reason, you can't use it directly and need indices instead, you can use find().
% if you really truly need indices instead
endptidx = find(endpts)
endptidx = 21×1
807 124117 134946 246304 371291 453988 479473 492705 497657 526278
  댓글 수: 6
DGM
DGM 2022년 6월 10일
I'm not sure if your x,y for the reference center are flipped. it's outside the image region.
% image recovered from screenshot
A = imread('vessel.png');
A = A>128; % binarize
% skeletonize
B = bwskel(A,'minbranchlength',50);
% fill loops
B = imfill(B,'holes');
% skeletonize to get rid of filled loops
B = bwskel(B,'minbranchlength',50);
% get endpoints as a logical image
endpts = bwmorph(B,'endpoints');
% these might be flipped
x=500;
y=1000;
[endpt_Y endpt_X] = find(endpts); %[row col]
% this is the square of the euclidean distance
% if all you need is to optimize distance, there's no need for sqrt()
% if you actually need the distance for something else, you can add it.
Dsquared = sum(([endpt_Y endpt_X] - [y x]).^2,2);
% find most distal endpoint
[~,mxidx] = max(Dsquared);
mostdistal = [endpt_X(mxidx) endpt_Y(mxidx)]
mostdistal = 1×2
818 19
% plot some stuff
imshow(B); hold on
plot(x,y,'x','markersize',20) % specified centroid
plot(mostdistal(1),mostdistal(2),'o','markersize',20)
ylim([0 1050]) % adjust axes to show marker
ZWY
ZWY 2022년 6월 10일
I got it. Thanks all for helping, really appreciate it!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by