Skip to contents

This tool calculates the percentile of the center cell in a moving filter window applied to an input image (x). This indicates the value below which a given percentage of the neighbouring values in within the filter fall. For example, the 35th percentile is the value below which 35% of the neighbouring values in the filter window may be found. As such, the percentile of a pixel value is indicative of the relative location of the site within the statistical distribution of values contained within a filter window.

When applied to input digital elevation models, percentile is a measure of local topographic position, or elevation residual.

Usage

wbw_percentile_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

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

This tool takes advantage of the redundancy between overlapping, neighbouring filters to enhance computationally efficiency, using a method similar to Huang et al. (1979). This efficient method of calculating percentiles requires rounding of floating-point inputs, and therefore the user must specify the number of significant digits (sig_digits) to be used during the processing.

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#percentile_filter

Examples

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