title: Using regionprops in Python
body: <p>I am trying to analyze greyscale TIFF stacks, in which a given frame will look like <a href="https://i.stack.imgur.com/nkQpj.png" rel="nofollow noreferrer">this</a>. I filter it (using Gaussian blur), and then binarize it (using Otsu's method for threshold).</p>
  
  <p>MATLAB code, which works great: </p>
  
  <pre><code>image_conncomp = bwconncomp(image_binary); # entire stack is held in image_binary
  
  for i=1:image_conncomp.NumObjects
      object_size = length(image_conncomp.PixelIdxList{i});
  end
  </code></pre>
  
  <p>Each white spot in the example image is picked up, and its volume (in pixels) is pretty accurately given by <code>object_size</code>.</p>
  
  <p>Python code:</p>
  
  <pre><code>from skimage import measure
  
  labels = measure.label(image_binary, background=1) # same image_binary as above
  propsa = measure.regionprops(labels)
  
  for label in propsa:
      object_size = len(label.coords)
  </code></pre>
  
  <p>The Python code seems to work decently... except that most detected objects will have <code>object_size</code> of 1 - 200, and then a couple will have a size of several thousand pixels. </p>
  
  <p>What are these functions doing differently? I would be happy to try another approach in Python to get calculate object sizes, but I struggled to find another one. It'd be great to have a Python version of this code, if I could find a good substitute for Matlab's <code>bwconncomp</code> function.</p>
  
  <p><a href="https://i.stack.imgur.com/vXbW1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vXbW1.png" alt="enter image description here"></a></p>