I have a need to find connected components in a binary uint8 image of size 480x640. I have over 3500 such images that need their connected components (8 way connectivity) found. I found that using skimage.measure.label has been the fastest even though ndimage is supposed to be faster on binary images. CV2's connectedComponents has been the slowest so far.
Are there any faster ways to achieve the same in the same libraries or using alternate libraries?
skimage
measure.label(
(image == LABEL_DICT[feature_1]).astype(np.uint8),
connectivity=2,
background=0,
return_num=True,
)
ndimage
structure = np.array([
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
])
label_img, num_components = scipy.label(
(image == LABEL_DICT[feature_1]).astype(np.uint8),
structure
)
cv2
cv2.connectedComponents((image == LABEL_DICT[feature_1]).astype(np.uint8), connectivity=8)