smooth_map: Smooth an input map

View source: R/smooth_map.R

smooth_mapR Documentation

Smooth an input map

Description

Smooths out inconsistencies in the map by performing a function on each pixel based on the values of surrounding pixels. Can also remove dark RGB values, typically used for map text, boundaries etc.

Usage

smooth_map(in.raster, window.size = 25, smooth.function = mean, dark.rm = TRUE, darkValue = 100, clip.frame = FALSE, frame.type = "black")

Arguments

in.raster

The SpatRaster object to be smoothed. This must be an RGB raster object, i.e. with three colour bands. Other types of raster may return an error, but can be converted e.g. in QGIS.

window.size

Integer. Default = 25. Must be odd. Passed to focal via matrix to determine the size in pixels of the window (larger window = greater generalization).

smooth.function

Function. Name of an R function to apply within the window specified. Default = mean. Other functions e.g. max, min, modal are possible but run very slowly. See focal for details.

dark.rm

Logical. Reduce the effect of map text, boundaries etc. by removing the darkest pixels prior to smoothing. Default is TRUE.

darkValue

Integer. Value below which all RGB layers should have for a pixel to be removed prior to smoothing. Default is 100. Too high values result in the appearance of large patches of white (NA) appear. Too low and text etc can interfere with land use categories.

clip.frame

Logical. Should the smoothed map be 'clipped' to remove areas of the input raster that are not mapped (for example because the image is not straight)? Default is FALSE, which can be useful for mosaicking maps later, while TRUE keeps the classification within the bounds of the input map.

frame.type

Character. If clipping the frame, are the unmapped values 'black' (i.e. RGB values all zero - quite primitive, and not always a very clean clip), or 'na'. Choosing incorrectly will just mean that the frame doesn't get clipped. Default is 'black'.

Details

See focal for details.

Value

A smoothed raster object

Author(s)

Alistair Auffret and Adam Kimberley

References

Auffret, A.G., Kimberley, A., et al., 2017, HistMapR: Rapid digitization of historical maps in R, Methods in Ecology and Evolution, doi: 10.1111/2041-210X.12788., Link. GitHub repository.

Hijmans, R.J. (2023) terra: Spatial Data Analysis. R package version 1.7-29, https://CRAN.R-project.org/package=terra.

Examples

	ras.loc <- system.file("data/in.ras.tiff", package="HistMapR")
	in.ras <- rast(ras.loc)
  set.names(in.ras, c("red","green","blue"))
	ras.smoothed<-smooth_map(in.raster=in.ras, window.size = 5, smooth.function = mean, dark.rm = TRUE, darkValue = 80, clip.frame = FALSE)
	plotRGB(ras.smoothed)	

AGAuffret/HistMapR documentation built on Feb. 23, 2025, 1:11 a.m.