Answers.Body: <p>This answer assumes that knots are one continuous path and links are multiple linked ;) paths.</p>
  <p>The part that makes your examples tricky is that the images are 2D representations of a 3D thing, and &quot;over/under&quot; is implied by breaks in the path.</p>
  <p>The computer vision algorithms that will help you are <a href="https://en.wikipedia.org/wiki/Topological_skeleton" rel="nofollow noreferrer">skeletonization</a>, 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.</p>
  <ol start="0">
  <li>Preprocess your image if necessary (threshold).</li>
  <li>Compute the skeleton of your image if necessary</li>
  <li>Find and label connected components of skeletons (image A below)</li>
  <li>Find tips of connected components (image B)</li>
  <li>Say two components are the same if there are tips close enough to each other.</li>
  <li>If there is one connected component, it's a knot, otherwise it's a link.</li>
  </ol>
  <p>I ran <a href="https://imagej.net/plugins/analyze-skeleton/" rel="nofollow noreferrer">this method</a> on your image to produce images A and B. <a href="https://skeleton-analysis.org/stable/index.html" rel="nofollow noreferrer">Here's</a> a similar algorithm in python that looks to have similar functionality.</p>
  <h2>Step 2</h2>
  <p><a href="https://i.sstatic.net/gYiqzlvI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/gYiqzlvI.png" alt="enter image description here" /></a></p>
  <h2>Step 3</h2>
  <p><a href="https://i.sstatic.net/JvWyIO2C.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JvWyIO2C.png" alt="enter image description here" /></a></p>
  <h2>Step 4</h2>
  <p><a href="https://i.sstatic.net/zOmhvWW5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zOmhvWW5.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-09T16:09:25.173Z
Answers.Text: Huge thanks! What a great answer, insightful, informative. :)
Answers.UserDisplayName: Csaba Daniel Farkaš
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-10T14:41:07.267Z
Answers.Text: Glad you found it helpful :D
Answers.UserDisplayName: bogovicj
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-05T16:10:24.463Z
Answers.LastActivityDate: 2024-05-05T16:10:24.463Z
Answers.UserDisplayName: bogovicj
Body: <p>I'd like to create some algorithm that can tell apart <strong>knots</strong> from <strong>links</strong>.</p>
  <p><a href="https://i.sstatic.net/MDswvEpB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MDswvEpB.png" alt="enter image description here" /></a></p>
  <p>A knot is made up of one line, a link with multiple. As input, we expect images as above.</p>
  <p>Is there an algorithm capable of classifying the images?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-03T15:42:23.117Z
Comments.Text: How many of these examples do you have?
Comments.UserDisplayName: foreverska
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-03T15:47:52.600Z
Comments.Text: assume as many as you need
Comments.UserDisplayName: Csaba Daniel Farkaš
Tags: <computer-vision><classification><algorithm-request>
Title: Is there an algorithm capable of telling knots and links apart?
UserDisplayName: Csaba Daniel Farkaš
ThreadText: # Is there an algorithm capable of telling knots and links apart?
  
  (Asked by: username_0 on 2024-05-03)
  
  I'd like to create some algorithm that can tell apart **knots** from **links**.
  
  [![enter image description here](https://i.sstatic.net/MDswvEpB.png)](https://i.sstatic.net/MDswvEpB.png)
  
  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?
  
  **Tags:** computer-vision, classification, algorithm-request
  > **Comments:**
  > **username_1**: How many of these examples do you have?  
  > **username_0**: assume as many as you need  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-05-05. Score: 2 | Accepted answer
  
  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](https://en.wikipedia.org/wiki/Topological_skeleton), 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.
  
  0. Preprocess your image if necessary (threshold).
  1. Compute the skeleton of your image if necessary
  2. Find and label connected components of skeletons (image A below)
  3. Find tips of connected components (image B)
  4. Say two components are the same if there are tips close enough to each other.
  5. If there is one connected component, it's a knot, otherwise it's a link.
  
  I ran [this method](https://imagej.net/plugins/analyze-skeleton/) on your image to produce images A and B. [Here's](https://skeleton-analysis.org/stable/index.html) a similar algorithm in python that looks to have similar functionality.
  
  ## Step 2
  
  [![enter image description here](https://i.sstatic.net/gYiqzlvI.png)](https://i.sstatic.net/gYiqzlvI.png)
  
  ## Step 3
  
  [![enter image description here](https://i.sstatic.net/JvWyIO2C.png)](https://i.sstatic.net/JvWyIO2C.png)
  
  ## Step 4
  
  [![enter image description here](https://i.sstatic.net/zOmhvWW5.png)](https://i.sstatic.net/zOmhvWW5.png)
  
  > **Comments:**
  > **username_0**: Huge thanks! What a great answer, insightful, informative. :)  
  > **username_2**: Glad you found it helpful :D  
  
  ---
  
  