smoothSpatialAnnotation.Rd
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,
...
)
An object of class SPATA2
or, in case of S4 generics,
objects of classes for which a method has been defined.
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.
The smoothing method to be applied. Options include "chaikin", "densify", "ksmooth", and "spline".
Logical; if TRUE, the outer border of the annotation is smoothed.
Logical or numeric; if TRUE, all inner borders are smoothed. If a numeric value is provided, only the specified inner border is smoothed.
Character value or FALSE
. If character, the resulting
spatial annotation is stored under a new ID.
Logical value. Must be TRUE
to allow overwriting.
Additional arguments passed to the smoothing function smoothr::ksmooth()
, smoothr::chaikin()
, etc.
The updated input object, containing the added, removed or computed results.
Requires the package 'terra' and 'smoothr'.
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"))