sparrow.im.mask_to_original

sparrow.im.mask_to_original#

sparrow.im.mask_to_original(sdata, labels_layer, original_labels_layers, depth=400, chunks='auto')#

Map to original.

Maps labels from a labels layer (labels_layer) to their corresponding labels in original labels layers within a SpatialData object. The labels in labels_layers will be mapped to the label of the labels layers in original_labels_layers with which it has maximum overlap.

Parameters:
  • sdata (SpatialData) – Spatialdata object containing the mask and original labels layers.

  • labels_layer (str) – The name of the labels layer used as a mask for mapping.

  • original_labels_layers (list[str]) – The names of the original labels layers to which the mask labels are mapped.

  • depth (tuple[int, int] | int (default: 400)) – The depth around the boundary of each block to load when the array is split into blocks. This ensures that the split doesn’t cause misalignment along the edges. Default is 400. Set depth larger than the maximum cell diameter to avoid chunking effects.

  • chunks (str | int | tuple[int, int] | None (default: 'auto')) – Specification for rechunking the data before applying the function. If chunks is a Tuple, they should contain desired chunk size for ‘y’, ‘x’. ‘auto’ allows the function to determine optimal chunking. Setting chunks to a relative small size (~1000) will significantly speed up the computations.

Return type:

DataFrame

Returns:

: A pandas DataFrame where each row corresponds to a unique cell id from the mask layer, and columns correspond to the original labels layers. Each cell in the DataFrame contains the label from the original layer that overlaps most with the mask label.

Raises:
  • AssertionError – If arrays from different labels layers do not have the same shape.

  • AssertionError – If depth is provided as a Tuple but does not match (y, x) dimensions.

  • AssertionError – If chunks is a Tuple, and does not match (y, x) dimensions.

  • AssertionError – If the number of blocks in the z-dimension is not equal to 1.

Notes

This function is designed to facilitate the comparison or integration of segmentation results by mapping mask labels back to their original labels.