1 Introduction

Color images are often corrupted by impulse noise. It brings difficulties to subsequent image processing techniques. Therefore, impulse noise removal is an important procedure in image processing field.

Many filters have been proposed to process impulse noise so far. Generally, nonlinear filters’ effect on images corrupted by impulse noise is better than that of linear filters [1]. Some classical nonlinear filters, such as the median filter (MF) [2] and the vector median filter (VMF) [3], are used to handle impulse noise. In the noise removing stage, three channels of color images are restored independently with MF. In this way, local incongruous color may be produced, and the tone and detail information may be destroyed. However, the VMF takes into account the relationship of the red, green and blue channels by utilizing Euclidean distance and is more suitable for color images. Except for the distance measurement, angular measurement is also introduced in other vector filters like the basic vector directional filter (BVDF) [4] and the directional distance filter (DDF) [5]. The weighted median filter (WMF) [6], center-weighted median filter (CWMF) [7], and center-weighted vector median filter (CWVMF) [8] allot different weights to the pixels, especially larger weight to the central pixel. These weighted filters only are effective when the color images are slightly corrupted.

However, the aforementioned filters are operated on all pixels regardless of whether they are noisy or not, which leads to the loss of details and blur of edges in restored images. Therefore, the switching vector filter (SVF) method for detecting noisy pixels is a two-step algorithm: the first step is to detect the noisy pixels; the second step is to replace the noisy pixels with the output of some robust filters. A statistic theory rank-ordered differences statistic (RODS) is applied to color images [9]. The value of ROD indicates whether the pixel is corrupted or not by comparing it with a predefined threshold. The localized rank-ordered differences vector filter (LRODF) [10] is proposed to be applied to high-density noise that is more stable and effective. However, operations are performed in more windows with this method, which causes the algorithm requiring more time to complete. An adaptive filter (AVMF) [11] based on rank-ordered statistics is proposed. Its detection is made through comparing the central pixel with the average of low-rank pixels. Some improved filters are proposed. Modified switching median filter (MSMF) [12] combines the AVMF with four one-dimensional Laplacian operators to preserve the edges and details. Weights are used in a new filter named adaptive rank-weighted switching filter (RWASF) [13] to achieve better denoising results, but it is not effective at high noise density. A genetic expression programming-based approach is proposed [14]. At the same time, a switching weighted vector median filter (SWVMF) [15] assigns different weights on neighboring pixels by distinguishing whether the neighbors are on edges or not. But the detection method is not yet improved to achieve better performance. The filter based on peer group [16, 17] identifies a group for every pixel, and the average of the group is used to replace the considered pixel’s value. Another kind of difference measurement between two color pixels named quaternion-based distance, instead of Euclidean distance, is widely used [18, 19]. Fuzzy theory is also introduced to remove impulse noise, and these fuzzy-based filters [20, 21] are usually effective but complex. Just recently, a new adaptive switching median filter is proposed that is based on evidential reasoning (ASMF) [22]. The algorithm is considering the extreme property and discontinuity property of impulse noise simultaneously.

As the diversity and complexity of pixels’ values are around edges in color images, there are many noisy pixels which are actually normal pixels in these filters. Therefore, a pixel grouping method based on noise density estimation is introduced. In the proposed method, Laplacian convolution is used in corrupted images and those detected pixels are marked as noise candidates firstly. Next, the pixels grouping method protects the false-detected pixels. Finally, a modified arithmetic mean filter (AMF) is used to process polluted pixels. The experiments show that the method outperforms comparative algorithms in terms of PSNR and SSIM [23].

The rest is organized as follows: In Sect. 2, the detailed flow of the proposed method is described; in Sect. 3, some parameters are chosen and the experimental results are shown; in Sect. 4, the final conclusions are summarized.

2 The proposed method

2.1 Impulse noise model

Color images are often corrupted by impulse noise; thereby, the models are generally divided into two main types: salt-and-pepper noise model and random-value noise model. In this paper, the most common noise can be expressed as follows:

