Scratch detection technology for product surface based on improved contourlet transform

A method of surface scratch detection is proposed in order to realize the automatic detection of surface scratches of molded products. This method uses contourlet transform to decompose the image, extracts the mean and variance of the different sub-bands and different directions for the matrix as the eigenvectors, and uses the distance between the calculation point and the scoring center to identify scratches, to construct a product scratch detection system based on contourlet transform. Experimental results show that compared with traditional methods, the method has higher retrieval accuracy and retrieval speed.


Introduction
In the molding process, scratches that differ in the length, direction and depth often exist in product surface. Defective products need to be discarded through scratch detection, which can be realized by real-time monitoring of molded products using machine vision technology. The product surface image collected by the camera isprocessed to decide whether the productis scratched and forwarded to the controller to be dealt with.
The surface scratches of the product are caused by the collision friction of the mold during the manufacturing process. The main features of the collected images are as follows: 1) Due to the differenceinillumination and depth, the surface showed irregular grayscale changes.
2) Due to frequent mechanical collision, fixed image acquisition device cannot guarantee zero geometric deviation between the images collected at different times, and the high frequency signal at the edge of the image has an influence on the extraction.
3) A scratch is usually a multi-directional irregular line of 3 ~ 10pixels width. In view of the above problems, research has been done from different aspects. Standard detection techniques [1,2,3] deal with regions of interest based on different space-time averages and median filtering. These low-computational-cost methods work perfectly on still images, but are less effective on sequence images, are prone to blurring, and are more severe due to the fixed position of vertical scratches. The Kokaram model mentioned in literature [4,5] is one of the most common airspace models, which proposes cosine distribution for the brightness attenuation of the scratch, and uses the median filter and the Hough transform to perform the initial screening, and then uses Gibbs sampling to get the edge distribution of the center brightness of the scratch to decide whether it is scratch or false alarm. This method tends to missscratches that are shorter than half the length of the image. In   [6] , a vertical scribe detection method based on wavelet analysis is proposed. The algorithm first carries out two-layer wavelet decomposition of the image, and then marks all possible scratches according to the relevant characteristics of the wavelet coefficients in the horizontal and vertical directions. But this method is applied to film scratches, which is different from mold surface scratches.
Based on the above literature, this paper adopts the Contourlet transform in multi-scale analysis, and proposes a product scratches detection algorithm using non-subsampled Contourlet transform. The mean and variance of the transform coefficient matrix are extracted as scratch features by non-subsampled Contourlet transform, to achieve automatic detection of the product surface scratches.

Non-subsampled contourlet transform
The Contourlet transform is proposed by M.N.Do and Martin Vetterli based on the idea of clustering base functions near the same scale with a local direction transformation to obtain a sparse representation of an image, also called the Pyramide Directional Filter Bank (PDFB). In the Contourlet transform, multi-scale analysis and direction analysis are separate processes.Laplacian pyramid (LP) proposed by Burt and Adelson [7] is used to obtain multi-scale decomposition, allowing different numbers of decomposition directions for each scale.The base structure of contour segmentapproximates the original image, the support interval of the base is a "long strip" structurewith changing aspect ratio, with the directional anisotropy, so the coefficients representing the edge of image have more energy compaction.
However, LP uses two-bit separable biorthogonal filter group for decomposition and reconstruction, interlaced sampling of the filtered image will produce spectral aliasing. In order to eliminate the aliasing of spectrum and to enhance the invariance of the direction translation, a non-subsampled Contourlet transform (NSCT) using àtrous [8] [9] algorithm is proposed. NSCT is composed of non-subsampled pyramid (NSP) and nonsubsampled directional filter banks (NSDFB), where the NSP is used to provide a multi-scale analysis feature, and the NSDFB is used to provide directional features. The structure and frequency domain decomposition of the two layers of NSCT are shown in Fig.1. On the basis of the Contourlet transform, the required non-downsampling operations in the NSCT construct are implemented by the àtrous algorithm. The multi-resolution decomposition in NSCT is achieved by a translation invariant filter bank that satisfies the Bozout identity (fully reconstructed) condition, instead of LP decomposition. NSP and NSDFB can ensure that the signal is fully reconstructed by the condition that the filter is as follows: H 0 (z) and H 1 (z)represents the decomposition filter, G 0 (z) and G 1 (z) represents the reconstruction filter.
The structure of NSP is similar to that of the non-sampling wavelet transform designed with àtrousalgorithm,the output of the up-samplingis used as the next filter, to avoid the displacement between the pixels due to sampling and to satisfy translation invariance. NSDFB decomposesthe image spectrum into wedge-shaped regions, but only upsamples individual filters, thus obtaining a non-down-sampling filter.
It can be seen from above that the NSCT transform has the advantages of translational invariance and high accuracy in retrieving geometric structural information of the image, in addition to the advantages of Contourlet transform.

