问题
I have some image processing that allows me to extract a binary image containing thick segments and i'm facing the issue that these segments may cross each other. Hence I need to find an efficient way to separate them, i'll have to implement this in C++ so anything OpenCV-based would help.
Here is a sample input image, both "blobs" would need to be split in 3 different segments.
I have tried 2 ideas until now, I'm stuck with both of them and that's why I'm asking here if there are any "state of the art" solution to this apparently simple problem.
My first idea was to compute the skeleton of the blobs, find intersection points. This part was easy. Then I planned to start with an end-point, traverse the segment until I reach an intersection and "cross the intersection". If you look at the bottom blob, the skeleton can produce weird "Y" shapes even when a "T" shape was expected, making it impossible to decide how to traverse an intersection.
Second idea was to compute the distance transform, followed by the gradient direction, and then I still need a way to merge pixels with similar direction and a way to handle endpoints / intersections.
回答1:
It is a good idea to use a skeleton, as this will make the processing independent of the stroke width. Near a junction, the skeleton is perturbed so that the direction locally changes.
You can consider a skeleton and split at the junction points (connected to more than two independent curves). You will build a graph where the edges are arcs between the junction points. Make sure to preserve connexity.
Then you can estimate the direction of an arc by finding points that are one and two thicknesses away from the junction. You will pair the edges such that the (green) points form the best alignment. You can do this in a greedy way (best fit first), until you exhaust all possible matchings or until the angle is considered too large.
The crossings with a wide angle are challenging because they will form a skeleton with two distant junctions. When matching a curve to another, you might consider matchings with distant curves, provided there is a path in between, such that it fits inside a stripe as large as the strokes.
来源:https://stackoverflow.com/questions/59505748/separate-crossings-segments-in-binarised-image