An Improved Adaptive Weighted Mean Filtering Approach for Metallographic Image Processing**

Background: As noise brings great error in the analysis of metallographic images, an adaptive weightedmean filteringmethod proposed to overcome the shortcomings of the standardmean filteringmethod. Methods: The method used to detect the pulse noise points in the image, and then the modified mean method used to filter out the detected noise points. Patents on metallographic image processing have discussed for the development of the proposed methodology. Results: It is shown that filter window can be filtered in comparison with the conventional 3×3, 5×5 and 7×7 filt window to reduce noise detection and reduce the complexity of the weight calculation. Conclusion: It can be concluded that this method can better protect the details of the image, has better filtering effect than the standard mean filtering, and its processing speed is faster than the median filtering of the large window, which has profound significance for the edge detection and processing of the metallographic image.


Introduction
The use of image processing technologies has opened a new horizon towards the quantitative analysis of metal micrographs in the fields of metallurgy and manufacturing. The quantitative analysis includes measuring the length, width and area in order to evaluate the materialographic features like grain size, layers, and inclusions.
Automatic segmentation of metallographic images is a crucial step for this analysis of microstructures. In order to perform this task, a digital camera is added with the metallurgical microscope, which provides digital images. These images are analyzed automatically using image processing techniques. The block diagram representing the steps for metallographic image processing is shown in Figure 1. While capturing an image by using a camera, various type of disparities in the intensity of light, illusion and/or variations in contrast results were the errors in the image. Therefore, accurate segmentation of metallographic images is a difficult task.
There are many methods proposed in the literature for metallographic image segmentation. The most common method consists of converting the image to gray-scale and then applying to filter for noise removal. Finally, binarization is applied as the last step [2]. This process has been used by Marmo et al. in [3] to distinguish between the textures of carbonate rocks. Peregrina-Barreto et al. in [4] have utilized median filtering and thresholding for edge detection and image segmentation. The statistical methods used for image segmentation are discussed in [5].
The impulse noise in the image is generally characterized by the following characteristics: 1) randomness, not every pixel of the image is contaminated with the pulse noise, and the pixels of the noise pollution are randomly distributed [5]; 2) non-correlation, the pixel values polluted by noise on the image are non-correlated with each other, that is, there is no certain degree of correlation between the gray value of the polluted pixel point and the gray value of the pixel in the neighborhood; 3) equal probability, the pixel grey value of the picture with noise pollution is generally a maximum value or a minimum value, and the number of such extreme points is equal probability distribution on the image [6].
In order to effectively filter the impulse noise and improve the image visual effect, scholars have conducted a lot of in-depth research in recent years, and the research ideas mainly fall into two categories: One is to improve the median filter, and then the adaptive median filter, the weighted median filter, the value filter on the switch, the value filter, and the multi-level median filter, and so on [7][8][9][10].
Another method is the weighted mean filtering, non-local mean filtering and median adaptive mean filtering developed on the basis of mean filtering technology [11]. In addition, noise filtering algorithm based on transform domain has also been deeply studied and applied, such as wavelet threshold method, wavelet correlation denoising method and so on. The above various filtering algorithms realize the filtering of impulse noise by increasing the computational complexity to achieve multiple iterative cycles. Although the filtering effect is improved to a certain extent, the computational amount is greatly increased, which is difficult to adapt to the real-time requirements of image processing [12][13][14].
Recently, in literature, patents have also been detailed for the metallographic image processing. The adaptive filtering method has been discussed and proposed using motion estimation algorithms [15]. To preserve the edges from smoothing, adaptive filters have been used. A locally adaptive weighted method has been used to adjust the pixel value and adjustments of the nearby pixels are modified using the distance between the target pixel and the difference between their data values [16]. A patent on the artificial neural networks has been found for image enhancement and suspicious detection of area in an image. An adaptive multistage nonlinear filter has been used for noise suppression and image enhancement. This method has been utilized to construct the sub-images for diagnosis purposes. Further, a multistage artificial neural network has been proposed using kalman filter for training purposes [17]. Latala and Wojnar in [18] have proposed the use of shade correction, median filtering, binarization, and edge closing for edge detection of grains in austenitic stainless steel. An Adaptive trimmed mean autoregressive model for reduction of Poisson noise in scintigraphic images is proposed in [19] whereas, in [20], a weighted gradient filter for denoising of medical images is proposed.
Based on the analysis of the above algorithms, this paper proposes an improved adaptive mean filtering algorithm, which can effectively remove image noise and completely meet the requirements of subsequent processing. In this paper, the classical weighted mean filtering algorithm is improved in noise detection strategy, weight calculation method, filter template design and so on, and an improved adaptive weighted mean filtering algorithm is proposed.
The rest of the paper is organized as follows: Section 2 presents the experimental methods including improved adaptive weighted mean filtering. Section 3 gives the methodology in form of steps of adaptive weighted mean filtering. The results and analysis are provided in Section 4 and Section 5 holds the conclusion.

