troutpy.pp.add_morphological_metrics

troutpy.pp.add_morphological_metrics#

troutpy.pp.add_morphological_metrics(sdata, labels_key='cell_labels', copy=False)#

Extract cell morphology metrics from a labels layer and add them to sdata.table.obs.

Computes region properties (area, perimeter, solidity, axis lengths) via skimage.measure.regionprops_table and derives circularity, protrusion length, and morphological complexity. Existing overlapping columns are replaced.

Parameters:
  • sdata (spatialdata.SpatialData) – SpatialData object that must contain a "table" AnnData and the specified labels layer.

  • labels_key (str) – Key in sdata.labels identifying the segmentation label image.

  • copy (bool, optional) – If True, operate on a copy of sdata and return it. Otherwise modify in place and return None. Defaults to False.

Return type:

SpatialData | None

Returns:

spatialdata.SpatialData or None Updated SpatialData with morphology columns added to sdata.table.obs if copy=True; otherwise None.

Raises:

ValueError – If sdata does not contain a "table" AnnData object.