Median filter
From Wikipedia, the free encyclopedia
|
Image:Median filter example.jpg
Example of 3 median filters of varying radii applied to the same noisy photograph. Implemented in Adobe Photoshop.
In image processing it is usually necessary to perform high degree of noise reduction in an image before performing higher-level processing steps, such as edge detection. The median filter is a non-linear digital filtering technique, often used to remove noise from images or other signals. The idea is to examine a sample of the input and decide if it is representative of the signal. This is performed using a window consisting of an odd number of samples. The values in the window are sorted into numerical order; the median value, the sample in the center of the window, is selected as the output. The oldest sample is discarded, a new sample acquired, and the calculation repeats. Median filtering is a common step in image processing. It is particularly useful to reduce speckle noise and salt and pepper noise. Its edge-preserving nature makes it useful in cases where edge blurring is undesirable.
Exampleto demonstrate the median filter will be applied to the following array with a window size of 3, repeating edge values: x = [2 80 6 3] y[1] = Median[2 2 80] = 2 so where y is the median filtered output of x Common problemsA common problem with all filters based on all adjacent pixels is how to process the edges of the image. As the filter nears the edges, a median filter may not preserve its odd number of samples criteria. It is also more complex to write a filter that includes a method to specifically deal with the edges. Common solutions to the problem are:
Pseudo codeA simple median filter may look like this:
edgex := (window width / 2) rounded down
edgey := (window height / 2) rounded down
for x from edgex to image width - edgex:
for y from edgey to image height - edgey:
colorArray[window width][window height];
for fx from 0 to window width:
for fy from 0 to window height:
colorArray[fx][fy] := pixelvalue[x + fx - edgex][y + fy - edgey]
Sort colorArray[][];
pixelValue[x][y] := colorArray[window width / 2][window height / 2];
Notice that:
See alsoExternal linksImage:Arithmetic symbols.svg This applied mathematics-related article is a stub. You can help Wikipedia by expanding it.
eo:Vikipedio:Projekto matematiko/Mediana filtrilo ru:Медианный фильтрde:Medianfilter |


