I want to know about median filtering. Recently, I read that it is best for preserving edges. But how does it preserve edges?
I need complete knowledge of median filters. Why it is non-linear filter and why it is best, compared to linear filter?
I want to know about median filtering. Recently, I read that it is best for preserving edges. But how does it preserve edges?
I need complete knowledge of median filters. Why it is non-linear filter and why it is best, compared to linear filter?
Non-linearity
A linear filter is mathematically described by the convolution sum (for discrete signals) and the convolution integral for continuous signals. The median cannot be found using a linear function except in the trivial case where you have a discrete filter of size 1, which is why the median filter is non-linear.
Edge Preserving Properties.
Median filtering is one kind of smoothing technique, as is linear Gaussian filtering. All smoothing techniques are effective at removing noise in smooth patches or smooth regions of a signal, but adversely affect edges. Often though, at the same time as reducing the noise in a signal, it is important to preserve the edges. Edges are of critical importance to the visual appearance of images, for example. For small to moderate levels of (Gaussian) noise, the median filter is demonstrably better than Gaussian blur at removing noise whilst preserving edges for a given, fixed window size. However, its performance is not that much better than Gaussian blur for high levels of noise, whereas, for speckle noise and salt and pepper noise (impulsive noise), it is particularly effective. Because of this, median filtering is very widely used in digital image processing.
Source: Wikipedia
A median filter changes the value of one given pixel by the median value (or a weighted version) of a patch of pixels (most often around the given pixel). Generally, the patch contains an odd number of pixels: $\pm K$ above and below, left and right, with a total of $(2K+1)^2$.
I will details three basic scenarios:
It is non-linear, since the median of $(0,1,2)$ is $1$, the median of $(3,1,1)$ is $1$, but the median of $(0,1,2)+(3,1,1)$ is $3$, and not $1+1$.
So it can be better than linear filters, but this depends on the nature of edges, noise properties and patch size. Others sources on SE.DSP: