Grow lines along path

1 回表示 (過去 30 日間)
Victor Churchill
Victor Churchill 2019 年 5 月 10 日
コメント済み: Victor Churchill 2019 年 5 月 11 日
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 日
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".

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by