A new approach for SPN removal: nearest value based mean filter

In this study, a new adaptive filter is proposed to eliminate salt and pepper noise (SPN). The basis of the proposed method consists of two-stages. (1) Changing the noisy pixel value with the closest pixel value or assigning their average to the noisy pixel in case there is more than one pixel with the same distance; (2) the updating of the calculated noisy pixel values with the average filter by correlating them with the noise ratio. The method developed was named as Nearest Value Based Mean Filter (NVBMF), because of using the pixel value which the closest distance in the first stage. Results obtained with the proposed method: it has been compared with the results obtained with the Adaptive Frequency Median Filter, Adaptive Riesz Mean Filter, Improved Adaptive Weighted Mean Filter, Adaptive Switching Weight Mean Filter, Adaptive Weighted Mean Filter, Different Applied Median Filter, Iterative Mean Filter, Two-Stage Filter, Multistage Selective Convolution Filter, Different Adaptive Modified Riesz Mean Filter, Stationary Framelet Transform Based Filter and A New Type Adaptive Median Filter methods. In the comparison phase, nine different noise levels were applied to the original images. Denoised images were compared using Peak Signal-to-Noise Ratio, Image Enhancement Factor, and Structural Similarity Index Map image quality metrics. Comparisons were made using three separate image datasets and Cameraman, Airplane images. NVBMF achieved the best result in 52 out of 84 comparisons for PSNR, best in 47 out of 84 comparisons for SSIM, and best in 36 out of 84 comparisons for IEF. In addition, values nearly to the best result were obtained in comparisons where the best result could not be reached. The results obtained show that the NVBMF can be used as an effective method in denoising SPN.


INTRODUCTION
Image processing is one of the most studied areas in recent years. Development of computer technologies: It allows to increase the processing speed and therefore to perform complex operations with large data sizes. Images have large data sizes and carry a lot of information. For this reason, nowadays, subjects such as feature extraction, object detection, object tracking, image classification, pattern recognition are intensively studied in addition to classical image processing (image processing for visual purposes, image compression, etc.).

PROPOSED DENOISING METHOD Definitions and notions
This paper, let f x; y ð Þ ¼ ½f ij mÂn be an original image, f 0 x; y ð Þ ¼ ½f 0 ij mÂn restored image, y x; y ð Þ ¼ ½y ij mÂn 3 th stage result image, g x; y ð Þ ¼ ½g ij mÂn salt and pepper noisy image, and g 0 x; y ð Þ g x; y ð Þ mod 255 ð Þhence only pepper noisy image in g 0 x; y ð Þ ¼ ½g 0 ij mÂn in m Â n sizes. Definition 1. In the gray level images, the smallest value (c min ) is 0, and the largest value (c max ) is 255. SPN (salt and pepper noisy) and PN (pepper noisy) models with the same noise levels as follows: g ij ¼ c min ; with probability p c max ; with probability q f ij ; with probability 1 À p þ q ð Þ 8 < : Definition 2. NL is noisy levels. Noise level is the ratio of the number of zeros to the total number of pixels in g 0 ij . Z ij binary matrix in m Â n sizes.
Definition 3. S ij w ð Þ be a image window in ½g 0 ij mÂn . It is size of 11Â11 with central pixel coordinates (i,j). The pixel value with the smallest Euclidean distance or average of pixels with the same smalest Euclidean distance (npv).
Definition 4. b Mean ij w ð Þ be a image window in ½y ij mÂn . It is size of 3Â3 with central pixel coordinates (i,j). R ij is the average of nonzeros y i Ã j Ã values.

