A two-stage filter for removing salt-and-pepper noise using noise detector based on characteristic difference parameter and adaptive directional mean filter

In this paper, a two-stage filter for removing salt-and-pepper noise using noise detector based on characteristic difference parameter and adaptive directional mean filter is proposed. The first stage firstly detects the noise corrupted pixels by combining characteristic difference parameter and gray level extreme, then develops an improved adaptive median filter to firstly restore them. The second stage introduces a restoration scheme to further restore the noise corrupted pixels, which firstly divides them into two types and then applies different restoration skills for the pixels based on the classification result. One type of pixels is restored by the mean filter and the other type of pixels is restored by the proposed adaptive directional mean filter. The new filter firstly adaptively selects the optimal filtering window and direction template, then replaces the gray level of noise corrupted pixel by the mean value of pixels on the optimal template. Experimental results show that the proposed filter outperforms many existing main filters in terms of noise suppression and detail preservation.


Introduction
Digital images can be corrupted by impulse noise due to bit errors in the process of image acquisition and transmission [1][2][3]. Salt-and-pepper noise and random-valued noise are the two common types of impulse noise [4]. The salt-and-pepper noise can corrupt an image where each corrupted pixel takes either the maximum or minimum gray level. The salt-and-pepper noise can not only significantly deteriorate the quality of an image, but also bring some difficulty to the subsequent image analysis such as image segmentation [5], edge detection [6] and classification [7,8]. The goal of image denoising is removing noise as much as possible meanwhile preserving more edges and details. Hence, how to effectively remove the salt-and-pepper noise from corrupted images, keeps to be an important research task in image processing.
During the past several decades, many techniques have been developed to restore the corrupted image, such as the blind denoising method [9,10] and total-variation denoising a1111111111 a1111111111 a1111111111 a1111111111 a1111111111 the local window, then employs the ratios of these three groups to weight the non-extreme pixels, finally replaces the gray level of central pixel by the weighted gray level. The adaptive Type-2 fuzzy (ATF) approach [31] is proposed to remove salt-and-pepper noise which identifies the pixels based on their primary membership function values and then restores the noise corrupted pixels based on the detection results.
After deeply analyzing the performance of the existing main filters appeared in the literatures, we can find two disadvantages of their denoising schemes. One disadvantage is that most of them fail to perform well in the case of various noise densities. The other one is that although they can remove the salt-and-pepper noise from the image corrupted by high noise density, they still lead some important edges and details to be blurred. For more details, you can check the corresponding experimental results in section 3. In order to overcome the drawbacks, we propose a new two-stage filter for removing salt-and-pepper noise using noise detector based on characteristic difference parameter and adaptive directional mean filter in this paper. The proposed filter can effectively and accurately identify the noise corrupted pixels by combining the characteristic difference parameter and gray level extreme. After noise detection, the noise corrupted pixels are firstly restored by the improved adaptive median filter while the noise-free pixels are left unchanged to maintain image features. The second restoration scheme can achieve the better restoration result by proposing the adaptive directional mean filter. Compared with the above introduced filters, the proposed filter can not only effectively and accurately detect the salt-and-pepper noise, but also provide better image restoration performance in the case of various noise densities.
The other parts of this paper are organized as follows. In Section 2, we introduce the proposed method framework. Section 3 provides a number of experimental results to demonstrate the performance of the new method. Conclusions are finally drawn in Section 4.

The proposed filter
The proposed filter is composed of two stages: primary filtering stage and second restoration stage. The primary filtering stage firstly detects the noise corrupted pixels by combining the characteristic difference parameter and gray level extreme and then restores them by the improved adaptive median filter. In order to achieve the better restoration result, the second stage introduces a restoration scheme to secondly restore the gray levels of noise corrupted pixels. The restoration scheme firstly divides all the noise corrupted pixels into two types based on the value of characteristic difference parameter and then applies two different restoration skills for the pixels based on the classification result. And one type of pixels is secondly restored by the mean filter while the other type of pixels is secondly restored by the proposed adaptive directional mean filter. Fig 1 is the flow chart of the proposed filter.

