dem_filtering {lidaRtRee}R Documentation

Image pre-processing (non-linear filtering and Gaussian smoothing)

Description

applies two filters to an image:

  1. A non-linear filter: closing (mclosing) with disk kernel, or median (medianblur) with square kernel

  2. A 2D Gaussian smoother (The deriche filter is applied on both dimensions). Value-dependent smoothing is possible

Usage

dem_filtering(
  dem,
  nl_filter = "Closing",
  nl_size = 5,
  sigma = 0.3,
  padding = TRUE,
  sigmap = NULL
)

Arguments

dem

cimg object (e.g. obtained with as.cimg) or SpatRaster object (e.g. obtained with rast)

nl_filter

string. type of non-linear filter to apply: "None", "Closing" or "Median"

nl_size

numeric. kernel width in pixels for non-linear filtering

sigma

numeric or matrix. If a single number is provided, sigma is the standard deviation of the Gaussian filter, 0 corresponds to no smoothing. Unit is pixel in case dem is a cimg object, SpatRaster units otherwise. In case of a matrix, the first column corresponds to the standard deviation of the filter, and the second to thresholds for image values (e.g. a filter of standard deviation specified in line i is applied to pixels in image which values are between thresholds indicated in lines i and i+1). Threshold values should be ordered in increasing order.

padding

boolean. Whether image should be padded by duplicating edge values before filtering to avoid border effects

sigmap

deprecated (numeric or matrix). (old name for sigma parameter, retained for backward compatibility, overwrites sigma if provided, unit is pixel whatever the class of dem)

Value

A list of two cimg objects or a SpatRaster object with image after non-linear filter and image after both filters

See Also

maxima_detection, filters of imager package: mclosing, medianblur, deriche

Examples

data(chm_chablais3)
chm_chablais3 <- terra::rast(chm_chablais3)

# filtering with median and Gaussian smoothing
im <- dem_filtering(chm_chablais3, nl_filter = "Median", nl_size = 3, sigma = 0.8)

# filtering with median filter and value-dependent Gaussian smoothing
# (less smoothing for values between 0 and 15)
im2 <- dem_filtering(chm_chablais3,
  nl_filter = "Median", nl_size = 3,
  sigma = cbind(c(0.2, 0.8), c(0, 15))
)

# plot original image
terra::plot(chm_chablais3, main = "Initial image")

# plot image after median filter
terra::plot(im$non_linear_image, main = "Median filter")

# plot image after median and Gaussian filters
terra::plot(im$smoothed_image, main = "Smoothed image")

# plot image after median and value-dependent Gaussian filters
terra::plot(im2$smoothed_image, main = "Value-dependent smoothing")

[Package lidaRtRee version 4.0.5 Index]