Ameliorated mean adaptive median filtering algorithm

. Aiming at the problem that the quality of infrared image decreases due to the large amount of random noise in the process of collection and transmission of infrared image of electrical equipment, and the accuracy of automatic detection of electrical equipment decreases, based on the traditional adaptive median filter algorithm, the adaptive median filter is analyzed, which can filter only the salt and pepper noise below 25%. An improved mean adaptive median filtering algorithm is proposed to overcome the shortcomings of wave effect. Firstly, the filtering window is selected according to the decision setting condition, and then it is judged whether the K-mean value near the center point is a noise point, and if so, the window is increased, otherwise the average value is output. Finally, it is judged whether the value of the current pixel point is noise, and if so, the average value is output, otherwise, the current pixel value is output. The experimental results show that the algorithm can effectively filter salt and pepper noise and Gauss noise, while maintaining the image sharpness, and has good filtering performance on PSNR and MSE indicators.


Introduction
Infrared diagnosis technology has the characteristics of non-contact, intuitive and non-disintegration, which is widely used in the electric power industry for overheating defects and fault diagnosis and recognition of electrical equipment [1] . Technicians use hand-held infrared thermal imager to diagnose power equipment on site or collect infrared images of equipment for subsequent manual or computer recognition. In the real working environment, the scene of power equipment and thermal imager is more complex, so the infrared image collected will have different degrees of noise. The common noise types are Gauss noise, Rayleigh noise, salt and pepper noise, etc. Because of these factors, the infrared image generally has low contrast and low signal-to-noise ratio. The problems such as blurred imaging seriously affect the subsequent identification and fault diagnosis of power equipment [2] . High quality infrared image can not only improve the recognition of target equipment, but also help to judge the type and degree of fault. Therefore, the denoising of infrared image of power equipment is very important.
In order to remove noise from infrared image and keep image details as much as possible, the filtering algorithms proposed by domestic and foreign researchers are as follows: the minimum variance filtering has a good filtering effect on both salt-pepper noise and gaussian noise and can maintain the edge, but the disadvantage is that the computational amount is large; Non-local mean filtering has a good effect on gaussian noise; Switching median filtering needs to set correlation thresholds according to different conditions; Adaptive median filtering can select the size of the window from the noise concentration in the image, which has a good effect on filtering out low and medium concentration of pepper and salt noise, but it is easy to lose edge and fuzzy detail information in filtering out high concentration of pepper and salt noise, gaussian noise, etc. [3][4][5] . In terms of improving the noise reduction effect of adaptive median filtering, some scholars have proposed methods such as selecting the best filtering window [6][7] , determining the threshold value of noise points [8][9] , introducing weight function [10] , and so on.
Aiming at the shortcomings of the above algorithms in image denoising process, an improved adaptive median filtering algorithm is proposed based on consulting data and experiments. The algorithm can suppress the Gauss noise and salt and pepper noise in the neighborhood space, while retaining the details of the image.

Adaptive median filter
Conventional median filter has a better effect on eliminating salt and pepper noise, and it can protect image details better than the mean filter of the same window. However, this filter should be applied in the appropriate situation with the appropriate shape and size of the filter window. In the process of infrared image denoising of electrical equipment, there is a certain contradiction between noise suppression and detail protection of fault targets. If the filter window is larger, the effect of noise removal is better, but the ability of detail protection of target equipment is reduced, resulting in distortion of equipment boundary, such as thinning or coarsening. If the filter window is smaller, there will be some obvious noise points in the image, but the details of the image can be preserved well. This contradiction is particularly evident when the noise of infrared image is large. Because the size of the filter window used by the conventional median filter is fixed, the filter can not take into account both the size of the filter window and the protection details, so the contradiction can not be solved. Experience shows that if the spatial density of impulse noise is greater than 0.2, the filtering effect will be poor.
The adaptive median filtering method is improved on the basis of the traditional median filtering, which uses a rectangular area window. But the adaptive median filtering will increase or Reduce the size of the filter window according to the pre-set conditions during the filtering process, and then judges if the central pixel of the current window is noise, use the median value instead, otherwise output the current center pixel value.
The adaptive median filter can better deal with the impulse noise with the density of 0.2 to 0.25, while also better protect the image details, which is also a feature that traditional median filter does not have. The adaptive median filter also needs a rectangular window S xy . Unlike the traditional median filter, the size of the processing window will change during the filtering process. The window is an odd square matrix, and the point (x, y) of the center position is the pixel that the filter needs to process. The output of the filter is also a pixel value. According to the judgment conditions, the point to be processed is first judged whether it is a noise point, and then the value is used to replace the pixel value at the point (x, y).

