BinaryMaskCollection

class starfish.morphology.BinaryMaskCollection(pixel_ticks, physical_ticks, masks, log)[source]

Collection of binary masks with a dict-like access pattern.

Parameters
pixel_ticksUnion[Mapping[Axes, ArrayLike[int]], Mapping[str, ArrayLike[int]]]

A map from the axis to the values for that axis.

physical_ticksUnion[Mapping[Coordinates, ArrayLike[Number]], Mapping[str, ArrayLike[Number]]

A map from the physical coordinate type to the values for axis. For 2D label images, X and Y physical coordinates must be provided. For 3D label images, Z physical coordinates must also be provided.

masksSequence[MaskData]

A sequence of data for binary masks.

Attributes
max_shapeMapping[Axes, int]

Maximum index of contained masks.

Methods

from_binary_arrays_and_ticks(arrays, …)

Constructs a BinaryMaskCollection from an array containing the labels, a set of physical coordinates, and an optional log of how this label image came to be.

from_external_labeled_image(…)

Construct a BinaryMaskCollection from an external label image.

from_fiji_roi_set(path_to_roi_set_zip, …)

Construct BinaryMaskCollection from external Fiji ROI set.

from_label_array_and_ticks(array, …)

Constructs a BinaryMaskCollection from an array containing the labels, a set of physical coordinates, and an optional log of how this label image came to be.

from_label_image(label_image)

Creates binary masks from a label image.

mask_regionprops(mask_id)

Return the region properties for a given mask.

open_targz(path)

Load the collection saved as a .tar.gz file from disk

to_targz(path)

Save the binary masks to disk as a .tar.gz file.

uncropped_mask(index)

Some of the binary mask collections builders will crop the binary masks when constructing the collection.

masks

to_label_image

classmethod from_binary_arrays_and_ticks(arrays, pixel_ticks, physical_ticks, log)[source]

Constructs a BinaryMaskCollection from an array containing the labels, a set of physical coordinates, and an optional log of how this label image came to be. Masks are cropped to the smallest size that contains the non-zero values, but pixel and physical coordinates ticks are retained. Masks extracted from BinaryMaskCollections will be cropped. To extract masks sized to the original label image, use starfish.morphology.BinaryMaskCollection.uncropped_mask().

Parameters
arraysSequence[np.ndarray]

A set of 2D or 3D binary arrays. The ordering of the axes must be Y, X for 2D images and ZPLANE, Y, X for 3D images. The arrays must have identical sizes and match the sizes of pixel_ticks and physical_ticks.

pixel_ticksOptional[Union[Mapping[Axes, ArrayLike[int]], Mapping[str, ArrayLike[int]]]]

A map from the axis to the values for that axis. For any axis that exist in the array but not in pixel_ticks, the pixel coordinates are assigned from 0..N-1, where N is the size along that axis.

physical_ticksUnion[Mapping[Coordinates, ArrayLike[Number]], Mapping[str,
ArrayLike[Number]]]

A map from the physical coordinate type to the values for axis. For 2D label images, X and Y physical coordinates must be provided. For 3D label images, Z physical coordinates must also be provided.

logOptional[Log]

A log of how this label image came to be.

Returns
masksBinaryMaskCollection

Masks generated from the label image.

Return type

BinaryMaskCollection

classmethod from_external_labeled_image(path_to_labeled_image, original_image)[source]

Construct a BinaryMaskCollection from an external label image. Ex. the output from ilastik object classification

Parameters
path_to_labeled_imageUnion[str, Path]

Path to an external label image file

original_imageImageStack

Dapi image used in external segmentation workflow

Returns
BinaryMaskCollection
classmethod from_fiji_roi_set(path_to_roi_set_zip, original_image)[source]

Construct BinaryMaskCollection from external Fiji ROI set.

Parameters
path_to_roi_set_zipUnion[str, Path]

Path to an external fiji roi file

original_imageImageStack

image from same FOV used in fiji segmentation workflow

Returns
BinaryMaskCollection

Notes

This method only supports construction of masks from 2D polygons at this time.

Return type

BinaryMaskCollection

classmethod from_label_array_and_ticks(array, pixel_ticks, physical_ticks, log)[source]

Constructs a BinaryMaskCollection from an array containing the labels, a set of physical coordinates, and an optional log of how this label image came to be. Masks are cropped to the smallest size that contains the non-zero values, but pixel and physical coordinates ticks are retained. Masks extracted from BinaryMaskCollections will be cropped. To extract masks sized to the original label image, use starfish.morphology.BinaryMaskCollection.uncropped_mask().

Parameters
arraynp.ndarray

A 2D or 3D array containing the labels. The ordering of the axes must be Y, X for 2D images and ZPLANE, Y, X for 3D images.

pixel_ticksOptional[Union[Mapping[Axes, ArrayLike[int]], Mapping[str, ArrayLike[int]]]]

A map from the axis to the values for that axis. For any axis that exist in the array but not in pixel_ticks, the pixel coordinates are assigned from 0..N-1, where N is the size along that axis.

physical_ticksUnion[Mapping[Coordinates, ArrayLike[Number]], Mapping[str,
ArrayLike[Number]]]

A map from the physical coordinate type to the values for axis. For 2D label images, X and Y physical coordinates must be provided. For 3D label images, Z physical coordinates must also be provided.

logOptional[Log]

A log of how this label image came to be.

Returns
masksBinaryMaskCollection

Masks generated from the label image.

Return type

BinaryMaskCollection

classmethod from_label_image(label_image)[source]

Creates binary masks from a label image. Masks are cropped to the smallest size that contains the non-zero values, but pixel and physical coordinates ticks are retained. Masks extracted from BinaryMaskCollections will be cropped. To extract masks sized to the original label image, use starfish.BinaryMaskCollection.uncropped_mask().

Parameters
label_imageLabelImage

LabelImage to extract binary masks from.

Returns
masksBinaryMaskCollection

Masks generated from the label image.

Return type

BinaryMaskCollection

mask_regionprops(mask_id)[source]

Return the region properties for a given mask.

Parameters
mask_idint

The mask ID for the mask.

Returns
_RegionProperties

The region properties for that mask.

Return type

_RegionProperties

classmethod open_targz(path)[source]

Load the collection saved as a .tar.gz file from disk

Parameters
pathUnion[str, Path]

Path of the tar file to instantiate from.

Returns
masksBinaryMaskCollection

Collection of binary masks.

Return type

BinaryMaskCollection

to_targz(path)[source]

Save the binary masks to disk as a .tar.gz file.

Parameters
pathUnion[str, Path]

Path of the tar file to write to.

uncropped_mask(index)[source]

Some of the binary mask collections builders will crop the binary masks when constructing the collection. The purpose is to exclude the regions of the image that are entirely False. Use this method to obtain the mask sized according to the pixel and physical shape provided for the entire binary mask collection, use this method.

Return type

DataArray