Skip to contents

This tool performs a median filter on a raster image. Median filters, a type of low-pass filter, can be used to emphasize the longer-range variability in an image, effectively acting to smooth the image. This can be useful for reducing the noise in an image.

Usage

wbw_median_filter(x, filter_size_x = 11L, filter_size_y = 11L, sig_digits = 2L)

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

sig_digits

integer, default 2. Required for rounding of floating points inputs.

Value

WhiteboxRaster object containing filtered values

Details

The algorithm operates by calculating the median value (middle value in a sorted list) in a moving window centred on each grid cell. Specifically, this tool uses the efficient running-median filtering algorithm of Huang et al. (1979). The median value is not influenced by anomolously high or low values in the distribution to the extent that the average is. As such, the median filter is far less sensitive to shot noise in an image than the mean filter.

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.).

References

Huang, T., Yang, G.J.T.G.Y. and Tang, G., 1979. A fast two-dimensional median filtering algorithm. IEEE Transactions on Acoustics, Speech, and Signal Processing, 27(1), pp.13-18.

For more information, see https://www.whiteboxgeo.com/manual/wbw-user-manual/book/tool_help.html#median_filter

Examples

f <- system.file("extdata/dem.tif", package = "wbw")
wbw_read_raster(f) |>
  wbw_median_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.869999                       |
#> | max value   : 360.119995                      |
#> +-----------------------------------------------+