Contourlet Decomposition of Scratch Image
In the Contourlet-based scratches detection algorithm, it is assumed that the noise variance is known and the noise variance is estimated using the Monte Carlo method in the Contourlet field. But it is not realistic to know the noise variance in advance, and the Monte Carlo method is too costly. So we need to estimate the noise variance from the observable image, and to find a simple way to estimate the noise variance in the Contourlet field.
Since the Contourlet transform is not an orthogonal transformation, the noise coefficient ε j, k (m, n) in the contour wave domain is not equivalent to the mean 0 variance for the σ ε 2 Gaussian random variable, it is difficult to estimate the noise variance in the Contourlet field. In this paper, we propose a two-step method to estimate the noise variance in the Contourlet field. First, we use the robust median absolute deviation (MAD) to estimate the noise variance in the Contourlet field. Due to the orthogonal nature of the wavelet transform, the estimated noise variance is equivalent to the noise variance at the pixel level. Then, the noise variance of each contour decomposition sub-band can be calculated by the corresponding equivalent Contourlet filter. This process is summarized as follows: 1) First-order wavelet transform of the image, the standard deviation of noise is firstly estimated as: In which y HH (m,n)is the wavelet coefficients of the first order wavelet decomposition diagonal sub-band.
2) {h,g}represent for low-pass analysis and Laplacian pyramid synthesis filter, respectively. M is a sampling matrix. d j,k ,j=1,2,...,2 l -1represents the equivalent filter used in the j-layer k-direction sub-band in the directional filter used, while the equivalent Contourlet filter ) , ( , n m h k j  ,j = 1,2,...,J, k = 0,1,...,2 l -1 pressed in the z transform field as: In which D j,k (Z 1 ,Z 2 ) and ↓M j represent z-transform domain and two-dimensional reduction in d j,k (m,n). Note that the contours of each sub-band are calculated,

Detection of High Frequency Sub-bandScratches 3.2.1 Modulus Maxima Algorithm.
Only a few wavelet-based functions with vanishing moments near the singularity can "feel" the singularity of these points and produce important coefficients. Based on the wavelet maximum modulus detection method, it is necessary to determine the direction of the edge curve gradient by the phase angle of the model. The detected modulus maxima also require the connection operation along the edge of the modulus maxima curve. While the filter bank of the contourlet transform is inseparable, the coefficient matrix of each direction sub-band already contains enough direction information, that is, the specific sub-band contains the modulus maxima in the specific direction.
The direction filter decomposes the image in eight directions, and each point Coeffs i j,k (n) in the sub-band has eight directions that can be the equivalent gradient direction of the edge of the ArgCoeffs i j,k (n)direction.  (5) In the formula,r(n 1 ) and r(n 2 ) denote the horizontal and vertical coordinate deviations from the Coeffs i j,k (n)in the direction of Arg(Coeffs i j,k (n)).

Detection of High Frequency Edge using Double Threshold
Method. The two-threshold edge arrays T1 and T2 are obtained by using the double thresholdτ1 and τ2 (τ2 =α×τ1, αis the scale factor) respectively. T2 is obtained with a high threshold thus contains fewer false edges, but also some useful edge information are missing. Edge array T1obtained with a low threshold thus retains more information. Therefore, based on the edge array T2, the edge array T1 is used to complement, and finally the edge image is obtained.
The specific steps for connecting the edges are as follows.
Step1 Scan in array T2. When a nonzero pixel P is encountered, track the contour line with P as the starting point until the end point Q of the contour.
Step 2 Takes Q as the reference point, scan in the 8 areas at the Q point ofarray T1, if the non-zero pixel exists, it is a pixel in the outline of array T1.Include it to the array T2as Rpoint. Starting from R, repeat Step 1 until it cannot continue in arrays T1 andT2.
Step 3 After completing the connection of a contour line containing P in the two matrices, mark this contour line as "viewed" and return to Step 1 to find the next contour line. Repeat Steps 1 through 3 until no new contours are found in the array T2.

Description of the Algorithm.
In this paper, the algorithm for Contourlet transform of the detected image is described as follows: 1) Contourlet transform the image into two parts: low frequency image and high frequency image.
2) High frequency image edge detection. First set the low frequency coefficient to zero, keep the coefficient unchanged. The sub-bands of each direction on each scale are tested for modulus maxima. The edge matrix is detected and compensated by the double threshold. Finally, the Contourlet inverse transform is carried out to obtain the high frequency edge image.
3) Low frequency image edge detection. The low frequency edge matrix is detected by the canny operator to obtain the low frequency edge image. 4) Fusethe high frequency coefficient and low frequency coefficient to obtain the reconstructed image.

