Adaptive Edge Preserving Weighted Mean Filter for Removing Random-Valued Impulse Noise

: This paper proposes an adaptive noise detector and a new weighted mean ﬁlter to remove random-valued impulse noise from the images. Unlike other noise detectors, the proposed detector computes a new and adaptive threshold for each pixel. The detection accuracy is further improved by employing edge identiﬁcation stage to ensure that the edge pixels are not incorrectly detected as noisy pixels. Thus, preserving the edges avoids faulty detection of noise. In the ﬁltering stage, a new weighted mean ﬁlter is designed to ﬁlter only those pixels which are identiﬁed as noisy in the ﬁrst stage. Different from other ﬁlters, the proposed ﬁlter divides the pixels into clusters of noisy and clean pixels and thus takes into only clean pixels to ﬁnd the replacement of the noisy pixel. Simulation results show that the proposed method outperforms state-of-the-art noise detection methods in suppressing random valued impulse noise.


Introduction
For image analysis, de-noising is an important pre-processing step.Digital images are oftentimes corrupted by impulse noise during acquisition, transmission and impaired camera sensors [1], which degrades image features such as edges, sharpness, depth, etc.These degradations can severely hamper the performance of some post-processing steps such as image segmentation, edge detection, feature extraction, target detection, recognition and classification.Therefore, the removal of impulse noise from these images is one of the most fundamental problems in the field of digital image processing.It refers to the removal of noise from corrupted images and the preservation of useful information such as edges and discontinuities.Unlike Gaussian noise, Impulse noise does not corrupt every pixel in the image.It corrupts only certain number of pixels based on noise density.Impulse noise is of two types: Salt & Pepper Noise (SPN) and Random Valued Impulse Noise (RVIN) [2].SPN corrupts image with two fixed extreme Values while RVIN takes any arbitrary value in range [n min , n max ].For 8-bit images, n min = 0 and n max = 255.Therefore, detection of RVIN is much more complex and difficult as compare to SPN [3].For simplicity, let x i,j and c i,j be the intensities of pixels of noisy and original images, respectively.Then, the noise model for RVIN [4] can be described as: x i,j = c i,j , for p = 1 − p 0 , n i,j , for p = p 0 , (1) where n i,j shows gray level of uniformly distributed noise in range [n min ,n max ] while p 0 is the probability of noise.
To suppress impulse noise, different filters have been used.However, most of these filters have a disadvantage of losing some important information such as edges [5].These are simple low pass filters where, for every pixel, some operation is performed on all the neighboring pixels in the predefined window and the result replaces the central pixel.The simplest filter to remove impulse noise is median filter (MF) [6].This filter replaces every pixel in the image by the median value of the given window, irrespective of whether the pixel is noisy or non-noisy.Though MF is computationally simple and less expensive, but as the clean pixels are also replaced by median value of the selected window, this degrades the quality of image, and also produces edge jitters and streaking.Similarly, some patches are also created at higher noise density [7].
To make a trade-off between edges preservation and complexity, multiple variants of MF [8] have been proposed.Some proposed variants are Tri-State Median filter (TSMF) [9], Recursive Weighted Median Filter (RWMF) [10], the Multi-state Median Filter [11] the Central Weighted Median Filter (CWMF) [12], the Rank-Order Mean Filter and the Stack Filter [13].However, these filters still degrade the quality of images as they replace all pixels in the image without considering whether the test pixel is noisy or not [14].To overcome this drawback, several filtering schemes have been developed which are integrated with noise detectors.In these techniques, image de-noising is performed in two stages.In the first stage, the noisy pixels are detected by approximation from neighborhood pixels.In the second stage, only those pixels which are detected as noisy are cleaned while remaining pixels are left unchanged.The performance of detection stage heavily depends on the estimation of proper threshold value.A prior threshold is used by most of the techniques, where the predefined threshold is used throughout the image.Some notable examples of the filtering techniques which use a fixed threshold for noise detection are: adaptive center-weighted median (ACWM) filter [15], the optimal direction median filter [2], the two-pass switching rank-ordered arithmetic mean (TSRAM) [16] filter, Progressive Switching Median Filter (PSMF) [17], Luo-Iterative Median Filter (Luo) [18], Directional Weighted Median (DWM) filter [19], the contrast Enhancement-based Filter (CEF) [20] and robust outlyingness ratio non-local mean (ROR-NLM) [21], etc.The ACWM supresses the RVIN by using the difference between the output of CWM and the current pixel.In CEF, exponential function is used to enlarge the differences, which are then summed to detect the noisy pixels.The DWM only considers pixels along four certain directions to detect noise.Once the noise is detected, the noisy pixel is replaced by weighted median value in the optimal direction.In ROR-NLM [21], the weights of non-local means filter (NLM) [22] were used as noise detectors on initial denoised image.These filters usually perform well at lower noise density.However, at higher noise density, these filters have limited performance in terms of image details and edges preservation.This is because the statistics of the image are not uniform for the whole image, so the threshold value suitable for specific region may not be adapted well to other region in same image.In addition, the threshold value adjusted for a particular image may not work well for other image.
In order to reduce the shortcomings of the fixed threshold scheme, an Adaptive Switching Median Filter (ASWM) [23] was proposed.This filter automatically defines a new threshold for every pixel based on the local standard deviation, and does not require a priori knowledge for the threshold selection.Though this filter provides better detection results, when the noise is not too much high.However, due to random noise, some intensity values of noisy pixels may be very different from other neighbor pixels inside a current sliding window-in which case, the standard deviation of current window is very large, which can result a very large threshold.Thus, the higher standard deviation can cause inaccurate calculation of the local threshold.Secondly, the detected noisy pixel is replaced with simple median value of the whole current window.As the current sliding window also contains noisy pixels, the median value of such noisy window is thus not always accurate.This leads to incorrect replacement of a noisy pixel.Thus, the image details are not preserved.In order to overcome the shortcomings of this technique, we propose an adaptive two staged technique, where, for each pixel processing, a more accurate threshold is calculated.Hence, the main contributions of our proposed technique are: 1.
We propose an adaptive noise detector and a new weighted mean filter to remove random valued impulse noise from the images.

