This tool performs a k-nearest mean filter on a raster image. A mean filter can be used to emphasize the longer-range variability in an image, effectively acting to smooth or blur the image. This can be useful for reducing the noise in an image. The algorithm operates by calculating the average of a specified number (k) values in a moving window centred on each grid cell. The k values used in the average are those cells in the window with the nearest intensity values to that of the centre cell. As such, this is a type of edge-preserving smoothing filter. The bilateral_filter and edge_preserving_mean_filter are examples of more sophisticated edge-preserving smoothing filters.
Neighbourhood size, or filter size, is specified in the x and y dimensions using the filterx
and filtery
flags. These dimensions should be odd, positive integer values (e.g. 3, 5, 7, 9, etc.).
NoData values in the input image are ignored during filtering.
mean_filter, bilateral_filter, edge_preserving_mean_filter
def k_nearest_mean_filter(self, raster: Raster, filter_size_x: int = 3, filter_size_y: int = 3, k: int = 5) -> Raster: ...