sparrow.tb.add_regionprop_features#
- sparrow.tb.add_regionprop_features(sdata, labels_layer=None, table_layer=None)#
Enhances a SpatialData object with region property features calculated from the specified labels layer, updating its table attribute (
sdata.tables[table_layer]
) with these computed cellular properties.This function computes various geometric and morphological properties for each labeled region (presumed cells) found in the specified layer of the SpatialData object. These properties include measures such as area, eccentricity, axis lengths, perimeter, and several custom ratios and metrics providing insights into each cell’s shape and structure. The calculated properties are appended to the observations in the SpatialData object’s underlying table (
sdata.tables[table_layer]
).- Parameters:
sdata (
SpatialData
) – The SpatialData object containing spatial information about cells/nuclei. This object will be updated with new region property features.labels_layer (
Optional
[str
] (default:None
)) – The name of the layer insdata
that contains the labeled regions, typically derived from a segmentation process. Each distinct label corresponds to a different cell, and properties will be calculated for these labeled regions. If not provided, the function will default to the ‘last’ labels layer insdata
.table_layer (
Optional
[str
] (default:None
)) – The table layer insdata.tables
to which the features will be added.
- Returns:
: The original SpatialData object, updated to include a range of new region-specific property measurements in its
sdata.tables[table_layer].obs
attribute.
Notes
The function operates by pulling the required data (masks) into memory for processing, as the underlying ‘skimage.measure.regionprops’ functionality does not support lazy loading. Consequently, sufficient memory must be available for large datasets.
Computed properties are merged (using keys
_INSTANCE_KEY
and_REGION_KEY
insdata.tables[table_layer].obs
) with the existing observations within the SpatialData’s table (sdata.tables[table_layer].obs
).
Example
>>> sdata = sp.im.align_labels_layers( ... sdata, ... labels_layer_1="masks_nuclear", ... labels_layer_2="masks_whole", ... output_labels_layer="masks_nuclear_aligned", ... output_shapes_layer=None, ... overwrite=True, ... chunks=256, ... depth=100, ... ) >>> >>> sdata = sp.tb.allocate_intensity( ... sdata, img_layer="raw_image", labels_layer="masks_whole", output_layer="table_intensities", chunks=100 ... ) >>> >>> sdata = sp.tb.allocate_intensity( ... sdata, img_layer="raw_image", labels_layer="masks_nuclear_aligned", output_layer="table_intensities", chunks=100, append=True ... ) >>> >>> sdata = sp.tb.add_regionprop_features( ... sdata, labels_layer="masks_whole", table_layer="table_intensities", ... ) >>> >>> sdata = sp.tb.add_regionprop_features( ... sdata, labels_layer="masks_nuclear_aligned", table_layer="table_intensities", ... )