Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix on-demand calculation of BinaryMaskCollection's regionprops #1819

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion starfish/core/morphology/binary_mask/binary_mask.py
Original file line number Diff line number Diff line change
@@ -211,7 +211,9 @@ def mask_regionprops(self, mask_id: int) -> _RegionProperties:
mask_id + 1,
image,
)
mask_data.region_properties = regionprops(image.data)
measured_region_props = regionprops(image)
assert len(measured_region_props) == 1
mask_data.region_properties = measured_region_props[0]
return mask_data.region_properties

@property
Original file line number Diff line number Diff line change
@@ -44,6 +44,12 @@ def test_2d():
assert np.array_equal(region_1[Coordinates.X.value],
physical_ticks[Coordinates.X][3:6])

# verify that we can lazy-calculate the regionprops correctly.
region_0_props = binary_mask_collection.mask_regionprops(0)
region_1_props = binary_mask_collection.mask_regionprops(1)
assert region_0_props.area == 6
assert region_1_props.area == 5


def test_3d():
"""Simple case of BinaryMaskCollection.from_binary_arrays_and_ticks with 3D data. Pixel ticks
@@ -89,6 +95,12 @@ def test_3d():
assert np.array_equal(region_1[Coordinates.X.value],
physical_ticks[Coordinates.X][3:6])

# verify that we can lazy-calculate the regionprops correctly.
region_0_props = binary_mask_collection.mask_regionprops(0)
region_1_props = binary_mask_collection.mask_regionprops(1)
assert region_0_props.area == 6
assert region_1_props.area == 11


def test_no_mask():
"""Simple case of BinaryMaskCollection.from_binary_arrays_and_ticks with no masks. Pixel ticks