title: Robust image segmentation in OpenCV
body: <p>I'm trying to write an OpenCV program that counts fish eggs for someone else. It currently takes their uploaded image, normalizes, blurs, thresholds, dilates, distance transforms, thresholds again, and then finds contours (like in a typical watershed tutorial).</p>
  <p>The problem I'm having is that the lighting conditions can vary quite a bit, so even with my adaptive threshold values, the accuracy of the algorithm also varies wildly. If there's a gradient brightness across the image it seems to do especially poorly. Sometimes the objects are very bright against the background and other times they're almost the same luminosity. Are there any particularly effective ways to find objects in varying light conditions?</p>
  <p>Sample images:
  <img src="https://i.imgur.com/LoAaI4y.jpg" alt="img" />
  <a href="https://web.archive.org/web/20141016144205/http://giant.gfycat.com/ObviousSeveralAmethystinepython.gif" rel="nofollow noreferrer"><img src="https://web.archive.org/web/20141016144205/http://giant.gfycat.com/ObviousSeveralAmethystinepython.gif" alt="gif" /></a></p>