Improved adaptive weighted mean filtering
The traditional mean filter has a good effect on gaussian noise because it does not need to detect the noise intensity in advance, but it is not ideal for impulse noise. Based on this, the weighted mean filter is developed by assigning a certain weight to the pixel gray value of the noise points in the filter template, and then calculating the mean value as the output of the result. The limitations of this method are as follows: 1) the singleness of the filtering window. The filtering template of the same size is used for the whole image, and the size cannot be adjusted adaptively according to the characteristics of image details; 2) the weight value of lack of universality, literature [4], although their weight calculation method are given, but this kind of method to calculate or calculation is relatively complex, have very strong pertinence, either its versatility needs further validation. Based on the above analysis, the improvement ideas of this paper are as follows: The basis of noise filtering is to detect the image impulse noise effectively and distinguish the noise point from the non-noise point. Noise detection can be divided into two stages: coarse detection and secondary detection. The block diagram of Noise detection is given in Figure 2. In the coarse detection stage, a filter window of size m × m is used to slide on the image, and the number of the pixel gray value f (i, j) in the window is 255 or 0 pixels is marked, i.e.: Flag For the number of pixel points marked 1 or −1 is, the computer noise pollution intensity is, i.e.: If w < 1/3m 2 , it is deemed that the extreme point marked in the window is the noise point to be filtered directly; Otherwise, increase the filter window size (m + 2) * (m + 2) to continue the detection until the condition is met.
In the filter window m × m after the noise detection described above, the number of pixels determined as noise pixels in the window is removed to obtain a residual number of non-noise pixels, i.e.: The gray value of each pixel in set QI, J is calculated by the following formula, i.e.: Multiply the gray value of each pixel in set QI, J by their respective weights, and then obtain the new set, i.e.: The values in the new set QI, J are sorted by size, and the median value mean [fx(i, j) * qx(i, j)] is taken. At the same time, the average value average [fx(i, j) * qx(i, j)] of the set was calculated and compared, and the larger value is taken as the output of the filtering result.
Adaptive weighted mean filtering consists of two steps: (1) carry out noise detection on the image (2) filter the detected noise points.

Noise detection comparison
Noise detection is a key step, which provides the basis for the selection of pixels in the image. The standard mean filter does not carry out noise detection, it does not remove the impact of noise. The median filter will remove the noise from the noise, but when the noise is larger and the filter window is smaller, the impact of the noise will be present. The adaptive weighted mean filtering method proposed herein is to perform a weighted average filtering process after filtering the effects of noise so that only the target image is affected by the weighting. The purpose of noise detection and weight calculation is to improve the filtering effect, and the size and type of the filtering template determine the filtering effect to a large extent. Generally speaking, the smaller filter window is not ideal for noise filtering, and the filter performance can be improved by appropriately increasing the window size. Based on the above principles, three types of filter templates are designed, as shown in Figure 3. Compared with the traditional 3×3, 5×5, 7×7 filtering window, the filtering window mentioned above can maintain the filtering effect while minimizing the time consumed by noise detection and reduce the complexity of weight calculation.