Proposed method
The IAWMF method is the development of the AWMF method of determining the weights. In this method, the weights of the noisy pixels are taken to 0, while the weights of the noisy pixels are associated with the Euclidean distance to the pixel to be filtered. Thus, the weight of the neighbouring pixel value nearly to the pixel to be filtered is provided to be higher. In this method, the weight values are determined by Eq. (10).
It is a positive approach to determine the weights by Euclidean distance in the IAWMF method. However, the association of weight with the fourth power of Euclidean distance causes the weights of long-distance pixels to get too small. Therefore, pixel values at the nearest distance predominantly affect the pixel value to be filtered.
The method suggested in the study is based on the calculation of the pixel value to be filtered in two stages. In the first stage, the nearest noiseless pixel value is assigned to the pixel to be filtered. If there is more than one pixel with the same distance value, their averages are assigned as pixels values. At this stage, the filter size 11 × 11 is used. The reason for this is to guarantee the presence of noiseless pixels in the filter even at high level noise. However, because noise is randomly distributed throughout the image, even a large filter size may sometimes not guarantee noiseless pixels in the frame. In this case, it is assigned as the pixel value to be filtered by taking the average of the previously filtered pixel values.
Images with a low level noise usually have multiple pixel with the lowest Euclidean distance. Thus, the noisy pixel value in the first stage is calculated by taking the average of these pixels. As the noise ratio in the image increases, the number of pixels with the lowest Euclidean distance will decrease; whereas at high levels of noise, there will usually be only one pixel with the lowest Euclidean distance. In this case, this value will be assigned to the noisy pixel.
In the first stage, the closest pixel value is usually assigned without averaging in images with a high noise ratio. Although this value is close to the original value, this prevents the image from reaching sufficient quality in terms of resolution. For this reason, in cases where the noise ratio is above 45%, the second stage is applied after the first stage. At second stage, an average filter at 3 × 3 size is applied. Pixels with the value of 0 are ignored when applying the Average filter. The algorithm and flow chart of the proposed method is given below (Fig. 1).

Quality metrics
In this section, image quality metrics are provided in order to compare denoising filters used for salt and peppers noisy image. Peak Signal-to-Noise Ratio (PSNR), Structural Similarity (SSIM) and Image Enhancement Factor (IEF) were used in the study to evaluate the image quality. PSNR and MSE (Enginoğlu, Erkan & Memiş, 2019;Turan, 2021;Olmez, Sengur & Özmen Koca, 2020) defined as: For each pixel of PN noisy image ½g 0 ij mÂn If g 0 ij 6 ¼ 0 For each pixel of the image ½y ij mxn If NL>0.45 Turan, 2021;Olmez, Sengur & Özmen Koca, 2020;Wang et al., 2004) defined as: Yes No

Yes No
For each pixel of g'(x,y)

For each pixel of y(x,y)
Yes No Read: g(x,y) and Convert: g(x,y) to g'(x,y) and Compute: , NL Figure 1 The flowchart of NVBMF.

Image databases
In the study, three different image datasets are used to compare the methods: MATLAB Library images can be accessed from a computer with the MATLAB R2020b program installed using the given directory (MATLAB\R2020b\toolbox\images\imdata).
The proposed method and other methods were compared using datasets. Noise was added to each image at the ratios of 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9. For example, 1,800 PSNR, SSIM, and IEF results were obtained for BSDS. The average of all levels of noise was calculated separately for each image quality metric (PSNR, SSIM, IEF). In addition, the general average of all levels of noise has been added to the tables.
In addition, all methods were compared for six images (three from datasets and three from outside of datasets). Thus, it was ensured that the individual performances of all methods on images were observed.

