1 Introduction

Image denoising is an important part of digital image processing. This process effectively removes or reduces the degradations that can creep in while the images are being obtained or transmitted. The impulse noises can be removed by using many different types of non-linear filters [1]. One of the prominent non-linear filters is a median filter. This can be used for the removal of impulse noise since it is having better denoising capability and better computational efficiency. Median filters can be classified as multi-state type [2,3,4] and pattern classification type filters [5,6,7].

Among the pattern classification-type filters, Switching Median Filter (SMF) is widely used in many applications [8]. This filter detects the pixel which is noisy based on the difference between the original noisy image and the output of the median filter. Median filtering is then carried out only for the detected pixel which is noisy. However, due to this median filtering, color distortions may occur.

To overcome the above problem, Vector Median Filter (VMF) which treats the given input signal as a vector which is having RGB components is widely used [9]. A Robust Switch type VMF (RSVMF) is also proposed in recent years [10]. It has high noise removal ability and high resistance to color distortions. But this is not reliable as the details are sometimes over smoothed.

An improved quantized adaptive switching median filter has been proposed for reducing impulse noise in gray-scale digital images [11]. The proposed filter has been implemented using five processing blocks. The experimental results show the median filter occupied low Mean Square Error (MSE) and high Structure Similarity Index (SSIM) for highly corrupted images. The quality of restored images can be measured using Peak Signal to Noise Ratio (PSNR) value, which is not measured in the quantized adaptive switching median filter.

Several researchers have recommended using Artificial intelligence (AI) for reducing impulse noise in digital images. The impulse noise levels in the digital images have been reduced using different approaches like Fuzzy [12,13,14], Artificial Neural Networks (ANN) [15,16,17], Support vector machines (SVMs) [18]. The artificial intelligence method is quite complex, as it takes more parameters for reducing the impulse noise signal which involves more processing time. It requires a large number of input images for the training phase which increases the complexity.

Zhang et al., proposed an adaptive switching median filter based on evidential reasoning for reducing impulse noise signal [19]. An uncertainty that happened in impulse noise detection has been reported using basic belief assignment (BBA) functions. The proposed median filter occupied more noise density and it attained a longer processing time. Therefore, an improved performance median filter is needed for digital images to reduce the impulse noise.

The impulse noise density signal has been removed by the combined filters methods like adaptive vector median filter and weighted mean filter for color images [20]. These filters are applied over noisy and non-noisy pixels in the noise removal process. The proposed filter achieved improved performance in impulse noise density, but it occupied high computational complexity in noise removal procedures. A cluster-based adaptive fuzzy median filter was proposed for reducing impulse noise signals [21]. Directional rank order absolute difference (DROD) method used in the adaptive fuzzy median filter provided effective impulse noise removal. This methodology utilized a smaller number of processing windows, which eventually reduced computation cost but color artifacts might be the problem.

Yan used the L0 norm to explain the sparsity of the impulse noise, but he handled the L0 norm by introducing a binary matrix that represents the set of pixels that are not affected by the impulse noise [22, 23].

The proposed methodology reduces random valued impulse noise without generating color artifacts in the processed image. Also, L2 norm-based distance calculation is employed in the noise detector rather than L1 norm, this improves the PSNR value and TPR and reduces the NMSE, thereby guarantees the efficient denoising strategy. There are two broad classifications of impulse noise [24]. They are Salt and Pepper Noise, and Random Valued Impulse Noise.

The other name for salt and pepper noise is intensity spikes. This can happen while an image is being transmitted. It can also occur due to faulty pixel elements in the sensors of the acquisition device such as a camera. Sometimes it happens due to defective locations in the memory which happens during the digitization process. The two possible values are 0 and 1. These two values have a probability of less than 0.1. For random valued impulse noise intensity level lies between 0 and 255. The entire image has randomly distributed noise. Any intensity level value can occur as noise which has an equal probability as that of the noise.

Mathematical representation of random valued impulse noise is given in Eq. 1.

