Median filter

This tool performs a median filter on a raster image. Median filters 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. The algorithm operates by calculating the median value (middle value in a sorted list) in a moving window centred on each grid cell. 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. Because it requires sorting the values in the window, a computationally intensive task, the median filter is considerably less efficient than other smoothing filters. This may pose a problem for large images or large neighbourhoods.

Neighbourhood size, or filter size, is determined by the user-defined x and y dimensions. These dimensions should be odd, positive integer values (e.g. 3, 5, 7, 9, etc.) The user may also define the neighbourhood shape as either squared or rounded. A rounded neighbourhood approximates an ellipse; a rounded neighbourhood with equal x and y dimensions approximates a circle.

NoData values in the input image are ignored during filtering. When the neighbourhood around a grid cell extends beyond the edge of the grid, NoData values are assigned to these sites. The output raster is of the float data type and continuous data scale.

See Also:


The following is an example of a Python script that uses this tool:

wd = pluginHost.getWorkingDirectory()
inputFile = wd + "input.dep"
outputFile = wd + "output.dep"
xDim = "3"
yDim = "3"
rounded = "false"
reflectEdges = "true"
args = [inputFile, outputFile, xDim, yDim, rounded, reflectEdges]
pluginHost.runPlugin("FilterMedian", args, False)

This is a Groovy script also using the tool:

def wd = pluginHost.getWorkingDirectory()
def inputFile = wd + "input.dep"
def outputFile = wd + "output.dep"
def xDim = "7"
def yDim = "7"
def rounded = "true"
def reflectEdges = "true"
String[] args = [inputFile, outputFile, xDim, yDim, rounded, reflectEdges]
pluginHost.runPlugin("FilterMedian", args, false)