Converts a raster mask into a vectorized sf object, with various options
for morphological operations and filtering.
Usage
mosaic_vectorize(
mask,
aggregate = NULL,
watershed = TRUE,
tolerance = 1,
extension = 1,
opening = FALSE,
closing = FALSE,
filter = FALSE,
erode = FALSE,
dilate = FALSE,
fill_hull = FALSE,
lower_size = NULL,
upper_size = NULL,
topn_lower = NULL,
topn_upper = NULL,
smooth = FALSE
)Arguments
- mask
An optional mask (SpatRaster) to mask the mosaic.
- aggregate
The size as a fraction (percentage) of the input image size. Either a scalar (eg., 50), or a length-two numeric vector. In the last, different percentage reduction/expansion can be used for columns, and rows, respectively.
- watershed
If
TRUE(default), performs watershed-based object detection. This will detect objects even when they are touching one another. If FALSE, all pixels for each connected set of foreground pixels are set to a unique object. This is faster but is not able to segment touching objects.- tolerance
The minimum height of the object in the units of image intensity between its highest point (seed) and the point where it contacts another object (checked for every contact pixel). If the height is smaller than the tolerance, the object will be combined with one of its neighbors, which is the highest. Values < 1.0 are interpreted as relative tolerance (percentage of the peak height). Values >= 1.0 are interpreted as absolute tolerance in pixels (linear Euclidean distance).
- extension
Radius of the neighborhood in pixels for the detection of neighboring objects. A higher value smooths out small objects.
- opening, closing, filter, erode, dilate
Morphological operations (brush size), applied in hierarchical order.
- fill_hull
Fill holes in the binary image? Defaults to
FALSE.- lower_size, upper_size
Lower and upper size limits for object filtering.
- topn_lower, topn_upper
Select top
nobjects based on area.- smooth
Smoothes the contours using a moving average filter. Default is
FALSE.
Value
An sf object containing vectorized features from the raster mask,
with added area measurements.
Examples
if (FALSE) { # interactive()
library(pliman)
mask <- image_pliman("mask.tif")
shp <- mosaic_vectorize(mask, watershed = FALSE)
mosaic_plot(mask)
shapefile_plot(shp, add = TRUE, lwd = 3)
}
