Here is a black image with some white lines. I would like to grow these lines to be a single connected component that hits the boundary and is as thin as possible. I have tried 'imdilate' but then when I try to thin or skeletonize it with 'bwmorph' it disconnects from the boundary. So alternatively, I just need a skeletonization/thinning code that doesn't remove boundary points.
Any ideas? Thank you!

답변 (1개)

darova
darova 2019년 5월 10일

0 개 추천

clc,clear
I = imread('bw.jpg');
I1 = im2bw(rgb2gray(I));
% crop black rectangle first
[i1, j1] = find(~I1,1,'first');
[i2, j2] = find(~I1,1,'last');
I2 = I1(i1:i2,j1:j2);
I3 = imdilate(I2,true(7,7));
I4 = bwmorph(I3,'skel',inf);
I5 = bwmorph(I4,'spur',inf);
I1(i1:i2,j1:j2) = I5;
imshow(I1)
Don't know how to get rid of those spurs now
img.png

댓글 수: 1

Victor Churchill
Victor Churchill 2019년 5월 11일
Right, the spurs are tough. I'm just looking to extrapolate a full segmentation from this near-segmentation that "makes sense".

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

질문:

2019년 5월 10일

댓글:

2019년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by