# How to get the centerline of a binary region

조회 수: 16(최근 30일)
댓글: Image Analyst 2021년 10월 18일
I have a binarize image below, I am trying to find the centerline of the image such as that in red on the binarize image. I did use the bskel function but get branches. I am hoping to elimated (prone or remove) all branches.
Any suggestions will be most appreciated. Any other way to do this another than using bskel will be great too. 댓글을 달려면 로그인하십시오.

### 채택된 답변

DGM 2021년 10월 17일
There's this.
B = bwmorph(A,'skel',inf); % skeletonize
B = imfill(B,'holes'); % get rid of any tiny closed paths
B = bwmorph(B,'skel',inf); % finish skeletonizing
% remove endpoints until only two are left
while true
e = bwmorph(B,'endpoints');
if nnz(e)>2
B = B & ~e;
else
break;
end
end
imshow(B) 댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

KSSV 2021년 10월 17일
You can get the indices of white pixels using find and to the data you can try fitting a line or quadratic equation using polyfit.
[y,x] = find(I) ;
p = polyfit(x,y,2) ;
xi = linspace(min(x),max(x)) ;
yi = polyval(p,xi) ;
plot(X,y,'.k')
hold on
plot(xi,yi,'r')
##### 댓글 수: 1표시숨기기 없음
Image Analyst 2021년 10월 18일
This is exactly how I'd do it.

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

### Community Treasure Hunt

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

Start Hunting!