Noise detection.
In an image corrupted by salt-and-pepper noise, the gray level of noise corrupted pixel takes either the maximum or minimum gray level. Hence, the traditional switching median filter identifies the pixel with the maximum or minimum gray level as a noise corrupted pixel. However, the pixels with gray level extreme are not all the noise corrupted pixels. Therefore, the noise detector based on the judgement of gray level extreme cannot accurately detect the noise corrupted pixels. In order to achieve the better detection result, the proposed filter designs an improved noise detector by combining the characteristic difference parameter and gray level extreme.
Before introducing the characteristic difference parameter, the gray level difference is firstly introduced to compare the gray levels of two pixels. For any one pixel P i,j in a corrupted image, the gray level difference G k between the pixel P i,j and its neighborhood pixel P s k ;t k is calculated as follows: where (s k , t k ) 2 O, O denotes a detection window whose radius is w. g i,j and g s k ;t k denote the gray level of pixel P i,j and P s k ;t k , respectively. After that, a parameter T is selected as the threshold to judge the value of gray level difference. Considering that the parameter has a close relation with the corrupted image, the value of the parameter is varying based on various images. And in the proposed filter, the parameter is selected based on the statistical result for the gray levels of all pixels in the corrupted image. Besides, the size of the detection window is a key factor of affection on noise detection performance. The size of the detection window should be small in the case of low noise density but be large in the case of high noise density. Hence, the detection windows with different sizes are used for the corrupted image. After a number of experiments, it can be seen that the sizes of 3 × 3 and 5 × 5 are suitable while the noise density is lower than 50%; while the noise density locates between 60% and 80%, size of 7 × 7 is usually the best choice, and the size of 9 × 9 is suitable for the 90% noise density. Then the gray level difference between central pixel P i,j and its neighborhood pixel P s k ;t k can be judged by comparing the values of G k and T as follows: 1. If G k > T, it means that the gray level difference between pixel P i,j and P s k ;t k is large.
2. If G k � T, it means that the gray level difference between pixel P i,j and P s k ;t k is small. Based on the above analysis, it can be judged that whether the gray level difference between central pixel and each neighborhood pixel in the detection window is large. However, the comprehensive gray level difference between central pixel and all neighborhood pixels in the detection window cannot be obtained. Hence, a characteristic difference parameter is introduced to solve the problem. For any one pixel P i,j in the corrupted image, its characteristic difference parameter C i,j is calculated as follows: 1. According to formula (1), calculate the gray level difference G k between central pixel P i,j and its neighborhood pixel P s k ;t k in the detection window one by one.
2. Compare the values of gray level difference G k and threshold T, if G k > T, the characteristic difference parameter The characteristic difference parameter can reflect the comprehensive gray level difference between the central pixel and its neighborhood pixels in the detection window, which can be used to judge that whether the central pixel is a noise corrupted pixel. The detailed analysis is given as follows: 1. If pixel P i,j is an edge pixel, the gray level of pixel P i,j is close to the gray levels of its neighborhood pixels on the edge direction but different from the gray levels of other neighborhood pixels in the detection window. Then the gray level difference between central pixel and its neighborhood pixel on the edge direction is small and less than the value of threshold T. But the gray level difference between central pixel and other neighborhood pixels is large and greater than the value of threshold T. Since the number of neighborhood pixels on the edge direction is less than the number of other neighborhood pixels, the characteristic difference parameter C i,j is large. However, considering that the number of neighborhood pixels on the edge direction is at least 2w, the characteristic difference parameter C i,j is less than or equal to 2w(2w + 1).
2. If pixel P i,j is a noise-free pixel in a flat region, the gray levels of all pixels in the detection window are close. Then the gray level difference between central pixel and each neighborhood pixel is much small and less than the value of threshold T. Hence, the value of characteristic difference parameter C i,j is small and less than 2w(2w + 1).
3. If the central pixel P i,j is a noise corrupted pixel located on an edge, the gray level of pixel P i,j is much different from the gray levels of its neighborhood pixels in the detection window while the gray levels of pixels on the edge direction are close. But the gray level difference between central pixel and each neighborhood pixel is large and greater than the value of threshold T. Hence, the characteristic difference parameter C i,j is large and greater than 2w(2w + 1).
4. If pixel P i,j is a noise corrupted pixel in a flat region, the gray level of pixel P i,j is much different from the gray levels of its neighborhood pixels in the detection window while the gray levels of its neighborhood pixels are close. Then the gray level difference between central pixel and each neighborhood pixel is large and greater than the value of threshold T. Hence, the characteristic difference parameter C i,j is large and greater than 2w(2w + 1).
From the above analysis, it can be learned that the characteristic difference parameter can be used to distinguish noise corrupted pixels from noise-free ones in a corrupted image. And the threshold is selected to judge the value of characteristic difference parameter. The value of the threshold to is equal to the number of all the pixels except for the pixels on the diagonal in the detection window. Then the proposed filter can effectively and accurately detect the noise corrupted pixels by combining characteristic difference parameter and gray level extreme. And for any one pixel P i,j , its characteristic can be identified in the following way: where N and S denote the noise corrupted pixels and noise-free ones, respectively. w is the radius of the detection window. g i,j is the gray level of pixel P i,j .
The pseudo codes of the process of noise detection are provided as follows: For each pixel P i,j in the corrupted image:

