← Image Processing for EveryoneToolsInVisionLearning Center
Neighborhood Filters · Lesson 32

Median and Edge-Preserving Choices

A few isolated bright specks appear over a clean metal surface.

Watch the lesson

Median and Edge-Preserving Choices explained visually

1:25

A few isolated bright specks appear over a clean metal surface. English captions are optional and start off. The complete transcript follows the written lesson.

Lesson overview

What you will learn

A few isolated bright specks appear over a clean metal surface.

  1. A practical question
  2. The useful idea
  3. Work through the example
  4. Limits and next step
01

A practical question

A few isolated white specks appear on the metal surface. One speck has intensity two hundred and fifty, while nearby values are ten and eleven. An average would be dragged upward by that extreme value. A median filter asks a different question: what is the middle value after sorting the neighborhood? For ten, eleven, and two hundred and fifty, the answer is eleven.

02

The useful idea

That makes the median useful for some isolated outliers. It is not a weighted sum like the averaging kernel from our earlier example. Try it on a copy of the part and compare the specks before and after. Then inspect a genuinely thin scratch or narrow line. The filter can change a small real feature as well as unwanted noise.

03

Work through the example

If the noise is more like broad grain than isolated specks, another filter may be a better choice. We should choose from the observed noise pattern and test against the detail the inspection must retain. Keep the neighborhood size, the original image, and a few difficult cases for comparison.

04

Limits and next step

Our filters have changed the pixel values. Now we'll measure where those values change sharply across the image by looking at horizontal and vertical gradients.

Worked example

For neighboring values 10, 11, and 250, the median is 11.

Knowledge check

Quick check: test your understanding

Try it yourself: In the situation described above, explain the method and one reason its output might be misleading.

Check the reasoning

A median filter chooses the middle neighborhood value, unlike a weighted average. It is useful for some outliers, but it can alter narrow real structures too.

What is the main idea behind median and edge-preserving choices?

A median filter chooses the middle neighborhood value, unlike a weighted average.

How is it used in the example?

For neighboring values 10, 11, and 250, the median is 11.

What limitation should be checked?

It is useful for some outliers, but it can alter narrow real structures too.

Further reading

Digital Image Processing, 4th edition — Rafael C. Gonzalez and Richard E. Woods.

Original ToolsInVision teaching examples. Editorial approach · Suggest a correction

Accessible referenceLesson 32 transcript197 words · Video transcript · Matches the published narration and captionsOpen transcript

A few isolated white specks appear on the metal surface. One speck has intensity two hundred and fifty, while nearby values are ten and eleven. An average would be dragged upward by that extreme value. A median filter asks a different question: what is the middle value after sorting the neighborhood? For ten, eleven, and two hundred and fifty, the answer is eleven.

That makes the median useful for some isolated outliers. It is not a weighted sum like the averaging kernel from our earlier example. Try it on a copy of the part and compare the specks before and after. Then inspect a genuinely thin scratch or narrow line. The filter can change a small real feature as well as unwanted noise.

If the noise is more like broad grain than isolated specks, another filter may be a better choice. We should choose from the observed noise pattern and test against the detail the inspection must retain. Keep the neighborhood size, the original image, and a few difficult cases for comparison.

Our filters have changed the pixel values. Now we'll measure where those values change sharply across the image by looking at horizontal and vertical gradients.