title: Finding midlines of polygons using Voronoi diagrams
body: <p>I am using the Voronoi diagram-based approach outlined <a href="https://stackoverflow.com/questions/37820629/centerline-of-a-polygonal-blob-binary-image">here</a> to find midlines of binary masks of root images.  I am using the Python code more or less exactly as described:</p>
  
  <pre><code>import skimage.morphology as morphology
  
  WHITE = 255
  
  image_bool = binary_mask == WHITE
  d = morphology.disk(2)
  img = morphology.binary_closing(image_bool, selem=d)
  skeleton = morphology.medial_axis(img)
  </code></pre>
  
  <p>Then comes the graphing: I feed the skeletonized image into buildTree, as described in user Gabriel's iPython notebook:
  <a href="https://github.com/gabyx/WormAnalysis/blob/master/SkeletonTest/Skeletonize.ipynb" rel="nofollow noreferrer">https://github.com/gabyx/WormAnalysis/blob/master/SkeletonTest/Skeletonize.ipynb</a></p>
  
  <p>In general, this produces great results.  However, the method occasionally fails in two distinct ways:</p>
  
  <p>1) The graphs do not always extend the full length of the root:</p>
  
  <p><a href="https://i.stack.imgur.com/6yTtY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6yTtY.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/BemwQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BemwQ.png" alt="Midline that does not extend fully"></a></p>
  
  <p>2) The graphs sometimes connect "prematurely" to a point along the root contour that may appear to be the longest path, but clearly does not conform to what I would call the "midline".  This happens for a diverse range of polygon shapes:</p>
  
  <p><a href="https://i.stack.imgur.com/UIFDd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UIFDd.png" alt="rod-like polygon with graph"></a></p>
  
  <p><a href="https://i.stack.imgur.com/DBMaY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DBMaY.png" alt="rod-like polygon with midline"></a></p>
  
  <p><a href="https://i.stack.imgur.com/JT1Xy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JT1Xy.png" alt="circle-like polygon with graph"></a></p>
  
  <p><a href="https://i.stack.imgur.com/XFMCT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XFMCT.png" alt="circle-like polygon with midline"></a></p>
  
  <p><a href="https://i.stack.imgur.com/20Q7x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/20Q7x.png" alt="rod-like polygon with midline with graph"></a></p>
  
  <p><a href="https://i.stack.imgur.com/l1jYM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l1jYM.png" alt="polygon with sharp vertices with midline"></a></p>
  
  <p>This final case is an artificial mask -- none of my actual roots have perfectly flat tips -- but I think it represents the problem quite well.  </p>
  
  <p>Does anyone with a more refined understanding of Voronoi diagrams have any tips for how to address either of these problems, while still retaining this general approach.</p>
  
  <p>Thanks!</p>