Skip to content

salahashraf253/Image-Filtering-using-Alpha-Trim-filter-and-Adaptive-median-filter

Repository files navigation

Image Filter using Alpha trim & Adaptive median filter

Project Demo

Image.Filters.Demo.mp4

Order Statistics Filters

In image processing, filter is usually necessary to perform a high degree of noise reduction in an image before performing higher-level processing steps. The order statistics filter is a non-linear digital filter technique, often used to remove speckle (salt and pepper) noise from images. We target two common filters in this project:

The main idea of both filters is to sort the pixel values in a neighborhood region with certain window size and then chose/calculate the single value from them and places it in the center of the window in a new image, see figure 1. This process is repeated for all pixels in the original image.

1. Alpha-trim filter

2. Adaptive median filter

First: Alpha-trim Filter

The idea is to calculate the average of some neighboring pixels' values after trimming out (excluding) the smallest T pixels and largest T pixels. This can be done by repeating the following steps for each pixel in the image: 1. Store the values of the neighboring pixels in an array. The array is called the window, and it should be odd sized. 2. Sort the values in the window in ascending order. 3. Exclude the first T values (smallest) and the last T values (largest) from the array. 4. Calculate the average of the remaining values as the new pixel value and place it in the center of the window in the new image, see figure 1. This filter is usually used to remove both salt & pepper noise and random noise. See figure 2

Note

  • We work on gray-level images. So, each pixel has a value ranged from 0 to 255. Where 0 is the black pixel and 255 is the white pixel.

Second: Adaptive Median Filter

The idea of the standard median filter is similar to alpha-trim filter but instead we calculate the median of neighboring pixels' values (middle value in the window array after sorting). It's usually used to remove the salt and pepper noise, see figure 3. However, the standard median filter has the following drawbacks:

  1. It fails to remove salt and pepper noise with large percentage (greater than 20%) without causing distortion in the original image.
  2. It usually has a side-effect on the original image especially when it’s applied with large mask size, see figure 2 with window 7×7.
Adaptive median filter is designed to handle these drawbacks by:
  1. Seeking a median value that’s not either salt or pepper noise by increasing the window size until reaching such median.
  2. Replace the noise pixels only. (i.e. if the pixel is not a salt or a pepper, then leave it).

Sample run using alpha-trim filter with window size 5 & trim value 5

Sample run using adaptive median filter with window 9

Algorithms used :

  • Quick Sort
  • Counting Sort
  • Select the Kth element using Modified Bubble Sort
  • Select the Kth element using Max & Min Heap
  • Select the Kth element using Randomized selection