How big each object is, in units somebody can use

Description

One row per object. voxels is the count, which means nothing outside one scanner, and spacing turns it into a number a reader can compare - the same argument mask_volume() makes for one class, applied per object. That is the question this whole feature is for: how many nuclei, and how big is each one.

Usage

instance_sizes(labels, spacing = NULL)

Arguments

labels An instance label map from predict() - one integer per object, 0 for background. Two dimensions for an image, three for a volume.
spacing The size of one voxel in millimetres: two numbers for an image, three for a volume. Unset means the result counts voxels and says nothing about size.

Details

The unit is decided by the rank, and the column 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 ends up in a paper as a bare number.

Without spacing there is no such column at all, rather than a count pretending to be a measurement.

Value

A data frame with object, voxels and, when spacing is given, area_mm2 or volume_ml. One row per object present, in increasing object number; an object number absent from the map gets no row, because a model that found objects 1, 2 and 4 found three objects.

See Also

overlay_instances() to look at them, mask_volume() for one class of a semantic mask.

Examples

library("rplatypus")

labels <- matrix(0L, nrow = 8, ncol = 8)
labels[2:4, 2:4] <- 1L
labels[6:7, 6:8] <- 2L
instance_sizes(labels)
  object voxels
1      1      9
2      2      6
# 0.5 mm pixels: object 1 is 9 pixels, so 9 * 0.25 = 2.25 mm^2.
instance_sizes(labels, spacing = c(0.5, 0.5))
  object voxels area_mm2
1      1      9     2.25
2      2      6     1.50