spateo.segmentation.external.stardist#

Use StarDist for cell identification and labeling. https://github.com/stardist/stardist

[Schmidt18] and [Weigert20]

Module Contents#

Functions#

_stardist(→ numpy.ndarray)

Run StarDist on the provided image.

_stardist_big(→ numpy.ndarray)

Run StarDist on the provided image.

_sanitize_labels(→ numpy.ndarray)

Sanitize labels obtained from StarDist.

stardist(adata, model, 2D_versatile_he, ...)

Run StarDist to label cells from a staining image.

Attributes#

spateo.segmentation.external.stardist.StarDist2D[source]#
spateo.segmentation.external.stardist._stardist(img: numpy.ndarray, model: Union[typing_extensions.Literal[2D_versatile_fluo, 2D_versatile_he, 2D_paper_dsb2018], stardist.models.StarDist2D] = '2D_versatile_fluo', **kwargs) numpy.ndarray[source]#

Run StarDist on the provided image.

Parameters:
img

Image as a Numpy array.

model

Stardist model to use. Can be one of the three pretrained models from StarDist2D: 1. ‘2D_versatile_fluo’: ‘Versatile (fluorescent nuclei)’ 2. ‘2D_versatile_he’: ‘Versatile (H&E nuclei)’ 3. ‘2D_paper_dsb2018’: ‘DSB 2018 (from StarDist 2D paper)’ Or any generic Stardist2D model.

**kwargs

Additional keyword arguments to StarDist2D.predict_instances() function.

Returns:

Numpy array containing cell labels.

spateo.segmentation.external.stardist._stardist_big(img: numpy.ndarray, model: Union[typing_extensions.Literal[2D_versatile_fluo, 2D_versatile_he, 2D_paper_dsb2018], stardist.models.StarDist2D] = '2D_versatile_fluo', **kwargs) numpy.ndarray[source]#

Run StarDist on the provided image.

Parameters:
img

Image as a Numpy array.

model

Stardist model to use. Can be one of the three pretrained models from StarDist2D: 1. ‘2D_versatile_fluo’: ‘Versatile (fluorescent nuclei)’ 2. ‘2D_versatile_he’: ‘Versatile (H&E nuclei)’ 3. ‘2D_paper_dsb2018’: ‘DSB 2018 (from StarDist 2D paper)’ Or any generic Stardist2D model.

**kwargs

Additional keyword arguments to StarDist2D.predict_instances_big() function.

Returns:

Numpy array containing cell labels.

spateo.segmentation.external.stardist._sanitize_labels(labels: numpy.ndarray) numpy.ndarray[source]#

Sanitize labels obtained from StarDist.

StarDist sometimes yields disconnected labels. This function removes these problems by selecting the largest area.

Parameters:
labels

Numpy array containing labels

Returns:

Sanitized labels.

spateo.segmentation.external.stardist.stardist(adata: anndata.AnnData, model: Union[typing_extensions.Literal[2D_versatile_fluo, 2D_versatile_he, 2D_paper_dsb2018], stardist.models.StarDist2D] = '2D_versatile_fluo', tilesize: int = 2000, min_overlap: Optional[int] = None, context: Optional[int] = None, normalizer: Optional[csbdeep.data.Normalizer] = PercentileNormalizer(), equalize: float = 2.0, sanitize: bool = True, layer: str = SKM.STAIN_LAYER_KEY, out_layer: Optional[str] = None, **kwargs)[source]#

Run StarDist to label cells from a staining image.

Note

When using min_overlap, the crucial assumption is that all predicted object instances are smaller than the provided min_overlap. Also, it must hold that: min_overlap + 2*context < tilesize. https://github.com/stardist/stardist/blob/858cae17cf17f979122000ad2294a156d0547135/stardist/models/base.py#L776

Parameters:
adata

Input Anndata

img

Image as a Numpy array.

model

Stardist model to use. Can be one of the three pretrained models from StarDist2D: 1. ‘2D_versatile_fluo’: ‘Versatile (fluorescent nuclei)’ 2. ‘2D_versatile_he’: ‘Versatile (H&E nuclei)’ 3. ‘2D_paper_dsb2018’: ‘DSB 2018 (from StarDist 2D paper)’ Or any generic Stardist2D model.

tilesize

Run prediction separately on tiles of size tilesize x tilesize and merge them afterwards. Useful to avoid out-of-memory errors. Can be set to <= 0 to disable tiling. When min_overlap is also provided, this becomes the block_size parameter to StarDist2D.predict_instances_big().

min_overlap

Amount of guaranteed overlaps between tiles.

context

Amount of image context on all sides of a tile, which is dicarded. Only used when min_overlap is not None. By default, an automatic estimate is used.

normalizer

Normalizer to use to perform normalization prior to prediction. By default, percentile-based normalization is performed. None may be provided to disable normalization.

equalize

Controls the clip_limit argument to the clahe() function. Set this value to a non-positive value to turn off equalization.

sanitize

Whether to sanitize disconnected labels.

layer

Layer that contains staining image. Defaults to stain.

out_layer

Layer to put resulting labels. Defaults to {layer}_labels.

**kwargs

Additional keyword arguments to pass to StarDist2D.predict_instances().