
Morphological transformations using terra (optimized for VisiumHD)
Source:R/edge_helper_functions_VisiumHD.R
focal_transformations_terra.RdTerra-only implementation of focal operations for connecting outlier regions.
Arguments
- r
A
SpatRasterobject with binary values (1=outlier, 0=normal).- min_cluster_size
Minimum size (in bins) for small hole removal.
Value
A SpatRaster object after applying focal
transformations (fill, outline, star) and small hole removal.
Examples
# Create a dummy binary SpatRaster for demonstration
if (requireNamespace("terra", quietly = TRUE)) {
r <- terra::rast(matrix(c(0, 0, 0, 0, 1, 0, 0, 0, 0), nrow = 3),
extent = terra::ext(0, 3, 0, 3)
)
# Run the focal transformations
# result <- focal_transformations_terra(r, min_cluster_size = 5)
}