Median filter

../../_images/airplane_sap25.png ../../_images/airplane_sap25_med3_it2.png

Description

The median filter is well known for its ability to greatly reduce salt & pepper noise without too much altering the contours of the elements present in the scene.

Salt & pepper noise is characterized by either black or white pixels. The example in the left image above is a salt & pepper noise corrupted image at 25%, ie. a quarter of the pixels are either black or white. The image on the right shows the result obtained by two passes of a 3x3 median filter.

The median operator used to denoise an image applies to each pixel, on a square window with side k centered on the pixel. The corresponding pixel value in the output image is the median of the pixel values ​​in the window.

../../_images/median-principe.png

Several methods allow to select the median of a set of values; They are based on one of the following principles

  • sorting the values, then selecting the value located in the middle

  • the generation of the histogram, then the counting of the values

Implementing a median filter

One main source code is provided. It includes, in a certain mess, the functions for loading and saving .pgm images as well as all the ecosystem allowing to measure and configure the execution of GPU kernels.

One kernel skeleton is also provided.

One Makefile allows to easly compile the source code.

Experiences and measurements

  • Download then compile the provided codes. The produced executable is called fkern and expects a path to a .pgm image as its command line argument. Here is one at download.

  • Edit the kernel skeleton so that it performs a median filter of size 3x3.

  • Measure its performance on the provided .pgm image.

  • Try to implement other techniques and compare their respective performances.