Steps of adaptive weighted mean filtering
Step 1: Initially, in the first step, a filter template size 3 is taken and it is slide into the noise image. When the template is in any position, the pixel is in the pattern (1) in the template, and it is marked for noise detection. The process is shown in Figure 3a.
Step 2: Thereafter, count the number of pixels in step 1 as noise pixels. Then, calculate the noise intensity w1 according to formula (2). If w1 < 2, then the marking point is treated as the noise point, and system moves to step 6; Otherwise, go to step 3.
Step 3: Take the filter template of the size of 5 for the sound check mark. The number of the filter is calculated by the size of the filter. Calculate the corresponding noise intensity w2. If w2 < 4, go to step 7; Otherwise, go to step 4.
Step 4: the filter template size 7 in Figure 3c is used to detect and mark noise according to formula (1). The number of noise points in the filter template size is calculated to be 3, and the noise intensity is calculated to be w3. If w3 < 11, go to step 8. Otherwise continue to increase the size, in general, the size of the filter template can meet the requirements.
Step 5: when the size of the filter template is 3, the number of noise points in the template is removed to get the non-noise pixel gray value set Q1I, J, and the corresponding weight qx of each non-noise point pixel is calculated according to formula (4).
Step 6: multiply the weight qx calculated in step 5 with the corresponding pixel gray value f (x, y) to obtain a new set Q1I, J.  (i, j)], the mean value will be output as the filtering result. Otherwise, the median value will be output as the filtering result. Go to step 9.
Step 7: in the case of the filter template size 5, repeat step 5, step 6, calculate the corresponding number, and output the filter output, which is 9.
Step 8: in the case of filter template size 7, repeat steps 5~6 to complete the filter result output and turn to step 9.
Step 9: slide the filter template below the size to complete the filtering of the whole image.
Step 10: the filtered image in step 9 is decomposed into three wavelet layers using the basis function "db7" to obtain the wavelet coefficients of different amplitudes.
Step 11: for the wavelet coefficients with different amplitudes, the enhancement function models defined in equation (6) are adopted and processed respectively.
Step 12: reconstruct the enhanced wavelet coefficients of step 11 to obtain the enhanced filtered image. The gray value of 9 pixel points shown in Table 1, P4 is assumed to be the noise point. Then, in the standard mean filtering, the gray value of P4 is: g = P 0 + P 1 + P 2 + . . . + P 8 9 In this way, although the gray value of P4 can be replaced by g, the gray value of the surrounding pixels is different from that of P4.
After this treatment, the main influence of some edge points with larger gray value cannot be seen. The median filter sorts the gray value of 9 pixels and selects the gray value of the fifth pixel, as shown in Table 2. In this way, the noise point of pixel 2 and 5 is replaced by the gray value of 13. In this way, the point noise is filtered out, but sometimes the noise is likely to be selected when there are too many noise components, so the output image will be affected by the noise.

Results and analysis
It is necessary to assign a value to that threshold value T when the weight mean value of the gray scale of the signal point is used instead of the gray value of the current pixel point. It is found that the choice of T is related to the noise density. The experimental test results using Lena images are shown in Table 1. As can be seen from Table 3, when T=2, the peak signal-to-noise ratio (PSNR) of the denoised image is larger and the denoising effect is better. Therefore, the simulation experimental renderings in this paper are obtained when T=2.  The comparison of the effect of 70% noised Lena image processed by various algorithms is shown in Figure 4. It can be observed from Figure 4 that when the noise density reaches 70%, noise blocks appear in the image processed by the median filtering algorithm.
The mean filtering algorithm makes the image unusually fuzzy. After being processed by the algorithm in literature [7] and the algorithm in this paper, image noise is well removed. In particular, the image processed by the algorithm in this paper is relatively clear and smooth and can better protect the detailed information of the image. As can be seen from Figure 5, after the processing of the median filtering algorithm and mean filtering algorithm for 90% noised Lena graphs, the noise in the image is almost not removed. After the processing of the algorithm in literature [7], obvious pepper noise blocks appear in the image. In order to verify the filtering effect of the algorithm, the peak signal-to-noise ratio (PSNR) and mean square error (MSE) of the image are selected as objective evaluation criteria, which are defined as follows: Where, f (I, j) represents the gray value of each pixel of the original image, g(I, j) represents the gray value of each pixel of the processed image, M and N represent the width and height of the image, lg represents the logarithm with base 10, and L is the gray level of the image (L is 255 in this experiment). It can be seen from the above formula that: the larger the PSNR value, the better the filtering effect; The smaller the MSE value, the better the filtering effect. After the processing of the median filtering algorithm, mean filtering algorithm, literature [7] algorithm and the filtering algorithm in this paper, the PSNR of the adaptive weighted mean filtering algorithm is generally higher than that of the literature [7] algorithm, median filtering algorithm and mean filtering algorithm. Therefore, the denoising effect of the adaptive weighted mean filtering algorithm has obvious advantages.

Conclusion
By using the classical weighted mean filter in the field of noise detection, calculating method of power and the design of the filter template, we give you the exact steps of the adaptive weighted average filter algorithm. Compared with mean filter, weighted mean filter and weighted median filter, this algorithm has better antinoise performance and has certain universality. Adaptive weighted mean filtering is used to detect the noise points in the gray gold image, and to filter out the noise points that are detected by the modified mean filter method.

Current & future developments
This method can detect the noise points and then remove the noise points, and then carry out the weighted operation. It greatly mitigates that contradiction between noise suppression and detail preserving, so that the adaptive weighted mean filter can keep the edge feature of the target in the metallographic image well while filtering out the noise in the metallographic image so that the filtering effect has more excellent filtering effect than the standard mean value filter.