Skip to content

Instantly share code, notes, and snippets.

@andrewgiessel
Created August 1, 2013 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewgiessel/6134640 to your computer and use it in GitHub Desktop.
Save andrewgiessel/6134640 to your computer and use it in GitHub Desktop.
python code to exclude pixel islands of a given size, requires mahotas for building a label matrix (could use pymorph instead)
import mahotas
def excludePixels(image, size_cutoff=1):
labeled_image = mahotas.label(image)[0]
for label_id in range(labeled_image.max()+1):
label_id_index = labeled_image == label_id
if label_id_index.sum() <= size_cutoff:
labeled_image[label_id_index] = 0
return labeled_image>0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment