Improving Wavelet Threshold De-noising Applied on Parts Detection

. The traditional filtering methods such as median filter and mean filter always blurrs image features, resulting in poor noise reduction effect. Wavelet transform has unique adaptability due to its variable resolution, which can better implement wavelet denoising on the basis of image feature. Aiming at the shortcoming of traditional wavelet transform threshold denoising, based on the hard threshold and soft threshold function, this paper proposes improved adaptive thresholding function. By comparing and validating, this method obtains the smaller mean square error (MSE) and higher peak signal to noise ratio. Meanwhile, this method improves the quality of detection images, and reduces the impact on images brought by noise from external enviroment and internal system. So, this can be applied to image noise reduction of the detection system.


Introduction
In the machine vision detection system, the image acquisition and transmission process is easily affected by the external environment and the internal influence of the system, so as to obtain blurred images. The noise obtained in the image is often the key factor that determines the final detection accuracy, so it is necessary to remove the noise in the preprocessing to provide higher-quality images for the subsequent detection process [1] [2] [3] .
The principle of wavelet threshold de-noising method is to process the decomposed wavelet coefficients through reasonable threshold function and threshold setting, to remove the coefficients caused by noise based on threshold value, and only to keep the wavelet coefficients generated by the original image. Finally, the original image is reconstructed by inverse transformation with wavelet coefficients, that is, the process of noise reduction is completed. Therefore, the selected threshold value and threshold function applied on wavelet coefficients need to remove as much noise as possible and retain useful information. Due to the features of multi-resolution analysis, wavelet can be used to represent signals well, thus achieving fine effect of noise reduction.
In this paper, an improved method of wavelet denoising is proposed, starting from the selection of the form of threshold function, to improve the threshold function and threshold setting, preserving the advantages of hard threshold and soft threshold processing function, which can improve the quality of wavelet denoising. The wavelet transform is used for noise reduction, and the wavelet basis is selected to decompose the image, and the decomposed coefficients are processed with corresponding thresholds. Experimental results show that the improved threshold function can improve the effect of wavelet denoising.

Wavelet transform theory
When analyzing the signal with discontinuity and sharp changes, the wavelet transform first divides the signal with different frequencies by the function, and then studies the signal with appropriate resolution at different scales. Fourier transform adopts infinite long triangle function as the base function. Nonlocal and infinite function cannot give a valid approximation to those signal with continuous change, especially those change suddenly and drastically. However, wavelet transform uses finite wavelet basis, which can effectively complete signal approximation through stretching and translation transformation [4] [5] [6] .
In practical application, the image signal detected by vision usually contains sharp or abrupt parts, and the mixed noise is usually not smooth white noise. The traditional denoising method will blur edges and ignore the details, while wavelet analysis can analyze in time and frequency domain at the same time. In the low frequency part, wavelet transform has higher frequency-domain resolution and lower time-domain resolution. On the contrary, higher time-domain resolution and lower frequency-resolution can be obtained in the high-frequency part [7] . The image signal can be observed with variable resolution by using the feature of wavelet transform, since, the overall and detailed information of the image can be obtained effectively. At the same time, in different scales, the mutant and noise signal in the image will show completely different opposite characteristics, which can be used to filter noise and restore the original image, then finally achieve the effect of image denoising.
The decomposition process of two-dimensional discrete wavelet is to carry out high-pass filtering and low-pass filtering on the line direction of the image first, and then high-pass filtering and low-pass filtering on the column direction respectively after the lower sampling. Finally obtain the approximate wavelet coefficient of the image, the wavelet coefficient of horizontal, vertical and diagonal direction.
The advantage of wavelet analysis over traditional time-frequency analysis is that the signal can be decomposed at any time-frequency resolution, so as to accurately depict the signal shape. The denoising effect obtained by the wavelet transform constructed by different wavelet basis is different. Moreover, selected wavelet basis should satisfy those particular properties such as symmetry, tight support, orthogonality and high vanishing moment as much as possible [8] .
In this paper, db wavelet is selected as the primary function of wavelet denoising. Taking the effect of decomposition scale on denoising into account. If the number of decomposition layers is too large, each layer will threshold the wavelet coefficient, resulting in the filter of useful information, decreasing the signal-to-noise ratio instead of improving. However, if the number of decomposition layers is too small, the wavelet coefficients generated by the noise transformation cannot be effectively removed. The effect of denoising is not obvious, and the signal-to-noise ratio will not be greatly improved, but the signal-to-noise ratio will not decrease. According to the features of the part image, db4 is adopted as the wavelet basis in this paper to decompose the image [9] [10] .
With the opposite characteristics of signal and noise in different wavelet scale, the image with noise is denoised by wavelet transform. The effect of wavelet denoising mainly depends on four aspects, which are the selection of wavelet basis function [11] , the number of layers of wavelet decomposition, the threshold processing function and the selection of threshold.
The whole process of wavelet filtering is mainly divided into three steps [9][12] [13] . First, multiscale wavelet transform is applied to noise signal. Secondly, the wavelet coefficients obtained by image decomposition are processed to remove the coefficients caused by noise transformation while retaining the wavelet coefficients obtained by image itself through wavelet transformation. Thirdly, the image is reconstructed by inverse wavelet transform. The specific implementation process is shown in figure 1.