Ameliorated mean adaptive median filtering
Aiming at the problem that the adaptive median filtering algorithm can only remove the salt and pepper noise with the concentration below 0.25, an Ameliorated mean Adaptive Median Filtering algorithm (AAMF) is proposed, which can remove higher concentration of salt and pepper noise and Gaussian noise in the field space, and can maintain the clarity and detail of the infrared image of electrical equipment.
The use of sections to divide the text of the paper is optional and left as a decision for the author. Where the author wishes to divide the paper into sections the formatting shown in Table 1 should be used.
(1) If the pixel to be processed is a non-noise point, the current pixel is output. If the pixels to be processed is a noise point, then the point is isolated in the adaptive window, so finding K points in the adaptive window which are close to the center gray value to get the average gray level is beneficial to suppress the noise.
(2) Specific steps: Stage 1: (1) Selecte K similar pixels in the center of the adaptive window (initial window 3 *3), and find the maximum Z max and minimum Z min in the filter window m ×m.
(4) If M xy < M max , repeat the first stage operation, otherwise output Z xy .
Stage 2: (1)B 1 =Z xy -Z min ；B 2 =Z xy -Z max ； If B 1 > 0 and B 2 < 0, Z xy is the output value, otherwise Zmean is output. The flow chart of the algorithm is shown in Figure 1.

Image quality evaluation index
The Peak Signal to Ratio (PSNR) is used to evaluate the denoising effect of infrared images of electrical equipment. The principle is to evaluate the image quality by comparing the Peak Signal energy of infrared images with the noise intensity after denoising. If the calculated PSNR value is improved, it indicates that the infrared image of electrical equipment after denoising is getting better and better, while the PSNR value decreases gradually, indicating that the distortion degree between the standard image and the filtered image increases. The calculation formula is as follows: (1) Among them, MSE refers to the mean square error (the average of the squared error of the gray value of each pixel):

(2)
Where X is a standard image (an infrared image that is not contaminated by noise); is an infrared image after noise removal; Ω is a pixel coordinate set of the image. Therefore, the larger the PSNR value, the better the effect of the algorithm on infrared image noise removal.
The mean square error (MSE) is the mean square value of the gray difference between the original infrared image and the filtered image. The smaller the MSE value is, the better the effect of the filtered infrared image is, and vice versa.

Experimental data
In this paper, infrared images of electrical equipment are selected as experimental data. In order to verify the rationality of the improved algorithm, four different filtering algorithms are programmed and experimented. The experimental environment is Intel Core (TM) i5-7300HQ CPU, 2.50 GHz, memory 8 GB, operating system 64-bit Windows 10, simulation software MATLAB R 2016a. The experimental results are shown in Figures 2 and 3 below.
Adding 0.4 salt and pepper noise to the infrared image of the fuse, four different filtering algorithms are used to filter the image respectively. The effect of noise reduction is shown in Figure 2  Although there is no obvious noise in adaptive median filtering, some details are lost; Ⅲ. The KNN algorithm can suppress noise effectively, but the brightness is decreased; Ⅳ. This Ameliorated algorithm (AAMF) can remove salt & pepper noise and Gauss noise effectively, and maintain better image brightness, details and edge features. The image quality is obviously better than other algorithms.  It is reflected in Table 1 and Table 2 that the difference between the filtered image and the standard original image with the noise concentration increases, which leads to the decrease of PSNR value. Although the PSNR value of AAMF algorithm declines gradually, the rate of decline is significantly lower than that of the other three algorithms, which shows that the improved algorithm can remove noise effectively at different concentrations.

Conclusions
In this paper, AAMF algorithm is proposed to deal with salt & pepper noise and Gauss noise which are more than 25% of the total noise. Compared with the traditional algorithm, the advantage of this algorithm is that it can not only ensure the clarity and edge of infrared image, but also remove the high concentration of salt and pepper noise and Gaussian noise when denoising the infrared image of electrical equipment, which achieves the expected purpose of the algorithm improvement. It provides a good solution for the shortcomings of the traditional adaptive median filter. A large number of experiments show that the proposed algorithm has achieved good results in infrared image denoising of electrical equipment. It not only shows clear image details in subjective vision, but also shows good filtering performances in PSNR and MSE indicators.