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, pad = TRUE, padValue = NA)

Arguments

in.raster

The raster 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.

pad

Logical. Pad the raster to avoid shrinkage. Default is TRUE. See focal for details.

padValue

Value to pad the raster with. Default = NA.

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. (2016) raster: Geographic Data Analysis and Modeling. R package version 2.5-8, http://CRAN.R-project.org/package=raster.

Examples

	data(HistMapRex)
	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, pad = TRUE, padValue = NA)
	plotRGB(ras.smoothed)	

AGAuffret/HistMapR documentation built on July 20, 2023, 2:43 a.m.