First noise restoration.
After noise detection, an improved adaptive median filter is introduced to firstly restore the gray levels of the noise corrupted pixels. And for each noise corrupted pixel, its gray level is replaced by the mean value of the gray levels of its neighboring pixels in the adaptive window. However, the noise-free ones are left unchanged to maintain the features of the original image. The primary filtering process is given as follows: 1. For any one pixel p i,j in the corrupted image, select a detection window of suitable size with a small radius w and set the maximum radius of the detection window to be w max . , which are the maximum value, minimum value and median value among the gray levels of the pixels in the detection window, respectively.

Compare
, then go to the step 5) and calculate the characteristic difference parameter C i,j ; Otherwise, w = w + 1.
4. If w � w max , go to the step 2); Otherwise, the restoration gray level of the pixel g 1 i;j ¼ S med i;j ðw max Þ, and stop.
Þ and C i,j > 2w(2w + 1), the pixel p i,j is corrupted, and the restoration gray level of the pixel g 1 i;j ¼ S med i;j ðwÞ; Otherwise, the pixel p i,j is uncorrupted, g 1 i;j ¼ g i;j , and stop.
On this basis, according to the result of noise detection the primary restoration gray level g 1 i;j of the pixel p i,j is calculated as follows: where imadpmed() denotes the improved adaptive median filter.

Second restoration stage 2.2.1 Noise classification.
Since the improved adaptive median filter cannot restore the corrupted image well in the case of high noise density, the second stage introduces a restoration scheme to secondly restore the gray levels of noise corrupted pixels. Considering that the characteristic difference parameter can reflect the comprehensive gray level difference between each pixel and its neighborhood pixels in a local window, then before the second restoration, the restoration scheme firstly divides all the noise corrupted pixels into two types based on the value of characteristic difference parameter in a 3 × 3 window. And then according to the classification result two different restoration skills are used to secondly restore the noise corrupted pixels. Besides, the gray levels of noise-free pixels are still left unchanged to maintain image features.
Refer to the calculation process of the characteristic difference parameter in the previous section, for the noise corrupted pixel p i,j , its characteristic difference parameter C 3 i;j in the 3 × 3 window O 3 centered at the position (i,j) is calculated as follows: 1. According to the formula (1), calculate the gray level difference G 3 k between central pixel p i,j and its neighborhood pixel p s k ;t k in the window O 3 one by one.

Compare the values of gray level difference
Since the radius of the 3 × 3 window is 1, the threshold for characteristic difference parameter C 3 i;j is selected to be 6. Then based on the value of characteristic difference parameter C 3 i;j , the comprehensive gray level difference between the noise corrupted pixel p i,j and its neighborhood pixels after primary filtering is judged as follows: i;j � 6, it means that after primary filtering the gray level of noise corrupted pixel p i,j is not much different from the gray levels of its neighborhood pixels.

If C 3
i;j > 6, it means that after primary filtering the gray level of noise corrupted pixel p i,j is much different from the gray levels of its neighborhood pixels.
According to the above judgement process, the comprehensive gray level differences between each noise corrupted pixel and all the neighborhood pixels in the 3 × 3 window can be judged. And based on the judgement result, all the noise corrupted pixels after primary filtering can be divided into two types. Among all the noise corrupted pixels, the noise corrupted pixels whose characteristic difference parameters in the 3 × 3 window are greater than 6 belong to one type and the rest of the noise corrupted pixels belong to the other type.

