Skip to contents

Polygonise an existing mask file (e.g. Cellpose, StarDist, or QuPath output, or a prior annotatR export) into an editable annot_layer. A sidecar <path>.legend.json is used to recover labels when present.

Usage

at_read_mask(
  path,
  level = 0L,
  connectivity = c(8L, 4L),
  simplify = 0,
  min_area = 0,
  legend = NULL,
  call = rlang::caller_env()
)

Arguments

path

Path to a mask file (TIFF, PNG, or RDS).

level

Integer pyramid level to record on the ROIs. Default 0.

connectivity

8 (default) or 4 pixel connectivity.

simplify

Non-negative simplification tolerance for the polygons.

min_area

Minimum polygon area in pixels to keep. Default 0.

legend

Optional legend tibble (value, label) overriding the sidecar / pixel-value labelling.

call

The calling environment, for error reporting.

Value

An annot_layer with one ROI per connected region.

Examples

m <- at_mask(at_example_project(), "labelled")
f <- tempfile(fileext = ".tif")
at_write_mask(m, f)
at_read_mask(f)
#> <annot_layer> file2564201a3479
#> ROIs: 3  |  labels: "necrosis", "tumour", and "stroma"
#> visible: TRUE  |  locked: FALSE  |  z: 1