| Title: | Region-of-Interest Annotation for Hyperspectral Data |
|---|---|
| Description: | Annotate multiple layers of regions of interest in hyperspectral data cubes and their associated display rasters. Annotations are stored as validated simple-feature geometries in image pixel coordinates with explicit pyramid-level transforms, and can be rasterised to binary, labelled, or multi-class integer masks for downstream segmentation and classification workflows. A batch annotation application built on 'shiny' supports resumable sessions across image queues, live mask preview, and export to 'GeoJSON', 'QuPath', and 'TIFF' formats. A versioned partner contract exchanges hash-inventoried handoff directories, deep-learning training datasets and typed commands over an optional local control service. |
| Authors: | Raban Heller [aut, cre] (ORCID: <https://orcid.org/0000-0001-8006-9742>) |
| Maintainer: | Raban Heller <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.1 |
| Built: | 2026-11-03 18:11:02 UTC |
| Source: | https://github.com/CTTIR/hyperannotatR |
Add a layer to a project
at_add_layer(project, layer, call = rlang::caller_env())at_add_layer(project, layer, call = rlang::caller_env())
project |
An annot_project. |
layer |
An annot_layer with a name not already used in the project. |
call |
The calling environment, for error reporting. |
A new annot_project with the layer added. ROIs in layer whose
identifiers are missing, already used in the project, or repeated within
the layer are re-minted; the first occurrence of each valid id is kept.
The input is unchanged.
Other projects:
at_add_roi(),
at_example_project(),
at_layers(),
at_project(),
at_remove_layer(),
at_remove_roi(),
at_rois(),
at_summary(),
at_validate()
Add an ROI to a project layer
at_add_roi(project, layer, roi, call = rlang::caller_env())at_add_roi(project, layer, roi, call = rlang::caller_env())
project |
An annot_project. |
layer |
Single string name of the target layer. |
roi |
An annot_roi. |
call |
The calling environment, for error reporting. |
A new annot_project with the ROI added to the layer. A colliding ROI identifier is re-minted to keep identifiers unique across the project. The input is unchanged.
Other projects:
at_add_layer(),
at_example_project(),
at_layers(),
at_project(),
at_remove_layer(),
at_remove_roi(),
at_rois(),
at_summary(),
at_validate()
A launcher around at_app(): it builds the app object from explicit
arguments and runs it. Nothing is exchanged through global options.
at_annotate( x = NULL, labels = character(), layers = NULL, out_dir = NULL, launch.browser = TRUE, port = NULL, ..., call = rlang::caller_env() )at_annotate( x = NULL, labels = character(), layers = NULL, out_dir = NULL, launch.browser = TRUE, port = NULL, ..., call = rlang::caller_env() )
x |
What to annotate: an annot_session, annot_project, annot_image,
a character vector of image paths, a directory of images, or |
labels |
Character vector of the global label vocabulary. |
layers |
An annot_layer, a list of them, or |
out_dir |
Directory for autosave and exports. When |
launch.browser |
Passed to |
port |
Passed to |
... |
Passed to |
call |
The calling environment, for error reporting. |
Invisible NULL. Launches a Shiny application; called for side
effects.
Other shiny:
atCanvasOutput(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
if (interactive()) { at_annotate(at_example_session(5)) }if (interactive()) { at_annotate(at_example_session(5)) }
A content revision for annotations: the SHA-256 of the canonical record of
every layer (name, labels, colours, z-order, visibility, lock) and ROI (id,
layer, label, level, geometry WKB, source, lock, review status, plane and
attributes). It changes whenever annotation content changes and is
independent of timestamps, authors, file paths and pixel data. Partners pass
it back as expected_revision to detect stale patches.
at_annotation_revision(x, call = rlang::caller_env())at_annotation_revision(x, call = rlang::caller_env())
x |
An annot_project, annot_layer, or annot_session (combining every materialised project and the queue statuses). |
call |
The calling environment, for error reporting. |
A single string "sha256:<64 hex>".
Other interop:
at_commit_qupflowr(),
at_export_qupflowr(),
at_import_qupflowr(),
at_interop_capabilities(),
at_interop_manifest(),
at_stage_qupflowr()
proj <- at_project(at_example_image("cube")) at_annotation_revision(proj)proj <- at_project(at_example_image("cube")) at_annotation_revision(proj)
Construct the batch annotation application from explicit inputs, without
launching a browser or touching global options. The result can be run with
shiny::runApp(), embedded in another Shiny application, or exercised in
tests; at_annotate() is a launcher around it.
at_app( input = NULL, session = NULL, control = "off", labels = character(), layers = NULL, out_dir = NULL, read_only = FALSE, view = NULL, ..., call = rlang::caller_env() )at_app( input = NULL, session = NULL, control = "off", labels = character(), layers = NULL, out_dir = NULL, read_only = FALSE, view = NULL, ..., call = rlang::caller_env() )
input |
What to annotate: an annot_project, annot_image, a
character vector of image paths, a directory of images, or |
session |
An annot_session to resume. Supply |
control |
|
labels, layers, out_dir
|
Passed to |
read_only |
Logical; disable all annotation edits (view and inspect only). |
view |
Optional initial band view, e.g.
|
... |
Reserved; must be empty. |
call |
The calling environment, for error reporting. |
All Shiny sessions of one app object share its in-memory queue: reloading the page or opening a second tab continues from the latest edits instead of the session the app was built with. Edits are stored per queue entry; two tabs editing the same image keep the last edit.
Annotations autosave to the session's out_dir (unless the session was
created with autosave = FALSE); the app warns when that folder is inside
R's temporary directory, which is deleted when R exits. Before it first
replaces an existing _session.rds that holds another queue or more ROIs,
the app keeps a timestamped _session-*.previous.rds copy.
The Data page reads folder and handoff paths on the machine running R. The
app is meant for local use. Set
options(hyperannotatR.app_root = "/allowed/folder") to restrict canonical
image paths and known ENVI/TIVITA companions to that folder. This is not an
operating-system sandbox: custom readers, external references and concurrent
filesystem changes need separate controls in a shared deployment.
A shiny.appobj.
at_annotate(), at_control_start()
Other shiny:
atCanvasOutput(),
at_annotate(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
app <- at_app(input = at_example_path("cube")) class(app) ## Not run: shiny::runApp(app) ## End(Not run)app <- at_app(input = at_example_path("cube")) class(app) ## Not run: shiny::runApp(app) ## End(Not run)
Detect the backend for a file
at_backend_detect(path, call = rlang::caller_env())at_backend_detect(path, call = rlang::caller_env())
path |
Single string file path. |
call |
The calling environment, for error reporting. |
The name of the first available backend (in priority order) that can
read path. Errors informatively if none can.
Other backends:
at_backend_get(),
at_backend_list(),
at_backend_register(),
at_close_image(),
at_cubert_export_envi(),
at_image_capabilities(),
at_read_image(),
at_tile(),
at_tivita_profile()
Get a registered backend
at_backend_get(name, call = rlang::caller_env())at_backend_get(name, call = rlang::caller_env())
name |
Single string backend name. |
call |
The calling environment, for error reporting. |
The annot_backend object.
Other backends:
at_backend_detect(),
at_backend_list(),
at_backend_register(),
at_close_image(),
at_cubert_export_envi(),
at_image_capabilities(),
at_read_image(),
at_tile(),
at_tivita_profile()
List registered image backends
at_backend_list(call = rlang::caller_env())at_backend_list(call = rlang::caller_env())
call |
The calling environment, for error reporting. |
A tibble::tibble with columns name (character), description
(character), extensions (character, comma-separated), and available
(logical), plus metadata_only and window_read (logical; NA when unknown).
A 0-row tibble with these columns when nothing is registered.
Other backends:
at_backend_detect(),
at_backend_get(),
at_backend_register(),
at_close_image(),
at_cubert_export_envi(),
at_image_capabilities(),
at_read_image(),
at_tile(),
at_tivita_profile()
at_backend_list()at_backend_list()
Backends are how hyperannotatR reads image formats. Each supplies functions to read an image's metadata, fetch tiles, detect whether it can read a file, and report whether its optional dependencies are installed.
at_backend_register( name, read_fn, tile_fn, detect_fn, available_fn, description = "", extensions = character(), call = rlang::caller_env(), capabilities = list(metadata_only = NA, window_read = NA, samples = "unqualified", io = "unknown"), close_fn = NULL )at_backend_register( name, read_fn, tile_fn, detect_fn, available_fn, description = "", extensions = character(), call = rlang::caller_env(), capabilities = list(metadata_only = NA, window_read = NA, samples = "unqualified", io = "unknown"), close_fn = NULL )
name |
Single string backend name (unique). |
read_fn |
|
tile_fn |
|
detect_fn |
|
available_fn |
|
description |
Single string human-readable description. |
extensions |
Character vector of file extensions the backend handles. |
call |
The calling environment, for error reporting. |
capabilities |
Additive list declaring metadata_only, window_read, samples and io. Omitted capabilities are unknown. Readers can override these per image in meta$capabilities. |
close_fn |
Optional function(img) releasing runtime resources. |
The registered annot_backend, invisibly.
at_backend_list(), at_read_image()
Other backends:
at_backend_detect(),
at_backend_get(),
at_backend_list(),
at_close_image(),
at_cubert_export_envi(),
at_image_capabilities(),
at_read_image(),
at_tile(),
at_tivita_profile()
List the display band operations the app and the control service accept. Derived views are display products: they carry their parent digest, band list, operation and parameters, and are never written back as analysis input.
at_band_operations()at_band_operations()
A tibble::tibble with columns operation, n_bands (integer;
NA means one or more), params (comma-separated parameter names) and
description.
Other hsi:
at_band_view(),
at_convert_values(),
at_cubert_export_envi(),
at_hsi_meta(),
at_read_stats(),
at_tivita_profile()
at_band_operations()at_band_operations()
Evaluate one of at_band_operations() on a window of an image. The result
is a display product: a [y, x, k] array (k = 3 for "rgb", otherwise 1)
with provenance attributes, which hyperannotatR never uses as analysis input.
at_band_view( img, operation = "rgb", bands = NULL, params = list(), level = 0L, xrange = NULL, yrange = NULL, call = rlang::caller_env() )at_band_view( img, operation = "rgb", bands = NULL, params = list(), level = 0L, xrange = NULL, yrange = NULL, call = rlang::caller_env() )
img |
An annot_image. |
operation |
A registered operation name. |
bands |
Band indices (defaults depend on the operation). |
params |
Named list of operation parameters. |
level, xrange, yrange
|
Passed to |
call |
The calling environment, for error reporting. |
A numeric array with attributes operation, bands,
wavelengths, params, parent_digest, transform_digest, level and
display_product = TRUE.
Other hsi:
at_band_operations(),
at_convert_values(),
at_cubert_export_envi(),
at_hsi_meta(),
at_read_stats(),
at_tivita_profile()
cube <- at_example_image("cube") v <- at_band_view(cube, "normalized_difference", bands = c(30, 10)) attr(v, "operation")cube <- at_example_image("cube") v <- at_band_view(cube, "normalized_difference", bands = c(30, 10)) attr(v, "operation")
Band (channel) table
at_bands(x, call = rlang::caller_env())at_bands(x, call = rlang::caller_env())
x |
An annot_image. |
call |
The calling environment, for error reporting. |
A tibble::tibble with one row per band and the columns:
indexBand index, 1-based (integer).
nameBand name (character); a default "Band k" when unnamed.
wavelengthCentre wavelength (double); NA when not spectral
or unknown for that band. Never interpolated.
unitDeclared spectral coordinate unit (character); NA when
not spectral or when the unit is unknown. Scalar metadata applies to
all bands; per-band units are preserved without conversion.
fwhmFull width at half maximum in the wavelength unit
(double); NA when the source does not declare it.
orderPosition of the band in file/manifest order (integer).
wavelength_status"ok", "missing", "duplicate" or
"non_numeric" (character).
Always has at_n_bands(x) rows. The first four columns are unchanged
from hyperannotatR 0.1; the remaining columns were added in 0.2.0.
Other images:
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Apply a function to every project in a session
at_batch_apply( session, fn, ..., scope = "all", progress = TRUE, call = rlang::caller_env() )at_batch_apply( session, fn, ..., scope = "all", progress = TRUE, call = rlang::caller_env() )
session |
An annot_session. |
fn |
A function |
... |
Passed to |
scope |
|
progress |
Logical; show a progress bar. Default |
call |
The calling environment, for error reporting. |
The annot_session with modified projects. An image whose project
cannot be materialised, or for which fn errors or does not return an
annot_project, keeps its previous project; the failures are reported in
one warning and attached as the "batch_errors" attribute, a
tibble::tibble with columns idx, image and message.
Other batch:
at_batch_check_geometry(),
at_export_all(),
at_summary_table()
Run at_check_geometry() on every materialised project in the session and
stack the reports. Like at_check_geometry() (and unlike the assertion
at_validate()), this returns a report rather than throwing.
at_batch_check_geometry(session, call = rlang::caller_env())at_batch_check_geometry(session, call = rlang::caller_env())
session |
An annot_session. |
call |
The calling environment, for error reporting. |
A tibble::tibble with columns image, roi_id, issue, and
severity. A 0-row tibble when all geometry is valid.
Other batch:
at_batch_apply(),
at_export_all(),
at_summary_table()
The canvas shows one embedded, downsampled image with the project's ROIs drawn in their label colours (hidden layers are left out; locked layers cannot be erased or moved on the canvas). It pans with a drag and zooms with the mouse wheel or a two-finger pinch. When no image can be shown, it says why instead of keeping a previous image.
at_canvas( img, project = NULL, tool = "pan", width = NULL, height = NULL, elementId = NULL, options = list(), view = NULL, call = rlang::caller_env() )at_canvas( img, project = NULL, tool = "pan", width = NULL, height = NULL, elementId = NULL, options = list(), view = NULL, call = rlang::caller_env() )
img |
An annot_image to display. |
project |
Optional annot_project whose ROIs are shown initially. |
tool |
Initial tool: one of |
width, height
|
Widget dimensions. |
elementId |
Optional element id. |
options |
A list of extra options passed to the widget:
|
view |
Optional band view passed to |
call |
The calling environment, for error reporting. |
An htmlwidget object.
In Shiny, the canvas with output id id sends these inputs. Each value is a
list entry_id, revision, payload: the identity rendered when the
gesture began (the project's meta$entry_id and meta$annotation_revision,
or the element id and 0 for a project without them) and the event data.
A render or at_canvas_set_annotations() with a different identity cancels
unfinished gestures, and stale events are never sent.
<id>_createdA drawn GeoJSON feature in level-0 pixels; target
holds options$creationTarget (layer, label) as it was when the
drawing began. A click with the rectangle or circle tool is not a shape.
<id>_editedroi_id, layer, label and the moved geometry
(sent only after an actual drag).
<id>_erasedThe erased ROI id.
<id>_selectedThe ids of the selected ROIs (possibly none).
<id>_probedx, y: the probed level-0 pixel position.
<id>_reflection_seedx, y and target: a clicked pixel
for a reflection proposal. It does not create an ROI.
<id>_viewportzoom, center_x, center_y and bounds
(xmin, ymin, xmax, ymax in level-0 pixels) after a pan or zoom.
<id>_readyready and error: whether the image is displayed.
A drawn or moved shape is shown dashed until new annotations arrive, and disappears after a few seconds if none do, so the canvas does not keep showing an ROI the app did not accept.
at_canvas_proxy(), at_tile_source()
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
at_canvas(at_example_image("tissue"))at_canvas(at_example_image("tissue"))
Zoom the canvas to a bounding box
at_canvas_fit(proxy, bbox = NULL, call = rlang::caller_env())at_canvas_fit(proxy, bbox = NULL, call = rlang::caller_env())
proxy |
An |
bbox |
Optional |
call |
The calling environment, for error reporting. |
The proxy, invisibly.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
Mirrors the leafletProxy() pattern: update a live canvas without
re-rendering the whole widget. Inside a Shiny module, pass the module's
(un-namespaced) output id; it is namespaced with the module session, as
leaflet::leafletProxy() does.
at_canvas_proxy(id, session = shiny::getDefaultReactiveDomain())at_canvas_proxy(id, session = shiny::getDefaultReactiveDomain())
id |
The canvas output id. |
session |
The Shiny session. |
An atcanvas_proxy object.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
Replace the annotations on a canvas
at_canvas_set_annotations( proxy, project, layer = NULL, call = rlang::caller_env() )at_canvas_set_annotations( proxy, project, layer = NULL, call = rlang::caller_env() )
proxy |
An |
project |
An annot_project. |
layer |
Optional layer filter. |
call |
The calling environment, for error reporting. |
The proxy, invisibly.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
Retained for API compatibility; it has no visible effect on the built-in
canvas. The canvas shows one embedded image rendered in R, and cannot
recompute bands in the browser. To change the displayed bands, re-render the
widget with a view (see at_canvas() and at_band_view()), as the
annotation app does.
at_canvas_set_band(proxy, band, call = rlang::caller_env())at_canvas_set_band(proxy, band, call = rlang::caller_env())
proxy |
An |
band |
A band index or a length-3 vector of band indices. |
call |
The calling environment, for error reporting. |
The proxy, invisibly.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
Overlay a mask on the canvas
at_canvas_set_overlay(proxy, mask, alpha = 0.5, call = rlang::caller_env())at_canvas_set_overlay(proxy, mask, alpha = 0.5, call = rlang::caller_env())
proxy |
An |
mask |
An |
alpha |
Overlay opacity. Default |
call |
The calling environment, for error reporting. |
The proxy, invisibly.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
Highlight selected ROIs on a canvas
at_canvas_set_selection( proxy, roi_ids = character(), call = rlang::caller_env() )at_canvas_set_selection( proxy, roi_ids = character(), call = rlang::caller_env() )
proxy |
An |
roi_ids |
Character vector of ROI ids to highlight (empty clears). |
call |
The calling environment, for error reporting. |
The proxy, invisibly.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
Set the active drawing tool
at_canvas_set_tool(proxy, tool, call = rlang::caller_env())at_canvas_set_tool(proxy, tool, call = rlang::caller_env())
proxy |
An |
tool |
One of the canvas tools. |
call |
The calling environment, for error reporting. |
The proxy, invisibly.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_tile_source(),
renderAtCanvas()
Report ROIs in a constrained layer that fall outside their container region.
A layer declares the constraint through its metadata, e.g.
at_layer("state", within = list(layer = "anatomy", label = "wound")); then
every ROI in state must be spatially covered by the union of the anatomy
layer's wound ROIs. This enforces the annotation rule that a class is
painted only inside its region of interest. The report mirrors the shape of
at_check_geometry().
at_check_containment(project, tol = 0, call = rlang::caller_env())at_check_containment(project, tol = 0, call = rlang::caller_env())
project |
An annot_project. |
tol |
Non-negative slack, in level-0 pixels, by which the container is
grown before testing, to tolerate sub-pixel tracing overhang. Default |
call |
The calling environment, for error reporting. |
A tibble::tibble with columns roi_id, layer, issue,
severity ("warning" for an ROI outside its container, "error" for a
missing/empty container), and fixable (always FALSE). A 0-row tibble
when every constrained ROI is contained, or when no layer declares a
within constraint.
at_check_geometry(), at_validate()
Other geometry:
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
anatomy <- at_layer_add(at_layer("anatomy", labels = "wound"), at_roi_rect(2, 2, 8, 8, label = "wound")) state <- at_layer("state", labels = "injury", within = list(layer = "anatomy", label = "wound")) state <- at_layer_add(state, at_roi_rect(0, 0, 4, 4, label = "injury")) at_check_containment(at_project(at_example_image("cube"), list(anatomy, state)))anatomy <- at_layer_add(at_layer("anatomy", labels = "wound"), at_roi_rect(2, 2, 8, 8, label = "wound")) state <- at_layer("state", labels = "injury", within = list(layer = "anatomy", label = "wound")) state <- at_layer_add(state, at_roi_rect(0, 0, 4, 4, label = "injury")) at_check_containment(at_project(at_example_image("cube"), list(anatomy, state)))
Check the geometry of every ROI in a project
at_check_geometry(project, call = rlang::caller_env())at_check_geometry(project, call = rlang::caller_env())
project |
An annot_project. |
call |
The calling environment, for error reporting. |
A tibble::tibble with columns roi_id (character), issue
(character), severity (character, "error"/"warning"), and fixable
(logical). Detected issues: self-intersection, invalid geometry, zero area,
degenerate rings, out-of-bounds vertices, duplicate consecutive vertices,
ring orientation, NA coordinates, empty geometry, and a pyramid level the
image does not have (level_out_of_range). A 0-row tibble when all
geometry is valid.
at_fix_geometry(), at_validate()
Other geometry:
at_check_containment(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
at_check_geometry(at_example_project())at_check_geometry(at_example_project())
Clip an ROI to image bounds
at_clamp(roi, dims, call = rlang::caller_env())at_clamp(roi, dims, call = rlang::caller_env())
roi |
An annot_roi. |
dims |
Integer |
call |
The calling environment, for error reporting. |
An annot_roi clipped to [0, width] x [0, height]. Warns if the
clip empties the geometry.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
at_clamp(at_roi_rect(-5, -5, 20, 20, label = "a"), dims = c(10, 10))at_clamp(at_roi_rect(-5, -5, 20, 20, label = "a"), dims = c(10, 10))
Drop an image's runtime pixel handle, calling the backend's close_fn when
it declares one.
at_close_image(x)at_close_image(x)
x |
An annot_image or annot_project. |
The image or project with its runtime handle released; assign the result. Later tile requests reopen the image from its source. Releasing a retained pixel snapshot loses those pixels when the source has changed or cannot be reopened. Built-in window readers open a connection per read and hold no persistent connection.
Other images:
at_bands(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Other backends:
at_backend_detect(),
at_backend_get(),
at_backend_list(),
at_backend_register(),
at_cubert_export_envi(),
at_image_capabilities(),
at_read_image(),
at_tile(),
at_tivita_profile()
cube <- at_close_image(at_example_image("cube")) dim(at_tile(cube, xrange = c(1, 4), yrange = c(1, 4), bands = 1))cube <- at_close_image(at_example_image("cube")) dim(at_tile(cube, xrange = c(1, 4), yrange = c(1, 4), bands = 1))
Apply an at_stage_qupflowr() patch. Conflicting operations are never
applied. The commit is idempotent: repeating it with the same
idempotency_key and the same patch returns the original receipt without
applying anything again, while the same key with a different patch aborts
with IDEMPOTENCY_CONFLICT. When the patch targets a saved project file (or
destination names one), the file is re-read and its revision re-checked
immediately before writing; an existing file is only replaced with
overwrite = TRUE. A <file>.commit.json receipt records the key across R
sessions. The project and receipt are staged together; a failed publication
restores both previous files, or reports retained recovery backups if
restoration also fails. Writers to the same destination must be
serialised; this is not a cross-file transaction against process or machine
failure. A replay aborts with REVISION_CONFLICT if the saved project has
changed since that receipt was written. Reusing a cached key for a different
destination aborts with IDEMPOTENCY_CONFLICT.
at_commit_qupflowr( x, idempotency_key = NULL, destination = NULL, overwrite = FALSE, call = rlang::caller_env() )at_commit_qupflowr( x, idempotency_key = NULL, destination = NULL, overwrite = FALSE, call = rlang::caller_env() )
x |
An |
idempotency_key |
Optional client key; defaults to one derived from the patch id. |
destination |
Optional project |
overwrite |
Logical; allow replacing an existing project file. |
call |
The calling environment, for error reporting. |
An at_commit_receipt: a list with state = "committed",
patch_id, idempotency_key, previous_revision, new_revision,
applied and conflicts (operation tibbles), project, written (path or
NA), committed_at and replayed.
Other interop:
at_annotation_revision(),
at_export_qupflowr(),
at_import_qupflowr(),
at_interop_capabilities(),
at_interop_manifest(),
at_stage_qupflowr()
proj <- at_example_project() partner <- at_layer_add(at_layer("regions"), at_roi_rect(10, 10, 40, 40, label = "tumour", id = "partner-1")) rc <- at_commit_qupflowr(at_stage_qupflowr(proj, partner)) rc$new_revisionproj <- at_example_project() partner <- at_layer_add(at_layer("regions"), at_roi_rect(10, 10, 40, 40, label = "tumour", id = "partner-1")) rc <- at_commit_qupflowr(at_stage_qupflowr(proj, partner)) rc$new_revision
Describe the annotatr-control-v1 protocol this hyperannotatR version speaks,
without starting anything: endpoints, typed operations, limits, security
rules and the digests of the shipped JSON Schemas. A client compares this
(or the /v1/handshake response) with its own expectations before sending
commands.
at_control_capabilities()at_control_capabilities()
A list with protocol, protocol_version, annotatr_version,
status (see at_interop_capabilities()), endpoints, operations,
limits, security, schemas (file name -> SHA-256) and digest.
at_control_start(), at_control_command()
Other control:
at_control_close(),
at_control_command(),
at_control_connect(),
at_control_events(),
at_control_request_status(),
at_control_start(),
at_control_state(),
at_control_stop()
cc <- at_control_capabilities() cc$operationscc <- at_control_capabilities() cc$operations
Close the control service a handle refers to. For a local handle this is
at_control_stop(); for a remote handle it sends POST /v1/close, after
which that service stops accepting requests while its host process and any
app keep running. Neither path terminates a process. A close is not
revision-checked, so concurrent edits in an attached app never make it
fail; unsaved app edits stay in the app.
at_control_close(handle, call = rlang::caller_env())at_control_close(handle, call = rlang::caller_env())
handle |
An |
call |
The calling environment, for error reporting. |
The close response (remote) or TRUE (local), invisibly.
Other control:
at_control_capabilities(),
at_control_command(),
at_control_connect(),
at_control_events(),
at_control_request_status(),
at_control_start(),
at_control_state(),
at_control_stop()
Send one annotatr-control-v1 operation. The command is a list with
operation (one of at_control_capabilities()$operations), payload
(a list) and expected_revision (the state_revision the command is based
on). request_id and idempotency_key are generated when absent and
content_sha256 is always computed from the canonical payload. A stale
revision raises an at_conflict_error (REVISION_CONFLICT); re-sending the
same command with the same idempotency key returns the original result
(replayed = TRUE in the response) instead of applying it twice. The
service keeps the most recent 1000 request records; a replay of an older
key raises IDEMPOTENCY_EXPIRED instead of executing again, and a large
stored response (for example a mask preview PNG) is replayed in compact
form with response_truncated = TRUE. close is the only operation that
does not check expected_revision. Errors carry the same condition class
as the corresponding local call.
at_control_command(handle, command, call = rlang::caller_env())at_control_command(handle, command, call = rlang::caller_env())
handle |
An |
command |
A list with |
call |
The calling environment, for error reporting. |
The response data (a list) with the response envelope in
attr(, "response").
Other control:
at_control_capabilities(),
at_control_close(),
at_control_connect(),
at_control_events(),
at_control_request_status(),
at_control_start(),
at_control_state(),
at_control_stop()
sess <- at_session(rep(at_example_path("cube"), 3)) h <- at_control_start(sess, serve = FALSE) st <- at_control_state(h) at_control_command(h, list(operation = "context.goto", payload = list(queue_index = 2), expected_revision = st$state_revision)) at_control_stop(h)sess <- at_session(rep(at_example_path("cube"), 3)) h <- at_control_start(sess, serve = FALSE) st <- at_control_state(h) at_control_command(h, list(operation = "context.goto", payload = list(queue_index = 2), expected_revision = st$state_revision)) at_control_stop(h)
Build a remote handle for a control service started in another R process, from its lifecycle manifest and token file. The handshake is checked before the handle is returned: protocol, major version and instance id must match the manifest.
at_control_connect(manifest, token_file, call = rlang::caller_env())at_control_connect(manifest, token_file, call = rlang::caller_env())
manifest |
Path of the |
token_file |
Path of the token file passed to |
call |
The calling environment, for error reporting. |
An at_control_handle of kind "remote".
Other control:
at_control_capabilities(),
at_control_close(),
at_control_command(),
at_control_events(),
at_control_request_status(),
at_control_start(),
at_control_state(),
at_control_stop()
Read control events after a cursor
at_control_events( handle, after = NULL, limit = 100L, call = rlang::caller_env() )at_control_events( handle, after = NULL, limit = 100L, call = rlang::caller_env() )
handle |
An |
after |
Optional event cursor ( |
limit |
Maximum number of events to return (a positive integer; the service caps a page at 500). |
call |
The calling environment, for error reporting. |
A list with events, next_cursor, resync_required, has_more
and state_revision.
Other control:
at_control_capabilities(),
at_control_close(),
at_control_command(),
at_control_connect(),
at_control_request_status(),
at_control_start(),
at_control_state(),
at_control_stop()
After a lost response, ask the service what happened to a request id. An
unknown id raises REQUEST_NOT_FOUND and has no side effect.
at_control_request_status(handle, request_id, call = rlang::caller_env())at_control_request_status(handle, request_id, call = rlang::caller_env())
handle |
An |
request_id |
The |
call |
The calling environment, for error reporting. |
The request record: request_id, operation, status
("completed" or "failed"), http_status, timestamps, extensions
and the stored response.
Other control:
at_control_capabilities(),
at_control_close(),
at_control_command(),
at_control_connect(),
at_control_events(),
at_control_start(),
at_control_state(),
at_control_stop()
Start an annotatr-control-v1 service for a session so that a partner
process (for example qupflowR) can read state and events and send typed
commands. Nothing is started unless this function is called with
control = "loopback". The service binds only to 127.0.0.1, requires a
random 256-bit bearer token that expires after ttl_seconds, rejects
browser-origin requests, enforces JSON size and path limits, and resolves
file references only below root. There is no endpoint that evaluates code.
at_control_start( session, control = "loopback", host = "127.0.0.1", port = 0L, ttl_seconds = 900L, root = NULL, token_file = NULL, read_only = FALSE, max_body_bytes = 1048576L, serve = TRUE, call = rlang::caller_env() )at_control_start( session, control = "loopback", host = "127.0.0.1", port = 0L, ttl_seconds = 900L, root = NULL, token_file = NULL, read_only = FALSE, max_body_bytes = 1048576L, serve = TRUE, call = rlang::caller_env() )
session |
What to control: an annot_session (or anything
|
control |
Must be |
host |
Must be |
port |
Port; |
ttl_seconds |
Token lifetime in seconds (1 to 86400). |
root |
Directory for payload references, exports, training exports and
the lifecycle manifest; defaults to |
token_file |
Optional path of a new file to receive the token (for a client process). It must not exist yet. The token needs a cryptographically secure random source ( |
read_only |
Logical; refuse annotation mutations. |
max_body_bytes |
Maximum request body size. |
serve |
Logical; start the HTTP listener. With |
call |
The calling environment, for error reporting. |
The token is never written into URLs, logs, downloads, manifests or RDS
files. In-process calls use the returned handle; a separate client process
reads the token from token_file, which is created exclusively with
owner-only permissions (on Windows, file modes are not enforced; keep the
file in a directory only the user can read). A sanitised lifecycle manifest
annotatr-control-<instance_id>.json is written to root at start and
rewritten when the service stops. If startup fails, its listener, expiry
timer, registry entries and newly created token file are removed.
The service stops itself when the token expires: either when the expiry
timer runs or, if a request arrives first (for example after the computer
slept), on that request. Error messages sent to clients never contain
absolute local paths. Request bodies whose declared Content-Length
exceeds max_body_bytes, and requests that fail the Host, Origin or token
checks, are refused before the body is read (a chunked body without
Content-Length is buffered by httpuv and then refused).
Two options bound work done for clients: hyperannotatR.control_mask_max_pixels
(default 4096^2) is the largest mask mask.preview builds (without a
level it picks the finest pyramid level within the budget), and
hyperannotatR.control_hash_max_bytes (default 256 MiB) is the largest queue
entry whose content id GET /v1/state computes before the entry is visited
(larger entries report image_id: null until then).
An at_control_handle (a list with kind = "local", instance_id,
session_id, host, port, pid, manifest, expires_at); its print
method never shows the token.
at_control_stop(), at_control_command(), at_app()
Other control:
at_control_capabilities(),
at_control_close(),
at_control_command(),
at_control_connect(),
at_control_events(),
at_control_request_status(),
at_control_state(),
at_control_stop()
sess <- at_session(rep(at_example_path("cube"), 2)) h <- at_control_start(sess, serve = FALSE) at_control_state(h)$state_revision at_control_stop(h)sess <- at_session(rep(at_example_path("cube"), 2)) h <- at_control_start(sess, serve = FALSE) at_control_state(h)$state_revision at_control_stop(h)
Read the state of a control service
at_control_state(handle, call = rlang::caller_env())at_control_state(handle, call = rlang::caller_env())
handle |
An |
call |
The calling environment, for error reporting. |
The state snapshot (a list) with state_revision, event_cursor,
queue, current (image, layers, ROI summaries, annotation revision),
view, selection, staged, last_commit and status fields.
Other control:
at_control_capabilities(),
at_control_close(),
at_control_command(),
at_control_connect(),
at_control_events(),
at_control_request_status(),
at_control_start(),
at_control_stop()
Stop a service started by at_control_start() in this R process: close the
listener, invalidate its token and rewrite its lifecycle manifest as
stopped. A handle from another process (or a remote handle from
at_control_connect()) is refused with an at_auth_error (NOT_OWNER); no
process is ever terminated.
at_control_stop(handle, call = rlang::caller_env())at_control_stop(handle, call = rlang::caller_env())
handle |
An |
call |
The calling environment, for error reporting. |
TRUE invisibly when the service was stopped, FALSE if it had
already stopped.
Other control:
at_control_capabilities(),
at_control_close(),
at_control_command(),
at_control_connect(),
at_control_events(),
at_control_request_status(),
at_control_start(),
at_control_state()
The only supported ways to change value semantics. Raw counts become
reflectance through an explicit dark/white calibration, and reflectance
becomes (pseudo-)absorbance as -log10(reflectance). Anything else, or a
conversion without the calibration it needs, is refused with a classified
error instead of being approximated.
at_convert_values( x, from = NULL, to = c("reflectance", "absorbance"), calibration = NULL, call = rlang::caller_env() )at_convert_values( x, from = NULL, to = c("reflectance", "absorbance"), calibration = NULL, call = rlang::caller_env() )
x |
A numeric vector, matrix or |
from |
The unit of |
to |
Target unit: |
calibration |
For |
call |
The calling environment, for error reporting. |
x converted, with attribute value_unit set to to and
conversion recording the operation. Reflectance values <= 0 give NA
absorbance; a zero white-minus-dark denominator gives NA.
Other hsi:
at_band_operations(),
at_band_view(),
at_cubert_export_envi(),
at_hsi_meta(),
at_read_stats(),
at_tivita_profile()
at_convert_values(c(0.5, 0.1), from = "reflectance", to = "absorbance") at_convert_values(c(100, 550, 1000), from = "raw", to = "reflectance", calibration = list(white = 1000, dark = 100))at_convert_values(c(0.5, 0.1), from = "reflectance", to = "absorbance") at_convert_values(c(100, 550, 1000), from = "raw", to = "reflectance", calibration = list(white = 1000, dark = 100))
The portable fallback for Cubert data: the CUVIS SDK itself writes an ENVI
export, which hyperannotatR (and tools without the SDK) can then read through the
envi backend. Requires cuvis.r and a usable CUVIS SDK.
at_cubert_export_envi(path, dir, measurement = 1L, call = rlang::caller_env())at_cubert_export_envi(path, dir, measurement = 1L, call = rlang::caller_env())
path |
Path to a |
dir |
Output directory for the SDK's ENVI export (created if needed). |
measurement |
1-based measurement index within the session. |
call |
The calling environment, for error reporting. |
The files written into dir (character), invisibly.
Other backends:
at_backend_detect(),
at_backend_get(),
at_backend_list(),
at_backend_register(),
at_close_image(),
at_image_capabilities(),
at_read_image(),
at_tile(),
at_tivita_profile()
Other hsi:
at_band_operations(),
at_band_view(),
at_convert_values(),
at_hsi_meta(),
at_read_stats(),
at_tivita_profile()
## Not run: at_cubert_export_envi("measurement.cu3s", tempfile("envi-")) ## End(Not run)## Not run: at_cubert_export_envi("measurement.cu3s", tempfile("envi-")) ## End(Not run)
Return the project for the image at the cursor, materialising it from the
image (and applying the session's layer template) if it has not been visited.
A stored project whose pixel handle was not saved is reopened from its
recorded source (see at_inspect_source() when that is impossible).
at_current(session, call = rlang::caller_env())at_current(session, call = rlang::caller_env())
session |
An annot_session. |
call |
The calling environment, for error reporting. |
An annot_project.
Other sessions:
at_example_session(),
at_goto(),
at_manifest(),
at_next(),
at_prev(),
at_resume(),
at_session(),
at_session_status(),
at_set_status()
Return the pixel dimensions c(width, height) of an annot_image at a
given pyramid level.
at_dims(x, level = 0L, call = rlang::caller_env()) ## S3 method for class 'annot_image' dim(x)at_dims(x, level = 0L, call = rlang::caller_env()) ## S3 method for class 'annot_image' dim(x)
x |
An annot_image. |
level |
Integer pyramid level, |
call |
The calling environment, for error reporting. |
dim() on an annot_image returns c(width, height, bands) at
level 0. Note the order: width first, unlike the [y, x, band] arrays
returned by at_tile(), so nrow() gives the width.
An integer vector of length 2, c(width, height).
at_n_levels(), at_is_pyramidal()
Other images:
at_bands(),
at_close_image(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
# Image handles come from at_read_image(); see the images vignette.# Image handles come from at_read_image(); see the images vignette.
Read a bundled example image
at_example_image( which = c("tissue", "multiplex", "cube"), call = rlang::caller_env() )at_example_image( which = c("tissue", "multiplex", "cube"), call = rlang::caller_env() )
which |
One of |
call |
The calling environment, for error reporting. |
The tissue example is a PNG and needs magick; the multiplex example needs tiff; the cube needs nothing beyond hyperannotatR.
An annot_image.
Other example data:
at_example_path(),
at_example_project(),
at_example_session()
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
img <- at_example_image("cube") at_dims(img)img <- at_example_image("cube") at_dims(img)
Path to a bundled example file
at_example_path( which = c("tissue", "multiplex", "cube"), call = rlang::caller_env() )at_example_path( which = c("tissue", "multiplex", "cube"), call = rlang::caller_env() )
which |
One of |
call |
The calling environment, for error reporting. |
A single string file path to the example asset.
Other example data:
at_example_image(),
at_example_project(),
at_example_session()
at_example_path("tissue")at_example_path("tissue")
A populated example project
at_example_project(call = rlang::caller_env())at_example_project(call = rlang::caller_env())
call |
The calling environment, for error reporting. |
An annot_project over the tissue example with one layer of three labelled regions.
Other example data:
at_example_image(),
at_example_path(),
at_example_session()
Other projects:
at_add_layer(),
at_add_roi(),
at_layers(),
at_project(),
at_remove_layer(),
at_remove_roi(),
at_rois(),
at_summary(),
at_validate()
proj <- at_example_project() at_rois(proj)proj <- at_example_project() at_rois(proj)
Copies the tissue example into a temporary directory n times so the queue
has real files to iterate.
at_example_session(n = 5L, call = rlang::caller_env())at_example_session(n = 5L, call = rlang::caller_env())
n |
Number of images in the queue. Default |
call |
The calling environment, for error reporting. |
An annot_session.
Other example data:
at_example_image(),
at_example_path(),
at_example_project()
Other sessions:
at_current(),
at_goto(),
at_manifest(),
at_next(),
at_prev(),
at_resume(),
at_session(),
at_session_status(),
at_set_status()
sess <- at_example_session(3) at_session_status(sess)sess <- at_example_session(3) at_session_status(sess)
Export every selected image's annotations in the requested formats, isolating per-image failures so one bad image never aborts the run.
at_export_all( session, dir, formats = c("mask_tiff", "geojson", "qupath", "rds", "csv"), scope = c("complete", "all", "current", "flagged"), mask_type = c("labelled", "binary", "multiclass"), level = 0L, overwrite = FALSE, progress = TRUE, call = rlang::caller_env() )at_export_all( session, dir, formats = c("mask_tiff", "geojson", "qupath", "rds", "csv"), scope = c("complete", "all", "current", "flagged"), mask_type = c("labelled", "binary", "multiclass"), level = 0L, overwrite = FALSE, progress = TRUE, call = rlang::caller_env() )
session |
An annot_session. |
dir |
Output directory (created if needed). |
formats |
Any of |
scope |
|
mask_type |
Mask type for |
level |
Integer pyramid level. Default |
overwrite |
Logical; overwrite existing files. Default |
progress |
Logical; show a progress bar. Default |
call |
The calling environment, for error reporting. |
Derived filenames use safe portable components; display names stay
in the receipt and annotation metadata. Case-folded collisions are given
deterministic suffixes, including cross-format and sidecar collisions.
The complete plan (including manifests) rejects descendant symlinks before
writing outputs. Existing mask/legend bundles are skipped as a whole unless
overwrite=TRUE. Files are staged and publication failures roll back prior
files. Callers must serialize concurrent exports and avoid changing the
destination filesystem during a run: preflight and multiple renames are
not a race-free filesystem transaction. Receipt files are replaced each
run, independently of the item overwrite policy.
An invisible export-receipt tibble::tibble with columns entry_id,
image, format, path, bytes, n_rois, status, and message. Also
written to _export_manifest.csv alongside the exports. Additive columns
sidecar_path and sidecar_bytes describe mask legends. Byte counts are
doubles. Status is "ok" for a complete published bundle, "error" for a
failed item, or "skipped" when an existing bundle is protected. Every
image-format request has a row, even if loading the image fails. Receipt
publication or annotation-summary failures warn and are also retained in
receipt_error / summary_error attributes; the item receipt is returned.
at_write_masks(), at_manifest()
Other batch:
at_batch_apply(),
at_batch_check_geometry(),
at_summary_table()
sess <- at_example_session(2) dir <- file.path(tempdir(), "hyperannotatR-export") at_export_all(sess, dir, formats = "geojson", scope = "all", progress = FALSE)sess <- at_example_session(2) dir <- file.path(tempdir(), "hyperannotatR-export") at_export_all(sess, dir, formats = "geojson", scope = "all", progress = FALSE)
Write a new, self-contained handoff directory for a partner package such as
qupflowR. It contains only neutral, relative files: image.json,
annotations_qupath.geojson (QuPath 0.4+ dialect), optionally
annotations.geojson, one integer mask per layer under masks/ with a
.legend.json sidecar, optional tables/rois.csv, an optional
hyperannotatR-internal objects/project.rds, hsi_manifest.json for spectral
images, manifest.json (at_interop_manifest()) and integrity.json, the
SHA-256 inventory of every other file. The handoff digest is the SHA-256 of
the canonical integrity.json. Absolute paths are never used as identity.
at_export_qupflowr( x, destination, formats = c("qupath_geojson", "mask_tiff", "manifest"), overwrite = FALSE, level = 0L, mask_type = c("labelled", "multiclass", "binary"), scope = c("all", "current", "complete"), call = rlang::caller_env() )at_export_qupflowr( x, destination, formats = c("qupath_geojson", "mask_tiff", "manifest"), overwrite = FALSE, level = 0L, mask_type = c("labelled", "multiclass", "binary"), scope = c("all", "current", "complete"), call = rlang::caller_env() )
x |
An annot_project or annot_session (materialised entries are
exported under |
destination |
Path of the handoff directory to create. |
formats |
Any of |
overwrite |
Logical; replace an existing handoff directory. |
level |
Integer pyramid level for coordinates and masks. Default |
mask_type |
Mask type for mask files: |
scope |
For sessions: |
call |
The calling environment, for error reporting. |
Files are written into a hidden sibling staging directory and moved into
place only when complete, so a failed export never leaves a directory that
looks valid. An existing destination is replaced only with
overwrite = TRUE, and only when it is itself a handoff directory; if the
new directory cannot be moved into place the previous one is restored. The
optional objects/project.rds holds no pixels, read identity or local path
(the image source is reduced to its file name).
An at_handoff_receipt (invisibly): a list with destination,
handoff_digest, files (a tibble of path, size_bytes, sha256,
format, role, entry_id), manifest, skipped entries and
overwritten.
at_import_qupflowr(), at_interop_manifest()
Other interop:
at_annotation_revision(),
at_commit_qupflowr(),
at_import_qupflowr(),
at_interop_capabilities(),
at_interop_manifest(),
at_stage_qupflowr()
dest <- file.path(tempdir(), "handoff-example") rc <- at_export_qupflowr(at_example_project(), dest, overwrite = TRUE) rc$handoff_digest rc$files[, c("path", "format")]dest <- file.path(tempdir(), "handoff-example") rc <- at_export_qupflowr(at_example_project(), dest, overwrite = TRUE) rc$handoff_digest rc$files[, c("path", "format")]
Compute per-band summary statistics of image values inside each ROI. Reads
one tile covering each ROI's clipped bounding box; an image-sized bounding
box can allocate an image-sized tile. Polygon centre membership
and point containing cells follow the pixel-coverage contract in at_mask().
For example, point (5, 5) selects matrix row 6, column 6.
at_extract( project, img = NULL, stat = "mean", layer = NULL, label = NULL, level = 0L, bands = NULL, call = rlang::caller_env(), nonfinite = c("propagate", "omit", "error") )at_extract( project, img = NULL, stat = "mean", layer = NULL, label = NULL, level = 0L, bands = NULL, call = rlang::caller_env(), nonfinite = c("propagate", "omit", "error") )
project |
An annot_project. |
img |
An annot_image; defaults to the project's image. Supplying an alternate image asserts spatial registration on the same level-0 pixel grid. Its level-0 extent must match; differing pyramid dimensions are handled using the alternate image's actual level dimensions. |
stat |
One or more of |
layer, label
|
Optional filters. |
level |
Integer pyramid level. Default |
bands |
Optional band indices; all bands by default. |
call |
The calling environment, for error reporting. |
nonfinite |
Policy for NA, NaN and infinite samples: |
A long tibble::tibble with columns roi_id, layer, label,
band (integer), band_name, wavelength (NA when not spectral),
unit (declared wavelength unit, NA if unknown), stat, value, n_px
(selected support), n_valid (finite samples), and n_invalid.
Empty selections produce zero rows. Band order follows requested indices;
wavelength values and units are preserved, without implicit conversion.
The analysis attribute records policy, level, source, bands and limitations.
Values come directly from tiles, independently of display contrast. The
raster backend itself uses display conversion and cannot preserve original
high-bit-depth samples; raw TIFF/OME/ENVI readers have separate contracts.
at_extract_spectrum(), at_extract_pixels()
Other extraction:
at_extract_pixels(),
at_extract_spectrum()
proj <- at_example_project() at_extract(proj, stat = "mean")proj <- at_example_project() at_extract(proj, stat = "mean")
Extract per-pixel values under ROIs
at_extract_pixels( project, img = NULL, layer = NULL, level = 0L, bands = NULL, max_px = 1e+06, call = rlang::caller_env() )at_extract_pixels( project, img = NULL, layer = NULL, level = 0L, bands = NULL, max_px = 1e+06, call = rlang::caller_env() )
project |
An annot_project. |
img |
An annot_image; defaults to the project's image. Supplying an alternate image asserts spatial registration on the same level-0 pixel grid. Its level-0 extent must match; differing pyramid dimensions are handled using the alternate image's actual level dimensions. |
layer |
Optional layer filter. |
level |
Integer pyramid level. Default |
bands |
Optional band indices; all bands by default. |
max_px |
Maximum number of pixels to extract before aborting. Default
|
call |
The calling environment, for error reporting. |
A long tibble::tibble with columns roi_id, layer, label, x,
y, band, and value. A 0-row tibble with these columns when nothing
matches.
Other extraction:
at_extract(),
at_extract_spectrum()
Extract mean/median spectra for a spectral cube
at_extract_spectrum( project, img = NULL, stat = "mean", layer = NULL, label = NULL, level = 0L, call = rlang::caller_env(), nonfinite = c("propagate", "omit", "error") )at_extract_spectrum( project, img = NULL, stat = "mean", layer = NULL, label = NULL, level = 0L, call = rlang::caller_env(), nonfinite = c("propagate", "omit", "error") )
project |
An annot_project. |
img |
An annot_image; defaults to the project's image. Supplying an alternate image asserts spatial registration on the same level-0 pixel grid. Its level-0 extent must match; differing pyramid dimensions are handled using the alternate image's actual level dimensions. |
stat |
|
layer, label
|
Optional filters. |
level |
Integer pyramid level. Default |
call |
The calling environment, for error reporting. |
nonfinite |
Policy for NA, NaN and infinite samples: |
The long tibble of at_extract(), restricted to spectral bands and
sorted by ROI, declared unit, wavelength, then band index. Values are not
converted between units; equal wavelengths retain band order.
Other extraction:
at_extract(),
at_extract_pixels()
cube <- at_example_image("cube") proj <- at_project(cube, at_layer_add(at_layer("roi"), at_roi_circle(16, 16, 5, label = "roi"))) at_extract_spectrum(proj)cube <- at_example_image("cube") proj <- at_project(cube, at_layer_add(at_layer("roi"), at_roi_circle(16, 16, 5, label = "roi"))) at_extract_spectrum(proj)
Apply sf::st_make_valid() to invalid ROIs, drop duplicate consecutive
vertices, re-orient holes that wind like their exterior ring, and clip
out-of-bounds geometry to the image bounds (an intersection, so a polygon
stays a polygon), reporting what changed.
at_fix_geometry(project, verbose = TRUE, call = rlang::caller_env())at_fix_geometry(project, verbose = TRUE, call = rlang::caller_env())
project |
An annot_project. |
verbose |
Logical; whether to report repairs. Default |
call |
The calling environment, for error reporting. |
The annot_project with repaired geometry. Repairs are reported via
cli::cli_inform() when verbose is TRUE. Issues that cannot be repaired
(zero area, degenerate, empty, NA coordinates, or a clip that would
leave nothing inside the image) are left in place and reported.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
Convert between image orientation (top-left origin, y down) and GIS orientation (bottom-left origin, y up). Self-inverse.
at_flip_y(roi, height, call = rlang::caller_env())at_flip_y(roi, height, call = rlang::caller_env())
roi |
An annot_roi. |
height |
Numeric image height in pixels at the ROI's reference level. |
call |
The calling environment, for error reporting. |
An annot_roi with the y-axis flipped.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
at_flip_y(at_roi_rect(0, 0, 10, 5, label = "a"), height = 100)at_flip_y(at_roi_rect(0, 0, 10, 5, label = "a"), height = 100)
Jump to a specific image
at_goto(session, i, call = rlang::caller_env())at_goto(session, i, call = rlang::caller_env())
session |
An annot_session. |
i |
Integer image index (1-based) within the queue. |
call |
The calling environment, for error reporting. |
A new annot_session with the cursor at i.
Other sessions:
at_current(),
at_example_session(),
at_manifest(),
at_next(),
at_prev(),
at_resume(),
at_session(),
at_session_status(),
at_set_status()
Return the backend-agnostic metadata record hyperannotatR keeps for an image:
acquisition identity, storage layout, value semantics, geometry convention,
plane selection, and calibration/transform digests. Fields a backend cannot
establish are NA (never guessed), and wavelength_status in at_bands()
flags missing or duplicated wavelengths instead of interpolating them.
at_hsi_meta(x, call = rlang::caller_env())at_hsi_meta(x, call = rlang::caller_env())
x |
An annot_image. |
call |
The calling environment, for error reporting. |
A named list with the elements vendor, instrument,
acquisition_id, format, backend, image_kind ("spectral",
"multichannel", "rgb" or "grayscale"), width, height, n_bands,
n_levels, dtype, value_unit (one of "raw", "reflectance",
"radiance", "intensity", "absorbance", "unknown"), scale_factor,
offset, nodata, valid_range, interleave, byte_order,
header_bytes, axis_order, pixel_size, pixel_unit, origin,
y_direction, series_id, plane (list of zero-based c, z, t),
wavelength_unit, calibration, calibration_digest, transform_digest,
profile, window_read and pan_sharpened.
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Other hsi:
at_band_operations(),
at_band_view(),
at_convert_values(),
at_cubert_export_envi(),
at_read_stats(),
at_tivita_profile()
at_hsi_meta(at_example_image("cube"))[c("image_kind", "value_unit", "interleave")]at_hsi_meta(at_example_image("cube"))[c("image_kind", "value_unit", "interleave")]
Report how an image's pixels are read: whether opening it reads metadata only, whether tiles are read as windows from the file, what the samples mean, and where they come from.
at_image_capabilities(x)at_image_capabilities(x)
x |
An annot_image or annot_project. |
A list with metadata_only and window_read (logical; NA when a
third-party backend does not declare them), samples ("raw-scalar-v1"
for stored values, "display-converted-0-255" for display conversions,
"unqualified" when undeclared) and io ("binary", "native",
"eager", "memory" or "unknown"), plus an optional lifecycle. An
image whose handle holds decoded pixels reports memory access even for a
backend that normally reads windows.
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Other backends:
at_backend_detect(),
at_backend_get(),
at_backend_list(),
at_backend_register(),
at_close_image(),
at_cubert_export_envi(),
at_read_image(),
at_tile(),
at_tivita_profile()
at_image_capabilities(at_example_image("cube"))$window_readat_image_capabilities(at_example_image("cube"))$window_read
Read only the neutral contract, validate it, and return a namespaced
hyperannotatR result together with a conversion report. For a handoff directory
the SHA-256 inventory (missing, extra, duplicate, resized, altered or
symlinked files), the manifest schema and major version, ROI id uniqueness
and the id join between manifest and GeoJSON, layers, planes, mask
dimensions, integer values and legend completeness are all checked. Every
file the manifest references must be a clean relative path listed in the
verified inventory; unlisted operating-system metadata files (.DS_Store,
._*, Thumbs.db, desktop.ini) are ignored with a warning. Any failure
aborts with a classified at_error: at_validation_error for integrity,
schema and join failures, at_protocol_error for an unsupported major
version, at_limit_error for oversized inventories and at_io_error for
missing files. Nothing is written, no analysis is started, and foreign
objects are never returned as if they were hyperannotatR objects: imported ROIs
carry source = "imported" and partner fields under
attributes$qupflowr. Features of a single GeoJSON file that carry no id
get a minted one and are flagged (attributes$qupflowr$id_minted), so
at_stage_qupflowr() creates them instead of joining them to an existing
ROI; two features with the same id are refused (DUPLICATE_ID). Handoff
coordinates are read at the export level recorded in the manifest. An RDS
file is refused, because deserialising it is not a neutral read.
at_import_qupflowr( file, format = c("auto", "handoff", "qupath_geojson", "geojson", "mask", "npy"), expected_revision = NULL, call = rlang::caller_env() )at_import_qupflowr( file, format = c("auto", "handoff", "qupath_geojson", "geojson", "mask", "npy"), expected_revision = NULL, call = rlang::caller_env() )
file |
A handoff directory (or its |
format |
|
expected_revision |
Optional |
call |
The calling environment, for error reporting. |
An at_import_report: a list with status, format,
source_name, handoff_digest, manifest, checks (tibble of check,
status, detail), objects (layers: named list of annot_layer;
masks: named list of annot_mask; images: image records), conversion
(tibble with one row per ROI: roi_id, layer, label,
source_object_id, object_type, geometry_fidelity, geometry_match
("exact" bytes, "equivalent" within 1e-9 after level normalisation,
"changed", or NA without a manifest record), notes) and
annotation_revision of the imported layers.
at_export_qupflowr(), at_stage_qupflowr()
Other interop:
at_annotation_revision(),
at_commit_qupflowr(),
at_export_qupflowr(),
at_interop_capabilities(),
at_interop_manifest(),
at_stage_qupflowr()
dest <- file.path(tempdir(), "handoff-import-example") at_export_qupflowr(at_example_project(), dest, overwrite = TRUE) rep <- at_import_qupflowr(dest) rep$checksdest <- file.path(tempdir(), "handoff-import-example") at_export_qupflowr(at_example_project(), dest, overwrite = TRUE) rep <- at_import_qupflowr(dest) rep$checks
Validate a saved project or session file and report the state of its image sources, without repairing anything or reading pixels.
at_inspect_saved(path)at_inspect_saved(path)
path |
A saved project or session RDS file. |
A list with valid (logical), class (the saved object's class),
issues (character; why the file is invalid or ambiguous) and sources
(one at_inspect_source() report per stored project). Invalid or
ambiguous structures are reported without guessing repairs.
at_inspect_source(), at_load_session()
Other io:
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Report whether the file an image (or project) was read from is still available and unchanged, so a saved project can be reopened or relinked deliberately.
at_inspect_source(x)at_inspect_source(x)
x |
An annot_image or annot_project. |
A list with status, path, backend, options (the recorded
reader options) and options_inferred (TRUE for a legacy image whose
options were not recorded). status is "available", "missing",
"changed", "in_memory" (pixels held in memory, no source file) or
"unresolved". Size and modification time detect many source
replacements, but are not a content checksum. Composite sources also
validate every declared companion input, such as an ENVI header and
payload.
at_relink_source(), at_inspect_saved()
Other io:
at_inspect_saved(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Report what this hyperannotatR installation can exchange with a partner package
such as qupflowR, and how far each capability has been qualified. Profiles
follow the partner contract: I0 file interchange, I1 public R API, I2 the
local control service (annotatr-control-v1) and I3 the embeddable app
object from at_app(). A profile is "supported" only with implementation,
runtime dependencies and qualification evidence; implemented profiles that
have not passed their tests against a real partner client are "planned";
profiles whose optional runtime is missing are "unavailable". Every entry
carries a reason when it is not supported.
at_interop_capabilities( target = c("package", "hsi", "app", "control"), call = rlang::caller_env() )at_interop_capabilities( target = c("package", "hsi", "app", "control"), call = rlang::caller_env() )
target |
One or more of |
call |
The calling environment, for error reporting. |
A list of class at_capabilities with schema, schema_version,
annotatr_version, r_version, source_revision, consumer, profiles
(I0-I3), limits, and the requested sections package, hsi, app,
control, plus digest: the SHA-256 of the canonical JSON of the report
without digest itself.
at_interop_manifest(), at_control_capabilities()
Other interop:
at_annotation_revision(),
at_commit_qupflowr(),
at_export_qupflowr(),
at_import_qupflowr(),
at_interop_manifest(),
at_stage_qupflowr()
caps <- at_interop_capabilities() caps$profiles$I0$status caps$digestcaps <- at_interop_capabilities() caps$profiles$I0$status caps$digest
Describe hyperannotatR objects for a partner such as qupflowR without exposing
local paths: images are identified by content hash (image_id) and file
basename; annotations by string ROI ids and an at_annotation_revision();
masks by type, integer dtype, background, dimensions, level and legend. The
coordinate convention, band/wavelength table, HSI value semantics, plane,
calibration and transform digests are recorded explicitly. QuPath hierarchy
and native ROI shapes, which hyperannotatR does not model, are reported as
"unknown" or "approximated", never invented.
at_interop_manifest( x, destination = NULL, hash_sources = TRUE, call = rlang::caller_env() )at_interop_manifest( x, destination = NULL, hash_sources = TRUE, call = rlang::caller_env() )
x |
An annot_project, annot_session, annot_image, annot_layer,
annot_roi or |
destination |
Optional path: an existing directory (the manifest is
written as |
hash_sources |
Logical; hash image source files (needed for a
content-derived |
call |
The calling environment, for error reporting. In a session manifest every ROI and layer record carries the |
The manifest (a list of class at_interop_manifest); invisibly when
destination is given.
at_export_qupflowr(), at_interop_capabilities()
Other interop:
at_annotation_revision(),
at_commit_qupflowr(),
at_export_qupflowr(),
at_import_qupflowr(),
at_interop_capabilities(),
at_stage_qupflowr()
m <- at_interop_manifest(at_example_project()) m$annotations$annotation_revision m$images[[1]]$image_idm <- at_interop_manifest(at_example_project()) m$annotations$annotation_revision m$images[[1]]$image_id
Is the image pyramidal?
at_is_pyramidal(x, call = rlang::caller_env())at_is_pyramidal(x, call = rlang::caller_env())
x |
An annot_image. |
call |
The calling environment, for error reporting. |
A logical scalar. TRUE when more than one pyramid level exists.
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Is the image a spectral cube?
at_is_spectral(x, call = rlang::caller_env())at_is_spectral(x, call = rlang::caller_env())
x |
An annot_image. |
call |
The calling environment, for error reporting. |
A logical scalar. TRUE when the image carries per-band wavelengths.
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Create a layer
at_layer( name, labels = character(), style = at_style(), ..., call = rlang::caller_env() )at_layer( name, labels = character(), style = at_style(), ..., call = rlang::caller_env() )
name |
Single string layer name (unique within a project). |
labels |
Character vector; the controlled label vocabulary for the layer. |
style |
An |
... |
Additional named metadata stored on the layer.
Set |
call |
The calling environment, for error reporting. |
An annot_layer with no ROIs and a resolved colour mapping.
Other layers:
at_layer_add(),
at_layer_n(),
at_layer_remove(),
at_layer_rois(),
at_style()
lyr <- at_layer("tumour", labels = c("tumour", "stroma")) at_layer_n(lyr)lyr <- at_layer("tumour", labels = c("tumour", "stroma")) at_layer_n(lyr)
Add an ROI to a layer
at_layer_add(layer, roi, call = rlang::caller_env())at_layer_add(layer, roi, call = rlang::caller_env())
layer |
An annot_layer. |
roi |
An annot_roi. |
call |
The calling environment, for error reporting. |
A new annot_layer with the ROI appended. The label vocabulary and
colour mapping are extended if the ROI introduces a new label (following
the colour specification given to at_layer()). A missing, empty or
colliding ROI identifier is re-minted to one unused in the layer. The
input is unchanged.
Other layers:
at_layer(),
at_layer_n(),
at_layer_remove(),
at_layer_rois(),
at_style()
lyr <- at_layer("tumour", labels = "tumour") lyr <- at_layer_add(lyr, at_roi_rect(0, 0, 10, 10, label = "tumour")) at_layer_n(lyr)lyr <- at_layer("tumour", labels = "tumour") lyr <- at_layer_add(lyr, at_roi_rect(0, 0, 10, 10, label = "tumour")) at_layer_n(lyr)
Number of ROIs in a layer
at_layer_n(layer, call = rlang::caller_env())at_layer_n(layer, call = rlang::caller_env())
layer |
An annot_layer. |
call |
The calling environment, for error reporting. |
An integer scalar.
Other layers:
at_layer(),
at_layer_add(),
at_layer_remove(),
at_layer_rois(),
at_style()
Remove an ROI from a layer
at_layer_remove(layer, id, call = rlang::caller_env())at_layer_remove(layer, id, call = rlang::caller_env())
layer |
An annot_layer. |
id |
Single string ROI identifier. |
call |
The calling environment, for error reporting. |
A new annot_layer without the identified ROI. Warns if the ROI is not present and returns the layer unchanged.
Other layers:
at_layer(),
at_layer_add(),
at_layer_n(),
at_layer_rois(),
at_style()
Layer ROI table
at_layer_rois(layer, image = NULL, call = rlang::caller_env())at_layer_rois(layer, image = NULL, call = rlang::caller_env())
layer |
An annot_layer. |
image |
annot_image defining actual pyramid dimensions. Required when any ROI is stored at a nonzero level; no scale is inferred without it. |
call |
The calling environment, for error reporting. |
An ROI table (see at_rois() for the column contract). A 0-row table
with the same columns when the layer has no ROIs.
Other layers:
at_layer(),
at_layer_add(),
at_layer_n(),
at_layer_remove(),
at_style()
Layer summary table
at_layers(project, call = rlang::caller_env())at_layers(project, call = rlang::caller_env())
project |
An annot_project. |
call |
The calling environment, for error reporting. |
A tibble::tibble with one row per layer and the columns name
(character), n_rois (integer), labels (list of character), visible
(logical), locked (logical), and z (integer). A 0-row tibble with these
columns when the project has no layers.
Other projects:
at_add_layer(),
at_add_roi(),
at_example_project(),
at_project(),
at_remove_layer(),
at_remove_roi(),
at_rois(),
at_summary(),
at_validate()
Load a project
at_load_project(path, call = rlang::caller_env())at_load_project(path, call = rlang::caller_env())
path |
Path to a saved project |
call |
The calling environment, for error reporting. |
The annot_project. Its image is reopened from the saved source
descriptor; when the source is missing, changed or ambiguous the
annotations still load, pixel access fails with a pointer to
at_relink_source(), and at_inspect_source() reports why. Warns if the
file was written by a newer hyperannotatR.
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Load a session
at_load_session(path, call = rlang::caller_env())at_load_session(path, call = rlang::caller_env())
path |
Path to a saved session |
call |
The calling environment, for error reporting. |
The annot_session. A file written before sessions recorded queue
entry identities gets one per queue row. Stored projects are reopened
lazily by at_current(). Warns if written by a newer hyperannotatR.
at_save_session(), at_resume()
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Session progress manifest with per-label counts
at_manifest(session, call = rlang::caller_env())at_manifest(session, call = rlang::caller_env())
session |
An annot_session. |
call |
The calling environment, for error reporting. |
A tibble::tibble with idx, entry_id, export_stem, name,
path, status, n_layers, n_rois, and one integer column per label in
the session vocabulary giving its ROI count per image. n_rois counts the
ROIs of materialised projects (otherwise the manifest's stored count). A
label that clashes with one of the fixed column names gets a label_
prefix.
Other sessions:
at_current(),
at_example_session(),
at_goto(),
at_next(),
at_prev(),
at_resume(),
at_session(),
at_session_status(),
at_set_status()
Produce a binary, labelled, or multi-class integer mask from annotations. This is the package's core output artifact.
at_mask( x, type = c("binary", "labelled", "multiclass"), layer = NULL, label = NULL, level = 0L, background = 0L, touches = FALSE, dims = NULL, values = NULL, overlap = c("last", "first", "max", "min", "error", "bitor"), engine = c("stars", "terra"), call = rlang::caller_env(), image = NULL )at_mask( x, type = c("binary", "labelled", "multiclass"), layer = NULL, label = NULL, level = 0L, background = 0L, touches = FALSE, dims = NULL, values = NULL, overlap = c("last", "first", "max", "min", "error", "bitor"), engine = c("stars", "terra"), call = rlang::caller_env(), image = NULL )
x |
An annot_roi, annot_layer, or annot_project. |
type |
|
layer |
Optional layer name(s) to restrict to (projects only). Unknown names are an error. |
label |
Optional label(s) to restrict to. |
level |
Integer pyramid level at which to rasterise. Default |
background |
Integer background value. Default |
touches |
Logical; see the coverage contract. Default |
dims |
Optional |
values |
Optional named integer vector mapping labels to explicit class
codes (e.g. |
overlap |
How overlapping ROIs resolve: |
engine |
|
call |
The calling environment, for error reporting. |
image |
Optional annot_image for standalone ROIs or layers. Required
when changing coordinate levels; dimensions alone do not define a scale.
Projects always use their own image. Without |
Pixel-coverage contract. Pixel (i, j) covers the half-open square
[j-1, j) x [i-1, i) with (0, 0) at the top-left corner of the top-left
pixel; its centre is (j - 0.5, i - 0.5). With touches = FALSE (default) a
pixel is included when its centre lies inside the polygon. Boundary ties use
the symbolic sample (x + epsilon, y + epsilon^2) as epsilon tends to zero
from above, without a finite coordinate shift. Equivalently, scanline edges
are active on [minY, maxY) and crossing pairs fill [left, right).
Hole rings exclude pixels by parity regardless of winding; MULTIPOLYGON
components combine by union. Thin polygons containing no selected centres
have empty masks. This rule is shared by both engines and all overlap paths.
POINT and MULTIPOINT geometries select their half-open containing cells:
(5, 5) selects row 6, column 6. Extraction uses the same membership and
bounds. With touches = TRUE, polygon coverage uses the selected engine's
all-touched rasterisation; lines and other geometry types also retain the
selected engine's rasterisation behavior. Engine equality is guaranteed for
centre-based polygons and points. ROI coordinates use the image convention
(top-left origin, y down).
Full-grid allocation is checked against
getOption("hyperannotatR.max_read_bytes", 1024^3) before rasterisation,
using a conservative estimate of 32 bytes per pixel for arrays and working
copies. The default allows 33,554,432 pixels. This is not a bound on total
process memory or geometry/native-library overhead. Trusted larger masks
require raising that option; over-budget requests fail with
READ_BUDGET_EXCEEDED, and unsupported array sizes with MASK_TOO_LARGE.
An annot_mask: a matrix (logical for "binary", otherwise integer)
with attributes legend (a tibble with columns value, label, layer,
roi_id, n_px, colour), level, dims, mask_type,
source_project, mask_metadata and created. An all-background mask of
the correct dimensions is returned when there are no ROIs. The mask_metadata attribute has schema version 1 and records
encoding (binary, instance, categorical, or bitfield), background,
overlap policy, grid (dimensions, level, origin, stride), source descriptor
and entry provenance, and the complete label codebook. Supplied values
retain mapped-but-absent classes with zero counts. Bitfields require unique
positive single-bit codes and zero background; category 3 is exclusive
unless bitfield encoding is explicitly declared.
at_write_mask(), at_read_mask(), at_mask_stats()
Other masks:
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
proj <- at_example_project() m <- at_mask(proj, type = "multiclass") table(as.integer(m))proj <- at_example_project() m <- at_mask(proj, type = "multiclass") table(as.integer(m))
Per-class Dice and Jaccard (IoU) plus an overall accuracy and Cohen's kappa,
comparing a reference mask a against a second mask b (e.g. a hyperannotatR
mask against a .npy ground truth, or two annotators). Versioned metadata,
grids, source provenance, encodings and semantic codebooks are validated.
Plain matrices are explicit-code legacy categorical inputs and require finite
representable integer values; missing values are rejected.
at_mask_agreement( a, b, background = 0L, labels = NULL, call = rlang::caller_env(), alignment = c("check", "assert"), code_alignment = c("strict", "by-label", "by-id") )at_mask_agreement( a, b, background = 0L, labels = NULL, call = rlang::caller_env(), alignment = c("check", "assert"), code_alignment = c("strict", "by-label", "by-id") )
a |
Reference |
b |
Comparison |
background |
Integer value treated as unlabeled/background and excluded
from the per-class rows (still counted for overall accuracy/kappa).
Defaults to declared metadata background, or |
labels |
Optional named vector or legend tibble ( |
call |
The calling environment, for error reporting. |
alignment |
|
code_alignment |
|
Categorical/binary classes use equality; bitfields use class memberships, with overall accuracy measuring exact membership-set agreement and kappa NA. Instance maps use stable unique ROI IDs, never display class names. No spatial instance matching is inferred. Absent classes retain rows with NA Dice/IoU; background-only accuracy is 1 and kappa is NA (zero Cohen denominator). Mean Dice/IoU exclude absent classes and are NA if none are defined.
A tibble::tibble with one row per class: value, label,
n_true, n_pred, tp, fp, fn, dice, iou. The overall
attribute is a list of accuracy, kappa, mean_dice, mean_iou, and
n_px, encoding, alignment, code_alignment, background and
nonfinite (always "error"). A comparison attribute retains validated
input metadata and legends for interpretation.
Other masks:
at_mask(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
m <- at_mask(at_example_project(), "multiclass") ag <- at_mask_agreement(m, m) attr(ag, "overall")$kappam <- at_mask(at_example_project(), "multiclass") ag <- at_mask_agreement(m, m) attr(ag, "overall")$kappa
Object boundaries of a mask
at_mask_boundary(mask, width = 1L, call = rlang::caller_env())at_mask_boundary(mask, width = 1L, call = rlang::caller_env())
mask |
An |
width |
Integer boundary thickness in pixels. Default |
call |
The calling environment, for error reporting. |
A logical matrix marking boundary pixels (where a 4-neighbour has a different value).
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
Keep foreground state codes inside the requested anatomy class and outside artefacts, using each mask's declared background and class membership. An anatomy bitfield includes composite samples containing the requested bit.
at_mask_derive( state, anatomy, artefact = NULL, keep_label = "wound", background = NULL, call = rlang::caller_env(), alignment = c("legacy", "assert") )at_mask_derive( state, anatomy, artefact = NULL, keep_label = "wound", background = NULL, call = rlang::caller_env(), alignment = c("legacy", "assert") )
state |
An |
anatomy |
An |
artefact |
Optional |
keep_label |
The anatomy label whose region is kept (e.g. |
background |
Output background value. |
call |
The calling environment, for error reporting. |
alignment |
|
An annot_mask retaining state encoding and the full state codebook,
with counts recomputed, zero counts for absent classes, and alignment
provenance recorded in mask_metadata$derivation.
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
proj <- at_example_project() # A single-layer project derives trivially; the four-layer HSI workflow passes # separate anatomy/state/artefact masks. See the masks vignette. m <- at_mask(proj, "multiclass") at_mask_derive(m, m, keep_label = at_mask_legend(m)$label[1])proj <- at_example_project() # A single-layer project derives trivially; the four-layer HSI workflow passes # separate anatomy/state/artefact masks. See the masks vignette. m <- at_mask(proj, "multiclass") at_mask_derive(m, m, keep_label = at_mask_legend(m)$label[1])
Legend of a mask
at_mask_legend(mask, call = rlang::caller_env())at_mask_legend(mask, call = rlang::caller_env())
mask |
An |
call |
The calling environment, for error reporting. |
The mask's legend tibble::tibble (value, label, layer,
roi_id, n_px, colour).
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
at_mask_legend(at_mask(at_example_project(), "labelled"))at_mask_legend(at_mask(at_example_project(), "labelled"))
Nearest-neighbour downsample only (interpolating a label mask would invent labels that do not exist).
at_mask_preview(mask, max_dim = 1024L, call = rlang::caller_env())at_mask_preview(mask, max_dim = 1024L, call = rlang::caller_env())
mask |
An |
max_dim |
Integer maximum dimension of the preview. Default |
call |
The calling environment, for error reporting. |
A downsampled annot_mask with membership-aware counts recomputed.
Metadata records the preview dimensions and sampling stride, its parent
grid, and the original source provenance. No full-resolution counts are
copied onto the sampled matrix.
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
Stack per-layer masks into a 3D array
at_mask_stack(project, layers = NULL, level = 0L, call = rlang::caller_env())at_mask_stack(project, layers = NULL, level = 0L, call = rlang::caller_env())
project |
An annot_project. |
layers |
Optional layer name(s) to include; all by default. Unknown names are an error. |
level |
Integer pyramid level. Default |
call |
The calling environment, for error reporting. |
A 3D integer array [y, x, layer], one multi-class plane per layer;
the third dimension is named by layer. Codes are local to each layer; the
legends attribute is a named list of the per-layer legends (see
at_mask_legend()) that maps them back to labels.
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
Per-value statistics of a mask
at_mask_stats(mask, pixel_size = NULL, call = rlang::caller_env())at_mask_stats(mask, pixel_size = NULL, call = rlang::caller_env())
mask |
An |
pixel_size |
Optional positive physical pixel size |
call |
The calling environment, for error reporting. |
A tibble::tibble with one row per mask value: value, label,
n_px, area_px, area_physical, frac_total, bounding box
(bbox_xmin, bbox_ymin, bbox_xmax, bbox_ymax), and centroid
(centroid_x, centroid_y). Every bitfield membership contributes to its
class count, including composite samples; categorical counts are exclusive.
Mapped-but-absent classes have zero counts. A 0-row tibble is returned only
when the codebook is empty.
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
at_mask_stats(at_mask(at_example_project(), "labelled"))at_mask_stats(at_mask(at_example_project(), "labelled"))
Image metadata
at_meta(x, key = NULL, call = rlang::caller_env())at_meta(x, key = NULL, call = rlang::caller_env())
x |
An annot_image. |
key |
Optional single string. When supplied, the corresponding metadata element is returned; otherwise the whole metadata list is returned. |
call |
The calling environment, for error reporting. |
When key is NULL, a list of all metadata (including source,
backend, dtype, pixel_unit, and any backend-specific entries). When
key is supplied, the single element (or NULL if absent).
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Number of bands (channels)
at_n_bands(x, call = rlang::caller_env())at_n_bands(x, call = rlang::caller_env())
x |
An annot_image. |
call |
The calling environment, for error reporting. |
An integer scalar.
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Number of pyramid levels
at_n_levels(x, call = rlang::caller_env())at_n_levels(x, call = rlang::caller_env())
x |
An annot_image. |
call |
The calling environment, for error reporting. |
An integer scalar; 1 when the image has no pyramid.
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Advance to the next image
at_next(session, call = rlang::caller_env())at_next(session, call = rlang::caller_env())
session |
An annot_session. |
call |
The calling environment, for error reporting. |
A new annot_session with the cursor advanced (clamped at the end).
Other sessions:
at_current(),
at_example_session(),
at_goto(),
at_manifest(),
at_prev(),
at_resume(),
at_session(),
at_session_status(),
at_set_status()
Physical pixel size
at_pixel_size(x, call = rlang::caller_env())at_pixel_size(x, call = rlang::caller_env())
x |
An annot_image. |
call |
The calling environment, for error reporting. |
A numeric vector of length 2, the physical size of one level-0 pixel
as c(x, y), in the units given by at_meta(x, "pixel_unit").
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_read_image(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Plot generic for hyperannotatR objects
at_plot(x, ...)at_plot(x, ...)
x |
An annot_image, annot_project, annot_layer, or |
... |
Passed to the specific plot function. For layers, passed to
|
A ggplot2::ggplot object.
Other plots:
at_plot_image(),
at_plot_mask(),
at_plot_overlay(),
at_plot_project(),
at_plot_spectrum(),
at_plot_summary()
at_plot(at_example_project())at_plot(at_example_project())
Plot an image
at_plot_image( img, level = NULL, bands = NULL, rgb = NULL, max_dim = 1024L, call = rlang::caller_env() )at_plot_image( img, level = NULL, bands = NULL, rgb = NULL, max_dim = 1024L, call = rlang::caller_env() )
img |
An annot_image. |
level |
Pyramid level to sample; chosen automatically when |
bands |
Optional band index for single-band display. |
rgb |
Optional length-3 vector of band indices, or wavelengths in nm for
a spectral cube, for a false-colour composite. Each channel of an |
max_dim |
Maximum display dimension (auto-downsampled). Default |
call |
The calling environment, for error reporting. |
A ggplot2::ggplot object. Non-finite samples are drawn transparent.
Other plots:
at_plot(),
at_plot_mask(),
at_plot_overlay(),
at_plot_project(),
at_plot_spectrum(),
at_plot_summary()
at_plot_image(at_example_image("tissue"))at_plot_image(at_example_image("tissue"))
Plot a mask
at_plot_mask(mask, legend = TRUE, call = rlang::caller_env())at_plot_mask(mask, legend = TRUE, call = rlang::caller_env())
mask |
An |
legend |
Logical; show the fill legend. Default |
call |
The calling environment, for error reporting. |
A ggplot2::ggplot object.
Other plots:
at_plot(),
at_plot_image(),
at_plot_overlay(),
at_plot_project(),
at_plot_spectrum(),
at_plot_summary()
at_plot_mask(at_mask(at_example_project(), "labelled"))at_plot_mask(at_mask(at_example_project(), "labelled"))
Plot ROIs overlaid on the image
at_plot_overlay(project, img = NULL, layer = NULL, call = rlang::caller_env())at_plot_overlay(project, img = NULL, layer = NULL, call = rlang::caller_env())
project |
An annot_project. |
img |
An annot_image; the project's image by default. |
layer |
Optional layer filter. |
call |
The calling environment, for error reporting. |
A ggplot2::ggplot object with the image and ROI outlines (points as markers), both in level-0 image coordinates.
Other plots:
at_plot(),
at_plot_image(),
at_plot_mask(),
at_plot_project(),
at_plot_spectrum(),
at_plot_summary()
at_plot_overlay(at_example_project())at_plot_overlay(at_example_project())
Plot a project's ROIs
at_plot_project( project, layer = NULL, label = NULL, show_labels = TRUE, alpha = NULL, call = rlang::caller_env() )at_plot_project( project, layer = NULL, label = NULL, show_labels = TRUE, alpha = NULL, call = rlang::caller_env() )
project |
An annot_project. |
layer, label
|
Optional filters. |
show_labels |
Logical; draw label text at centroids. Default |
alpha |
Fill opacity; a sensible default when |
call |
The calling environment, for error reporting. |
A ggplot2::ggplot object in level-0 image coordinates with the y axis pointing down, as in the image. Empty projects give a valid empty plot.
Other plots:
at_plot(),
at_plot_image(),
at_plot_mask(),
at_plot_overlay(),
at_plot_spectrum(),
at_plot_summary()
at_plot_project(at_example_project())at_plot_project(at_example_project())
Plot spectra
at_plot_spectrum( spectra, colour_by = c("label", "roi_id", "layer"), ribbon = TRUE, call = rlang::caller_env() )at_plot_spectrum( spectra, colour_by = c("label", "roi_id", "layer"), ribbon = TRUE, call = rlang::caller_env() )
spectra |
The long tibble from |
colour_by |
One of |
ribbon |
Logical; draw a min-max ribbon per colour group (and
statistic) wherever the group holds more than one ROI. Default |
call |
The calling environment, for error reporting. |
A ggplot2::ggplot object with one line per ROI and statistic.
Other plots:
at_plot(),
at_plot_image(),
at_plot_mask(),
at_plot_overlay(),
at_plot_project(),
at_plot_summary()
Plot a project summary
at_plot_summary(project, call = rlang::caller_env())at_plot_summary(project, call = rlang::caller_env())
project |
An annot_project. |
call |
The calling environment, for error reporting. |
A ggplot2::ggplot object of per-label ROI area distributions.
Other plots:
at_plot(),
at_plot_image(),
at_plot_mask(),
at_plot_overlay(),
at_plot_project(),
at_plot_spectrum()
Step back to the previous image
at_prev(session, call = rlang::caller_env())at_prev(session, call = rlang::caller_env())
session |
An annot_session. |
call |
The calling environment, for error reporting. |
A new annot_session with the cursor decremented (clamped at 1).
Other sessions:
at_current(),
at_example_session(),
at_goto(),
at_manifest(),
at_next(),
at_resume(),
at_session(),
at_session_status(),
at_set_status()
Create an annotation project
at_project(image, layers = list(), ..., call = rlang::caller_env())at_project(image, layers = list(), ..., call = rlang::caller_env())
image |
An annot_image the annotations refer to. |
layers |
An annot_layer, a list of them, or an empty list (default). |
... |
Additional named project metadata (e.g. |
call |
The calling environment, for error reporting. |
An annot_project bundling the image, layers, metadata, and
provenance (creation time, hyperannotatR version, R version, author, and an
edit log).
at_add_layer(), at_add_roi(), at_rois(), at_mask()
Other projects:
at_add_layer(),
at_add_roi(),
at_example_project(),
at_layers(),
at_remove_layer(),
at_remove_roi(),
at_rois(),
at_summary(),
at_validate()
# An annot_image comes from at_read_image() or at_example_image(): # proj <- at_project(at_example_image("tissue"), # at_layer("tissue", labels = "tissue"))# An annot_image comes from at_read_image() or at_example_image(): # proj <- at_project(at_example_image("tissue"), # at_layer("tissue", labels = "tissue"))
Read ROIs from a GeoJSON file
at_read_geojson( path, layer_name = NULL, level = 0L, flip_y = FALSE, height = NULL, call = rlang::caller_env(), coordinate_level = NULL, legacy_levels = c("error", "recorded") )at_read_geojson( path, layer_name = NULL, level = 0L, flip_y = FALSE, height = NULL, call = rlang::caller_env(), coordinate_level = NULL, legacy_levels = c("error", "recorded") )
path |
Path to a GeoJSON file. |
layer_name |
Layer name for the imported ROIs; taken from the features'
|
level |
Integer level to record when a feature has no |
flip_y |
Logical; invert the y-axis on read. Default |
height |
Image height in pixels, required when |
call |
The calling environment, for error reporting. |
coordinate_level |
Optional integer overriding every recorded |
legacy_levels |
How to interpret files without the coordinate schema
marker: |
A FeatureCollection, a single Feature or a bare array of features
is accepted. Features without a geometry ("geometry": null) carry no
region and are skipped with a warning; any other document is refused with
an at_validation_error of code INVALID_GEOJSON.
A named list of annot_layer objects (one per distinct layer
property), or a single annot_layer when layer_name is supplied.
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Read an image into a lightweight annot_image handle, auto-detecting the backend from the file unless one is named.
at_read_image(path, backend = NULL, ..., call = rlang::caller_env())at_read_image(path, backend = NULL, ..., call = rlang::caller_env())
path |
Single string path to an image file. |
backend |
Optional backend name; auto-detected when |
... |
Passed to the backend's reader. They must be plain serializable values (numbers, strings, logicals and lists of them): they are recorded in the image's source descriptor so a saved project can reopen the file the same way. |
call |
The calling environment, for error reporting. |
An annot_image whose source is the absolute path of the file,
with a source_descriptor (path, backend, options, file signature) and a
per-read cache identity.
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_tile(),
at_wavelengths(),
hyperannotatR-classes
Other backends:
at_backend_detect(),
at_backend_get(),
at_backend_list(),
at_backend_register(),
at_close_image(),
at_cubert_export_envi(),
at_image_capabilities(),
at_tile(),
at_tivita_profile()
img <- at_read_image(at_example_path("tissue")) at_dims(img)img <- at_read_image(at_example_path("tissue")) at_dims(img)
Polygonise an existing mask file (e.g. Cellpose, StarDist, or QuPath output,
or a prior hyperannotatR export) into an editable annot_layer. Explicit metadata
and legend/level arguments take precedence over embedded RDS metadata, then
the <path>.legend.json sidecar. Bitfields polygonise each class membership.
Legacy masks default to exclusive values and zero background, recorded as
legacy-default; incomplete legacy bitfield legends require an explicit
encoding override. Malformed/future metadata and inconsistent dimensions
fail rather than silently discarding labels. Sampled previews or translated
grids cannot be polygonised as editable ROIs; import the original-resolution
mask with unit stride and zero origin.
at_read_mask( path, level = NULL, connectivity = c(8L, 4L), simplify = 0, min_area = 0, legend = NULL, call = rlang::caller_env(), metadata = NULL )at_read_mask( path, level = NULL, connectivity = c(8L, 4L), simplify = 0, min_area = 0, legend = NULL, call = rlang::caller_env(), metadata = NULL )
path |
Path to a mask file (TIFF, PNG, RDS, or NPY). NPY sidecar storage
orientation is recovered automatically for polygonisation. PNG input must
be unsigned 8/16-bit grayscale without palette, colour, alpha channels or
|
level |
Integer pyramid level to record on the ROIs. |
connectivity |
Single finite whole number |
simplify |
Non-negative simplification tolerance for the polygons. |
min_area |
Minimum polygon area in pixels to keep. Default |
legend |
Optional legend tibble ( |
call |
The calling environment, for error reporting. |
metadata |
Optional named list overriding semantic |
An annot_layer with one ROI per connected region. Recovered semantic
metadata is retained in layer$meta$mask_metadata, including empty layers.
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_npy(),
at_write_mask(),
at_write_masks(),
at_write_npy()
m <- at_mask(at_example_project(), "labelled") f <- tempfile(fileext = ".tif") at_write_mask(m, f) at_read_mask(f)m <- at_mask(at_example_project(), "labelled") f <- tempfile(fileext = ".tif") at_write_mask(m, f) at_read_mask(f)
.npy integer maskRead a NumPy integer array (e.g. a ground-truth annotation mask) into a
lossless annot_mask – values are preserved exactly, including composite
bitfield codes. Use this (not at_read_mask(), which polygonises) when the
raw integer matrix is what you need, for example to derive a training mask or
compute agreement against another mask.
at_read_npy( path, level = NULL, transpose = FALSE, legend = NULL, call = rlang::caller_env(), metadata = NULL )at_read_npy( path, level = NULL, transpose = FALSE, legend = NULL, call = rlang::caller_env(), metadata = NULL )
path |
Path to a |
level |
Integer pyramid level to record. |
transpose |
Logical; transpose the array on read, for files stored in
the native cube order |
legend |
Optional legend tibble ( |
call |
The calling environment, for error reporting. |
metadata |
Optional named list overriding semantic |
The header is validated strictly (NPY format versions 1-3, 2-D shapes,
scalar integer dtypes of 1, 2, 4 or 8 bytes in either byte order) and the
payload length is checked before reading; values that do not fit a 32-bit
integer mask (including INT_MIN, R's missing-value code) are refused, never
truncated. Reads are bounded by option hyperannotatR.max_read_bytes and
headers by hyperannotatR.max_npy_header_bytes.
An integer annot_mask preserving encoding, background, codebook,
grid and source metadata. Without encoding metadata, imports use exclusive
instance values and zero background with status legacy-default; signed
representable codes are preserved. A declared storage orientation must
match transpose, even for square arrays. Malformed sidecars are rejected.
at_write_npy(), at_read_mask()
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_write_mask(),
at_write_masks(),
at_write_npy()
m <- at_mask(at_example_project(), "labelled") f <- tempfile(fileext = ".npy") at_write_npy(m, f) at_read_npy(f)m <- at_mask(at_example_project(), "labelled") f <- tempfile(fileext = ".npy") at_write_npy(m, f) at_read_npy(f)
Reads QuPath 0.4+ exports (a native feature array, a FeatureCollection or a
single Feature) and the legacy hyperannotatR 0.1 dialect.
classification.name (or the joined names of a derived class, e.g.
"Tumor: Positive") becomes the ROI label, the classification colour (a
current color RGB array or a legacy colorRGB integer) the layer style
colour, and features without a classification are labelled
"unclassified". Everything else QuPath carries is kept, never invented,
under each ROI's attributes$qupath: the object id and type, name,
measurements (with explicit value_state), the image plane (zero-based
c, z, t; c = NA for all channels), metadata, a nucleus geometry, and
roi_native = "ellipse" with geometry_fidelity = "approximated" for
polygonised ellipses. A hyperannotatR id stored in metadata.annotatr_roi_id
is restored as the ROI id; ordinary external ids are kept unchanged.
at_read_qupath( path, layer_name = "qupath", level = 0L, call = rlang::caller_env(), coordinate_level = NULL, legacy_levels = c("error", "recorded") )at_read_qupath( path, layer_name = "qupath", level = 0L, call = rlang::caller_env(), coordinate_level = NULL, legacy_levels = c("error", "recorded") )
path |
Path to a QuPath GeoJSON file. |
layer_name |
Layer name for the imported ROIs. Default |
level |
Integer fallback level for features without level metadata.
Default |
call |
The calling environment, for error reporting. |
coordinate_level |
Optional integer overriding every recorded |
legacy_levels |
How to interpret files without the coordinate schema
marker: |
Input is validated strictly and keys are matched exactly: malformed
structure, contradictory duplicate fields (identical duplicates, which
QuPath 0.7.0 emits, are accepted), conflicting colours or object types for
a feature, conflicting colours for one label, and repeated ROI ids are
refused with an at_validation_error of code INVALID_GEOJSON.
An annot_layer.
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Read ROIs from a CSV with WKT geometry
at_read_rois_csv( path, layer_name = "csv", call = rlang::caller_env(), coordinate_level = NULL, legacy_levels = c("error", "recorded") )at_read_rois_csv( path, layer_name = "csv", call = rlang::caller_env(), coordinate_level = NULL, legacy_levels = c("error", "recorded") )
path |
Path to a CSV with at least |
layer_name |
Layer name for the imported ROIs. Default |
call |
The calling environment, for error reporting. |
coordinate_level |
Optional integer overriding every recorded |
legacy_levels |
How to interpret files without the
|
An annot_layer.
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Report how many tiles were requested from an image's backend, how many payload bytes were read from its file by windowed readers, and how many bytes were returned as decoded arrays. Cache hits are not counted as reads.
at_read_stats(img, reset = FALSE, call = rlang::caller_env())at_read_stats(img, reset = FALSE, call = rlang::caller_env())
img |
An annot_image. |
reset |
Logical; reset the counters for this image after reporting. |
call |
The calling environment, for error reporting. |
A list with tiles (integer), file_bytes, decoded_bytes and
max_tile_bytes (doubles), plus window_read (logical) and the current
max_tile_bytes_limit from option hyperannotatR.max_tile_bytes.
Other hsi:
at_band_operations(),
at_band_view(),
at_convert_values(),
at_cubert_export_envi(),
at_hsi_meta(),
at_tivita_profile()
cube <- at_example_image("cube") invisible(at_tile(cube, xrange = c(1, 4), yrange = c(1, 4), bands = 1:2)) at_read_stats(cube)$tilescube <- at_example_image("cube") invisible(at_tile(cube, xrange = c(1, 4), yrange = c(1, 4), bands = 1:2)) at_read_stats(cube)$tiles
Point a saved image (or project) at its source file again, for example after the file moved, or accept a source that changed since it was saved. The replacement is read with the selected reader and must have the same geometry; annotations are never changed.
at_relink_source(x, path, backend = NULL, options = NULL)at_relink_source(x, path, backend = NULL, options = NULL)
x |
An annot_image or annot_project. Annotations and geometry are preserved. |
path |
Replacement source path (may be the same path to revalidate). |
backend |
Reader backend; defaults to the saved backend. |
options |
Reader options as a list; defaults to the saved options. |
The updated image or project. Dimensions, pyramid levels, band count and wavelengths must agree. Relinking explicitly accepts the new source and refreshes image metadata from the selected reader.
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Remove a layer from a project
at_remove_layer(project, name, call = rlang::caller_env())at_remove_layer(project, name, call = rlang::caller_env())
project |
An annot_project. |
name |
Single string layer name. |
call |
The calling environment, for error reporting. |
A new annot_project without the named layer. The input is unchanged.
Other projects:
at_add_layer(),
at_add_roi(),
at_example_project(),
at_layers(),
at_project(),
at_remove_roi(),
at_rois(),
at_summary(),
at_validate()
Remove an ROI from a project
at_remove_roi(project, id, call = rlang::caller_env())at_remove_roi(project, id, call = rlang::caller_env())
project |
An annot_project. |
id |
Single string ROI identifier. |
call |
The calling environment, for error reporting. |
A new annot_project without the identified ROI. Warns and returns the project unchanged if the identifier is not found.
Other projects:
at_add_layer(),
at_add_roi(),
at_example_project(),
at_layers(),
at_project(),
at_remove_layer(),
at_rois(),
at_summary(),
at_validate()
A more discoverable alias for at_load_session().
at_resume(path, call = rlang::caller_env())at_resume(path, call = rlang::caller_env())
path |
Path to a saved session |
call |
The calling environment, for error reporting. |
The restored annot_session.
at_save_session(), at_load_session()
Other sessions:
at_current(),
at_example_session(),
at_goto(),
at_manifest(),
at_next(),
at_prev(),
at_session(),
at_session_status(),
at_set_status()
ROI area
at_roi_area( roi, level = 0L, units = c("px", "physical"), call = rlang::caller_env(), image = NULL )at_roi_area( roi, level = 0L, units = c("px", "physical"), call = rlang::caller_env(), image = NULL )
roi |
An annot_roi. |
level |
Integer pyramid level at which to express the area. Default |
units |
Either |
call |
The calling environment, for error reporting. |
image |
Optional annot_image defining actual pyramid dimensions.
Required when |
A numeric scalar area, or NA_real_ for non-areal geometry (points,
lines).
Other rois:
at_roi_bbox(),
at_roi_centroid(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_point(),
at_roi_polygon(),
at_roi_rect()
at_roi_area(at_roi_rect(0, 0, 10, 5, label = "a"))at_roi_area(at_roi_rect(0, 0, 10, 5, label = "a"))
ROI bounding box
at_roi_bbox(roi, call = rlang::caller_env())at_roi_bbox(roi, call = rlang::caller_env())
roi |
An annot_roi. |
call |
The calling environment, for error reporting. |
A numeric vector c(xmin, ymin, xmax, ymax) in the ROI's stored
coordinates.
Other rois:
at_roi_area(),
at_roi_centroid(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_point(),
at_roi_polygon(),
at_roi_rect()
at_roi_bbox(at_roi_circle(50, 50, 10, label = "a"))at_roi_bbox(at_roi_circle(50, 50, 10, label = "a"))
Buffer an ROI
at_roi_buffer(roi, dist, call = rlang::caller_env())at_roi_buffer(roi, dist, call = rlang::caller_env())
roi |
An annot_roi. |
dist |
Numeric buffer distance in pixels (may be negative to erode). |
call |
The calling environment, for error reporting. |
An annot_roi with the buffered geometry.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
at_roi_buffer(at_roi_point(10, 10, label = "a"), dist = 5)at_roi_buffer(at_roi_point(10, 10, label = "a"), dist = 5)
ROI centroid
at_roi_centroid(roi, call = rlang::caller_env())at_roi_centroid(roi, call = rlang::caller_env())
roi |
An annot_roi. |
call |
The calling environment, for error reporting. |
A numeric vector c(x, y) in the ROI's stored coordinates (at its
own level).
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_point(),
at_roi_polygon(),
at_roi_rect()
at_roi_centroid(at_roi_rect(0, 0, 10, 10, label = "a"))at_roi_centroid(at_roi_rect(0, 0, 10, 10, label = "a"))
The circle is approximated by a regular polygon of n_seg segments.
at_roi_circle( x, y, r, label, level = 0L, n_seg = 64L, ..., call = rlang::caller_env() )at_roi_circle( x, y, r, label, level = 0L, n_seg = 64L, ..., call = rlang::caller_env() )
x, y
|
Numeric centre coordinates in image pixels. |
r |
Positive numeric radius in pixels. |
label |
Single string class label. |
level |
Integer pyramid level the coordinates refer to. Default |
n_seg |
Integer number of polygon segments approximating the circle. |
... |
Additional named attributes stored on the ROI. The reserved names
|
call |
The calling environment, for error reporting. |
An annot_roi with POLYGON geometry and attributes$shape = "circle", so exports can flag the polygon as an approximation.
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_centroid(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_point(),
at_roi_polygon(),
at_roi_rect()
r <- at_roi_circle(50, 50, r = 10, label = "nucleus")r <- at_roi_circle(50, 50, r = 10, label = "nucleus")
Test whether points fall inside an ROI
at_roi_contains(roi, x, y, call = rlang::caller_env())at_roi_contains(roi, x, y, call = rlang::caller_env())
roi |
An annot_roi. |
x, y
|
Numeric coordinate vectors of equal length in the ROI's stored coordinate level. |
call |
The calling environment, for error reporting. |
A logical vector of length length(x).
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
at_roi_contains(at_roi_rect(0, 0, 10, 10, label = "a"), c(5, 20), c(5, 20))at_roi_contains(at_roi_rect(0, 0, 10, 10, label = "a"), c(5, 20), c(5, 20))
Distance between two ROIs
at_roi_distance(roi1, roi2, call = rlang::caller_env(), image = NULL)at_roi_distance(roi1, roi2, call = rlang::caller_env(), image = NULL)
roi1, roi2
|
annot_roi objects. |
call |
The calling environment, for error reporting. |
image |
annot_image defining actual pyramid dimensions; required for any nonzero ROI level because measurements are reported at level 0. |
A numeric scalar distance in level-0 pixels.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
Create an elliptical ROI
at_roi_ellipse( x, y, rx, ry, rotation = 0, label, level = 0L, n_seg = 64L, ..., call = rlang::caller_env() )at_roi_ellipse( x, y, rx, ry, rotation = 0, label, level = 0L, n_seg = 64L, ..., call = rlang::caller_env() )
x, y
|
Numeric centre coordinates in image pixels. |
rx, ry
|
Positive numeric semi-axis lengths in pixels. |
rotation |
Rotation of the major axis in degrees, clockwise in image
orientation. Default |
label |
Single string class label. |
level |
Integer pyramid level the coordinates refer to. Default |
n_seg |
Integer number of polygon segments approximating the ellipse. |
... |
Additional named attributes stored on the ROI. The reserved names
|
call |
The calling environment, for error reporting. |
An annot_roi with POLYGON geometry and attributes$shape = "ellipse", so exports can flag the polygon as an approximation.
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_centroid(),
at_roi_circle(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_point(),
at_roi_polygon(),
at_roi_rect()
r <- at_roi_ellipse(50, 50, rx = 20, ry = 10, rotation = 30, label = "cell")r <- at_roi_ellipse(50, 50, rx = 20, ry = 10, rotation = 30, label = "cell")
A freehand trace is stored as a closed polygon, optionally simplified.
at_roi_freehand( coords, label, level = 0L, simplify = 0, ..., call = rlang::caller_env() )at_roi_freehand( coords, label, level = 0L, simplify = 0, ..., call = rlang::caller_env() )
coords |
Two-column numeric matrix of vertices in drawing order. |
label |
Single string class label. |
level |
Integer pyramid level the coordinates refer to. Default |
simplify |
Non-negative Douglas-Peucker tolerance ( |
... |
Additional named attributes stored on the ROI. The reserved names
|
call |
The calling environment, for error reporting. |
An annot_roi with POLYGON geometry.
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_centroid(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_point(),
at_roi_polygon(),
at_roi_rect()
pts <- cbind(c(0, 5, 10, 5), c(0, 2, 0, -2)) r <- at_roi_freehand(pts, label = "trace")pts <- cbind(c(0, 5, 10, 5), c(0, 2, 0, -2)) r <- at_roi_freehand(pts, label = "trace")
Turn a single parsed GeoJSON feature (a list with geometry and optional
properties) into an annot_roi. Useful for consuming interactive drawing
output.
at_roi_from_geojson( feature, label = NULL, level = 0L, source = "manual", call = rlang::caller_env() )at_roi_from_geojson( feature, label = NULL, level = 0L, source = "manual", call = rlang::caller_env() )
feature |
A parsed GeoJSON feature: a list with a |
label |
Single string class label; taken from |
level |
Integer pyramid level. Default |
source |
Provenance source string. Default |
call |
The calling environment, for error reporting. |
An annot_roi.
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_centroid(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_sf(),
at_roi_point(),
at_roi_polygon(),
at_roi_rect()
feat <- list(geometry = list(type = "Polygon", coordinates = list(list(c(0, 0), c(4, 0), c(4, 4), c(0, 4), c(0, 0))))) at_roi_from_geojson(feat, label = "region")feat <- list(geometry = list(type = "Polygon", coordinates = list(list(c(0, 0), c(4, 0), c(4, 4), c(0, 4), c(0, 0))))) at_roi_from_geojson(feat, label = "region")
Create an ROI from an existing sf geometry
at_roi_from_sf(geometry, label, level = 0L, ..., call = rlang::caller_env())at_roi_from_sf(geometry, label, level = 0L, ..., call = rlang::caller_env())
geometry |
An |
label |
Single string class label. |
level |
Integer pyramid level the coordinates refer to. Default |
... |
Additional named attributes stored on the ROI. The reserved names
|
call |
The calling environment, for error reporting. |
An annot_roi wrapping the supplied geometry.
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_centroid(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_point(),
at_roi_polygon(),
at_roi_rect()
g <- sf::st_point(c(3, 4)) r <- at_roi_from_sf(g, label = "imported", source = "imported")g <- sf::st_point(c(3, 4)) r <- at_roi_from_sf(g, label = "imported", source = "imported")
Test whether two ROIs intersect
at_roi_overlaps(roi1, roi2, call = rlang::caller_env(), image = NULL)at_roi_overlaps(roi1, roi2, call = rlang::caller_env(), image = NULL)
roi1, roi2
|
annot_roi objects. |
call |
The calling environment, for error reporting. |
image |
Optional annot_image; required for mixed coordinate levels. |
A logical scalar: TRUE when the ROIs share any point, including
ROIs that only touch along an edge or at a corner.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
Create a point ROI
at_roi_point(x, y, label, level = 0L, ..., call = rlang::caller_env())at_roi_point(x, y, label, level = 0L, ..., call = rlang::caller_env())
x, y
|
Numeric coordinates of the point, in image pixels. |
label |
Single string class label. |
level |
Integer pyramid level the coordinates refer to. Default |
... |
Additional named attributes stored on the ROI. The reserved names
|
call |
The calling environment, for error reporting. |
An annot_roi with POINT geometry.
at_roi_rect(), at_roi_polygon()
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_centroid(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_polygon(),
at_roi_rect()
r <- at_roi_point(10, 20, label = "cell") at_roi_centroid(r)r <- at_roi_point(10, 20, label = "cell") at_roi_centroid(r)
Create a polygon ROI
at_roi_polygon( coords, label, level = 0L, hole = NULL, ..., call = rlang::caller_env() )at_roi_polygon( coords, label, level = 0L, hole = NULL, ..., call = rlang::caller_env() )
coords |
Either a two-column numeric matrix of exterior-ring vertices, or a list of such matrices where the first is the exterior ring and any others are holes. Rings are closed automatically. |
label |
Single string class label. |
level |
Integer pyramid level the coordinates refer to. Default |
hole |
Optional list of two-column matrices giving additional holes,
combined with any holes supplied via |
... |
Additional named attributes stored on the ROI. The reserved names
|
call |
The calling environment, for error reporting. |
An annot_roi with POLYGON geometry.
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_centroid(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_point(),
at_roi_rect()
sq <- matrix(c(0, 0, 10, 0, 10, 10, 0, 10), ncol = 2, byrow = TRUE) r <- at_roi_polygon(sq, label = "region")sq <- matrix(c(0, 0, 10, 0, 10, 10, 0, 10), ncol = 2, byrow = TRUE) r <- at_roi_polygon(sq, label = "region")
Create a rectangular ROI
at_roi_rect( xmin, ymin, xmax, ymax, label, level = 0L, ..., call = rlang::caller_env() )at_roi_rect( xmin, ymin, xmax, ymax, label, level = 0L, ..., call = rlang::caller_env() )
xmin, ymin, xmax, ymax
|
Numeric bounds in image pixels. |
label |
Single string class label. |
level |
Integer pyramid level the coordinates refer to. Default |
... |
Additional named attributes stored on the ROI. The reserved names
|
call |
The calling environment, for error reporting. |
An annot_roi with POLYGON geometry (an axis-aligned rectangle).
Other rois:
at_roi_area(),
at_roi_bbox(),
at_roi_centroid(),
at_roi_circle(),
at_roi_ellipse(),
at_roi_freehand(),
at_roi_from_geojson(),
at_roi_from_sf(),
at_roi_point(),
at_roi_polygon()
r <- at_roi_rect(0, 0, 10, 5, label = "tissue") at_roi_bbox(r)r <- at_roi_rect(0, 0, 10, 5, label = "tissue") at_roi_bbox(r)
Transform an ROI's coordinates from one pyramid level to another, assuming a
power-of-two pyramid. For an exact transform against a real image pyramid
(which need not be power-of-two), use at_transform() with the
annot_image.
at_roi_rescale( roi, from_level = roi$level, to_level, call = rlang::caller_env() )at_roi_rescale( roi, from_level = roi$level, to_level, call = rlang::caller_env() )
roi |
An annot_roi. |
from_level |
Integer source pyramid level. Defaults to the ROI's own
|
to_level |
Integer target pyramid level. |
call |
The calling environment, for error reporting. |
An annot_roi with coordinates at to_level and its level field
set to to_level. Power-of-two scaling is exact in floating point, so the
transform is exactly invertible.
at_transform()
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
r <- at_roi_rect(0, 0, 100, 100, label = "a") r2 <- at_roi_rescale(r, from_level = 0, to_level = 2) identical( sf::st_coordinates(sf::st_geometry(r)), sf::st_coordinates(sf::st_geometry(at_roi_rescale(r2, 2, 0))) )r <- at_roi_rect(0, 0, 100, 100, label = "a") r2 <- at_roi_rescale(r, from_level = 0, to_level = 2) identical( sf::st_coordinates(sf::st_geometry(r)), sf::st_coordinates(sf::st_geometry(at_roi_rescale(r2, 2, 0))) )
Build a band straddling an ROI's boundary – the natural shape for a
"penumbra" region along an injury or wound margin. The ring extends outer
units outside the boundary and inner units inside it, formed as the set
difference of the outward and inward buffers.
at_roi_ring( roi, outer, inner = 0, label = roi$label, call = rlang::caller_env() )at_roi_ring( roi, outer, inner = 0, label = roi$label, call = rlang::caller_env() )
roi |
An annot_roi. |
outer |
Non-negative outward width (dilation) of the ring. |
inner |
Non-negative inward width (erosion) of the ring. Default |
label |
Label for the derived ring ROI. Default the source ROI's label. |
call |
The calling environment, for error reporting. |
A derived annot_roi (an annulus) with source = "derived".
at_roi_buffer(), at_roi_difference()
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
inj <- at_roi_rect(10, 10, 20, 20, label = "injury") at_roi_ring(inj, outer = 3, label = "penumbra")inj <- at_roi_rect(10, 10, 20, 20, label = "injury") at_roi_ring(inj, outer = 3, label = "penumbra")
Combine ROIs geometrically. Each accepts several annot_roi via ..., or a
single annot_layer. Multi-part results are returned as one ROI with
MULTIPOLYGON geometry (the return type is always a single annot_roi).
When every input is a polygon the result is a POLYGON or MULTIPOLYGON;
parts of lower dimension (edges or corners that ROIs only touch along) are
dropped, and an empty result is an empty polygon, with a warning.
at_roi_union(..., call = rlang::caller_env(), image = NULL) at_roi_intersect(..., call = rlang::caller_env(), image = NULL) at_roi_difference(..., call = rlang::caller_env(), image = NULL) at_roi_symdiff(..., call = rlang::caller_env(), image = NULL)at_roi_union(..., call = rlang::caller_env(), image = NULL) at_roi_intersect(..., call = rlang::caller_env(), image = NULL) at_roi_difference(..., call = rlang::caller_env(), image = NULL) at_roi_symdiff(..., call = rlang::caller_env(), image = NULL)
... |
Two or more annot_roi, or a single annot_layer. |
call |
The calling environment, for error reporting. |
image |
Optional annot_image defining actual pyramid dimensions. Required for mixed levels. With it, results use level 0; without it, all operands must share a level and the result retains that level. |
Bare ROIs at different pyramid levels are an error with code
MIXED_LEVELS; pass image to combine them at level 0. The result takes
the label and author of the first ROI, but not its lock, review status,
QuPath object identity or shape attributes.
A single annot_roi with source = "derived".
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_simplify(),
at_rois_overlap(),
at_snap(),
at_transform()
a <- at_roi_rect(0, 0, 6, 6, label = "x") b <- at_roi_rect(4, 4, 10, 10, label = "x") at_roi_area(at_roi_intersect(a, b))a <- at_roi_rect(0, 0, 6, 6, label = "x") b <- at_roi_rect(4, 4, 10, 10, label = "x") at_roi_area(at_roi_intersect(a, b))
Simplify an ROI
at_roi_simplify(roi, tolerance, call = rlang::caller_env())at_roi_simplify(roi, tolerance, call = rlang::caller_env())
roi |
An annot_roi. |
tolerance |
Non-negative Douglas-Peucker tolerance ( |
call |
The calling environment, for error reporting. |
An annot_roi with simplified geometry.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_rois_overlap(),
at_snap(),
at_transform()
at_roi_simplify(at_roi_circle(50, 50, 10, n_seg = 128, label = "a"), 1)at_roi_simplify(at_roi_circle(50, 50, 10, n_seg = 128, label = "a"), 1)
Return a tidy table of ROIs, optionally filtered by layer and/or label.
at_rois(project, layer = NULL, label = NULL, call = rlang::caller_env())at_rois(project, layer = NULL, label = NULL, call = rlang::caller_env())
project |
An annot_project. |
layer |
Optional single layer name to filter to. |
label |
Optional character vector of labels to filter to. |
call |
The calling environment, for error reporting. |
Coordinates in the geometry column, together with area_px and the
centroid, are expressed at pyramid level 0. The level column is 0;
source_level records the stored level at which each ROI was defined.
Older tables used level for the stored reference level despite
returning level-0 geometry. Consumers needing that provenance must now use
source_level. The stored ROI geometry, level, and identifier are unchanged.
A tibble::tibble with one row per ROI and, in this exact order, the columns:
roi_idUnique identifier (character).
layerLayer name (character).
labelClass label (character).
geom_typeGeometry type, e.g. "POLYGON" (character).
levelCoordinate pyramid level, always 0 (integer).
source_levelStored ROI reference level (integer provenance).
area_pxArea in level-0 pixels (double); NA for points/lines.
centroid_x,centroid_y
Centroid at level 0 (double).
n_verticesVertex count (integer).
created,modified
Timestamps (POSIXct).
authorAuthor (character).
sourceProvenance source (character).
geometryThe sf geometry column (sfc), at level 0.
Returns a 0-row tibble with these columns if no ROIs match.
at_layers(), at_mask()
Other projects:
at_add_layer(),
at_add_roi(),
at_example_project(),
at_layers(),
at_project(),
at_remove_layer(),
at_remove_roi(),
at_summary(),
at_validate()
# proj <- at_example_project() # at_rois(proj)# proj <- at_example_project() # at_rois(proj)
Pairwise ROI overlaps within a layer
at_rois_overlap(layer, call = rlang::caller_env(), image = NULL)at_rois_overlap(layer, call = rlang::caller_env(), image = NULL)
layer |
An annot_layer. |
call |
The calling environment, for error reporting. |
image |
annot_image defining actual pyramid dimensions; required for any nonzero ROI level because measurements are reported at level 0. |
A tibble::tibble with columns id_a, id_b (character),
overlap_px (double, level-0 pixels), and jaccard (double). A 0-row
tibble with these columns when no ROIs overlap with positive area.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_snap(),
at_transform()
The project is written atomically: to a temporary file in the target
directory that then replaces path, so a failed write keeps the previous
file. An image read with at_read_image() is saved with a versioned source
descriptor (path, reader, options and file signature) instead of its
pixels, and is reopened from it on load. A hand-built in-memory image keeps
its pixels.
at_save_project(project, path, overwrite = FALSE, call = rlang::caller_env())at_save_project(project, path, overwrite = FALSE, call = rlang::caller_env())
project |
An annot_project. |
path |
Output |
overwrite |
Logical; overwrite an existing file. Default |
call |
The calling environment, for error reporting. |
The path, invisibly.
at_load_project(), at_inspect_saved()
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_session(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
p <- tempfile(fileext = ".rds") at_save_project(at_example_project(), p)p <- tempfile(fileext = ".rds") at_save_project(at_example_project(), p)
The session is written atomically, with each stored project's image saved
as a source descriptor rather than pixels (see at_save_project()).
at_save_session( session, path = NULL, overwrite = FALSE, call = rlang::caller_env() )at_save_session( session, path = NULL, overwrite = FALSE, call = rlang::caller_env() )
session |
An annot_session. |
path |
Optional output path; defaults to |
overwrite |
Logical; overwrite an existing file, including the default
|
call |
The calling environment, for error reporting. |
The session as saved (validated, with persisted projects), invisibly.
at_load_session(), at_resume()
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_write_geojson(),
at_write_qupath(),
at_write_rois_csv()
Create a batch annotation session
at_session( paths, labels = character(), layers = NULL, out_dir = .session_out_dir(), autosave = TRUE, ..., call = rlang::caller_env() )at_session( paths, labels = character(), layers = NULL, out_dir = .session_out_dir(), autosave = TRUE, ..., call = rlang::caller_env() )
paths |
Character vector of image file paths forming the queue. |
labels |
Character vector of the global label vocabulary. Duplicates are dropped. |
layers |
An annot_layer, a list of them, or |
out_dir |
Directory for autosave and exports. Defaults to a new,
unique directory under |
autosave |
Logical; whether to autosave on annotation commits. Default
|
... |
Additional named session metadata. |
call |
The calling environment, for error reporting. |
An annot_session with a manifest over paths, all statuses
"pending", the cursor at the first image, and projects not yet
materialised.
at_next(), at_current(), at_resume()
Other sessions:
at_current(),
at_example_session(),
at_goto(),
at_manifest(),
at_next(),
at_prev(),
at_resume(),
at_session_status(),
at_set_status()
# Build a session over the bundled example image copied several times: # sess <- at_example_session(3)# Build a session over the bundled example image copied several times: # sess <- at_example_session(3)
The session manifest
at_session_status(session, call = rlang::caller_env())at_session_status(session, call = rlang::caller_env())
session |
An annot_session. |
call |
The calling environment, for error reporting. |
The manifest tibble::tibble with columns idx, entry_id,
export_stem, path, name, status, project_path, n_rois, and
modified.
Other sessions:
at_current(),
at_example_session(),
at_goto(),
at_manifest(),
at_next(),
at_prev(),
at_resume(),
at_session(),
at_set_status()
Set the status of a queued image
at_set_status(session, i, status, call = rlang::caller_env())at_set_status(session, i, status, call = rlang::caller_env())
session |
An annot_session. |
i |
Integer image index (1-based) within the queue. |
status |
One of |
call |
The calling environment, for error reporting. |
A new annot_session with the status updated.
Other sessions:
at_current(),
at_example_session(),
at_goto(),
at_manifest(),
at_next(),
at_prev(),
at_resume(),
at_session(),
at_session_status()
Snap ROI vertices to a grid
at_snap(roi, grid = 1, call = rlang::caller_env())at_snap(roi, grid = 1, call = rlang::caller_env())
roi |
An annot_roi. |
grid |
Positive numeric grid spacing in pixels. Default |
call |
The calling environment, for error reporting. |
An annot_roi with vertices rounded to the nearest grid multiple. A geometry that snapping makes invalid (e.g. a collapsed ring) is repaired with a warning.
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_transform()
at_snap(at_roi_point(3.4, 5.6, label = "a"), grid = 1)at_snap(at_roi_point(3.4, 5.6, label = "a"), grid = 1)
Compute, without applying, the changes a partner patch would make to an
hyperannotatR project: ROIs are joined by id and classified as create,
update, unchanged, delete (only with delete_missing = TRUE) or
conflict. Reviewed or locked ROIs, and ROIs in locked layers, are never
changed automatically, and nothing is created in or moved into a locked
layer; such changes become conflicts. Incoming ROIs whose id was minted on
import (features without an id) are always created, with an id unique in
the project. Incoming ROIs at another pyramid level are compared, and
updates stored, at the level of the existing ROI. A patch that repeats an
ROI id aborts (DUPLICATE_ID). When expected_revision is given and the
project has moved on, staging aborts with an at_conflict_error
(REVISION_CONFLICT).
at_stage_qupflowr( x, patch, expected_revision = NULL, delete_missing = FALSE, call = rlang::caller_env() )at_stage_qupflowr( x, patch, expected_revision = NULL, delete_missing = FALSE, call = rlang::caller_env() )
x |
An annot_project, or the path of a saved project |
patch |
An import report from |
expected_revision |
Optional revision of |
delete_missing |
Logical; treat ROIs absent from the patch's layers as
deletions. Default |
call |
The calling environment, for error reporting. |
An at_staged_patch: a list with patch_id, state = "staged",
created, base_revision, proposed_revision, operations (tibble of
op, roi_id, layer, label, reason), summary (counts by op),
base, proposed (the would-be project), target_path and
patch_digest.
Other interop:
at_annotation_revision(),
at_commit_qupflowr(),
at_export_qupflowr(),
at_import_qupflowr(),
at_interop_capabilities(),
at_interop_manifest()
proj <- at_example_project() partner <- at_layer_add(at_layer("regions"), at_roi_rect(10, 10, 40, 40, label = "tumour", id = "partner-1")) st <- at_stage_qupflowr(proj, partner, expected_revision = at_annotation_revision(proj)) st$summaryproj <- at_example_project() partner <- at_layer_add(at_layer("regions"), at_roi_rect(10, 10, 40, 40, label = "tumour", id = "partner-1")) st <- at_stage_qupflowr(proj, partner, expected_revision = at_annotation_revision(proj)) st$summary
Construct a style specification for an annot_layer.
at_style( colour = NULL, fill_alpha = 0.3, stroke_width = 2, visible = TRUE, locked = FALSE, z = 1L, call = rlang::caller_env() )at_style( colour = NULL, fill_alpha = 0.3, stroke_width = 2, visible = TRUE, locked = FALSE, z = 1L, call = rlang::caller_env() )
colour |
Either |
fill_alpha |
Fill opacity in |
stroke_width |
Stroke width in pixels. Default |
visible |
Logical; whether the layer is drawn. Default |
locked |
Logical; whether the layer is protected from edits. Default
|
z |
Integer draw order (higher is drawn later, on top). Affects mask
overlap resolution. Default |
call |
The calling environment, for error reporting. |
A named list of class annot_style.
Other layers:
at_layer(),
at_layer_add(),
at_layer_n(),
at_layer_remove(),
at_layer_rois()
at_style(fill_alpha = 0.5, z = 2)at_style(fill_alpha = 0.5, z = 2)
Summarise a project
at_summary(project, call = rlang::caller_env())at_summary(project, call = rlang::caller_env())
project |
An annot_project. |
call |
The calling environment, for error reporting. |
An annot_summary object: a list with n_layers, n_rois,
per-label ROI counts, and total area per label.
Other projects:
at_add_layer(),
at_add_roi(),
at_example_project(),
at_layers(),
at_project(),
at_remove_layer(),
at_remove_roi(),
at_rois(),
at_validate()
at_summary(at_example_project())at_summary(at_example_project())
Session summary statistics
at_summary_table( session, by = c("image", "label", "layer"), call = rlang::caller_env() )at_summary_table( session, by = c("image", "label", "layer"), call = rlang::caller_env() )
session |
An annot_session. |
by |
Grouping: |
call |
The calling environment, for error reporting. |
A tibble::tibble with the grouping key plus n_rois,
total_area_px, mean_area, and sd_area. Image summaries also include
entry_id, so repeated display names remain separate. A 0-row tibble when
there are no ROIs.
Other batch:
at_batch_apply(),
at_batch_check_geometry(),
at_export_all()
The single, format-independent tile accessor. Returns a numeric array with
dimensions [y, x, band] — always three-dimensional, even for a single band.
at_tile( img, level = 0L, xrange = NULL, yrange = NULL, bands = NULL, call = rlang::caller_env() )at_tile( img, level = 0L, xrange = NULL, yrange = NULL, bands = NULL, call = rlang::caller_env() )
img |
An annot_image. |
level |
Integer pyramid level. Default |
xrange, yrange
|
Optional integer |
bands |
Optional integer band indices. |
call |
The calling environment, for error reporting. |
A numeric array with dimensions [y, x, band]. An image whose
pixel handle was not saved is reopened from its source descriptor; a
missing or ambiguous source is an error with code IMAGE_UNAVAILABLE and
a changed source IMAGE_CHANGED (see at_inspect_source() and
at_relink_source()).
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_wavelengths(),
hyperannotatR-classes
Other backends:
at_backend_detect(),
at_backend_get(),
at_backend_list(),
at_backend_register(),
at_close_image(),
at_cubert_export_envi(),
at_image_capabilities(),
at_read_image(),
at_tivita_profile()
img <- at_example_image("tissue") dim(at_tile(img, xrange = c(1, 16), yrange = c(1, 16)))img <- at_example_image("tissue") dim(at_tile(img, xrange = c(1, 16), yrange = c(1, 16)))
Build a tile-source descriptor for the canvas
at_tile_source( img, level_max = NULL, tile_size = 512L, embed = TRUE, view = NULL, call = rlang::caller_env() )at_tile_source( img, level_max = NULL, tile_size = 512L, embed = TRUE, view = NULL, call = rlang::caller_env() )
img |
An annot_image. |
level_max |
Optional maximum level to expose; the image maximum by default. |
tile_size |
Tile size in pixels. Default |
embed |
Logical; embed a downsampled base image as a data URI (for the
self-contained canvas). Default |
view |
Optional band view: a list with |
call |
The calling environment, for error reporting. |
A list describing the image for the widget: width, height
(level-0 pixels), nBands, and the pyramid description tileSize,
minLevel and maxLevel (informational: the built-in canvas displays a
single embedded image rather than streaming tiles). When embed is
TRUE it also has dataUri (a PNG data URI); when no image could be
encoded, dataUri is absent and displayError says why, and the canvas
shows that message instead of an image. viewError says why view was
not applied, when it was not.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
renderAtCanvas()
A profile states everything needed to decode a bare *_SpecCube.dat file;
hyperannotatR never infers these from a file name. The default arguments describe
the documented 640 x 480 x 100-band layout (500-995 nm), which is a profile
like any other and can be replaced for a different device.
at_tivita_profile( name = .TIVITA_DEFAULT_PROFILE, width = 640L, height = 480L, bands = 100L, header_values = 3L, value_bytes = 4L, endian = c("big", "little"), axis_order = "x,y,band", wavelengths = seq(500, 995, by = 5), wavelength_unit = "nm", value_unit = "reflectance", call = rlang::caller_env() )at_tivita_profile( name = .TIVITA_DEFAULT_PROFILE, width = 640L, height = 480L, bands = 100L, header_values = 3L, value_bytes = 4L, endian = c("big", "little"), axis_order = "x,y,band", wavelengths = seq(500, 995, by = 5), wavelength_unit = "nm", value_unit = "reflectance", call = rlang::caller_env() )
name |
Profile identifier recorded in the image metadata. |
width, height, bands
|
Cube dimensions (columns x, rows y, bands). |
header_values |
Number of leading values before the payload. |
value_bytes |
Bytes per value ( |
endian |
|
axis_order |
Storage order from slowest to fastest varying axis; only
|
wavelengths |
Numeric band-centre wavelengths (length |
wavelength_unit |
Wavelength unit, default |
value_unit |
What the values mean: one of |
call |
The calling environment, for error reporting. |
A list of class at_tivita_profile.
Other hsi:
at_band_operations(),
at_band_view(),
at_convert_values(),
at_cubert_export_envi(),
at_hsi_meta(),
at_read_stats()
Other backends:
at_backend_detect(),
at_backend_get(),
at_backend_list(),
at_backend_register(),
at_close_image(),
at_cubert_export_envi(),
at_image_capabilities(),
at_read_image(),
at_tile()
at_tivita_profile()$bands small <- at_tivita_profile("bench_4x3x2", width = 4, height = 3, bands = 2, wavelengths = c(600, 700))at_tivita_profile()$bands small <- at_tivita_profile("bench_4x3x2", width = 4, height = 3, bands = 2, wavelengths = c(600, 700))
Run independent checks on an exported training dataset: the integrity
inventory (schema, safe paths, symbolic links, sizes and SHA-256 hashes,
missing and unlisted files), the manifest schema, split leakage (every
group and image in exactly one split, every tile in its image's split),
mask dimensions and orientation, integer label range against the class
legend, the recorded overlap counts, and a mask -> ROI -> mask round trip
on a sample of tiles. When the source x is supplied, each sampled tile is
also re-rasterised from the annotations and compared exactly. Tile files
outside the verified inventory are never opened. A check that cannot run
on a malformed manifest is reported as "fail" rather than raising an
error; only an unsupported major version aborts (PROTOCOL_MISMATCH).
at_training_check( dataset, x = NULL, max_roundtrip_tiles = 20L, call = rlang::caller_env() )at_training_check( dataset, x = NULL, max_roundtrip_tiles = 20L, call = rlang::caller_env() )
dataset |
Path of a dataset written by |
x |
Optional source annot_session or annot_project. |
max_roundtrip_tiles |
Maximum number of tiles sampled for round trips. |
call |
The calling environment, for error reporting. |
A tibble of class at_training_check with check, status
("ok", "warn", "fail") and detail.
Other training:
at_training_export(),
at_training_import()
Tile annotated images into a portable training dataset with integer masks,
deterministic grouped splits and a complete provenance manifest. Splits are
assigned per group (by default per image, or by subject_id/sample_id
from groups), so tiles of one group never occur in two splits. Masks are
written as integer TIFF (or NPY) with background 0; class codes are shared
across the dataset and instance ids are only produced for
mask_type = "instance". Tiles that do not fit the image are excluded as
partial; empty and ambiguous (overlapping labels) tiles are counted and
handled by policy. Image bytes are excluded unless include_images = TRUE.
at_training_export( x, destination, split = NULL, tile_size = 256L, overlap = 0L, level = 0L, mask_type = c("labelled", "instance", "binary"), bands = NULL, include_images = FALSE, seed = 1L, group_by = c("image_id", "sample_id", "subject_id"), groups = NULL, fractions = c(train = 0.7, validation = 0.15, test = 0.15), label_map = NULL, empty_tiles = c("keep", "exclude"), mask_format = c("tiff", "npy"), normalization = NULL, overwrite = FALSE, call = rlang::caller_env() )at_training_export( x, destination, split = NULL, tile_size = 256L, overlap = 0L, level = 0L, mask_type = c("labelled", "instance", "binary"), bands = NULL, include_images = FALSE, seed = 1L, group_by = c("image_id", "sample_id", "subject_id"), groups = NULL, fractions = c(train = 0.7, validation = 0.15, test = 0.15), label_map = NULL, empty_tiles = c("keep", "exclude"), mask_format = c("tiff", "npy"), normalization = NULL, overwrite = FALSE, call = rlang::caller_env() )
x |
An annot_session (materialised entries) or annot_project. |
destination |
New dataset directory. |
split |
Optional explicit assignment: a named list
( |
tile_size |
Tile edge length in pixels at |
overlap |
Tile overlap in pixels ( |
level |
Pyramid level. |
mask_type |
|
bands |
Band indices recorded (and written with |
include_images |
Logical; also write float32 NPY image tiles. |
seed |
Split seed (recorded). |
group_by |
Group column used for splitting: |
groups |
Optional data frame with |
fractions |
Named split fractions. Split names (here and in |
label_map |
Optional named integer class codes ( |
empty_tiles |
|
mask_format |
|
normalization |
Optional list describing value normalisation applied downstream (recorded, not applied). |
overwrite |
Logical; replace an existing dataset directory. |
call |
The calling environment, for error reporting. |
mask_type uses training terminology: "labelled" is a semantic class-code
mask (hyperannotatR "multiclass"), "instance" has one id per ROI (hyperannotatR
"labelled"), "binary" marks foreground. The mapping is recorded in the
manifest.
An at_training_export list: destination, dataset_digest,
manifest, files and checks (from at_training_check()).
at_training_check(), at_training_import()
Other training:
at_training_check(),
at_training_import()
sess <- at_example_session(2) for (i in 1:2) sess$projects[[i]] <- at_example_project() ds <- at_training_export(sess, file.path(tempdir(), "train-example"), tile_size = 256, overwrite = TRUE) ds$manifest$counts$tiles # Both example entries show the same picture, so they form one image # group and land in one split: tiles of one image never leak across splits. ds$manifest$counts$images_by_splitsess <- at_example_session(2) for (i in 1:2) sess$projects[[i]] <- at_example_project() ds <- at_training_export(sess, file.path(tempdir(), "train-example"), tile_size = 256, overwrite = TRUE) ds$manifest$counts$tiles # Both example entries show the same picture, so they form one image # group and land in one split: tiles of one image never leak across splits. ds$manifest$counts$images_by_split
Convert an integer prediction mask into ROIs and stage them against a
project; nothing is committed. The prediction must match the image
dimensions at level, contain only integers, and every non-background value
must be in label_map; otherwise the import aborts. Optional per-pixel
confidence below min_confidence is set to background first. Model and
prediction digests and the confidence policy are recorded on every ROI,
which starts as review_status = "unreviewed". Reviewed or locked
annotations are never overwritten: with replace = TRUE they become staged
conflicts.
at_training_import( x, predictions, label_map, level = 0L, source = "dnn_prediction", model = list(name = NA_character_, version = NA_character_, sha256 = NA_character_), confidence = NULL, min_confidence = NULL, layer = "predictions", replace = FALSE, stage = TRUE, call = rlang::caller_env() )at_training_import( x, predictions, label_map, level = 0L, source = "dnn_prediction", model = list(name = NA_character_, version = NA_character_, sha256 = NA_character_), confidence = NULL, min_confidence = NULL, layer = "predictions", replace = FALSE, stage = TRUE, call = rlang::caller_env() )
x |
An annot_project. |
predictions |
A mask file (TIFF/PNG/NPY), an |
label_map |
Named integer vector |
level |
Pyramid level of the prediction grid. |
source |
ROI source string. Default |
model |
List with |
confidence |
Optional numeric matrix of per-pixel confidence. |
min_confidence |
Optional threshold applied to |
layer |
Target layer name. Default |
replace |
Logical; stage removal of existing unreviewed ROIs of |
stage |
Logical; return an |
call |
The calling environment, for error reporting. |
An at_staged_patch (or an annot_layer when stage = FALSE)
with attribute prediction_digest.
Other training:
at_training_check(),
at_training_export()
Unlike at_roi_rescale() (which assumes a power-of-two pyramid), this uses
the actual level dimensions of an annot_image, so it is exact for pyramids
with any downsampling ratio.
at_transform( roi, from_level = roi$level, to_level, img, call = rlang::caller_env() )at_transform( roi, from_level = roi$level, to_level, img, call = rlang::caller_env() )
roi |
An annot_roi. |
from_level |
Integer source pyramid level; defaults to, and must equal,
the ROI's |
to_level |
Integer target pyramid level. |
img |
The annot_image whose pyramid defines the level dimensions. |
call |
The calling environment, for error reporting. |
An annot_roi with coordinates at to_level. Invertible within
floating-point precision (relative tolerance 1e-12).
Other geometry:
at_check_containment(),
at_check_geometry(),
at_clamp(),
at_fix_geometry(),
at_flip_y(),
at_roi_buffer(),
at_roi_contains(),
at_roi_distance(),
at_roi_overlaps(),
at_roi_rescale(),
at_roi_ring(),
at_roi_setops,
at_roi_simplify(),
at_rois_overlap(),
at_snap()
img <- at_example_image("multiplex") r <- at_roi_rect(0, 0, 100, 100, label = "a") at_transform(r, from_level = 0, to_level = 2, img = img)img <- at_example_image("multiplex") r <- at_roi_rect(0, 0, 100, 100, label = "a") at_transform(r, from_level = 0, to_level = 2, img = img)
Check that layer names are unique, ROI identifiers are unique across the project, every ROI has one geometry at a pyramid level the image has, and all geometries are valid.
at_validate(project, call = rlang::caller_env())at_validate(project, call = rlang::caller_env())
project |
An annot_project. |
call |
The calling environment, for error reporting. |
The project, invisibly, if valid; otherwise an error describing the violated invariant.
at_check_geometry()
Other projects:
at_add_layer(),
at_add_roi(),
at_example_project(),
at_layers(),
at_project(),
at_remove_layer(),
at_remove_roi(),
at_rois(),
at_summary()
proj <- at_validate(at_example_project())proj <- at_validate(at_example_project())
Band centre wavelengths
at_wavelengths(x, call = rlang::caller_env())at_wavelengths(x, call = rlang::caller_env())
x |
An annot_image. |
call |
The calling environment, for error reporting. |
A numeric vector of length at_n_bands(x) for a spectral image, or
numeric(0) when the image is not spectral.
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
hyperannotatR-classes
Write a project's ROIs to GeoJSON
at_write_geojson( project, path, layer = NULL, level = 0L, flip_y = FALSE, overwrite = FALSE, call = rlang::caller_env() )at_write_geojson( project, path, layer = NULL, level = 0L, flip_y = FALSE, overwrite = FALSE, call = rlang::caller_env() )
project |
An annot_project. |
path |
Output file path. |
layer |
Optional layer filter. |
level |
Integer pyramid level for the coordinates and the exported
|
flip_y |
Logical; invert the y-axis (for GIS-oriented consumers). Default
|
overwrite |
Logical; overwrite an existing file. Default |
call |
The calling environment, for error reporting. |
The output path, invisibly.
at_read_geojson(), at_write_qupath()
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_qupath(),
at_write_rois_csv()
p <- tempfile(fileext = ".geojson") at_write_geojson(at_example_project(), p)p <- tempfile(fileext = ".geojson") at_write_geojson(at_example_project(), p)
Write a mask to disk
at_write_mask( mask, path, format = c("tiff", "png", "rds"), bits = c(16L, 8L), legend = TRUE, overwrite = FALSE, call = rlang::caller_env() )at_write_mask( mask, path, format = c("tiff", "png", "rds"), bits = c(16L, 8L), legend = TRUE, overwrite = FALSE, call = rlang::caller_env() )
mask |
An |
path |
Output file path. |
format |
|
bits |
Single finite whole-number bit depth for TIFF: |
legend |
Logical; also write a |
overwrite |
Logical; overwrite an existing file. Default |
call |
The calling environment, for error reporting. |
TIFF exports preserve unsigned 8/16-bit codes; PNG exports are
unsigned 8-bit only, regardless of bits. Samples must be finite integers
in the selected unsigned range; invalid samples reject before writing.
TIFF writing requires tiff or a capable magick build. PNG writing
requires magick with exact grayscale support. Missing exact conversion
capability produces an error rather than a quantized output. The caller's
explicit path is respected. Mask and legend are staged before either is
replaced; a preexisting sidecar also requires overwrite=TRUE. Publication
failure rolls back prior files. Concurrent writers must be serialized.
The output path, invisibly.
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_masks(),
at_write_npy()
m <- at_mask(at_example_project(), "labelled") f <- tempfile(fileext = ".tif") at_write_mask(m, f)m <- at_mask(at_example_project(), "labelled") f <- tempfile(fileext = ".tif") at_write_mask(m, f)
Batch-write the masks of a project
at_write_masks( project, dir, per = c("layer", "roi", "class", "project"), type = c("labelled", "binary", "multiclass"), level = 0L, overwrite = FALSE, call = rlang::caller_env() )at_write_masks( project, dir, per = c("layer", "roi", "class", "project"), type = c("labelled", "binary", "multiclass"), level = 0L, overwrite = FALSE, call = rlang::caller_env() )
project |
An annot_project. |
dir |
Output directory (created if needed). |
per |
One of |
type |
Mask type passed to |
level |
Integer pyramid level. Default |
overwrite |
Logical; overwrite existing files. Default |
call |
The calling environment, for error reporting. |
Output plans reject symlinked descendants and aliases before writing. Callers must serialize concurrent writes and keep destination paths stable; preflight plus staged renames is not a race-free filesystem transaction.
An invisible export-receipt tibble::tibble with columns path,
type, n_px, bytes, name, status, message, sidecar_path, and
sidecar_bytes. Counts and bytes use double precision. Display names are
retained in name; filenames use safe components with unique suffixes.
Each item is "ok", "error", or "skipped"; one failure does not abort
later items. A TIFF and its legend form one staged output bundle.
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_npy()
.npy fileWrite an annot_mask as a lossless integer NumPy array, for interchange with
Python tools. A <path>.legend.json sidecar (value -> label, plus the mask
metadata and storage orientation) is written alongside so the array stays
self-describing. Unlike at_write_mask(), values are stored raw (no
bit-depth normalisation), so bitfield artefact masks survive intact. The
array and legend are staged as one output bundle; an existing sidecar also
requires overwrite = TRUE. Values outside the chosen dtype are refused
before anything is written. Concurrent writers must be serialised.
at_write_npy( mask, path, dtype = c("int32", "uint8", "int16"), transpose = FALSE, legend = TRUE, overwrite = FALSE, call = rlang::caller_env() )at_write_npy( mask, path, dtype = c("int32", "uint8", "int16"), transpose = FALSE, legend = TRUE, overwrite = FALSE, call = rlang::caller_env() )
mask |
An |
path |
Output file path. |
dtype |
NumPy integer dtype: |
transpose |
Logical; write the transpose, i.e. numpy shape
|
legend |
Logical; also write a |
overwrite |
Logical; overwrite an existing file. Default |
call |
The calling environment, for error reporting. |
The output path, invisibly.
at_read_npy(), at_write_mask()
Other masks:
at_mask(),
at_mask_agreement(),
at_mask_boundary(),
at_mask_derive(),
at_mask_legend(),
at_mask_preview(),
at_mask_stack(),
at_mask_stats(),
at_read_mask(),
at_read_npy(),
at_write_mask(),
at_write_masks()
m <- at_mask(at_example_project(), "labelled") f <- tempfile(fileext = ".npy") at_write_npy(m, f)m <- at_mask(at_example_project(), "labelled") f <- tempfile(fileext = ".npy") at_write_npy(m, f)
The default dialect = "qupath" writes what QuPath 0.4 and later read
natively (verified with QuPath 0.7.0): objectType, classification with
an [r, g, b] colour, isLocked for locked ROIs, a deterministic UUID per
ROI as the feature id (QuPath replaces non-UUID ids; existing UUIDs are
kept), and hyperannotatR's own ROI id, layer, source and stored level in
properties.metadata. dialect = "legacy" writes the hyperannotatR 0.1 form
(object_type, signed colorRGB), which QuPath still reads with a
deprecation warning. Publication uses a staged replacement.
at_write_qupath( project, path, layer = NULL, level = 0L, overwrite = FALSE, dialect = c("qupath", "legacy"), call = rlang::caller_env() )at_write_qupath( project, path, layer = NULL, level = 0L, overwrite = FALSE, dialect = c("qupath", "legacy"), call = rlang::caller_env() )
project |
An annot_project. |
path |
Output file path. |
layer |
Optional layer filter. |
level |
Integer pyramid level for the coordinates and the |
overwrite |
Logical; overwrite an existing file. Default |
dialect |
|
call |
The calling environment, for error reporting. |
Every feature records the pyramid level of its written coordinates as the
level property, the ROI's stored level as source_level, and the marker
coordinate_schema = "annotatR-pixel-level-v1". QuPath keeps only
metadata through its own import and export, so the QuPath dialect repeats
the declaration there as annotatr_coordinate_schema and
annotatr_coordinate_level; at_read_qupath() restores ROIs at that level.
QuPath keeps one colour per classification name, so a label that has different colours in different layers is written with the first colour found for it.
The output path, invisibly.
at_read_qupath(), at_write_geojson()
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_rois_csv()
p <- tempfile(fileext = ".geojson") at_write_qupath(at_example_project(), p)p <- tempfile(fileext = ".geojson") at_write_qupath(at_example_project(), p)
One row per ROI with a WKT geometry column. Coordinates and level are
at level 0; source_level records the stored ROI level as provenance, and
coordinate_schema marks the file as recording the level of its
coordinates. WKT coordinates use 17 significant digits and a decimal point,
independently of session display options, to preserve double-precision
geometry.
at_write_rois_csv(project, path, overwrite = FALSE, call = rlang::caller_env())at_write_rois_csv(project, path, overwrite = FALSE, call = rlang::caller_env())
project |
An annot_project. |
path |
Output |
overwrite |
Logical; overwrite an existing file. Default |
call |
The calling environment, for error reporting. |
The path, invisibly.
Other io:
at_inspect_saved(),
at_inspect_source(),
at_load_project(),
at_load_session(),
at_read_geojson(),
at_read_qupath(),
at_read_rois_csv(),
at_relink_source(),
at_roi_from_geojson(),
at_save_project(),
at_save_session(),
at_write_geojson(),
at_write_qupath()
p <- tempfile(fileext = ".csv") at_write_rois_csv(at_example_project(), p)p <- tempfile(fileext = ".csv") at_write_rois_csv(at_example_project(), p)
Shiny output for the annotation canvas
atCanvasOutput(outputId, width = "100%", height = "600px")atCanvasOutput(outputId, width = "100%", height = "600px")
outputId |
Output id. |
width, height
|
Output dimensions. |
A Shiny output element.
Other shiny:
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source(),
renderAtCanvas()
hyperannotatR represents annotations with a small set of S3 classes. This page collects them so they can be cross-referenced from the documentation.
annot_imageA backend-agnostic image handle holding metadata and
the backend's pixel handle, read through at_tile(). Windowed backends
(ENVI, TIVITA) read only the requested window; the raster and TIFF
backends decode the whole image when it is read. Created by
at_read_image() or at_example_image().
annot_roiA single region of interest: an sf geometry in image
pixel coordinates at a declared pyramid level. Created by the
at_roi_*() constructors.
annot_layerA named collection of ROIs sharing a label vocabulary
and a visual style. Created by at_layer().
annot_projectAn image plus a named set of layers and provenance.
Created by at_project().
annot_sessionA resumable batch-annotation session over a queue of
images. Created by at_session().
annot_maskA rasterised mask: an integer matrix (binary,
labelled, multiclass, or bitfield-encoded) with a legend. Created by
at_mask().
annot_styleA layer style specification. Created by at_style().
annot_summaryA compact per-label project summary. Created by
at_summary().
Other images:
at_bands(),
at_close_image(),
at_dims(),
at_example_image(),
at_hsi_meta(),
at_image_capabilities(),
at_is_pyramidal(),
at_is_spectral(),
at_meta(),
at_n_bands(),
at_n_levels(),
at_pixel_size(),
at_read_image(),
at_tile(),
at_wavelengths()
Render an annotation canvas in Shiny
renderAtCanvas(expr, env = parent.frame(), quoted = FALSE)renderAtCanvas(expr, env = parent.frame(), quoted = FALSE)
expr |
An expression producing an |
env |
The environment to evaluate |
quoted |
Is |
A Shiny render function.
Other shiny:
atCanvasOutput(),
at_annotate(),
at_app(),
at_canvas(),
at_canvas_fit(),
at_canvas_proxy(),
at_canvas_set_annotations(),
at_canvas_set_band(),
at_canvas_set_overlay(),
at_canvas_set_selection(),
at_canvas_set_tool(),
at_tile_source()