title: Contour completion in image segmentation
body: <p>I am attempting to use machine learning (namely random forests) for image segmentation. The classifier utilizes a number of different pixel level features to classify pixels as either edge pixels or non edge pixels. I recently applied my classifier to a set of images that are pretty difficult to segment even manually (<a href="https://stackoverflow.com/questions/18972932/image-segmentation-based-on-edge-pixel-map">Image segmentation based on edge pixel map</a>) and am still working on obtaining reasonable contours from the resulting probability map. I also applied the classifier to an easier set of images and am obtaining quite good predicted outlines (Rand index > 0.97) when I adjust the threshold to 0.95. I am interested in improving the segmentation result by filtering contours extracted from the probability map. </p>
  
  <p>Here is the original image:</p>
  
  <p><img src="https://i.stack.imgur.com/bEri6.jpg" alt="Original image"></p>
  
  <p>The expert outlines:</p>
  
  <p><img src="https://i.stack.imgur.com/6hpG0.png" alt="Expert Outlines"></p>
  
  <p>The probability map generated from my classifier: </p>
  
  <p><img src="https://i.stack.imgur.com/X6xkx.png" alt="enter image description here"></p>
  
  <p>This can be further refined when I convert the image to binary based on a threshold of 0.95:</p>
  
  <p><img src="https://i.stack.imgur.com/Yk8Cl.png" alt="enter image description here"></p>
  
  <p>I tried filling holes in the probability map, but that left me with a lot of noise and sometimes merged nearby cells. I also tried contour finding in openCV but this didn't work either as many of these contours are not completely connected - a few pixels will be missing here and there in the outlines.</p>
  
  <p>Edit: I ended up using Canny edge detection on the probability map. </p>