title: How to delete small independent masks from images?
body: <p>I have binarized image. Yellow = 1 mask, purple = 0 background:</p>
  
  <p><a href="https://i.stack.imgur.com/K3sQA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K3sQA.png" alt="enter image description here"></a></p>
  
  <p>I can filter if the whole masks is small by some threshold this way:</p>
  
  <pre><code>def filter_image(img):
      if img.sum() &lt; 10:
          return np.zeros(img.shape)
      else:
          return img
  </code></pre>
  
  <p>However how get rid of this small yellow points?</p>