Skip to contents

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 sg_roi_transform() with the sg_roi_frame.

Usage

sg_roi_rescale(roi, from_level, to_level, call = rlang::caller_env())

Arguments

roi

An sg_roi.

from_level, to_level

Integer source and target pyramid levels.

call

The calling environment, for error reporting.

Value

An sg_roi with coordinates at to_level and its level field set to to_level. The transform is exactly invertible.

Examples

r <- sg_roi_rect(0, 0, 100, 100, label = "a")
r2 <- sg_roi_rescale(r, from_level = 0, to_level = 2)
identical(
  sf::st_coordinates(sf::st_geometry(r)),
  sf::st_coordinates(sf::st_geometry(sg_roi_rescale(r2, 2, 0)))
)
#> [1] TRUE