How to combine connected labels with multi-label segmentations #129
-
We are trying to replace SciPy's Consider this array: array([[[2, 1]], [[0, 0]]]) SciPy returns The only way I have found to get around this is using the Is there a more optimal method to accomplish this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi! That certainly works, though the delta feature uses a somewhat slower algorithm. Scipy treats the input as a binary mask. cc3d was written to accommodate dense segmentation, so you have to convert the input to a binary mask. import numpy as np
import cc3d
arr = np.array([[[2, 1]], [[0, 0]]], dtype=np.uint16)
np.greater(arr, 0, out=arr) # arr = arr > 0, but memory optimized
cc_labels, N = cc3d.connected_components(arr, connectivity=6, return_N=True) I think this will do what you want. The binarization step does add overhead, but it should be pretty dang fast. |
Beta Was this translation helpful? Give feedback.
This feature is released in 3.19.0. Beta, let me know if you run into any problems. You can use it by providing
binary_image=True
to the function. Note that I haven't used any superior binary algorithms yet, just getting this basic functionality in place.