sparrow.im.merge_labels_layers_nuclei#
- sparrow.im.merge_labels_layers_nuclei(sdata, labels_layer, labels_layer_nuclei_expanded, labels_layer_nuclei, threshold=0.5, depth=100, chunks='auto', output_labels_layer=None, output_shapes_layer=None, scale_factors=None, overwrite=False, iou_depth=2, iou_threshold=0.7)#
Merge labels layers using nuclei segmentation.
Given a labels layer obtained from nuclei segmentation (
labels_layer_nuclei
), and corresponding expanded nuclei (labels_layer_nuclei_expanded
), e.g. obtained throughsp.im.expand_labels_layer
, this function merges labels in labels layerlabels_layer_nuclei_expanded
withlabels_layer
in the SpatialData object, if corresponding nuclei inlabels_layer_nuclei
have less thanthreshold
overlap with labels fromlabels_layer
.- Parameters:
sdata (
SpatialData
) – The SpatialData object containing the labels layers.labels_layer (
str
) – The name of the labels layer to merge with nuclei labels.labels_layer_nuclei_expanded (
str
) – The name of the expanded nuclei labels layer.labels_layer_nuclei (
str
) – The name of the nuclei labels layer.threshold (
float
(default:0.5
)) – The threshold value to control the merging of labels. This value determines how the merge operation is conducted based on the overlap between the labels inlabels_layer_nuclei
andlabels_layer
.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. Please set depth>cell diameter + distance to avoid chunking effects.chunks (
str
|int
|tuple
[int
,int
] |None
(default:'auto'
)) – Specification for rechunking the data before applying the merge operation. This parameter defines how the data is divided into chunks for processing. If ‘auto’, the chunking strategy is determined automatically.output_labels_layer (
Optional
[str
] (default:None
)) – The name of the output labels layer where the merged results will be stored.output_shapes_layer (
Optional
[str
] (default:None
)) – The name of the output shapes layer where results will be stored if shape data is produced from the merge operation.scale_factors (
Optional
[Sequence
[Union
[dict
[str
,int
],int
]]] (default:None
)) – Scale factors to apply for multiscale processing.overwrite (
bool
(default:False
)) – If True, overwrites the output layer if it already exists insdata
.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
sdata
object with the merged labels layer added to the specified output layer. Ifoutput_shapes_layer
is provided, a shapes layer will be created corresponding to this labels layer.- Raises:
ValueError – If any of the specified labels layers cannot be found in
sdata
.ValueError – If the labels in
labels_layer_nuclei_expanded
do not match the labels inlabels_layer_nuclei
.
Notes
This function is designed to facilitate the merging of expanded nuclei labels with other label layers within a SpatialData object. It leverages dask for potential parallelism and out-of-core computation.