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

Adding method to binary mask collection that imports external labeled images #1731

Merged
merged 1 commit into from
Jan 22, 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
42 changes: 42 additions & 0 deletions starfish/core/morphology/binary_mask/binary_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

import numpy as np
import xarray as xr
from skimage import io
from skimage.measure import regionprops
from skimage.measure._regionprops import _RegionProperties

from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.morphology.label_image import LabelImage
from starfish.core.morphology.util import (
_get_axes_names,
Expand Down Expand Up @@ -262,6 +264,46 @@ def from_label_image(cls, label_image: LabelImage) -> "BinaryMaskCollection":
log,
)

@classmethod
def from_external_labeled_image(cls, path_to_labeled_image: Union[str, Path],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you write a docs for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup!

original_image: ImageStack):
"""
Construct a BinaryMaskCollection from an external label image. Ex. the output from
ilastik object classification

Parameters
----------
path_to_labeled_image : Union[str, Path]
Path to an external label image file
original_image : ImageStack
Dapi image used in external segmentation workflow

Returns
-------
BinaryMaskCollection
"""

# Load the label image generated from another program
label_image = io.imread(path_to_labeled_image)

# Get the physical ticks from the original dapi image
physical_ticks = {Coordinates.Y: original_image.xarray.yc.values,
Coordinates.X: original_image.xarray.xc.values}

# Get the pixel values from the original dapi image
pixel_coords = {Axes.Y: original_image.xarray.y.values,
Axes.X: original_image.xarray.x.values}

# Create the label image
label_im = LabelImage.from_label_array_and_ticks(
label_image,
pixel_ticks=pixel_coords,
physical_ticks=physical_ticks,
log=original_image.log
)
# Create the mask collection
return BinaryMaskCollection.from_label_image(label_im)

@classmethod
def from_binary_arrays_and_ticks(
cls,
Expand Down