Is there an algorithm capable of telling knots and links apart?

I'd like to create some algorithm that can tell apart knots from links.

A knot is made up of one line, a link with multiple. As input, we expect images as above.

Is there an algorithm capable of classifying the images?

• How many of these examples do you have? Commented May 3 at 15:42
• assume as many as you need Commented May 3 at 15:47

This answer assumes that knots are one continuous path and links are multiple linked ;) paths.

The part that makes your examples tricky is that the images are 2D representations of a 3D thing, and "over/under" is implied by breaks in the path.

The computer vision algorithms that will help you are skeletonization, and analysis of skeletons. Here's a sketch of an algorithm. Steps 0 and 1 may or may not be necessary, and will depend on how variable your images are.

1. Preprocess your image if necessary (threshold).
2. Compute the skeleton of your image if necessary
3. Find and label connected components of skeletons (image A below)
4. Find tips of connected components (image B)
5. Say two components are the same if there are tips close enough to each other.
6. If there is one connected component, it's a knot, otherwise it's a link.

I ran this method on your image to produce images A and B. Here's a similar algorithm in python that looks to have similar functionality.

Step 4

• Huge thanks! What a great answer, insightful, informative. :) Commented May 9 at 16:09
• Glad you found it helpful :D Commented May 10 at 14:41