$$\begin{aligned} x_i^{\left( k \right) } =\left\{ {{\begin{array}{l} {o_i^{\left( k \right) } \quad \quad \quad \quad \mathrm{with}~ \mathrm{probability} ~1-p_k } \\ {\left\{ {0-255} \right\} \quad \mathrm{with}~ \mathrm{probability} ~p_k } \\ \end{array} }} \right. \end{aligned}$$
(1)

The polluted color image is represented as x, while the original image is represented as o. Then, k represents the components of three channels of color images varying from 1 to 3. The \(p_k \) and i represent the probability of the noise and the coordinate of the pixel. In this model, every channel of the observation pixel is affected by noise independently. This kind of noise model is mainly used and discussed in this paper.

2.2 Pixels grouping

Detecting impulse-like pixels is to find those which vary greatly in intensity. The most common measurement of intensity difference between vector elements is Euclidean distance, which can be expressed as:

$$\begin{aligned} D_i = \sum \limits _{n=1}^N \left| {|x_i -x_n } \right| |_2 \end{aligned}$$
(2)

The larger the measurement value is, the less similar the current sample with other samples. Natural images are divided into small regions, each of which can be treated as stationary. Considering impulse noise, the noisy pixels are non-stationary, so measurement value of noisy pixels is larger than that of clean pixels.

In observation window, the pixels with large measurement values are more likely corrupted. Prevision of noise density p can separate pixels into normal group and noisy group:

$$\begin{aligned} N_{\mathrm{norm}} = \mathrm{round}\left( {N-N\times p} \right) \end{aligned}$$
(3)

\(N_{\mathrm{norm}}\) is the number of normal pixels in the observation window. Noise density is estimated in a small-sample group difficultly, so the population is utilized to estimate the noise density. An impulse noise estimator [24] for gray-value images based on image histogram is introduced, which is used in every channel of corrupted images separately, and we can get three estimated noise densities denoted by \(p_{1}, p_{2}\) and \(p_{3}\). According to noise model, the actual noise density P can be described as follows:

$$\begin{aligned} P=1-\left( {1-p_1 } \right) \left( {1-p_2 } \right) \left( {1-p_3 } \right) \end{aligned}$$
(4)

Since the corrupted pixels’ ratio varies around the noise density P, the size of normal group is smaller than average value of \(N_{\mathrm{norm}} \). The size of normal group fits the noise density linearly. When the noise density increases, the normal group’s size becomes smaller.

This grouping method can be used to correct some falsely detected cases in the stage of detecting impulse noise.

2.3 Two-stage detector

The grouping method based on noise density estimation distinguishes normal pixels from noisy ones. Laplacian convolution is sensitive to edges in different directions to improve the accuracy. It is essential to put emphasis on surrounding pixels from the same edge with the current pixel. Weights are assigned to pixels on the same line, with the central one weighting 4 and others weighting − 1. Laplacian convolution in 5 \(*\) 5 window is shown in Fig. 1.

Fig. 1
figure 1

Weights in Laplacian convolution

For the central pixel, there are four directions where pixels form a straight line in every channel. So after computing samples on one direction, the weight positions are changed, rotating the weights line 45 degrees to the right every time. The detection is expressed as follows:

$$\begin{aligned}&L^{\left( k \right) }\left( m \right) =x_0^{\left( k \right) } \times 4-x_1^{\left( k \right) } \left( m \right) -x_2^{\left( k \right) }\left( m \right) -x_3^{\left( k \right) } \left( m \right) \nonumber \\&\qquad -x_4^{\left( k \right) } \left( m \right) \hbox {} \end{aligned}$$
(5)

where \(x_0^{\left( k \right) } \) represents the component of the central pixel and \(x_1^{\left( k \right) }\), \(x_2^{\left( k \right) }\), \(x_3^{\left( k \right) }\), \(x_4^{\left( k \right) } \) represent neighboring pixels on the same direction. The m can be set from 1 to 4, representing different directions, and k from 1 to 3 represents different channels. Finally, four results are obtained in every channel, and these results will be applied to the next judgment:

$$\begin{aligned} \left\{ {{\begin{array}{l} {Lm^{\left( k \right) }=\min \left\{ {L^{\left( k \right) }\left( 1 \right) ,L^{\left( k \right) }\left( 2 \right) ,L^{\left( k \right) }\left( 3 \right) ,L^{\left( k \right) }\left( 4 \right) } \right\} } \\ \\ {Lf=\max \left\{ {Lm^{\left( 1 \right) },Lm^{\left( 2 \right) },Lm^{\left( 3 \right) }} \right\} } \\ \end{array} }} \right. \end{aligned}$$
(6)

From Eq. (6), firstly, a minimum is selected from the four difference values in every channel, and the edges can be protected since the differences among pixels on the same edge are the smallest. Then, the largest value of the former three results compares with threshold \(L_T \) because pixels are marked as noise as long as one channel is polluted. When Lf is larger than the threshold \(L_T \), the central pixel is marked as impulse noise candidate.

As the noise density increases, the value of the similarity measurement will be larger. These cases are more likely to happen where pixels on the same edge with the central pixel are mostly corrupted. For many filters [10,11,12], it is possible to regard normal pixels as noisy ones falsely.

In the previously mentioned condition, Laplacian convolution is also possible to make false detection, especially at the edges. For making detection more accurate, pixels which are not on the four directions in the observation window should be considered. Due to impulse noise model, there are statistical differences between the corrupted pixels and normal pixels. The former grouping method can be utilized to correct these error-detecting cases.

Fig. 2
figure 2

Flow of the modified AMF

Fig. 3
figure 3

PSNR of four images with impulse noise. a \(P=0.1\), b \(P=0.2\), c \(P=0.3\)

According to the grouping method, we get some results denoted by \(D_i \) (\(i=1, 2, 3 \ldots \hbox {N}\)). After sorting \(D_i \) into order by value, we can obtain some new results:\(D_1^{\prime } \le D_2^{\prime } \le D_3^{\prime } \le \ldots \le D_N^{\prime } \). The larger the sum of Euclidean distances is, the more likely the corresponding pixel is noisy. For judging the current pixel, a parameter Td representing normal group’s size is introduced. The pixels whose sum of Euclidean distances is in the range of the lowest Td values are thought to be not corrupted.

Considering the computational complexity of large window, a \(3\times 3\) sub-window is recommended. The parameter Td is the boundary between noisy pixels and normal pixels. The higher the noise density is, the smaller the Td is. Therefore, the linearly fitting relationship between the noise density and Td can be shown as:

$$\begin{aligned} {Td}=\hbox {round}\left( {a-P\times b} \right) \end{aligned}$$
(7)

The coefficients a and b are not equal to N for achieving optimal filtering results. Because N is the average value of the coefficient in all windows, the actual coefficients are varying around it. These changed coefficients make Td smaller than the average value of \(N_{\mathrm{norm}} \). More selection of coefficients is illustrated in the next.

If the sum of Euclidean distances of the central pixel is larger than Td other measurements, it is considered to be polluted and will be filtered. In image denoising, a modified AMF is proposed to restore the corrupted images. The average value of the Td most likely noise-free pixels is used to replace the central one to get a more robust result. The overall flow of the method is shown in Fig. 2:

3 Experimental results and analysis

The proposed method is evaluated by images: Lena, House, Pepper and so on. The criteria are used: peak-signal-to-noise ratio (PSNR) and structural similarity (SSIM). The mathematical expressions are shown as follows:

$$\begin{aligned} \hbox {PSNR}= & {} 20\log _{10} \left( {\frac{255}{\sqrt{\mathrm{MSE}}}} \right) \end{aligned}$$
(8)
$$\begin{aligned} \hbox {SSIM}\left( {{x},{y}} \right)= & {} \frac{\left( {2\mu _x \mu _y +c_1 } \right) \left( {2\sigma _{xy} +c_2 } \right) }{\left( {\mu _x^2 +\mu _y^2 +c_1 } \right) \left( {\sigma _x^2 +\sigma _y^2 +c_2 } \right) } \end{aligned}$$
(9)

In the SSIM expression, x and y represent two images. \(\mu \), \(\sigma \), \(\sigma ^{2}\) are the average value, covariance and variance, respectively.

3.1 Parameter selection

There are two parameters (PSNR and SSIM) being determined for getting optimal filtering results. The effect of PSNR is analyzed according to test images: “airplane” of size \(512 \times 512\), “sailboat” of size \(512 \times 512\), “house” of size \(256 \times 256\) and “pens” of size \(512 \times 480\). From Fig. 3, P represent the noise density. Some values of \(L_T \) with the same Td are used to choose the optimal \(L_T \). Most optimal results of the test pictures are achieved with \(L_T \) value 65 and 80. We set the threshold \(L_T \) as 75 and apply the parameter Td in the next experiments. There is a premise that the parameter Td denotes the rough average number of clean pixels in the observation window. Under this condition, the optimal value of Td varies with the noise density. The values of Td and PSNR are shown in Fig. 4. It can be concluded that the optimal value of Td is smaller when the noise density is higher.

The specific optimal values of Td with different noise densities are shown in Fig. 5. The straight line in the figure is drawn to approach these discrete spots. The parameter Td should be integer, so the value in different noise densities on the straight line is rounded. The equation can be expressed as:

(10)

Iteration framework is often used in impulse noise removal process since some noisy pixels are often missed in the first noise removing filter.

Fig. 4
figure 4

PSNR of four images with impulse noise. a Airplane, b sailboat, c house, d pens

Fig. 5
figure 5

Relation between Td and P

Fig. 6
figure 6

a Original image, b corrupted image by impulse noise with 0.6 noise density, c AVMF, d MSMF, e LRODF, f RWASF, g the proposed method

3.2 Comparison with other methods

To evaluate the efficiency of the proposed method, some state-of-the-art filters aimed at impulse noise are implemented. AVMF, MSMF, LRODF, and RWASF are selected to compare with the proposed method in terms of PSNR. The “Lena” of size \(512 \times 512\) and “peppers” of size \(512 \times 512\) are tested, and Figs. 6 and 7 show that the proposed method outperforms other filters both in image quality and in details losing. More detailed experimental results based on “boats” of size \(787\times 576\), “flower” of size \(512 \times 480\), “Lena” and “peppers” are shown in Table 1. For each performance measure, the optimal noise removal method indices are highlighted in boldface for the test images with different noise densities. Meanwhile, VMF, CWVMF, and SWVMF based on “Lena” and “Peppers” are selected to compare with the proposed method in terms of SSIM that is shown in Table 2. It can be seen in Tables 1 and 2 that the proposed method achieves higher value of PSNR and SSIM than the other methods in any noise density. It means that the quality of proposed filter is well and it has a better performance on detail preservation. Furthermore, to obtain statistical performance, we test our proposed filter in TID2008 [25] benchmark database which has 25 original color images. The average value of PSNR and SSIM results with different noise densities is listed in Table 3.

Fig. 7
figure 7

a Original image, b corrupted image by impulse noise with 0.5 noise density, c AVMF, d MSMF, e LRODF, f RWASF, g the proposed method

Table 1 Comparison of different filters in PSNR
Table 2 Comparison of different filters in SSIM
Table 3 SSIM and PSNR results of TID2008
Table 4 Statistics of the computational complexity

3.3 Computational cost

As is known, the computational cost is vital for a algorithm. Experiments were performed on a standard with a 2.3GHz Intel i5-6300U CPU and an 8G RAM. The software platform was MATALB R2014a. The time cost consumed by our filter for measuring of \(512*512\) color images (Lena image) is 53.68 ms. In addition to this, the computational number of the image (\(P=0.1\)) is shown in Table 4.

4 Conclusions

In this paper, a new switching filter combining two judgments for impulse noise removal for color images is proposed. A similarity measurement value based on Laplacian convolution is computed to find pixels whose values of similarity difference with neighboring pixels are significantly large. Then, a pixel grouping method is applied to distinguish the noisy pixels and normal pixels. False detection around edges and details can be reduced with the grouping method. The corrupted pixel is replaced by the average of normal pixels in the modified AMF. Extensive experiments show that the method achieves better performance.