2.
In contrast to other state-of-the-art noise detectors, the proposed detector computes a novel adaptive threshold for each pixel.The accuracy of the detection scheme is further enhanced by employing additional steps to avoid faulty detection of edge pixels, which are noisy pixels.This step indeed ensures the preservation of the edges avoiding faulty detection of noise.

3.
In the filtering stage, a novel weighted mean filter is designed to filter only those pixels which are identified as noisy in the detection stage.In contrast to the existing filtering techniques, the proposed filter first divides the pixels into clusters of clean and noisy pixels.Then, to design the filter, only clean pixels are utilized to find the replacement of the noisy pixel.
Extensive simulation results are presented that show that the proposed RVIN suppression mechanism is superior compared to the state-of-the-art schemes.

Proposed Noise Detection Scheme
In this section, we present the proposed efficient noise detector for the detection of noisy pixels.Before the detection process, window size is adjusted for the whole image.The window size is selected adaptively as it is set automatically based on the noise density.To estimate the noise density, we adopt the idea of the universal threshold [24].In this method, wavelet transform is used to estimate the noise density σ of the noisy signal using Robust Median Estimator as: where HF is the high frequency sub-band.In this technique, the noisy image or signal is divided into sub-bands of low and high frequencies.The edges, sharp details and sudden changes are found in the high frequencies [25].Thus, mostly, the high frequency components contain noise.Therefore, only a high frequency sub-band (HF) is used to estimate the noise of the signal, as illustrated in Equation (2).For example, if σ comes to be 50, the image has 50% noise and so on.The size of the window depends on σ, such that, for low σ, a smaller window is selected, while a larger window is selected for high σ.
Once the window is adjusted, then the detection process starts.Figure 1 illustrates the block diagram of the proposed noise detector.Each block given in Figure 1 is then elaborated with example in the following subsections.

