Skip to content

Commit

Permalink
fix+test(dust): invert was not actually called
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Dec 19, 2024
1 parent 147f543 commit f58a882
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,24 +1138,38 @@ def test_continuous_blocks(dtype, connectivity, order):
@pytest.mark.parametrize("connectivity", (6,18,26))
@pytest.mark.parametrize("order", ("C", "F"))
@pytest.mark.parametrize("in_place", (False, True))
def test_dust_static(dtype, connectivity, order, in_place):
@pytest.mark.parametrize("invert", (False, True))
def test_dust_static(dtype, connectivity, order, in_place, invert):
labels = np.zeros((100,100,10), dtype=np.uint8, order=order)
labels[:5,:5,:1] = 1
labels[20:40,20:40,:] = 2
recovered = cc3d.dust(
labels,
threshold=26,
connectivity=connectivity,
in_place=in_place
in_place=in_place,
invert=invert,
)
assert list(np.unique(recovered)) == [0,2]
if in_place:
assert list(np.unique(labels)) == [0,2]

if invert:
assert list(np.unique(recovered)) == [0,1]
if in_place:
assert list(np.unique(labels)) == [0,1]
else:
assert list(np.unique(labels)) == [0,1,2]
else:
assert list(np.unique(labels)) == [0,1,2]
assert list(np.unique(recovered)) == [0,2]
if in_place:
assert list(np.unique(labels)) == [0,2]
else:
assert list(np.unique(labels)) == [0,1,2]

ans = np.zeros((100,100,10), dtype=np.uint8, order=order)
ans[20:40,20:40,:] = 2

if invert:
ans[:5,:5,:1] = 1
else:
ans[20:40,20:40,:] = 2

assert np.all(ans == recovered)

Expand Down
2 changes: 1 addition & 1 deletion cc3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def dust(
if len(to_mask) == 0:
return img

mask = np.isin(cc_labels, to_mask, assume_unique=True, invert=False)
mask = np.isin(cc_labels, to_mask, assume_unique=True, invert=invert)
del cc_labels
img[mask] = 0
return img.view(orig_dtype)
Expand Down

0 comments on commit f58a882

Please sign in to comment.