Toggle Navigation
Digital Imaging: Imagine the Possibilities
Teledyne Logo

Bob’s Imaging Fundamentals #14: Noise Reduction – The Rank Filter

No, the Rank Filter is not the latest odor busting gizmo at the hardware store. It is in fact a type of noise filter used in image processing. Sometimes called a ‘Median Filter’ the Rank Filter is used to remove a very special kind of noise called ‘salt and pepper’ noise (I’m not making this up!). Salt and pepper noise typically looks like salt and pepper sprinkled all over your image. Let’s take a liberally seasoned Mr. Bug for example:

Although some people consider Salt & Peppered Bug a delicacy, most Machine Vision people prefer their bugs ‘au natural’.

This is one of those techniques in which each pixel an it’s neighbors must be processed in turn. So, let’s take a black pixel and a few of it’s neighbors as an example:

The first thing we do, is sort all the pixels in the neighborhood according to their strength:

Sorted list: 0, 113, 126, 129, *132*, 139, 166, 168, 202

Then, we take the pixel that is right in the middle of the ‘sorted list’ and replace the old ‘object’ pixel with the new ‘middle’ pixel. In other words, the old black pixel takes on the value of *132*.

So why does this work? Well, in the case of salt and pepper noise, the ‘noise-pixels’ have values which are usually much higher or much lower than the surrounding pixel. As a result, they invariably find themselves at the beginning or the end of the list. And, since it is always the middle or ‘median’ value that is used to replace the ‘object’ pixel, extreme valued pixels tend to get dropped. Now, let’s see what happens if we try it on our Salt and Peppered Bug:

There you have it, all the speckles are gone! And, if you look real hard, you may notice a slight difference between the original ‘Mr. Bug’ (top of article) and the ‘After Rank Filter’ version. Can you see it? The filtered version has lost some of its sharpness (if you don’t see it, concentrate on the bug’s spiky nose hairs). Although this is obviously an interesting and powerful tool, it does have one significant disadvantage, the ‘sort’ operation does require more processing than a normal convolution based filter. On the other hand, when it comes to removing salt & pepper from your bugs, the Rank Filter is hard to beat.