-
Notifications
You must be signed in to change notification settings - Fork 68
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
Clean up binary mask #1622
Clean up binary mask #1622
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1622 +/- ##
==========================================
- Coverage 90.09% 90.09% -0.01%
==========================================
Files 234 234
Lines 8764 8761 -3
==========================================
- Hits 7896 7893 -3
Misses 868 868
Continue to review full report at Codecov.
|
e231f98
to
69253ca
Compare
69253ca
to
b0301db
Compare
88e5b1a
to
8512135
Compare
1. Use typed axes/coordinates when possible. 2. Have `_get_axes_names` return axes/coordinates in the order they are expected in the numpy arrays. 3. Improve how we render the mask names. Test plan: `pytest starfish/core/binary_mask/test`
8512135
to
b8bfd88
Compare
|
||
Returns | ||
------- | ||
masks : BinaryMaskCollection | ||
Masks generated from the label image. | ||
""" | ||
props = regionprops(label_image) | ||
len_max_label = len(str(len(props) - 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is there the extra str conversion here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was tripped up by this too. Let's say we have 100 regions. len(props) - 1 gets you 99 as an int. Then str(99) gives you "99". Then len("99") gives you 2.
|
||
|
||
def fill_from_mask( | ||
mask: xr.DataArray, | ||
fill_value: int, | ||
result_array: np.ndarray, | ||
axes_order: Sequence[Union[str, Axes]] = AXES_ORDER, | ||
axes_order: Sequence[Union[str, Axes]] = (Axes.ZPLANE, Axes.Y, Axes.X), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use your get_axes_order helper method here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That basically happens in #1628
LabelImage requires all the pixel coordinate and physical coordinate values along each axis, so to facilitate the easy conversion to and from BinaryMaskCollection and LabelImage, we need to change the data model for BinaryMaskCollection. Previously, BinaryMaskCollection stored a series of xarrays for each of the masks. This does not guarantee that the pixel/physical coordinates for every position along each axis. Furthermore, it duplicates a lot of data. This new approach stores the coordinates as independent arrays, and then stores each mask as a naked np.ndarray with offsets. Conversions to and from LabelImage is pretty straightforward. Returning each mask as an xarray (to maintain compatibility with the existing API) requires generating an xarray on the fly, but is not terribly expensive. Writing to disk is now through a versioned interface similar to what was done for slicedimage. Test plan: Updated tests to reflect the API changes. Part of #1497 Depends on #1619, #1622
_get_axes_names
return axes/coordinates in the order they are expected in the numpy arrays.Test plan:
pytest starfish/core/binary_mask/test