HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Is there an efficient algorithm to extract the farthest ends of a thin contour?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
thecontourefficientendsalgorithmextracttherethinfarthest

Problem

Let's say you have pixel bitmaps that look something like this:

From this I can easily extract a contour, which will be a concave polygon defined by a set of 2D points. The question is what is the fastest algorithm to pick, from the set of polygon points, the ones that are closest to the natural "endings" of the contour (i.e. the two tips at the end of the U in this case) - so there are $2$ points in the output.

Somehow it looks like it should be related to curvature, although the algorithm should support a large variety of possible shapes, including S, W and other largely curved shapes so I'm hesitant to set any kind of threshold on curvature.

I've tried convex hull methods as well as a couple of variations of the rotating calipers method but still I've found nothing that will convince me that I can reliably and quickly identify the endings/tips of any curved thin line. It's always impressive how humans can pick up on these natural features so fast!

Solution

Run Flood Fill from any point and the farthest points in the both directions are your result. If you find that the distance in one of the directions is zero it means that it was one of them.

Exploiting the very same idea, if you try finding pixels with the least number of surrounding pixels and apply limited BFS Flood Fill to find out where it can go - at the endpoints there is only one way out. Also going by curvature and then applying the same idea would tell apart the extra bends from results.

Context

StackExchange Computer Science Q#60081, answer score: 2

Revisions (0)

No revisions yet.