Skip to content

Commit

Permalink
Add method to create masks grouped by label id
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikl committed Jun 10, 2020
1 parent 6f394df commit de19965
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/omero_rois/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,37 @@ def masks_from_label_image(
raise_on_no_mask)
masks.append(mask)
return masks


def masks_from_3d_label_image(
planes, rgba=None, c=None, t=None, text=None,
raise_on_no_mask=True):
"""
Create mask shapes from a 3d label image (background=0)
:param list of numpy.array planes: list of 2D label arrays in z order
:param rgba int-4-tuple: Optional (red, green, blue, alpha) colour
:param c: Optional C-index for the mask
:param t: Optional T-index for the mask
:param text: Optional text for the mask
:param raise_on_no_mask: If True (default) throw an exception if no mask
found, otherwise return an empty Mask
:return: A dictionary of OMERO masks with the labels as keys
({} if no labels found)
"""
maxlabel = 1
for plane in planes:
pmax = plane.max()
if pmax > maxlabel:
maxlabel = pmax

masks = {}
for label in range(1, maxlabel + 1):
label_masks = []
for z, plane in enumerate(planes):
mask = mask_from_binary_image(plane == label, rgba, z, c, t, text,
raise_on_no_mask)
label_masks.append(mask)
masks[label] = label_masks
return masks

0 comments on commit de19965

Please sign in to comment.