Skip to content

Commit

Permalink
Use masked fill to produce labeled images (#1582)
Browse files Browse the repository at this point in the history
Replace the existing code with masked fill.

Depends on #1579, #1581
  • Loading branch information
Tony Tung authored Oct 10, 2019
1 parent 3cd0df6 commit a1fbdfe
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions starfish/core/segmentation_mask/segmentation_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from skimage.measure import regionprops

from starfish.core.types import Axes, Coordinates
from .util import _get_axes_names
from .expand import fill_from_mask
from .util import _get_axes_names, AXES_ORDER


def _validate_segmentation_mask(arr: xr.DataArray):
Expand Down Expand Up @@ -148,7 +149,7 @@ def to_label_image(
self,
shape: Optional[Tuple[int, ...]] = None,
*,
ordering: Sequence[Axes] = (Axes.ZPLANE, Axes.Y, Axes.X)
ordering: Sequence[Axes] = AXES_ORDER,
):
"""Create a label image from the contained masks.
Expand Down Expand Up @@ -177,15 +178,7 @@ def to_label_image(
label_image = np.zeros(shape, dtype=np.uint16)

for i, mask in iter(self):
mask = mask.transpose(*[o.value for o in ordering if o in mask.coords])
coords = mask.values.nonzero()
j = 0
for o in ordering:
if o in mask.coords:
coords[j][:] += mask.coords[o].values[0]
j += 1
# align axes and insert into image
label_image[coords] = i + 1
fill_from_mask(mask, i + 1, label_image, ordering)

return label_image

Expand Down

0 comments on commit a1fbdfe

Please sign in to comment.