xdem.filters

Filters to remove outliers and reduce noise in DEMs.

Functions

distance_filter

xdem.filters.distance_filter(array, radius, outlier_threshold)[source]

Filter out pixels whose value is distant more than a set threshold from the average value of all neighbor pixels within a given radius. Filtered pixels are set to NaN.

TO DO: Add an option on how the “average” value should be calculated, i.e. using a Gaussian, median etc filter.

Parameters
  • array (ndarray) – the input array to be filtered.

  • radius (float) – the radius in which the average value is calculated (for Gaussian filter, this is sigma).

  • outlier_threshold (float) – the minimum difference abs(array - mean) for a pixel to be considered an outlier.

Return type

ndarray

Returns

the filtered array (same shape as input)

gaussian_filter_cv

xdem.filters.gaussian_filter_cv(array, sigma)[source]

Apply a Gaussian filter to a raster that may contain NaNs, using OpenCV’s implementation. Arguments are for now hard-coded to be identical to scipy.

N.B: kernel_size is set automatically based on sigma

Parameters
  • array (ndarray) – the input array to be filtered.

  • sigma – the sigma of the Gaussian kernel

Return type

ndarray

Returns

the filtered array (same shape as input)

gaussian_filter_scipy

xdem.filters.gaussian_filter_scipy(array, sigma)[source]

Apply a Gaussian filter to a raster that may contain NaNs, using scipy’s implementation. gaussian_filter_cv is recommended as it is usually faster, but this depends on the value of sigma.

N.B: kernel_size is set automatically based on sigma.

Parameters
  • array (ndarray) – the input array to be filtered.

  • sigma (float) – the sigma of the Gaussian kernel

Return type

ndarray

Returns

the filtered array (same shape as input)