Last active
August 24, 2018 14:40
-
-
Save khuangaf/a67c65c6b7b48f96fe5a01114fce2aab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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