Second noise restoration.
Based on the above noise classification result, two different restoration skills will be applied for the noise corrupted pixels. The noise corrupted pixels, whose characteristic difference parameters in the the 3 × 3 window are greater than 6, are secondly restored by the proposed adaptive directional mean filter. And the rest of the noise corrupted pixels are secondly restored by the mean filter in the 3 × 3 window. Then for any one pixel p i,j , its second restoration gray level g 2 i;j is calculated according to the following different situations: where mean 3 () denotes the mean filter with the filtering window of size 3 × 3. adpdir() is the proposed adaptive directional mean filter. The adaptive directional mean filter is developed to restore the gray levels of noise corrupted pixels based on the multi-directional image information. Firstly, the proposed filter designs four direction filtering templates in the filtering windows with different size, then adaptively selects the optimal filtering window and direction template according to the characteristics of pixels in the neighborhood, finally replaces the gray level of each noise corrupted pixel by the mean value of the gray levels of pixels on the optimal direction template. The detailed process of the adaptive directional mean filter is given as follows: Step 1: Establish a filtering window of size 3 × 3 as shown in Fig 2(A) and design four direction templates as shown in Fig 2(B).
At first, it should be judged that whether the optimal direction template can be selected from the four direction templates in the 3 × 3 filtering window. And the judgement condition is that all the pixels except for the central pixel on each direction template are noise-free pixels or second restored pixels. Considering that the filtering order of the denoising method are from left to right and from top to bottom, pixels P 1 , P 2 , P 3 , P 4 are noise-free pixels or second restored pixels. Then, only if all the pixels P 6 , P 7 , P 8 , P 9 are noise-free pixels, the optimal direction template can be selected from the four templates in the 3 × 3 filtering window. Otherwise, the size of the filtering window need to be further enlarged as shown in the next step. The selection process of the optimal direction template is as follows: 1. Calculate the absolute gray level difference a l of the pixels on every direction template E l except for the central pixel as follows: where l(1 � l � 4) is the direction index, g l s 1 ;t 1 and g l s 2 ;t 2 denote the gray levels of the pixels at the position (s 1 , t 1 ) and (s 2 , t 2 ) of the filtering template E l , respectively.
2. Identify the minimum gray level difference a l � among the four absolute gray level differences as follows: 3. Select the direction template with the minimum gray level difference as the optimal one, and denote it as E l � .
After selecting the optimal direction template, the noise-free pixels and the second restored pixels on the optimal direction template are selected to restore the gray level of the central pixel. And in this step, two pixels on the optimal direction template are selected to restore the gray level of the central pixel. Then the second restoration gray level g 2 i;j is the mean gray level of the two pixels on the optimal direction template and it is calculated as follows: where g l � s 1 ;t 1 and g l � s 2 ;t 2 denote the gray levels of the pixels at the position (s 1 , t 1 ) and (s 2 , t 2 ) of the optimal direction template E l � , respectively.
Besides, if the pixels P 6 , P 7 , P 8 , P 9 are not all noise-free pixels, the optimal direction template cannot be selected from the four templates in the 3 × 3 window and the next step will be performed.
Step 2: Enlarge the size of filtering window to be 5 × 5 as shown in Fig 3(A) and design four direction templates as shown in Fig 3(B).
Similar to the previous step, it should be judged that whether the optimal direction template can be selected from the four templates in the 5 × 5 filtering window. And the judgement condition is that except for the central pixel, there are at least two noise-free pixels or second restored pixels on each direction template. In other words, only if all the direction filtering template meet the condition, the optimal direction template can be selected from the four templates in the 5 × 5 filtering window. Otherwise, the size of filtering window need to be further enlarged as shown in the final step. From the previous step, it is known that the pixels P 1 , P 2 , P 3 , P 4 are noise-free pixels or second restored pixels. Therefore, the characteristics of other pixels P 6 , P 7 , P 8 , P 9 , P 10 , P 11 , P 12 , P 13 will be identified. And the first direction template as shown in Fig 3(B) is taken as an example to introduce the judgement process of pixels on the direction template as follows: 1. The pixel P 9 is firstly identified whether it is a noise-free pixel. If it is a noise-free pixel, pixel P 1 and pixel P 9 will be selected as the pixels on the direction template. Instead, if it is a noise corrupted pixel, the characteristic of pixel P 13 will be judged.
2. If the pixel P 13 is a noise-free pixel, pixel P 1 and pixel P 13 will be selected as the pixels on the direction template. Otherwise, if it is a noise corrupted pixel, the size of filtering window need to be further enlarged to be 7 × 7.
After judging the first direction template, the other three direction templates shown in Fig  3(B) will be judged that whether they can meet the condition. For all the four direction templates, if no need to enlarge the size of filtering window appears, the filtering window of size 5 × 5 can be used to restore the gray level of the central noise corrupted pixel. And similar to the step 1, the same selection process for the optimal direction template will be performed. Similarly, in this step two pixels are selected to restore the gray level of the central pixel. And according to the same calculated process as the step 1, the gray level of the central pixel will be replaced by the mean gray level of the selected pixels on the optimal direction template. Instead, if the optimal direction template cannot be selected from the four direction templates in the 5 × 5 filtering window, the final step will be performed.
Step 3: Further enlarge the size of filtering window to be 7 × 7 and design four direction templates as shown in Fig 4. From Fig 4, it can be seen that there are more pixels in every direction template in the 7 × 7 filtering window than the above two filtering windows. Hence, the filtering window will not be further enlarged up to now and the optimal direction template will be selected from the four direction templates as follows: 1. Identify all the noise-free and second corrected pixels on every direction template E l .
2. For each direction template E l , identify all the noise-free pixels and second restored pixels and then select the pixel with the maximum gray level g l max and the pixel with the minimum gray level g l min among all the noise-free pixels and second restored pixels. 3. Calculate the absolute gray level difference a l of g l max and g l min on every direction template as follows: where l(1 � l � 4) is the direction index.
4. Identify the minimum gray level difference a l � among the four absolute gray level differences by the following formula: 5. Select the direction template with the minimum gray level difference as the optimal one, and denote it as E l � .
Similar to the above steps, after selecting the optimal direction template the noise-free pixels and the second restored pixels on the optimal direction template are selected to restore the gray level of the central pixel. And the gray level of the central pixel will be replaced by the mean gray level of the selected pixels on the optimal direction template. Then the second restoration gray level g 2 i;j of the central pixel is calculated according to the following formula: where g l � s k ;t k denotes the selected pixel on the optimal direction template. The value of n is equal to the number of the selected pixels.

