How to fill the space in between the irregular lines?

2 views (last 30 days)
I have two line (like a curve) with some gap in it and running parallel in a binary image. I need to fill the gaps without disturbing the original structure, so at the end I get two lines running parallel without any gaps(One long and one short). Also this principle should apply if the number of lines increases(eg: 4 lines in an image). My lines never intersect each others, always I have them running parallel. Its not a homework, its part of my project I'm working. I'm in middle of something and I cant think some algorithm to work in a generic way(If number of lines increases). Any idea guys?

Answers (1)

Image Analyst
Image Analyst on 2 Feb 2015
Did you ever think of an algorithm that goes across the image filling in the space between the first line and the last line as you stated? Something like this
[rows, columns] = size(binaryImage);
for col = 1 : columns
thisColumn = binaryImage(:, col);
topRow = find(thisColumn, 1, 'first');
bottomRow = find(thisColumn, 1, 'last');
binaryImage(topRow : bottomRow, col) = true;
end
It should work for the image you showed but I can't know whether it will work for images you did not show me, like images with tons of lines all over the place at weird angles and spacings, like you dropped a box of toothpicks on the ground.
  1 Comment
Hoa
Hoa on 2 Feb 2015
yes I did something similar to this using regionprops('extrema') function I did some morphological operation and labeled the object and used something like this
x=[e(1,1).Extrema(4,1) e(2,1).Extrema(1,1)];
y=[ e(1,1).Extrema(4,2) e(2,1).Extrema(1,2)];
After that I draw a line between those coordinates.
Here is another image (shown below), in this case I have to change my Extrema coordinates. I would like to know if there is some general technique or method to take care of whatever angles and spacing. I mostly have 3 lines (curves) broken and running parallel in an image. I also thought about finding the local direction of the skeleton and then trace it along that direction.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!