This function applies a smoothing algorithm to the borders of a SpatialAnnotation object. It can smooth both outer and inner borders using various methods.

smoothSpatialAnnotation(
  object,
  id,
  method,
  outer = TRUE,
  inner = TRUE,
  new_id = FALSE,
  overwrite = FALSE,
  ...
)

Arguments

object

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

id

Character value specifying the ID of the spatial annotation of interest. If there is only one spatial annotation in the object, the function will default to using it. However, if there are multiple annotations, this argument must be explicitly specified to identify the target annotation.

method

The smoothing method to be applied. Options include "chaikin", "densify", "ksmooth", and "spline".

outer

Logical; if TRUE, the outer border of the annotation is smoothed.

inner

Logical or numeric; if TRUE, all inner borders are smoothed. If a numeric value is provided, only the specified inner border is smoothed.

new_id

Character value or FALSE. If character, the resulting spatial annotation is stored under a new ID.

overwrite

Logical value. Must be TRUE to allow overwriting.

...

Additional arguments passed to the smoothing function smoothr::ksmooth(), smoothr::chaikin(), etc.

Value

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

Note

Requires the package 'terra' and 'smoothr'.

Examples

library(SPATA2)

data("example_data")

object <- example_data$object_UKF313T_diet

ids <- getSpatAnnIds(object, tags = c("necrotic", "compr"), test = "identical")

plotSpatialAnnotations(object, ids = "necrotic_edge")

object <-
 smoothSpatialAnnotation(object, id = "necrotic_edge", method = "ksmooth", new_id = "necrotic_edge_sm", smoothness = 50)

plotSpatialAnnotations(object, ids = c("necrotic_edge", "necrotic_edge_sm"))