title: efficient implementation of matlab function "imfill(BW,'holes') " in c++ not using opencv
body: <p>I need to implement efficiently imfill(BW,'holes') function of matlab which fills the "holes" in binary images(0,1).</p>
  
  <p>Binary image is represented as a 2D matrix of 0 and 1s, where 1 represents white(bright) region and 0 represents black(dark) region.</p>
  
  <p>Hole is basically a "dark" region surrounded by "bright" regions. In other words 0s surrounded by 1s is a "hole". Another defintion for hole is : a dark region(0s) which cannot be reached through any of the four edges unless we cross some bright region(1s). Edges are always black(0s).</p>
  
  <p>Now I need to find holes(0s surrounded by 1s) and fill those holes(make those 0s as 1s).</p>
  
  <p>Is there any efficient algorithm possible?
  Please help.
  Thanks in advance.</p>
  
  <p>Example:
  You can follow the link below for an example:<a href="http://www.mathworks.in/help/images/ref/imfill.html" rel="nofollow">go to the bottom of the page and expand example: Fill Holes in a Binary Image</a></p>