Calculation of Separating Threshold
Once the window size is defined, the first step of the proposed noise detection process is the selection of separating threshold γ s .The algorithm to find separating threshold is illustrated with the help of example in Figure 2 and elaborated in the following steps.

1.
Let x i,j be the pixel under observation at location (i, j) to know whether it is noise or clean, then it is considered as a central pixel.Window of the size found in Equation ( 2) is set around the central pixel.

2.
The corresponding pixel values of of the current window are sorted in ascending order in vector s.The outliers are removed from s by adopting the "three sigma rule" with median absolute deviation (MAD) [21].The MAD for s is found as: Vector s is searched, and, if the difference between any value in s and the median value is greater than 3 × MAD, it is considered as an outlier and is not taken into account for further calculation.
After removal of outliers, let s n be the resultant vector, where n denotes the size of s n .

3.
Compute the absolute difference d k between every two adjacent pixels in s n as: where k = 1, 2, . . ., n − 1.

4.
The separating threshold γ s is found as: where We can observe that the term e 1 σ/100 depends upon the noise density σ.It can be observed that, for lower noise density, this term is large and, for higher noise density, this term is small.This term adjusts the threshold to ensure that clean pixels are not considered noisy pixels at very low noise density.Similarly, it also adjusts the threshold to make sure noisy pixels are not grouped into clean pixels, as this threshold will be used in grouping discussed in the following subsection.

Separation of Pixels into Clusters
Using the separating threshold γ s , in this section, we divide the pixels in the sorted vector s n in groups as follows: 1.
Initialize from the first pixel in sorted vector s n .If the difference between current pixel s i and next pixel s i+1 is less than or equal to γ s , keep the pixel s i+1 in the current group together with s i .2.
However, if the difference is greater than γ s , finish the current group and start a new group, such that the first element of the new group will be s i+1 .Apply the same procedure until the last element of vector s n .

3.
The clean and noisy groups are decided based on the size of the group.The first two largest clusters are considered as clean clusters while all other clusters are considered as noisy and are discarded.The clean clusters are denoted as g 1 and g 2 .Cluster g 1 is used in the detection phase while g 1 and g 2 are used in filtering.

Noise Detection
Using the results of the group stage, in this section, the noise detection stage is presented.The noise detector is: where threshold γ is and g 1 is the largest group discussed in the grouping stage.
Similarly, x i,j is the central pixel and µ is the mean value of g 1 .If the x i,j is detected as noisy, filtering is required to replace the x i,j with the filtered output.On the other hand, if x i,j is a clean pixel, it is left unchanged.

Edge Pixel Identification
In this section, we present a mechanism to avoid the faulty detection of edge pixels as noisy pixels.This step is performed only when the pixel is identified as a noisy pixel.This will make the detection scheme more robust by verification of the noisy pixels to avoid situations where the edge pixel is wrongly considered as a noisy pixel.This process is performed as follows: 1.
Keeping x i,j as a reference pixel, pixels present along four directions are taken into account.These four directions θ A , θ B , θ C and θ D are illustrated in Figure 3.

2.
θ A contains the pixels from the direction θ A excluding x i,j .Similarly, θ B , θ C and θ D contain the pixels from the directions θ B , θ C and θ D , respectively, excluding x i,j .

3.
Find the absolute difference between central pixel x i,j with all pixels along direction θ A .
The difference vector is defined as d A is searched to find the values less than or equal to m. Indexes of pixels corresponding to these values are identified in θ A .These pixels are stacked in vector v.The vector v is considered to be an edge if total number of pixels in v is at least 50% of direction θ A .
Step 4 is only performed if this condition holds true.Otherwise, discard the v and go to step 5.

5.
Take the standard deviation of central pixel x i,j with v.The pixel is identified as an edge if standard deviation of e and x i,j is less than or equal to threshold γ: 6.If x i,j is not identified an edge in direction θ A , then the three other directions θ B , θ C and θ D are checked for an edge identification by applying the five steps above on each direction.
If x i,j is not identified an edge in all four directions, it is considered a noisy pixel and filtering is required to de-noise it.

