Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand your question, you want a line through your object where every point is in the middle of the object, i.e. if you start from any point on the midline and walk in a direction perpendicular to the midline, you have to walk the same distance in both directions until you meet the border of the object:</p> <p><img src="https://i.stack.imgur.com/usJVh.png" alt="Hotdog with midline"></p> <p>(this is just an illustration - probably not the geometrically correct midline!)</p> <p>My quick&amp;dirty solution would be to start with a middle axis (that can easily be calculated from first and second-order moments) and refine it by taking each point on this line and find the nearest border points on a line perpendicular to the current direction at that point, and move the point to the geometric center of these two points:</p> <p><img src="https://i.stack.imgur.com/vDWxq.png" alt="Hotdog iteration 0"></p> <p>If you do this for every point, you should get a better approximation for the midline. </p> <p>I said this was quick&amp;dirty, because I'm not sure if simply repeating this procedure always converges to a stable solution. It probably depends on how you calculate the perpendicular direction of the midline in the presence of bends and kinks.</p> <p>One way around this is to use a more physically-inspired model: </p> <ul> <li>Calculate a distance transform for the inside of your object (the distance of each point to the closest border point)</li> <li>Find a smooth line through the object that maximizes the path integral of the distance transform image:</li> </ul> <p><img src="https://i.stack.imgur.com/szie0.png" alt="Distance transform"></p> <p>To find this line, I would use an algorithm similar to active contours/snakes:</p> <ul> <li>Start with the middle axis</li> <li>Apply two forces to each point: <ul> <li>One force "pushes" the line in the direction of the gradient of the distance transform (i.e. away from the closest border)</li> <li>The other force counters the stretching and bending of the snake, so it keeps a smooth shape where there is no clear distance transform gradient. (Google for active contour - this is fairly standard CV stuff, you'll find lots of good articles about it.)</li> </ul></li> <li>Repeat until convergence or some fixed iteration limit is reached</li> </ul> <p>You'll need to adjust a few parameters for these smoothness of the curve (as always with active contours), but your chances to get a well-defined and well-behaved approximation are far better than with the simple approach above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload