Skip to content

Instantly share code, notes, and snippets.

@khuangaf
Last active August 24, 2018 14:40
Show Gist options
  • Save khuangaf/a67c65c6b7b48f96fe5a01114fce2aab to your computer and use it in GitHub Desktop.
Save khuangaf/a67c65c6b7b48f96fe5a01114fce2aab to your computer and use it in GitHub Desktop.
def get_multi_masks(img):
'''
Get connected components (multi-masks)
args:
img: np.ndarray
return:
np.ndarray with same dimension as the input
'''
# Threshold the image to make it become either 0 or 1
_, thresh = cv2.threshold(img, 10, 255, cv2.THRESH_BINARY)
# The skimage label function find the connected component.
# The pixels of the first component is marked as 1,
# the pixels of the second one is marked as 2, and so on and so forth.
return label(thresh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment