Skip to content

Commit

Permalink
perf(dust): add precomputed_ccl parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Nov 26, 2024
1 parent fef66cc commit 060b2e4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cc3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def dust(
connectivity:int = 26,
in_place:bool = False,
binary_image:bool = False,
precomputed_ccl:bool = False,
) -> np.ndarray:
"""
Remove from the input image connected components
Expand All @@ -34,6 +35,9 @@ def dust(
connectivity: cc3d connectivity to use
in_place: whether to modify the input image or perform
dust
precomputed_ccl: for performance, avoid computing a CCL
pass since the input is already a CCL output from this
library.
Returns: dusted image
"""
Expand All @@ -43,10 +47,15 @@ def dust(
if not in_place:
img = np.copy(img)

cc_labels, N = connected_components(
img, connectivity=connectivity,
return_N=True, binary_image=bool(binary_image),
)
if precomputed_ccl:
cc_labels = np.copy(img, order="F")
N = np.max(cc_labels)
else:
cc_labels, N = connected_components(
img, connectivity=connectivity,
return_N=True, binary_image=bool(binary_image),
)

stats = statistics(cc_labels, no_slice_conversion=True)
mask_sizes = stats["voxel_counts"]
del stats
Expand Down

0 comments on commit 060b2e4

Please sign in to comment.