Make a line contiguous

Hello,

I am interested in how to make a line with gaps contiguous.

The line is obtained from examining a boundary between regions. However, there are moments where the resulting line is not contiguous (see example). I have been using the Paintbrush Tool to fill in the gaps to the best of my abilities which could be time consuming. I am interested in automating this process and I am curious if any scripts exist to obtain a result like Example 2 .

Any help would be appreciated!

example

example2

Looks like you may want to detect the end points of your segmentation.

This plugin should help:

Once you have the end point locations, use the macro command makeLine to connect them:

The challenge here might be figuring out which two end points to connect. The simplest scheme would be just to connect an endpoint to the nearest endpoint. This might not be so robust though. In a bigger scheme you would want to do a graph theory based analysis to determine the best end points to join together, but I’m not sure how to do that succinctly in a script.

1 Like

Hello markkitt,

Thank you! This helped out a lot.

I believe the next step would be to find a way to curve the line segment that joins two endpoints. I will try to search around to see if such a feat is possible, or else I will probably add on to this post. The overall goal is to automate this process as much as possible instead of filling it all by hand.

I appreciate your response and help!

Curve the line segment?

You might want to look into Bezier curves or splines of some sort:

You might also be interested in the Bresenham line and circle drawing algorithms:

Awesome! I think this might help.
Thank you, markkitt!