PCB Inspection Using Image Processing and Wavelet Transform Joaquín Santoyo1, J. Carlos Pedraza2, L. Felipe Mejía1, and Alejandro Santoyo3 1 Universidad Tecnológica de Querétaro, Av. Pie de la Cuesta s/n Lomas de San Pedrito Peñuelas Querétaro, Qro. C.P. 76148 México jsantoyo@uteq.edu.mx 2 Centro de Ingeniería y Desarrollo Industrial, Av. Pie de la Cuesta No. 702 Desarrollo san Pablo, Querétaro, Qro. C.P. 76130 México jpedraza@cidesi.mx 3 Universidad Autónoma de Querétaro, Centro Universitario, Cerro de las Campanas Querétaro, Qro. C.P. 76010 México alex@uaq.mx Abstract. In electronics mass-production manufacturing, printed circuit board (PCB) inspection is a time consuming task. Manual inspection does not guarantee that PCB defects can be detected. In this paper, a spatial filtering and wavelet-based automatic optical inspection system for detect PCB defects is presented. This approach combines wavelet image compression utility and spatial filtering. Defects are detected by subtracting the approximations of reference image wavelet transform and test image wavelet transform followed by a median filter stage. Finally, defect image is obtained by computing the inverse wavelet transform. Advantages of this approach are also described. 1 Introduction Manual inspection of printed circuit boards (PCB’s) has been displaced by automatic optical inspection due to human limitations. Automatic optical inspection (AOI) do the same labor as manual inspection with great advantages: it can recognize line width errors, shorts, pinholes, etc. Automatic inspection also has advantages over electrical contact testing: it can detect possible electric leakages, inductance and capacitance parasite due to nicks, mousebite etc. Inspection methods can be grouped in three main categories, as stated by Moganti et al. [1]: referential methods, rule-based methods and hybrid methods. Referential method needs a “good” sample to compare point-to-point with a regular sample. It has the disadvantage that some process deviations could be interpreted as defects. Non-referential methods or sometimes called design-rule verification method, do not require a gold sample to work with; they work with the PCB specifications design as a set of rules. Finally hybrid methods combine the advantages of referential and rule-base methods. Unfortunately this approach is a time consuming method due to double check. A. Gelbukh and A.F. Kuri Morales (Eds.): MICAI 2007, LNAI 4827, pp. 634–639, 2007. © Springer-Verlag Berlin Heidelberg 2007 PCB Inspection Using Image Processing and Wavelet Transform 635 Wavelet transform has been used in vision field for different applications: fingerprint recognition [2], medical image analysis [3], image noise removal [4], image compression [5], and others. Although some work on printed circuit board verification have been developed in recent years [6] , there are some aspects like image denoising that can be explored using other techniques. The aim of this work is find defects in printed circuit boards combining the recent wavelet transform for improve data processing and spatial filtering to reduce or eliminate noise in a proper way. 2 Wavelets The continuous Wavelet Transform f (a, b) of a continuous signal x(t ) is defined [7]: f (a, b) = ∞ ∫ x(t ) −∞ 1 ⎛t −b⎞ Ψ⎜ ⎟dt . a ⎝ a ⎠ (1) To assure the perfect reconstruction of the original signal, the wavelet Transform. must satisfy CΨ = ∞ ∫ −∞ Ψ ' (ω ) ω 2 dω < ∞ (2) where Ψ (ω ) denotes wavelet Fourier transform. This condition is the so-called admissibility criterion for the wavelet ψ (t ) . The continuous wavelet transform is difficult to evaluate for all scales and positions. Using the Discrete Wavelet Transform a suitable set of scales and positions can be chosen. The discrete wavelet transform of an image or function f ( x, y ) of size M x N is ' Wϕ ( j0 , m, n) = 1 MN W i ( j , m, n) = 1 MN M −1 N −1 ∑ ∑ f ( x, y )ϕ x =0 y =0 M −1 N −1 ∑ ∑ f ( x, y)ψ x =0 i j0 , m ,n ( x, y ) (3) j ,m ,n ( x, y ) (4) y =0 Where i ={ H, V, D} 3 Algorithm Proposal This proposal is a model-based method due to the comparison of a reference image and a test image. A second level Haar wavelet is applied to reference image. Haar 636 J. Santoyo et al. wavelet was chosen due to this wavelet is simplest, fastest and suitable for this approach [8]. The wavelet output approximations (coef1) are stored in memory and this step is made just once. A second level Haar wavelet is applied to test image and then the output wavelet transform (coef2) is subtracted from memory. The resulting matrix (coef3) has the information of defects if any and some noise. Noise is eliminated thresholding absolute values of coef3 and then applying a 5 x 5 median filter. This algorithm can be resumed as follows (Fig 1): coef1(x,y) Second level approximation Haar wavelet transform of reference image. coef2(x,y) Second level approximation Haar wavelet transform of test image. coef3(x,y) = coef1(x,y ) - coef1(x,y) if coef3(x,y) > t then coef3(x,y)=1, if not, coef3(x,y)=0. Coef4(x,y) = Defecto(m,n) = inverse wavelet transform of coef4(x,y) coef1(x,y) Reference Image Im1(x,y) Coef3(x,y)>t Wavelet Coef3(x,y) coef1(x,y)-coef2(x,y) Transform coef3(x,y) h(x,y) coef2(x,y) Test Image Im2(x,y) Coef4(x,y) Inverse Wavelet Transform Wavelet defecto(x,y) PCB defects Transform Fig. 1. Defect detection algorithm 4 Experiments and Results Two images of size 1000 x 1000 were used for testing this approach. Reference and test images are gray scale images of a real printed circuit board. Test image is a defective PCB corrupted with salt & pepper noise (Fig 2). The alignment of the test image is made manually. The approximation part of second level Haar wavelet for the reference image and test image is calculated. The size of the resulting approximation matrix is 250 x 250. Only the approximation part of the second level wavelet transform is used due to the great advantage of having all the meaningful information of the original image in just ¼ of the original size. PCB Inspection Using Image Processing and Wavelet Transform 637 Fig. 2. a) Reference Image b) Test image Fig. 3. Approximations for a) reference image b) test image For this implementation was found that 6 was the best threshold value before filtering. Several window filter sizes were used to eliminate the image noise; a 5 x 5 window size gave the best results. Finally second level Haar wavelet inverse transform is applied to coef3(x,y) and it is obtained an image that contains the detected defects (fig 4). Fig. 4. a) Difference image with noise b) Defects detected after filtering A classical image processing approach to detect defects was implemented at same time to compare results with the proposed algorithm. The stages for this approach were binarization, image difference and filtering all in full resolution. Defects were found without problem. Table 1 shows the comparison of operation time for every step for both implementations. Using the Wavelet-based approach a time reduction about 50% is obtained. The time consuming task is filtering. In both approaches, 638 J. Santoyo et al. filtering is used but in different domain: Wavelet–based (1/4 of original size) and full resolution. Due to this data compression, a reduction time in data processing can be obtained. Table 1. Inspection time for a) classical image processing approach b) wavelet.based approach Operation time (s) Operation Read image Second wavelet transform Binarization Image difference Median filtering Inverse wavelet Total Classical approach 0.546 Not used 0.078 0.047 0.813 Not used 1.484 Wavelet-based 0.546 0.094 Not used 0.001 0.094 0.026 0.761 Matlab was chosen as a platform to develop and test the algorithm using the Matlab’s Wavelets Toolbox. Tests were implemented in a laptop with a Centrino Duo processor. 5 Conclusions and Future Work The wavelet transform approximation is a compressed image that preserves the meaningful information necessary to complete the image processing and be able to detect any defect. The combination of using wavelets transforms and spatial filtering used in this approach has shown that defects in a printed circuit board can be detected in a similar way as a classical image processing method can do. This represents a great advantage when the verification of PCB’s is in real time due to reduction of processing data. Future work will be directed towards the classification of the defects not just found them. Aspects relative to defects like size, position, orientation and classification techniques must be investigated References 1. Moganti, M., Ercal, F., Dagli, C.H., Tsunekawa, S.: Automatic PCB Inspection Algorithms: A Survey. Computer Vision and Image Understanding 6,3(2), 287–313 (1996) 2. Tico, M., Immonen, E., Ramo, P., Kuosmanen, P., Saarinen, J.: Fingerprint recognition using wavelet features. In: International Symposium on Circuits and Systems, vol. 2(6-9), pp. 21–24 (2001) 3. Zhang, X., Yang, Y., Xu, X., Zhang, M.: Wavelet Based Neuro-Fuzzy Classification for EMG Control. In: International Conference on Comunications, Circuits and Systems, vol. 2, pp. 1087–1089 (2002) PCB Inspection Using Image Processing and Wavelet Transform 639 4. Huang, X., Madoc, A.C., Cheetham, A.D.: Multi-Noise Removal from Images by WaveletBased Bayesian Estimator. In: International Symposium on Multimedia Software Engineering, vol. 13(15), pp. 258–264 (2004) 5. Lazar, D., Averbuch, A.: Wavelet video compression using region based motion estimation and compensation. In: International Conference on Acoustics, Speech, and Signal Processing, vol. 3, pp. 1597–1600 (2001) 6. Ibrahimt, Z., Al-Attas, S.A.R., Osamu O., Mokji, M.M.: A Noise Elimination Procedure for Wavelet-Based Printed Circuit Board Inspection System. In: 5th Asian Control Conference, pp. 875–880 7. Mertins, A.: Wavelets, Filter Banks, Time-Frecuency Transforms and Applications, 1st edn. John Willey & Sons, England (1999) 8. Chengjiang, L.: Dissertation: Time and Space Efficient Wavelet Transform for Real-Time Applications. The Ohio State University (1999)