Threshold denoising
In the process of wavelet filtering, the selection of threshold function is the key problem to determine the quality of denoising. The primary threshold function is hard threshold function and soft threshold function. The hard threshold function directly sets those coefficients under threshold value λ to zero, while retains the wavelet coefficient that is greater than λ [14] .
Another form is the soft threshold function, which can get better signal approximation by shrinking those wavelet coefficients between 0 and threshold threshold [15] .
By comparing the image of the threshold function, it is not difficult to find that the hard threshold function has obvious discontinuity points, which will cause the image restored by denoising in this way having some distortion such as ringing, pseudo-gibbs effect, etc., while the ideal soft threshold function can get relatively small error. However, the shrinkage mode of soft threshold function determines that there must be an offset between the coefficient obtained by the ordinary soft threshold shrinkage and the coefficients after decomposition, which will affect the degree of similarity between the reconstructed image and the original image [16] . So, it is necessary to construct a better threshold function by modifying the above two elementary threshold functions.
In order to improve the discontinuity of hard threshold and the skewing of soft threshold, the curve approach can be used to eliminate the problem of migration brought by soft threshold shrinkage in high frequency coefficient, and at the same time, the discontinuity of hard threshold function can be improved. At present, the most frequently used threshold function adopts such a form between two threshold functions, which combines the advantages of both and eliminates their disadvantages to a certain extent, possing a good denoising capacity.

Improving threshold denoising
The adaptive wavelet threshold denoising adopted in this paper is improved in two key aspects, which is threshold function and threshold setting respectively. This paper proposes a new adaptive threshold function based on existing threshold function [17] .

Form of adaptive threshold function
As shown in equation (1), λ and γ is the upper and lower critical thresholds, where shrinks coefficients to curve or to zero. This threshold function integrates the advantages of hard threshold function, soft threshold function and semi-soft threshold function. In most cases, the performance of soft threshold function is better than that of hard threshold function, and due to the smoothness of the adaptive threshold function, the quality of denoising can be improved by setting adaptive threshold function to approach hard threshold function. The function can adapt to the change of signal due to its continuity at the threshold λ , and shrink wavelet coefficients under λ to zero. In this way, the soft and hard threshold function can be taken into account through the setting of λ and γ , which can achieve better denoising effect after combining above two functions.
Besides, another parameter α determines the shape and trend of the threshold function on the whole. The signal approximation can be improved to better adapt to different denoising objects by adjusting the size of the parameterα , so as to enhence the adaptability of the threshold denoising algorithm. In the two extreme cases where α is zero or one, the threshold function can approximate soft threshold function and hard threshold function. Figure 2 shows the form of adaptive threshold function proposed in this paper.

Comparison of functional form
The threshold function proposed in this paper is compared with hard threshold function and soft threshold function in term of functional form, and the results are shown in figure 2: It can be seen that the threshold function proposed in this paper improves its discontinuity relative to hard threshold function and its deviation from original image signal relative to soft threshold function. This function improves disadvantages of both and combines the advantages of both at the same time. So, it has fine continuity, reconstruction ability for detailed features and can eliminate visual distortion to a certain extent.