Experimental results
In order to demonstrate the effectiveness of the proposed filter, the proposed filter is firstly compared with five representative denoising methods include the switching median (SM) filter [20], the directional weighted median (DWM) filter [26], the modified directional weighted median (MDWM) filter [27], the modified directional weighted (MDW) filter [28] and the three-values-weighted (TVW) filter [30]. Three typical gray level images with different image features include Lena, Boat and Zelda are selected as the test images. The performance of image restoration results is quantitatively evaluated by two measures, namely, PSNR (peak signal-to-noise ratio) [32] and MSSIM (mean structural similarity) [33]. The higher the value of PSNR is, the better the quality of the restored image is. PSNR can be expressed as where MAX is the maximum gray level of an image and its value is 255 for a gray level image. The MSE denotes the mean square error between the original noise-free image and the restored image, which can be calculated by where s i,j andŝ i;j denote the original pixel and the restored pixel, respectively. M and N are the sizes of an image for the width and the height.
MSSIM reflects the structural similarity between the restored image and the original noisefree image. The higher value of MSSIM means that the structures in the restored image can be preserved more completely. MSSIM is defined as where x and y denote the original noise-free image and the restored image, respectively. W is the number of local windows in the image. The SSIM denote the structural similarity between the original noise-free image and the restored image which is given by where μ x and μ y are the means of the input image and the restored image, respectively. σ xy is the covariance of the input image and the restored image. s 2 x and s 2 y are the variances of the input image and the restored image, respectively. C 1 and C 2 are the constants which can be calculated according to the paper [24]. Table 1 presents the performance comparisons for the different filters in terms of PSNR value for the test images. It can be seen that in the case of low noise corruption (noise density less than 30%), all the filters can perform well. In the case of medium noise corruption, such as 40%-70% noise density, the MDWM, MDW, TVW filters and the proposed filter reveal the superior denoising performance then the SM and DWM filters. As to the cases of heavy noise corruptions (noise density higher than 80%), the TVW filter and the proposed filter achieve the better results than the SM, DWM, MDWM and MDW filters. And compared to other filters, the proposed filter can obtain the higher value of PSNR in the cases of various noise densities. Hence, Table 1 indicates that the proposed filter is able to more effectively remove saltand-pepper noise than other compared filters.
The performance comparisons for the different filters in terms of MSSIM value for the test images are shown in Table 2. One can observe that the MSSIM values of the restoration results of the SM and DWM filters are significantly less than the MDWM, MDW, TVW filters and the proposed filter in the case of various noise densities. It means that the MDWM, MDW, TVW filters and the proposed filter have stronger capability than the SM and DWM filters for preserving image structures. Besides, in the case of higher noise density, the TVW filter and the proposed filter can achieve the larger values of MSSIM than the MDWM and MDW filters. This indicates that the TVW filter and the proposed filter can preserve image structures better than the MDWM and MDW filters at heavy noise density. In addition, the proposed filter achieves the largest value of MSSIM among the different filters in the case of various noise densities. In other words, the structures in the restoration results of the proposed filter can be preserved more completely than other compared filters.
Tables 3 and 4 present the quantitative comparisons for the various filters in terms of the average PSNR value and the average MSSIM value for the three test images, respectively. According to Table 3, one can observe that the MDWM, MDW, TVW filters and the proposed filter achieve the larger average PSNR value than the SM and DWM filters in the cases of various noise densities. In the heavy noise corruption, the TVW filter and the proposed filter can perform better than the MDWM and MDW filters. And the proposed filter usually obtains the largest average PSNR value. From the quantitative comparisons as shown in Table 4, we can obtain the similar conclusions. Hence, the proposed filter can achieves the larger average values of PSNR and MSSIM than other filters which can indicate that the proposed filter outperforms than the other filters in image denoising and detail preservation.
In order to explore the visual quality of the various filters, we show the restored images in the case of different noise density. Figs 5, 6 and 7 show the restoration results of various filters for the Lena, Boat and Zelda images, respectively. And the test images are corrupted by saltand-pepper noise with 50% noise density. One can observe that the AM and DWM filters obtain the worst image restoration effect. Although they can remove the salt-and-pepper noise from the corrupted images, they still suffer from the blurred effect for the edges and details in the restored images. The MDWM, MDW, TVW filters and the proposed filter can efficiently remove the noise and be free from the blurred effect in the restored images. Besides, the TVW filter and the proposed filter achieve the better visual effect than other filters, because they can preserve more edges and contain less noise in the restoration images. Figs 8,9 and 10 show the restoration results of various filters for the test images which are corrupted by salt-and-pepper noise with 80% noise density. It can be found that the SM and DWM filters fail to restore the heavy noise corrupted image. The restored images of MDWM filter suffer from a great quantity of blurred effects for edges and details. Although the DWM filter can restore image edges and details from the noise corrupted image, plenty of residual noise still exists in the restored images. The TVW filter and the proposed filter can distinguish the contours of the test images, but the TVW filter still has a few white noise and black noise in the restored images. Therefore, the above restoration results clearly indicate that the proposed    In order to further demonstrate the effectiveness of the proposed filter, the proposed filter is compared with some state-of-the-art filters for noise removal as the adaptive weighted mean (AWM) filter [22], the adaptive decision based kriging interpolation (ADKI) filter [23], the adaptive iterative fuzzy (AIF) filter [29] and the adaptive Type-2 fuzzy (ATF) filter [31]. Table 5 presents the performance comparisons for the different filters in terms of PSNR for Lena image. It can be seen that the proposed filter can obtain the higher value of PSNR than AWM filter in the case of different noise density. Compared with the AIF and ATF filters, the proposed filter can achieve the higher value of PSNR in the case of heavy noise corruption (noise density higher than 80%). Although the ADKI filter can obtain the higher value of PSNR than the proposed filter in the case of different noise density, the operating conditions of the ADKI filter are stricter than the proposed filter. Hence, Table 5 shows that the proposed filter can perform better than some state-of-the-art filters. Table 6 presents the performance comparisons of the proposed filter in error rate for the test images. It can be seen that the error rate of the proposed filter increases with the noise density. However, in the case of low noise corruption (noise density less than 30%), the error rate of the proposed filter does not exceed 30. And in the case of medium noise corruption, such as 40%-70% noise density, the error rate of the proposed filter is less than 65. As to the cases of heavy noise corruptions (noise density higher than 80%), the error rate of the proposed filter is less than 85. Therefore, Table 6 indicates that the proposed filter is able to effectively and accurately detect the salt-and-pepper noise.

Conclusion
A new two-stage filter for removing salt-and-pepper noise using noise detector based on characteristic difference parameter and adaptive directional mean filter is proposed in this paper. There are three main contributions of the proposed filter. The first one is that the proposed filter introduces the noise detector based on the characteristic difference parameter and gray level extreme to effectively and accurately identify the noise corrupted pixels. The second one is that the proposed filter introduces a restoration scheme to secondly restore the noise corrupted pixels after primary filtering by two different restoration skills. The third one is that a new adaptive directional mean filter is developed in the restoration scheme which can effectively remove noise in the case of various noise densities meanwhile preserve some important edges and details especially at the high noise density. Experimental results on a series of images with varying noise densities show that the proposed method can perform better than many other existing main filters in terms of image denoising and detail preservation.