Experimental methods and results analysis
In this paper, industrial CCD camera is used. The relevant parameters are as follows: resolution 800 × 600, frame rate 14Hz, pixel size 7.4 × 7.4μm, exposure time 3μs-2s. The background computer configuration is as follows: Inter P4 1.6G, 2G memory. Figure 3 shows the results of different experimental images:  Figure 3.Processing results of scratch image In this paper, the peak signal-noise ratio (PSNR) and the subjective quality evaluation are used as the standard to measure the effect of the detection. The scraches are compared in the wavelet domain and the Contourlet field respectively. The subjective quality is divided into five levels: excellent, good, average, poor and very poor. Table 1 and Table 2 show the PSNR and subjective evaluation for different image restorations in the wavelet domain and Contourlet field. It can be seen from Table 1 and Table 2 that the detection in the Contourlet domain obtains a larger PSNR compared with that in the wavelet domain. From a subjective point of view, the boundaries obtained by the wavelet domain method are more likely to be blurred, whereasonly minor scratches can be seen on the partial imagein the Contourlet field.

Conclusion
To realize automatic detection of scratched molded products with image monitoring system, we propose a surface scratch detection technology based on Contourlet transform. The main innovations of this paper are as follows: (1) A non-subsampled Contourlet transform image decomposition method for scratched images is proposed. The processed images are not easily affected by factors such as light illumination and scratch depth, and have strong stability.
(2) Modulus maxima and double threshold method are used to detect high frequency edges. This method can sense the category of the corresponding pixels of scratch points in the original image, and accurately detect the scratches in the current image, and has high precision and low false positive rate.
(3) An automatic detection system of the product surface scratchesis designed and implemented. The system overcomes the adverse effects of the production environment on the image of the molded product, and further combines the Contourlet transform image processing technology, which guarantees the robustness of the light and the robustnessof geometric deviation.
Experiments show that the algorithmnot onlysuccessfully detectsand removes the scratches without affecting the rest of the image, but also is simple and effective. This method can be widely used in motion target detection, surface defect detection and environmental change detection, applicable to many fields such as military service, medicine, electronics, packaging, printing, security, intelligent transportation and robot engineering.