Lib4U

‎"Behind every stack of books there is a flood of knowledge."

Median Filter

bri2

Brief Description

The median filter is normally used to reduce noise in an image, somewhat like the mean filter. However, it often does a better job than the mean filter of preserving useful detail in the image.

How It Works

Like the mean filter, the median filter considers each pixel in the image in turn and looks at its nearby neighbors to decide whether or not it is representative of its surroundings. Instead of simply replacing the pixel value with the mean of neighboring pixel values, it replaces it with the median of those values. The median is calculated by first sorting all the pixel values from the surrounding neighborhood into numerical order and then replacing the pixel being considered with the middle pixel value. (If the neighborhood under consideration contains an even number of pixels, the average of the two middle pixel values is used.) Figure 1 illustrates an example calculation.

Figure 1 Calculating the median value of a pixel neighborhood. As can be seen, the central pixel value of 150 is rather unrepresentative of the surrounding pixels and is replaced with the median value: 124. A 3×3 square neighborhood is used here — larger neighborhoods will produce more severe smoothing.

Guidelines for Use

By calculating the median value of a neighborhood rather than the mean filter, the median filter has two main advantages over the mean filter:

  • The median is a more robust average than the mean and so a single very unrepresentative pixel in a neighborhood will not affect the median value significantly.
  • Since the median value must actually be the value of one of the pixels in the neighborhood, the median filter does not create new unrealistic pixel values when the filter straddles an edge. For this reason the median filter is much better at preserving sharp edges than the mean filter.

The image

fce5noi4

shows an image that has been corrupted by Gaussian noise with mean 0 and standard deviation (Eqn:eqnsigma) 8. The original image is

fce5

for comparison. Applying a 3×3 median filter produces

fce5med2

Note how the noise has been reduced at the expense of a slight degradation in image quality. The image

fce5noi5

has been corrupted by even more noise (Gaussian noise with mean 0 and Eqn:eqnsigma 13), and

fce5med3

is the result of 3×3 median filtering. The median filter is sometimes not as subjectively good at dealing with large amounts of Gaussian noise as the mean filter.

Where median filtering really comes into its own is when the noise produces extreme `outlier’ pixel values, as for instance in

fce5noi3

which has been corrupted with `salt and pepper’ noisei.e. bits have been flipped with probability 1%. Median filtering this with a 3×3 neighborhood produces

fce5med1

in which the noise has been entirely eliminated with almost no degradation to the underlying image. Compare this with the similar test on the mean filter.

Consider another example wherein the original image

sta2

has been corrupted with higher levels (i.e. p=5% that a bit is flipped) of salt and pepper noise

sta2noi1

After smoothing with a 3×3 filter, most of the noise has been eliminated

sta2med1

If we smooth the noisy image with a larger median filter, e.g. 7×7, all the noisy pixels disappear, as shown in

sta2med2

Note that the image is beginning to look a bit `blotchy’, as graylevel regions are mapped together. Alternatively, we can pass a 3×3 median filter over the image three times in order to remove all the noise with less loss of detail

sta2med3

In general, the median filter allows a great deal of high spatial frequency detail to pass while remaining very effective at removing noise on images where less than half of the pixels in a smoothing neighborhood have been effected. (As a consequence of this, median filtering can be less effective at removing noise from images corrupted with Gaussian noise.)

One of the major problems with the median filter is that it is relatively expensive and complex to compute. To find the median it is necessary to sort all the values in the neighborhood into numerical order and this is relatively slow, even with fast sorting algorithms such as quicksort. The basic algorithm can, however,be enhanced somewhat for speed. A common technique is to notice that when the neighborhood window is slid across the image, many of the pixels in the window are the same from one step to the next, and the relative ordering of these with each other will obviously not have changed. Clever algorithms make use of this to improve performance.

Interactive Experimentation

You can interactively experiment with this operator by clicking here.

Exercises

  1. Using the image

    bri2

    explore the effect of median filtering with different neighborhood sizes.

  2. Compare the relative speed of mean and median filters using the same sized neighborhood and image. How does the performance of each scale with size of image and size of neighborhood?
  3. Unlike the mean filter, the median filter is non-linear. This means that for two images A(x) and B(x):

    Eqn:eqnmed1

    Illustrate this to yourself by performing smoothing and pixel addition (in the order indicated on each side of the above equation!) to a set of test images. Carry out this experiment on some simple images,e.g.

    stp1

    and

    stp2

References

R. Boyle and R. Thomas Computer Vision: A First Course, Blackwell Scientific Publications, 1988, pp 32 – 34.

E. Davies Machine Vision: Theory, Algorithms and Practicalities, Academic Press, 1990, Chap. 3.

A. Marion An Introduction to Image Processing, Chapman and Hall, 1991, p 274.

D. Vernon Machine Vision, Prentice-Hall, 1991, Chap. 4.

Source:

http://homepages.inf.ed.ac.uk/rbf/HIPR2/median.htm

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Virtual Fashion Technology

Virtual Fashion Education

toitocuaanhem

"chúng tôi chỉ là tôi tớ của anh em, vì Đức Kitô" (2Cr 4,5b)

VentureBeat

News About Tech, Money and Innovation

digitalerr0r

Modern art using the GPU

Theme Showcase

Find the perfect theme for your blog.

lsuvietnam

Learn to Learn

Gocomay's Blog

Con tằm đến thác vẫn còn vương tơ

Toán cho Vật lý

Khoa Vật lý, Đại học Sư phạm Tp.HCM - ĐT :(08)-38352020 - 109

Maths 4 Physics & more...

Blog Toán Cao Cấp (M4Ps)

Bucket List Publications

Indulge- Travel, Adventure, & New Experiences

Lib4U

‎"Behind every stack of books there is a flood of knowledge."

The WordPress.com Blog

The latest news on WordPress.com and the WordPress community.

%d bloggers like this: