I am looking for an algorithm that fills a region with one color, but the edge of the region is not completely closed (i.e. one or more gaps are being left). The result is like the use of the Paint Bucket Tool with Gap Size option in Adobe Flash. We can assume that the input of the algorithm has to specify the largest size (straight line distance) of the gap.

My straightforward idea is (1) to fill the gaps in the edges (as shown in this webpage), and then (2) use the flood fill algorithm to perform the filling on a closed region. I have done (2) by using a recursive algorithm, but how should (1) be done?

Any alternative idea are also welcomed. Thanks!


This is clossing operator implemented as dilate-then-erode filter and then it is FloodFill.
Dilate filter is adding pixels that would became new hull.
Erode filter is cutting out pixels that are at the hull.
Here is try me link: Demo of operators
One thing that could be improved in this technique are gaps after filter.
enter image description here
You can get rid of it by applying dilation on color region.

This is one kind of solving, another would be to go along the edge and find pattern edge-gap-edge with given radius.
There are also caveats - if edge is not in single color, then operators must include that information or get binary representation (with binary data, e.g. 0 means empty, 1 means edge).
Clossing operator is easy to implement but slower than contour tracing.
You could trace edge by FloodFill starting from edge region, using BFS and going into counting mode after boundary is crossed, to check within gap radius.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.