DISCUSSIONS
In the first test phase, images of Cameraman and jelly beans (4.1.07) (https://dome.mit. edu/handle/1721.3/195767, https://sipi.usc.edu/database/database.php?volume=misc#top) were used. In this test stage, jelly beans (4.1.07) was used with 90% and 60% levels of noise, Cameraman 60% levels of noise, and the noisy images were denoised with NVBMF and other methods. NVBMF for denoising the 90% noisy jelly beans (4.1.07) image were obtained the best result in both PSNR and SSIM comparison than other methods (Fig. 2). NVBMF for denoising the 60% noisy Cameraman image were obtained the best result in the PSNR comparison and the third-best result in the SSIM comparison (Fig. 3). NVBMF for denoising 60% noisy jelly beans (4.1.07) image were obtained the best result in both PSNR and SSIM comparison (Fig. 4). In addition, eight different noisy Cameraman images from 10% to 80% were denoising with NVBMF, and the results are given in Fig. 5. Also, the proposed method has been tested with color images. eight different noisy jelly beans (4.1.07) images from 20% to 90% were denoising with NVBMF, and the results are given in Fig. 6.
In the second test phase, six images (Lena, Cameraman, Airplane, Micromarket, img_600 × 600_1 × 8 bit_B01C00GRAY_apples, 177083) were compared in all noise ratios. In this comparison, one image from each dataset and three images excluding the datasets were selected. Results are provided in Tables 1-3. Out of the 27 comparisons made for the Lena image, 17 of them reached the best result. The best results were obtained in seven out of nine comparisons for PSNR, six out of nine comparisons for SSIM, and four out of nine comparisons for IEF. The best result was achieved in 16 out of 27 comparisons made for the cameraman image. The best results were obtained in six out of nine comparisons for PSNR, five out of nine comparisons for SSIM, and five out of nine comparisons for IEF. The best results were achieved in 19 out of 27 comparisons made for the airplane image. The best results were obtained in six out of nine comparisons for PSNR, seven out of nine comparisons for SSIM, and six out of nine comparisons for IEF. The best results were achieved in 11 of the 27 comparisons made for the Micromarket image. The best results were obtained in four out of nine comparisons for PSNR, four out of nine comparisons for SSIM, and three out of nine comparisons for IEF. The best results were achieved in 16 out of 27 comparisons made for img_600 × 600_1 × 8 bit_B01C00GRAY_apples image. The best results were obtained in four out of nine comparisons for PSNR, seven out of nine comparisons for SSIM, and five out of nine comparisons for IEF. The best results were achieved in 11 out of 27 comparisons made for 187,083 images. The best results were obtained in three out of nine comparisons for PSNR, six out of nine comparisons for SSIM, and two out of nine comparisons for IEF.
The last test phase was completed on datasets. At this stage, noise from 10% to 90% has been added to the dataset images. Thus, nine noisy images with different levels of noise were obtained for each dataset image. Each of the noisy images was denoised with the compared noise removal methods and the results were averaged.

Statistical tests to compare performance between methods
In this section, the significance made of the comparisons between the method developed in this study and the state-of-the-art methods were tested. The significance test was performed with Wilcoxon signed-rank test because the data did not show normal distribution (Hung et al., 2022;Cevahir, 2020). The effect value of significance was determined by the Pearson Correlation Coefficient (r) (Cevahir, 2020). The results obtained are given in Tables 13-15. The method developed in this study was subjected to the Wilcoxon signed-rank test separately with each method used for comparison. Cases with p < 0.05 as a result of the test indicate that there is a significant difference between the methods compared. The cases where the Z value is negative (−) mean that there is a difference in favor of the developed method. Pearson correlation coefficient (r) expresses the effect value. A Pearson correlation coefficient of 0.1 is considered a small effect, 0.3 is considered a medium effect, and 0.5 is considered a large effect (Cevahir, 2020).
When Table 13 is examined, it can be seen that there is a significant difference in favor of the developed method in all comparisons of PSNR and SSIM between the developed method and the compared methods. In IEF comparisons, it can be seen that there is a significant difference in favor of the method developed in the others, except for one. It is seen that a significant difference creates a small effect in the IAWMF SSIM comparison, a significant difference creates a medium effect in the IAWMF IEF, DAMRmF comparisons. No significant difference was found in the DAMRmF IEF comparison. And a significant difference creates a large effect in all other comparisons.
When Table 14 is examined, it can be seen that there is a significant difference in favor of the developed method in all comparisons of SSIM, and IEF between the developed method and the compared methods. In PSNR comparisons, it can be seen that there is a significant difference in favor of the method developed in the others, except for one. In comparisons of IAWMF SSIM, IAWMF IEF, SFT_lp SSIM and ARmF IEF, it can be seen that a significant difference creates a medium effect. In comparisons of SFT_lp IEF, it can be seen that a significant difference creates a small effect. No significant difference was found in the SFT_lp PSNR comparison. And a significant difference creates a large effect in all other comparisons.
When Table 15 is examined, it can be seen that there is a difference in favor of the method developed according to Z values in all comparisons, except SFT_lp IEF. However, some of them were found to have significant differences. From PSNR comparisons, it can be seen that DAMF has a small effect, AFMF and SFT_lp have a medium effect, ASWMF, MSCF-1, DAMRmF, Bilal's Method have a large effect. From the SSIM comparisons, it can be seen that the IMF has a small effect, AWMF-DAMF-TSF have a medium effect, and AFMF-ASWMF-MSCF-1-DAMRmF-SFT_lp-Bilal's Method have a large effect. From the IEF comparisons, it can be seen that AWMF-DAMF-TSF has a small effect, DAMRmF has a medium effect and AFMF-ASWMFMSCF-1-Bilal's Mehod have a large effect. In the only SFT_lp IEF comparison, a small significant difference is in favor of SFT_lp. The effect rates in other comparisons were not found to be significant. It has been determined that there are differences in favor of the developed method in all of the comparisons except for three. According to the results obtained in the Berkeley dataset and the significance test results: Significant differences were found in favor of the developed method in all of the significance tests for PSNR and SSIM. Significant differences were found in 11 of 12 tests for IEF results. Only one found a difference in favor of SFT_lp, but this difference was not significant (does not meet the p < 0.05) condition. According to the results obtained in the TESTIMAGES dataset and the significance test results: There were significant differences in favor of the developed method in all of the significance tests for SSIM. Differences were found in favor of the developed method in all of the tests performed for PSNR. Except for one of these differences (does not meet the p < 0.05) condition, 11 are significant. Significant differences were found in favor of the method developed in 11 of the significance tests for IEF and against the method developed in one (SFT_lp). According to the significance test results for MATLAB library images: There were differences in favor of the developed method in all tests for PSNR. Except for five of these differences (does not meet the p < 0.05) condition, seven of them are significant. Differences were found in favor of the developed method in all of the tests performed for SSIM. Except for two of these differences (does not meet the p < 0.05) condition, 10 are significant. There were differences in favor of the developed method in eleven of the tests performed for IEF. All of these differences are significant. A significant difference was found against the developed method in one of them (SFT_lp). A total of 108 comparisons were made for significance tests. A difference was found in favor of the developed method in 105 of them. A total of 94 of the differences found in favor of the developed method are significant, 11 of them are not. Three differences were found against the developed method. Two of them are significant, one of them is not.
The differences against the developed method are the significance tests with the SFT_lp method. For this reason, there are nine tests in total when SFT_lp and the developed method significance tests are compared one to one. A big difference in favor of the Berkeley PSNR developed method, a big difference in favor of the Berkeley SSIM developed method, and a nonsignificant difference in favor of the Berkeley IEF SFT_lp were determined. Insignificant difference in favor of TESTIMAGES PSNR developed In this case, it can be said that the results obtained with the developed method are better than the compared methods.

CONCLUSIONS
An SPN filter based on the nearest pixel values is proposed in the study. NVBMF consists of two phases and uses 11 × 11 windows in the first phase. For the noisy center pixel, the nearest noiseless pixel value (averaged if more than one pixel with the same distance exists) is assigned. In the second phase, if the level of noise is more than 45%, also 3 × 3 avarage filter is used. In this phase, pixels that are not 0 are averaged as the center pixel value. The NVBMF (proposed) method implemented in two stages has yielded very good results in all levels of noise. In addition, NVBMF was compared with SPN filters developed recently and better results were obtained in many comparisons according to these methods. In addition, statistical tests show that the differences between the developed method and the compared methods are significant. A significant difference was found in 94 of 108 comparisons.
The use of image processing techniques and obtaining good results are positively affected by successful pre-processing and filter operations on images. In this respect, it is important to develop image filters that produce successful results. It is thought that the SPN removal filter developed in the study will contribute to the literature in this respect.
In the future, the focus is on developing filters based on machine learning to denoise SPN.

ADDITIONAL INFORMATION AND DECLARATIONS Funding
The author received no funding for this work.