sparrow.im.expand_labels_layer

sparrow.im.expand_labels_layer#

sparrow.im.expand_labels_layer(sdata, labels_layer, distance=10, depth=100, chunks='auto', output_labels_layer=None, output_shapes_layer=None, scale_factors=None, overwrite=False, iou_depth=2, iou_threshold=0.7)#

Expand cells in labels layer labels_layer of Spatialdata object with distance, using skimage.segmentation.expand_labels.

Parameters:
  • sdata (SpatialData) – The spatialdata object containing the labels layer to be expanded.

  • labels_layer (str) – The name of the labels layer to be expanded.

  • distance (int (default: 10)) – distance passed to skimage.segmentation.expand_labels.

  • depth (tuple[int, int] | int (default: 100)) – The depth around the boundary of each block to load when the array is split into blocks (for alignment). This ensures that the split isn’t causing misalignment along the edges. Default is 100. Please set depth>cell diameter + distance to avoid chunking effects.

  • chunks (str | int | tuple[int, int] | None (default: 'auto')) – The desired chunk size for the Dask computation, or “auto” to allow the function to choose an optimal chunk size based on the data. Default is “auto”.

  • output_labels_layer (Optional[str] (default: None)) – The name of the output labels layer where results will be stored. This must be specified.

  • output_shapes_layer (Optional[str] (default: None)) – The name for the new shapes layer generated from the aligned labels layer. If None, no shapes layer is created. Default is None.

  • scale_factors (Optional[Sequence[Union[dict[str, int], int]]] (default: None)) – Scale factors to apply for multiscale.

  • overwrite (bool (default: False)) – If True, overwrites the output layers if they already exist in sdata.

  • iou_depth (tuple[int, int] | int (default: 2)) – iou depth used for linking labels.

  • iou_threshold (float (default: 0.7)) – iou threshold used for linking labels.

Return type:

SpatialData

Returns:

: The modified spatial data object with the expanded labels layer.

Notes

The function works with Dask arrays and can handle large datasets that don’t fit into memory.

Examples

>>> sdata = expand_labels_layer(
        sdata,
        labels_layer='layer',
        distance=10,
        depth=(100, 100),
        chunks=(1024, 1024),
        output_labels_layer='layer_expanded',
        output_shapes_layer='layer_expanded_boundaries',
        overwrite=True,
    )