addInnerBorder: Add holes to spatial annotations

addInnerBorderR Documentation

Add holes to spatial annotations

Description

These methods allow the addition of an inner border to spatial annotations, creating holes.

Usage

addInnerBorder(object, ...)

## S4 method for signature 'SPATA2'
addInnerBorder(object, id, border_df, new_id = FALSE, overwrite = FALSE, ...)

## S4 method for signature 'SpatialAnnotation'
addInnerBorder(object, border_df, ...)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

...

Used to absorb deprecated arguments or functions.

id

Character value. The ID of the spatial annotation to which the hole is added.

border_df

A data.frame that contains the x- and y- positions of the vertices of the polygon that corresponds to the borders of the whole. See details for input requirements.

new_id

If character value, stores the resulting spatial annotatiton under the specified ID.

overwrite

Logical value. Must be TRUE to allow overwriting.

Details

If used on a SpatialAnnotation directly, the variables of border_df should be called x_orig and y_orig and should be scaled correspondingly. If used with the SPATA2 object, the variables can be called x and y, too. In that case, the function assumes that the coordinates are scaled to the image that is currently active and creates x_orig and y_orig accordingly.

Value

The updated input object, containing the added, removed or computed results.

See Also

activeImage(), SpatialAnnotation

Examples


library(SPATA2)
library(tidyverse)

data("example_data")

object <- example_data$object_UKF275T_diet

create_circle_polygon <- function(p, r, n) {

 angles <- seq(0, 2 * pi, length.out = n + 1)

 x_coords <- p[1] + r * cos(angles)
 y_coords <- p[2] + r * sin(angles)

 polygon_df <- tibble::tibble(x = x_coords, y = y_coords)

 return(polygon_df)

}

center <-
 getCoordsDf(object)[c("x", "y")] %>%
 map_dbl(.f = mean)

area_circle <- create_circle_polygon(center, r = 75, n = 100)

print(area_circle)

object <- addSpatialAnnotation(object, area = list(outer = area_circle), id = "circle")

plotSpatialAnnotations(object, ids = "circle")

hole <- create_circle_polygon(center, r = 25, n = 100)

object <- addInnerBorder(object, id = "circle", border_df = hole, new_id = "circle_with_hole")

plotSpatialAnnotations(object, ids = c("circle", "circle_with_hole"))



theMILOlab/SPATA2 documentation built on Feb. 8, 2025, 11:41 p.m.