$$Y_{ij} = \left\{ {\begin{array}{*{20}c} {n_{(i,j)} \;{\text{with}}\;{\text{probability}}\;p} \\ {X_{(i,j)} \;{\text{with}}\;{\text{probability}}\;1 - p} \\ \end{array} } \right.$$
(1)

where Yij represents the image affected by random valued impulse noise, n(i,j) represents the intensity of the noise corrupted pixel, X(i,j) represents the original image, p represents the probability of occurrence of the noise.

Based on the switching threshold, random valued impulse noises will be detected by Switching Median Filter (SMF). The absolute difference between the given input image and the output of the median filter is calculated and if it is greater than the switching threshold, that pixel will be considered as a noisy pixel. If it is not the case, the pixel will not be considered as a noisy pixel.

The input signal is considered as vectors unlike component-wise scalar processing [9]. Linear filtering is combined with the vector median operation. By doing so, the noise attenuation is improvised and filtering is done with appreciable edge response [25].

2 Methodology

To remove the random valued impulse, the switching median filter consists of a noise detector with auto tuning threshold function and a noise remover based on a vector median filter. The noisy pixels are identified by calculating the distance between the original image and the noisy image using L2 norm. The block diagram of the proposed methodology is shown in Fig. 1.

Fig. 1
figure 1

Block diagram of the proposed methodology

This SMF contains a detector which detects the noise and vector median filter which removes the noise. This detects if the particular pixel is noisy or not in each channel independently. Noise detector has a threshold auto-tuning function which is tuned depending on the performance of the filters. Then, VMF removes the particular detected pixel and replaces it.

2.1 Threshold method

The threshold value differs from image to image based on the image resolution, size, and intensity value and so on. The best threshold value cannot be predicted before noise detection in the spatial domain of color image processing. Best threshold value can be found using auto-tuning detector [8]. The threshold value is called the optimum threshold value for color image.

2.2 Noise detector

In the spatial domain process, the noise pixel detection uses a threshold value. Here, noise detection is based on distance distribution between noisy image and median filtered image. The noise pixel can be identified from the distance between two images based on the defined threshold value (\(\omega\)).

The noisy position image \({g}_{k}(i,j)\) is defined as

$$g_{k} \left( {i,j} \right) = \left\{ {\begin{array}{*{20}c} {1,} & {\left| {Y_{k} \left( {i,j} \right) - Y_{k,med} \left( {i,j} \right)} \right| \ge \omega } \\ {0,} & {{\text{otherwise}}} \\ \end{array} } \right.$$
(2)

where YK(i,j) represents the random valued impulse noisy image at the position (i,j), YKmed(i,j) represents the output of the median filter at the position (i,j), \(\omega\) represents the threshold value.

In this proposed detector, the optimum threshold value is calculated as

$${\omega }^{*}=\mathrm{argmin }J\left({P}_{d,\left(\omega \right)},{P}_{u}\right)$$
(3)

where J is a function to calculate the distance of the distribution. \({P}_{d,\left(\omega \right)}\) represents the probability density function of the detected noise with the threshold \(\omega\). \({P}_{u}\) represents the uniform distribution of the random valued impulse noise.

To compute the distance of distribution, we employ L2 norm which is defined as

$${L}_{2}\left({P}_{d\left(\omega \right)}{,P}_{u}\right)=\sqrt{\sum_{m=0}^{255}{\left|{P}_{d\left(\omega \right)}\left(m\right)-{P}_{u}(m)\right|}^{2}}$$
(4)

where \({P}_{d,\left(\omega \right)}(m)\) represents the probability density function of the detected noise with the threshold \(\omega\) for any random m. \({P}_{u}(m)\) represents the uniform distribution in the range of 1/256 for any random m.

If the distributions are same to each other, distance becomes less.

2.3 Noise remover

Pixel interpolation is one of the best methods for image signal power with reducing the occurrence of color artifacts. Noisy pixels are replaced by vector median filtered color image pixel in the noisy color image. The pixel interpolation is processed in Red, Green and Blue channels individually. The pixel interpolation can improve the PSNR value and also reduces the occurrence of color artifacts [26,27,28,29,30].

Here, the corrupted noisy pixel SR(i,j) in the red channel is replaced by VMF output pixel Yvmf,R(i,j). In the same manner, corrupted noisy pixels are removed in green and blue channels. The noise remover is defined by

$${S}_{k }\left(i,j\right)=\left\{\begin{array}{c}{Y}_{\mathrm{VMF},k}\left(i,j\right), {g}_{k}\left(i,j\right)=1\\ { Y}_{k}\left(i,j\right) otherwise\end{array}\right.$$
(5)

where \({S}_{k }\left(i,j\right)\) is the output image of our methodology used in the current study with kth component. \({Y}_{\mathrm{VMF},k}\left(i,j\right)\) represents the vector median filter output. \({Y}_{k}\left(i,j\right)\) represents the random valued impulse noise.

3 Results and discussions

To carry out the simulation, images from the website called FreeImages were utilized [24]. The efficacy and the soundness of the projected method are confirmed by experiments using a test image which is given in Fig. 2.

Fig. 2
figure 2

Noise-free test image

Noise is added to the noise-free image with different noise probabilities such as 0.01, 0.03, 0.05 and 0.1 is added to the noise-free image shown in Fig. 2 and the obtained outputs are compared as shown in Fig. 3.

Fig. 3
figure 3

a, b, c and d are the noisy images with noise probabilities 0.01, 0.03, 0.05 and 0.1 respectively

The outcomes obtained after filtering the above images are as follows:

3.1 Assessment of auto-threshold tuning methodology

3.1.1 Normalized mean square error

The normalized mean square error (NMSE) is calculated to validate the projected methodology. It is carried out for the original noise-free image which is shown in Fig. 2. The restored output image is shown in Fig. 4. Whenever the switching threshold is well tuned, NMSE becomes smaller. Figure 5 shows NMSE attained with altering the threshold of the Switching Median Filter.

Fig. 4
figure 4

a, b, c and d represent restored images with noise probabilities 0.01, 0.03, 0.05 and 0.1 respectively

Fig. 5
figure 5

NMSE obtained between the input image which is noise-free and the output image attained by the detector with changing threshold from 1 to 100

3.1.2 PSNR

The PSNR is frequently used as a measure of the reconstruction quality of noisy images. It should be high for a good quality restored image. PSNR obtained with changing \(\omega\) of the Switching Median Filter is shown in Fig. 6.

Fig. 6
figure 6

PSNR obtained with different thresholds for different noise probability restored images

3.1.3 L 2 Norm

The following Fig. 7 shows the graph between the L2 norm and the threshold.

Fig. 7
figure 7

L2 norm between noisy image and the detected image by varying threshold from 1 to 100

The L2 norm between the presumed noise and the normalized histogram of the noises sensed by the detector with changing threshold is shown in Fig. 7. The minimum L2 norm represents the tuned value of the threshold which can be computed from Fig. 7.

3.1.4 True positive rate (TPR)

In the field of image denoising, TPR is defined as the number of detected noisy pixels to the total number of noisy pixels available in the image. The value of TPR lies between 0 and 1. If the value of the TPR is larger, it indicates the better performance of the proposed algorithm.

The proposed methodology utilizes L2 norm for tuning the threshold of the noise detector. The results have been compared with L1 norm which is employed by Kubota et al., in their research for a similar random valued impulse noise removal problem.

From Table 1, it is understood that L2 norm outperforms L1 norm in terms of NMSE, PSNR and TPR. When L2 norm is used, NMSE gets reduced, PSNR and TPR values get improved as evident from Table 1 for different noise probability values.

Table 1 Comparison of L1 and L2 norm methods

4 Conclusion

A modified SMF has been elucidated in this paper. In this methodology, L2 norm is used to identify the optimal threshold value for auto-tuning the noise detector. It is noted that L2 norm outperforms L1 norm by reducing NMSE and increasing PSNR and TPR for tuning the threshold function. Since NMSE is less and PSNR and TPR are high, this methodology is not affected by color artifacts much. This methodology is simple yet powerful in removing random impulse noise without introducing color artifacts and blurring. The efficiency of this method was illustrated using the experimental results. The feature scope of this research work is to employ nature mimic algorithms such as gray wolf optimization, whale optimization techniques for finding the optimal threshold value for auto-tuning the noise detector in SMF. This may improve the PSNR value and TPR value and decrease the NMSE value.