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

Add method to create masks grouped by label id #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dominikl
Copy link
Member

Add a method to create masks from labelled z-stack image, grouped by label ids. These can used to create "3D'ish" ROIs. Input is a list of planes so that the output from the getPlanes() method can be used directly.

Copy link
Member

@sbesson sbesson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ability to transform multidimensional labelled image into a series of ROIs with all masks for a given label alongside a dimension is a use case we keep encountering. One small downside of the approach proposed in this PR is that it makes strong assumptions about the planes and a new method would be required e.g. if one wanted to group masks by label across the time dimension.

If the main objective is to group all masks by label for a listof planes, another option might be to use the return value of mask_from_label_image. As this API returns an ordered list of masks, where the list index is effectively the label value, it might be possible to combine it with Python's built-in zip/itertools.zip_longest functions e.g.

from itertools import ziplongest

masks_per_plane = []
for z, plane in enumerate(planes):
    masks = masks_from_label_image(plane, rgba, z, c, t, text, raise_on_no_mask=False)
    masks_per_plane.append(masks)

masks_per_label = list(zip_longest(*masks_per_plane))

Note the example above will fill missing values with None by default. For consistency, it might be preferable to fill it with empty masks.

src/omero_rois/library.py Outdated Show resolved Hide resolved
@dominikl
Copy link
Member Author

Indeed, the index of the masks coming from masks_from_label_image is basically the label. I rewrote the method accordingly, which makes it easier. I'm not sure about ziplongest... I rather write a few lines more code, but therefore make it a bit easier to understand what's actually going on.

src/omero_rois/library.py Outdated Show resolved Hide resolved
Copy link
Member

@sbesson sbesson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed earlier today, let us drive this functionality with the IDR submission as a concrete use case while we make progress on the API implementation and tests.

src/omero_rois/library.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants