Program to remove speckle (salt and pepper) noise from images. Two common filters in this are implemented in this project:
-
Alpha-trim filter
-
Adaptive median filter
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
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:
-
Store the values of the neighboring pixels in an array. The array is called the window, and it should be odd sized.
-
Sort the values in the window in ascending order.
-
Exclude the first T values (smallest) and the last T values (largest) from the array.
-
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.
This filter is usually used to remove both salt & pepper noise and random noise.
Alpha-trim filter implemented with TWO different algorithms:
-
Counting Sort
-
Selecting Kth smallest element in the array without sorting it (Textbook sec. 9.2). where K = T to exclude the smallest T values, then on the remaining array, apply the algorithm again to exclude the largest T values. Finally, calculate the average of the remaining values
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.
However, the standard median filter has the following drawbacks:
-
It fails to remove salt and pepper noise with large percentage (greater than 20%) without causing distortion in the original image.
-
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:
-
Seeking a median value that’s not either salt or pepper noise by increasing the window size until reaching such median.
-
Replace the noise pixels only. (i.e. if the pixel is not a salt or a pepper, then leave it).
Adaptive median filter implemented with TWO different algorithms:
-
Quick Sort
-
Counting Sort
-
Display two graphs to show the execution time against different window sizes (3, 5, 7,… Wmax), where Wmax is user input:
-
One graph for alpha-trim filter to compare its two methods (counting & selecting kth element)
-
Another graph for adaptive median filter to compare its two methods (quick & counting).
-