Threshold setting
Adjusting to changes of wavelet coefficients in different levels, it is necessary to set a separate threshold for the wavelet coefficients at each scale to shrink coefficients. As the number of decomposition layers increases, the threshold should be minished accordingly. Taking decomposotion level into consideration, which is consistent with variation of noise wavelet coefficients in reality, thus, this operation can reduce the influence of error caused by improper threshold setting to a certain extent. Therefore, it is necessary to consider the impact of the decomposition scale and select the threshold that can be more suitable for different noise situations [18] . Donoho threshold was used initially, and the selection formula(2) of threshold T was shown following: In practical application, better denoising effect can be obtained by choosing 3 T δ = . On this basis, considering the influence of decomposition scale, this paper introduces scale coefficient to set an independent threshold value for the coefficients of each level after wavelet decomposition to obtain better denoising effect. The selection formula of threshold T in this paper is shown as follows:

Comparison of different threshold functions
In order to judge the quality of wavelet threshold denoising, the criterion of discrimination should be introduced. Mean square error (MSE) or PSNR can be used to evaluate the similarity between the denoised image and the original image. The formula of MSE and PSNR is shown as follows: ( ) ( ) For the image mixed with gaussian white noise, the first thing to be determined is the value α that determines the shape and smoothness of the threshold function. The mean square error between the image and the original image under different valuesα is obtained through image noise denoising experiment simulation. The MSE results obtained by the experiment are shown in figure 3. The histogram height represents the size of MSE, that is, the lower the histogram height, the better the quality of denoising. Taking the magnitude of MSE and the continuity and smoothness of threshold function into account, 0.75 is selected as actual value. Within the range of variation of noise variance from 0 to 20, three threshold functions: hard threshold function, soft threshold function and adaptive threshold function proposed in this paper, were respectively tested and compared with MSE ( figure 4). It can be found that, compared with soft threshold function, the adaptive threshold function proposed in this paper largely eliminates the existing intrinsic offset. With the increase of noise variance, the denoising quality of image details is close to or even better than the hard threshold function.

Simulation experiment of parts
In industrial production, it is almost inseparable from the quality inspection of parts, especially some important precision parts, which have higher quality requirements than ordinary parts, and high requirements on the scratch, oil stain, dents and defect of parts surface. Figure 5 shows the image containing defect commonly existed in the process of part production. It can be found that the image processed by wavelet denoising with the adaptive threshold function proposed in this paper (figure 6) is effective and clear in edge details processing of noise on the part is more continuous, and the processing result is closer to the original image. As shown in table 1, mean square error of soft threshold processing function after denoising is the largest among the above three functions, and the effect is the poorest. When the noise variance is small, the mean square error of the adaptive threshold function is better than that of the hard threshold function unobviously. However, as the noise variance increases, the mean square error of this method is much smaller than that of the hard threshold function. In summary, among the above three functions, the threshold processing function proposed in this paper is the most effective.

Conclusion
Wavelet threshold denoising is a common and effective method for image denoising. As an important part of image preprocessing, it plays a key role in the detection accuracy of visual detection system. In this paper, the threshold processing function and the threshold selection in the process of wavelet noise reduction are improved respectively, and the deviation and distortion in the traditional threshold processing function are optimized. At the same time, the selection method of Donoho threshold was improved, the global threshold was abandoned, and the independent threshold corresponding to the decomposition scale was set for each decomposition layer. The wavelet denoising algorithm makes use of the above two improved methods and improves the representation ability of the threshold function to image signal. Moreover, the setting of independent threshold is more in line with the actual situation of coefficient distribution in wavelet decomposition, and the effective coefficient and noise coefficient under each decomposition scale are better separated, so as to effectively restrain and shrink the noise coefficient. It is shown that the proposed wavelet denoising algorithm can effectively remove noise, retain image edge feature information, reduce image bias and improve image visual effect and noise reduction quality. Such a pretreatment method to effectively improve image quality is of great significance for the improvement of final detection accuracy and quality in the automatic visual inspection field of industrial parts production.