Illustration
This section illustrates the noise detection of the proposed method with example.Consider the image patch given in Figure 4 that is taken from a 40% noisy "lena" image.The size of the window depends on the noisy density σ such that: To check whether the specified central pixel is noisy, the following steps are performed.

1.
Using Equation ( 2), the noise density of the whole image is calculated.As the noisy density is 40%, therefore, according to Equation (10), the window size is selected 5×5.

2.
Sort all the pixels inside the selected patch in ascending order as Next, the deference between every two consecutive pixels is found to be d = [0 0 0 0 1 0 1 1 0 1 0 14 2].

5.
The average value m of the vector d is equal to 1.4.Putting this value of m in Equation ( 5 Using Equation ( 8), threshold γ becomes 3. Similarly, mean value becomes µ = 66.9.
By employing Equation( 9), any value greater than 69 and less than 63 is considered to be noisy.
In this example, the value of the central pixel is 67; therefore, it is a clean pixel and does not need filtering.In case the pixel comes out to the noisy pixel, then we need filtering to replace the noisy pixel with estimated clean pixel.In the next section, we present the filtering scheme.

Proposed Filtering Scheme
After the detection of the noise, the appropriate filter is required to replace the noisy pixel.For this, we design a novel Weighted Mean Filter (WMF), which is more robust compared to the existing median and mean filters.In a smooth region, the absolute difference among all neighbor pixels is very small and the whole region is flat [26], so, in most cases, only one large clean group is formed.On the other hand, the region that contains the edge is not as flat, in which case more than one cluster is required to replace the noisy pixel.Therefore, in the proposed filtering scheme, the second largest group g 2 is also considered.We remark that the g 2 is not required in detection stage.Instead, there is a separate section for edge detection.The two largest groups are assigned weights based on standard deviation and size of the group.Supposing that x i,j is the noisy pixel at location (i, j), then the filtered pixel xi,j is given as: xi,j = mean{w 1 g 1 , w 2 g 2 }, (11) where is the replication operator [27] that shows the repetition of any term.For example, if w 1 is 2, and w 2 is 1, then g 1 is repeated two times while g 2 is repeated 1 time, such as xi,j = mean{g 1 , g 1 , g 2 }, as the size of g 1 is greater than g 2 .Therefore, to decide the weights, we also consider the standard deviation of both groups.The weights w 1 and w 2 are determined by a ratio R as: where s 1 , s 2 represents the size, while sd 1 and sd 2 represent the standard deviation of g 1 and g 2 , respectively.This relation defines the weights of g 2 with respect to g 1 .As the higher standard deviation means less correlation, it is inversely proportional to the R, while the larger size shows larger priority; therefore, it is in direct relation to R. Based on the value of R, the following weights are assigned in Equation (11).

1.
If the size of g 1 is very large compared to the size of g 2 or R ≤ 0.5, then w 1 = 1, w 2 = 0. 2.
Similarly, when 0.5 ≤ R ≤ 1, the assigned weights are: Finally, for 1 ≤ R ≤ 2, the assigned weights are: The filtering is further improved by only considering the closest neighbor pixels of the central pixel from the selected groups, such that, if there are at least three pixels from the selected groups which are in a 3 × 3 window around the central pixel, then take the mean value of only these closest pixels.

Summary of the Proposed Denoising Scheme
Although the proposed scheme gives good results in single iterations, with second iterations, it gives the best performance and there is no need to apply further iterations as in other iterative methods.The larger threshold value is used in the first iteration while a smaller threshold value is used in the second iteration [2].Therefore, if the threshold in the first iteration is 3×MAD, in the second iteration, the threshold is set to 1.5×MAD.We summarize our proposed technique in Algorithm 1 as: Algorithm 1: Proposed algorithm for random valued impulse noise removal.
Input : The noisy image X, with size of L 1 × L 2 1 Set iteration i=1. 2 Outer loop: for l 1 = 1, ...L 1 , Inner loop: for l 2 = 1, ....L 2 3 Set a sliding window centered at x i,j , the size of window is determined by σ. 4 Divide the window into groups of clean and noisy pixels using separating threshold computed in Equation ( 5).

Experimental Results
To assess the capability the proposed noise removal procedure, in this section, comprehensive numerical results are compared with other state-of-the-art techniques.
In Table 1, the noise detection results of noisy "lena" image with noise densities 40%, 50% and 60% are given.The table lists three results of the noise detection: the number of undetected noisy pixels (False Negative), the number of clean pixels that are falsely detected as noisy (False Positive) and the Total number (False Negative + False Positive).
From Table 1, it is clear that the proposed detection scheme has generated less 'Total' number than all of the above techniques especially at higher noise density.At lower noise density, only ROR-NLM produces a lower total number, but they produce much higher false negative terms, indicating that they miss most of the noisy pixels, and most of noise patches are left unchanged.Thus, the proposed detection technique shows superiority over other detection schemes.It is because a noise detector is considered to be efficient and robust, if it reduces both false positive and false negative numbers.When the noise density increases, the superiority of the proposed method is clear as it generates far less 'Total' terms than all other methods.This means that our technique is more efficient and robust, even at high noise density.

Comparison of Image Restoration
The de-noising performance of the proposed method is tested on different standard images such as Lena, pepper, Bridge, and Boat with different noise densities.All these images are 8-bit gray scale and have the same size of 512 × 512 pixels.It should be noted that the size of the window is defined only once based on the noise density using Equation ( 2), which is used on all pixels of the current image.In our case, for noise density less than 60%, window size of 5 × 5 is used, while window size of 7 × 7 is used otherwise.Peak Signal to Noise Ratio (PSNR) is used as quantitative measurement to compare the proposed method with different well known techniques.The PSNR is defined as: where MSE is mean squared error and is defined as: where O is the original clean image while R is the output restored image.Tables 2 and 3 illustrate comparison of the proposed method with other state-of-the-art methods.Tables 2 and 3 list the PSNR values of different test images that are contaminated by RVIN of noise densities ranges from 40% to 60%.From both tables, it is clear that our method has performed better as compared to all other listed methods in terms of PSNR.Figures 5 and 6 show de-noised results of Lena and Pepper images, respectively.From these figures, it is obvious that TSM, ACWM, PSM and Luo have created artifacts and damaged image details.While DWM, ASWM and ROR-NLM have performed better at lower noise densities, but their performance is degraded at higher noise densities.This is due to the fact that these filters replace the noisy pixel by considering all the window pixels.On the other hand, the proposed method only considers clean pixels to replace the noisy pixel.As the noise density increases, the number of corrupted pixels in the window are also increased, which increases the error when the central noisy pixel is replaced by mean or median value of noisy neighbor pixels.Finally, in Figure 7, we present performance results of different filters in restoring Lena image corrupted by different noise densities.These results confirm the results given in Tables 2  and 3 and clearly show that the proposed method outperforms other state of the art techniques.

Conclusions
In this paper, a new algorithm is presented to remove random valued impulse noise.The proposed approach is based on calculation of new and adaptive thresholds for every pixel.The pixels are divided into noisy and clean clusters.Then, only a clean cluster is used to calculate the threshold.A new edge identification step is proposed to ensure that a clean pixel is not considered as a noisy pixel falsely.If the pixel is identified as noisy, a novel weighted mean filter is designed to filter the noisy pixel.Instead of taking the mean of all pixels in the selected window, the proposed filter considers only

Figure 7 .
Figure 7. Results of different filters in restoring Lena image corrupted by different noise levels.

Table 1 .
Detection comparison of different filters at different noise densities.

Table 2 .
Peak Signal-to-Noise Ratio (dB) values of different filters for Lena and Pepper image corrupted by random valued impulse noise of different noise densities.