Grow lines along path
Show older comments
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!
Answers (1)
darova
on 10 May 2019
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

1 Comment
Victor Churchill
on 11 May 2019
Categories
Find more on Morphological Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!