title: regionprops vs. findContours
body: <p>Is there a way to get the same results for 
      cDist=regionprops(bwImg, 'Area');
  and openCV's findContours?</p>
  
  <p>Input image:
  <img src="https://i.stack.imgur.com/6Go2d.png" alt="enter image description here"></p>
  
  <p>Bw Input image:
  <img src="https://i.stack.imgur.com/nxYXT.png" alt="enter image description here"></p>
  
  <p>Here is what I have tried so far:</p>
  
  <pre><code>dst.convertTo(dst,CV_8U);
  cv::vector&lt;cv::vector&lt;cv::Point&gt; &gt; contours_1;
  cv::vector&lt;cv::Vec4i&gt; hierarchy_1;
  cv::findContours(dst,contours_1,hierarchy_1,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
  
  double maxLabelSize = (dst.rows/4.0) * (dst.cols/6.0);
  double minLabelSize = ((dst.rows/40.0) * (dst.cols/60.0));
  
  cv::vector&lt;cv::vector&lt;cv::Point&gt; &gt; goodContours;
  for (int i = 0; i &lt; contours_1.size(); i++)
  {
      double size = cv::contourArea(contours_1[i]);
      if (size &lt; maxLabelSize &amp;&amp; size &gt; minLabelSize)
      {
          goodContours.push_back(contours_1[i]);
      }
  }
  
  cv::Mat filterContours = cv::Mat::zeros(dst.size(),CV_8UC3);    
  for (int i = 0; i &lt; goodContours.size(); i++)
  {
      cv::RNG rng(12345);
      cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
      drawContours( filterContours, goodContours, i, color, 2, 8, hierarchy_1, 0, cv::Point() );
  }
  
  cv::imshow( "Contours", filterContours );
  cv::waitKey(0);
  </code></pre>
  
  <p>OpenCV result:
  <img src="https://i.stack.imgur.com/TcvOe.png" alt="OpenCV&#39;s result "></p>
  
  <p>Matlab's Version:</p>
  
  <pre><code>% Calculate each separated object area
      cDist=regionprops(bwImg, 'Area');
      cDist=[cDist.Area];
  
      % Label each object
      [bwImgLabeled, ~]=bwlabel(bwImg);
  
      % Calculate min and max object size based on assumptions
      maxLabelSize = prod(size(imageData)./[4 6]);
      minLabelSize = prod(size(imageData)./[4 6]./10);
  
      % Find label indices for objects that are too large or too small
      remInd = find(cDist &gt; maxLabelSize);
      remInd = [remInd find(cDist &lt; minLabelSize)];
  
      % Remove over/undersized objects
      for n=1:length(remInd)
          ri = bwImgLabeled == remInd(n);
          bwImgLabeled(ri) = 0;
      end
  </code></pre>
  
  <p>Matlab's result:
  <img src="https://i.stack.imgur.com/5m7wf.png" alt="Matlab&#39;s result"></p>
  
  <p>Please note the left bottom square is missing from the openCV image.</p>