Hubbry Logo
search
logo
1931004

Median filter

logo
Community Hub0 Subscribers
Write something...
Be the first to start a discussion here.
Be the first to start a discussion here.
See all
Median filter

The median filter is a non-linear digital filtering technique, often used to remove noise from an image, signal, and video. Such noise reduction is a typical pre-processing step to improve the results of later processing (for example, edge detection on an image). Median filtering is very widely used in digital image processing because, under certain conditions, it preserves edges while removing noise (but see the discussion below for which kinds of noise), also having applications in signal processing.

The main idea of the median filter is to run through the signal entry by entry, replacing each entry with the median of the entry and its neighboring entries. The idea is very similar to a moving average filter, which replaces each entry with the arithmetic mean of the entry and its neighbors. The pattern of neighbors is called the "window", which slides, entry by entry, over the entire signal. For one-dimensional signals, the most obvious window is just the first few preceding and following entries, whereas for two-dimensional (or higher-dimensional) data, the window must include all entries within a given radius or ellipsoidal or rectangular region (i.e., the median filter is not a separable filter).[citation needed]

To demonstrate, using a window size of three with one entry immediately preceding and following each entry, and zero-padded boundaries, a median filter will be applied to the following simple one-dimensional signal:

This signal has mainly small valued entries, except for one entry that is unusually high and considered to be a noise spike, and the aim is to eliminate it. So, the median filtered output signal y will be:

i.e.,

It is clear that the noise spike has been essentially eliminated (and the signal has also been smoothed a bit). The result of a moving average filter with the same window width on the same dataset would be y = (1.7, 28.3, 29.7, 29.3, 3.7, 1.7). It can be seen that the noise spike has infected neighbouring elements in the moving average signal, and that the median filter has performed much better (for this type of impulse noise). Median filtering works well for both positive impulses (spikes) and negative impulses (dropouts), so long as a window can be chosen so that the number of entries infected with impulse noise is (almost) always smaller than half of the window size.

When implementing a median filter, the boundaries of the signal must be handled with special care, as there are not enough entries to fill an entire window. There are several schemes that have different properties that might be preferred in particular circumstances:

Code for a simple two-dimensional median filter algorithm might look like this:

See all
User Avatar
No comments yet.