harpy.tb.add_regionprops#
- harpy.tb.add_regionprops(sdata, labels_name, table_name, output_table_name, properties=('area', 'eccentricity', 'major_axis_length', 'minor_axis_length', 'perimeter', 'centroid', 'convex_area', 'equivalent_diameter', 'major_minor_axis_ratio', 'perim_square_over_area', 'major_axis_equiv_diam_ratio', 'convex_hull_resid', 'centroid_dif'), overwrite=False)#
Calculates region property features from the specified labels element, and adds the results to the
AnnDataobject that annotates the labels element.This function computes various geometric and morphological properties for each instance found in the specified labels element of the SpatialData object. These properties include the following measures:
area
eccentricity
major_axis_length
minor_axis_length
perimeter
centroid
convex_area
equivalent_diameter
major_minor_axis_ratio
perim_square_over_area
major_axis_equiv_diam_ratio
convex_hull_resid
centroid_dif
These features are added to the
.obsattribute of theanndata.AnnDatatable at slotoutput_table_name.Note that calculation of perimeter and perim_square_over_area is not supported for 3D labels elements.
- Parameters:
sdata (
SpatialData) – The SpatialData object.labels_name (
str|list[str]) – The name of the labels element insdatathat contains the labeled regions, typically derived from a segmentation process. Each distinct label corresponds to a different instance, and properties will be calculated for these labeled regions.table_name (
str) – The table element insdata.tablesthat annotates the labels element, and to which the calculated features will be added.output_table_name (
str) – Output table element.properties (
str|tuple[str] (default:('area', 'eccentricity', 'major_axis_length', 'minor_axis_length', 'perimeter', 'centroid', 'convex_area', 'equivalent_diameter', 'major_minor_axis_ratio', 'perim_square_over_area', 'major_axis_equiv_diam_ratio', 'convex_hull_resid', 'centroid_dif'))) – The properties to calculate.overwrite (
bool(default:False)) – If True, overwrites the output element if it already exists insdata.
- Returns:
: The updated
sdataobject.
Notes
The function operates by pulling the required labels elements (masks) into memory for processing, as the underlying :func:’skimage.measure.regionprops’ functionality does not support lazy loading. Consequently, sufficient memory must be available for large datasets.
Example
import harpy as hp sdata = hp.datasets.pixie_example() sdata = hp.tb.allocate_intensity( sdata, image_name="raw_image_fov0", labels_name="label_whole_fov0", to_coordinate_system="fov0", mode="sum", output_table_name="table_intensities", overwrite=True, ) sdata = hp.tb.allocate_intensity( sdata, image_name="raw_image_fov1", labels_name="label_whole_fov1", to_coordinate_system="fov1", mode="sum", output_table_name="table_intensities", append=True, overwrite=True, ) sdata = hp.tb.add_regionprops( sdata, labels_name=["label_whole_fov0", "label_whole_fov1"], table_name="table_intensities", output_table_name="table_intensities", properties=["perimeter", "equivalent_diameter"], overwrite=True, )