Skip to contents

This tool performs a conservative smoothing filter on a raster image. A conservative smoothing filter can be used to remove short-range variability in an image, effectively acting to smooth the image. It is particularly useful for eliminating local spikes and reducing the noise in an image.

Usage

wbw_conservative_smoothing_filter(x, filter_size_x = 3L, filter_size_y = 3L)

Arguments

x

Raster object of class WhiteboxRaster. See wbw_read_raster() for more details.

filter_size_x

integer, X dimension of the neighbourhood size

filter_size_y

integer, Y dimension of the neighbourhood size

Value

WhiteboxRaster object containing filtered values

Details

The algorithm operates by calculating the minimum and maximum neighbouring values surrounding a grid cell. If the cell at the centre of the kernel is greater than the calculated maximum value, it is replaced with the maximum value in the output image. Similarly, if the cell value at the kernel centre is less than the neighbouring minimum value, the corresponding grid cell in the output image is replaced with the minimum value.

Neighbourhood size, or filter size, is specified in the x and y dimensions using filter_size_x and filter_size_y These dimensions should be odd, positive integer values (e.g. 3L, 5L, 7L, 9L, etc.).

Examples

f <- system.file("extdata/dem.tif", package = "wbw")
wbw_read_raster(f) |>
  wbw_conservative_smoothing_filter(filter_size_x = 3L, filter_size_y = 3L)
#> +-----------------------------------------------+ 
#> | WhiteboxRaster                                |
#> | dem.tif                                       |
#> |...............................................| 
#> | bands       : 1                               |
#> | dimensions  : 726, 800  (nrow, ncol)          |
#> | resolution  : 5.002392, 5.000243  (x, y)      |
#> | EPSG        : 2193  (Linear_Meter)            |
#> | extent      : 1925449 1929446 5582091 5585717 |
#> | min value   : 63.808151                       |
#> | max value   : 360.846832                      |
#> +-----------------------------------------------+