Skip to content

Instantly share code, notes, and snippets.

@jeanpat
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save jeanpat/8819895 to your computer and use it in GitHub Desktop.

Select an option

Save jeanpat/8819895 to your computer and use it in GitHub Desktop.
A python function relying on scipy.ndimage to extract region of interest in an image or in a stack of images with a a label image, spurious pixels are removed.
def extractParticles(greyIm, LabIm):
locations = nd.find_objects(LabIm)
i=1
extracted_images=[]
for loc in locations:
lab_image = np.copy(LabIm[loc])
grey_image = np.copy(greyIm[loc])
lab_image[lab_image<>i]=0
grey_image[lab_image <>i]=0
extracted_images.append(grey_image)
i=i+1
return extracted_images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment