How to extend lines in binary image?

9 views (last 30 days)
Ilya Tcenov
Ilya Tcenov on 1 Mar 2019
Edited: DGM on 27 Apr 2023
HI all,
I used an edge detector on a graysclae image and got a binary image that has many lines (lines are 1's and the background is 0's). Example is given bellow. I need to extend these lines, so that the intersections will devide the image to regions (marked in red).
I can use imdilate, but I dont want to make these lines thicker, I need to extend them. In some cases I need to extend these lines segnificantly, so imdilate cant do the job.
To conclude, I am looking for a way to extend binary lines (longer, not thicker) by a specified factor.
Thank you for your help.
Capture.JPG

Answers (2)

Image Analyst
Image Analyst on 1 Mar 2019
Try imclose(). It does imdilate() followed by imerode() to shring it back to the original size.
  5 Comments
Dillon Hudson
Dillon Hudson on 8 Apr 2023
I'm also looking for a solution to this problem. I'm looking for a way to connect the boundary of a line to the next closest line (not necessarily another boundary). Perhaps based on the rough direction the line was pointed i.e. take a boundary point and add to that line along the path it would take if it was lengthed. My lines are only a pixel wide (from edge detection) and span a number of angles and lengths.
The picture attached below is after one iteration of imclose with a square structuring element. Should I be using a different structuring element?
Something like this would be acceptable where the pink lines represent what I'd like to be white.
Image Analyst
Image Analyst on 27 Apr 2023
@Dillon Hudson please start your own discussion thread for this. It is possible though not trivial. And where the lines extend to depends on the order of the lines you connected before. It's not a unique solution.

Sign in to comment.


Víctor Llamas Martínez
Víctor Llamas Martínez on 27 Apr 2023
Edited: DGM on 27 Apr 2023
Hello.
In my case I ussually have to join points and lines that are closed together and in the most of the cases this code helps me out
se = strel('disk',2);
bw = imclose(bw,se);
imshow(bw)
With this you create a disk around each point of your binnary image and you try to find close points that are not connected with it. There is an example:
In this figure the line that must be continius is in some points disconnected, but aplying those code lines everithing gets connected propertly:
Perhaps some artifacts can appear in your image but by tuning the disk radius i think you can archieve an acceptable result.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!