Skip to main content

instance_sizes

instance_sizes(labels, spacing=None)

How big each object is, one row per object.

The unit is decided by the rank and the key is named after it rather than being called size with a note somewhere: area_mm2 for an image, volume_ml for a volume. A column whose unit lives in the documentation is a column that reaches a paper as a bare number. Without spacing there is no such key at all, rather than a count pretending to be a measurement.

Parameters

Name Type Description Default
labels np.ndarray One instance label map, one integer per object and 0 for background. Two dimensions for an image, three for a volume. required
spacing Any Voxel size in millimetres, one number per dimension. Unset means the rows count voxels and say nothing about size. None

Returns

Name Type Description
list[dict[str, Any]] One dict per object present, in increasing object number, with object, voxels
list[dict[str, Any]] and - when spacing is given - area_mm2 or volume_ml. An object number absent
list[dict[str, Any]] from the map gets no row, because a model that found objects 1, 2 and 4 found three
list[dict[str, Any]] objects.

Raises

Name Type Description
MeasureError If labels is not one map, or spacing has the wrong length.

labels = np.zeros((8, 8), dtype=int) labels[1:4, 1:4] = 1 labels[5:7, 5:8] = 2 instance_sizes(labels, spacing=(0.5, 0.5))[0] # 9 pixels of 0.25 mm^2 {‘object’: 1, ‘voxels’: 9, ‘area_mm2’: 2.25}