6th Internatonal Conference on Electronc, Mechancal, Informaton and Management (EMIM 2016) The Improved K-nearest Neghbor Solder Jonts Defect Detecton Meju Lu1, a, Lngyan L1, b *and Wenbo Guo1, c 1 Department of Informaton and Control Engneerng, Shenyang Janzhu Unversty, Shenyang 110168, Laonng, Chna. a 11404178112@qq.com, b 1159558936@qq.com, c 2217020304@qq.com Keywords: AOI; Feature extracton; Improved K-nearest neghbor algorthm; Solder jont defect detecton. Abstract. Amng at the problems such as defect msstatements, omssons are prone to happen when automatc optcal nspecton (AOI) system detects Prnted Crcut Board (PCB) solder jonts. The artcle puts forward a knd of method based on mproved K-nearest neghbor to test and classfy the qualty of solder jonts. Frstly, the orgnal mages collected by ndustral camera should be pretreated, and solder jonts should be postoned by usng the method of template matchng. Secondly, the features of solder jonts should be extracted and selected usefully through the experments. Fnally, the mproved K-nearest neghbor algorthm based on effectve feature s used to test and classfy solder jonts. Experments show that the mproved K-nearest neghbor algorthm has hgher accuracy and stronger adaptablty than neural network algorthm used for classfcaton. What s more, the cost of testng s also reduced effectvely. So we can conclude that the mproved K-nearest neghbor algorthm s useful for solder jonts testng. Introducton Wth the development of PCB assembly technque, the tradtonal manual vsual nspecton method s becomng more and more dffcult. Ths method s affected by subjectve factors easly, so t often happens to check wrongly or leak detecton. At present, there are some common detecton classfcaton methods such as AOI system [1-4], K-nearest neghbor method [5-8], BP neural network algorthm [9,10], etc. The common detecton algorthms used by AOI nspecton system stll exst error-prone, and they are always affected by external factors. The accuracy of detecton can't meet the requrements, and the process of usng s too complcated [11,12]. By comparson, Knearest neghbor method possessed the full capablty of smple method, unsupervsed tranng ablty, wthout pror model, etc. But t also has ts own dsadvantages, for example, easly affected by the surroundng nose and solated ponts n the sample. And the value of K wll nfluence the classfcaton result at the same tme. Amng at the dsadvantages of K-nearest neghbor method, some methods are proposed to mprove K-nearest neghbor method. Frst of all, the samples n the orgnal space are mapped n a hgh-dmensonal kernel space. The purpose s to promnent characterstc dfferences between the samples n dfferent categores, and make the samples lnear separable or approxmately lnear separable. Then K-nearest neghbor method s used to classfy n the kernel space, so the classfcaton error of nonlnear samples was reduced effectvely. Experments ndcate that the mproved K-nearest neghbor method obtaned the better classfcaton effect. Algorthm Descrpton K-nearest Neghbor Method. Suppose there are m categores, and each category has a sample ( w1, w2, wm ).For the classfcaton of unknown sample x, frstly calculated the dstance from the known category of samples xk, and then to fnd the closest sample. So the category of sample x s subordnate to the class. The followng s the dscrmnant functon of w class: 2016. The authors - Publshed by Atlants Press 651
d ( x) mn x x k, k 1,2, N (1) k If dm ( x) s equal to mn d ( x ), we can get the concluson: x s ncluded n w m.ths method s only defned accordng to the nearest sample. To avod the accdent of one sample, t should fnd K nearest neghbor samples. Then t s belonged to the knd of the most samples. Ths method s usually recorded as KNN. K-nearest neghbor method has perfect theoretcal basc, and t s an mportant knd of classfcaton methods. But the classfcaton effect s poorer when the boundary of the sample s nonlnear. Improved K-nearest Neghbor Method. To mprove K-nearest neghbor algorthm, the unclassfed samples n the orgnal space should be mapped to a hgh-dmensonal feature space (x). In ths way, the dfferences between samples stand out. Then use K-nearest neghbor algorthm to classfy the samples n hgh-dmensonal space. x ( x) (2) Unclassfed samples mapped n the hgh-dmensonal space are converted nto: x ), ( x ), ( x ). And the dstance formula between the samples s: ( 1 2 N 2 d ( x) ( x ) ( x j ) (3) Next K-nearest neghbor algorthm s used to classfy the knds of the samples n hghdmensonal space. The results show that the mproved K-nearest neghbor algorthm can reduce the error, and get better classfcaton results. Experment Based on the Improved K-nearest Neghbor Method The man types of defectve solder jonts have more solder, less solder, leakage weldng and connecton weldng, etc, as shown n Fg. 1; Solder jont defects exst dfferences n many aspects such as type, locaton, shape. So the tranng samples need to be preprocessed and sample features should be obtaned. The features are translated nto a hgh-dmensonal space and then the transformed features are traned to form the traner. (a) jont (b) (c) (d) Blstery solder (e) (f) Matte surface (g) Connecton weldng Fgure 1. The man types of solder jonts Ths artcle s n vew of the PCB solder jont detecton. Because the background of PCB s fxed, template matchng method may be used for the poston of solder jonts. Then extract the characterstcs of the solder jonts accordng to the feature and gray hstograms. Fnally, obtan the classfer through tranng the model based on the mproved K-nearest neghbor method, the specfc process of ths experment s shown as follows. 652
start tranng sample extract the key feature normalzaton processng The mproved K - neghbor classfcaton solder jont classfer The test mage extract the key feature normalzaton processng decson the defect classfcaton result end Fgure 2. The process of ths experment The Locaton of Solder Jonts Based on Template Matchng. The locaton of solder jonts s fxed, and the center of the solder jonts s closely related to the partcular locaton of PCB. Amng at the nterest regon, we can create a template to mprove the matchng speed. The basc process of solder jont locaton as follows: Step1.Frstly, determne the regon of nterest (ROI). It only needs to make sure the coordnates of top-left and bottom-rght ponts. Usng the functon of gen_rectangle() wll generate a rectangle regon. Then the functon of area_center() s used to fnd the center of rectangle regon. Fnally, the functon of reduce_doman () s used to obtan ROI from the mage, as shown n the Fg. 3; Step2. Establsh a ROI template by usng the functon of create_shape_model(). It also needs the functon of nspect_shape_model() to watch the template created. In addton, the functon of get_shape_model_contours () whch can obtan the contour outlne of the template s used for the followng matchng, as shown n the Fg. 4; Step3. Open another mage to match the template after created. In another word, fnd the part of template n the new mage. It can be fnshed by usng the functon of fnd_shape_model(). It stll needs to be transformed to dsplay after fndng the template, as shown n the Fg. 5; the functons of vector_angle_to_rgd () and affne_trans_contour_xld () are used to calculate a rgd affne transformaton. The role of the transformaton s to transform the reference mages nto the current mages. Step4. Make sure the locaton of every solder jont accordng to the relatonshp between each solder jont center and the template center after matchng, as shown n Fg. 6; Fgure3. The regon of nterest Fgure 4. The outlne of template Fgure 5. The template matchng Fgur6. The locaton of solder jonts The Feature Extracton of Solder Jonts. Feature extracton s the precondton of defect detecton, so you need to accurately extract the features of the solder jont. And then select effectve 653
features as the detecton bass through the experment. The artcle selects the characterstcs as follows: 1) The normalzed area (A). The area of the solder jont s only related to ts boundary, and here use the method of calculatng the number of pxels n solder jont (ncludng boundary) to normalze the area. Assumng that set 1 as the length of the square pxel, the formula of solder jont area: A 1 (4) 2) The crcumference of the solder jont regon (C). The regon s showed by chan codes, such as the outlne of solder jont x0l0 L1 L n, the start pont coordnate x 0, the Code word s shown as L. There s usng the method of Eucldean metrc, so the formula of C s shown as follows: 1 L {(0,2,4 )} C 2 L {(1,3,5 )} (5) C n 0 C 3) The hydraulc radus of solder jont (R). (6) R A / C (7) r 4) The sphercty of solder jont (S). The radus of nscrbe crcle s shown as, and r the radus of crcumcrcle crcle s shown as c. So the formula of S s shown as follows: S r / r (8) c 5) The moment of solder jont ( m ). N 1 m E[ n] h p( n) n 0 If =1, t would represent the mean of the mage. 6) The central moment of solder jont. (9) u E[( h E( h)) ] ( h m ) p( h) N 1 1 (10) h 0 If =2, t would represent the varance of gray value. Feature selecton s not the more, the better. It s necessary to select the typcal features. Varous features have large dfferences n such as number, unt and so on. So t needs to be normalzed: X ( Z Z) / S (11) The normalzed feature s shown as X, and Z represents the unnormalzed feature. Z s the mean value of Z,and S s the varance of Z. The Experments of Solder Jonts Defect Detecton. The steps of the experment are shown as follows: Step1. Frstly, the representatve samples are selected as the tranng samples. The features should be extracted and transformed nto a hgh-dmensonal feature space. And the dstrbuton of the representatve features should be descrbed n the feature space, as shown as Fg. 6; Step2. Then the functon of create_class_knn() can be used to generate a classfer based on the mproved K-nearest neghbor method. And the functon of add_samples_mage_class_knn() s used 654
to transform the tranng samples nto the data that the classfer can recognze. The functon of tran_class_knn () s used to form a taxonomc tree. Step3.Fnally, the functons of classfy_mage_class_knn() and regon_to_mean () are used to detect and classfy the testng samples and sgn the unqualfed samples, as shown as Fg. 7; (a) Normalzed crcumference and area (b) Hydraulc radus and sphercty property (c) Mean value and varance (d) Hydraulc radus and second-moment Fgure 7. The dstrbuton of samples n varous feature spaces Fgure 8. The detecton results based on the mproved K-nearest neghbor method From Fg. 7, we can see that solder jonts are roughly judged by crcumference and area. And most of the solder jonts can be dstngushed by the features of hydraulc radus and sphercty. Mean value can dscrmnate the types of the solder jonts well, but varance only can dscrmnate a part of solder jonts. Two-moment can dstngush the more solder jonts better, but t s less accurate to dstngush less and normal solder jonts. From Fg. 8, we see that the mproved K- nearest neghbor method can accurately detect unqualfed solder jonts. The Analyss of Experment Results In the artcle, the mproved K- nearest neghbor method s compared wth K- nearest neghbor method, AOI system and BP neural net. Ths experment amed at the three types of more solder, 655
normal solder and less solder. There are 90 tranng solder jonts and 209 testng solder jonts,as shown as Table 1. Table 1 Solder jont samples Type Sample Tranng samples Testng samples 26 23 32 37 Amount 41 90 140 209 The methods of mproved K- nearest neghbor, K- nearest neghbor, AOI system and BP neural net are compared to detect the solder jonts, the results are shown n table 2. The mproved K- nearest neghbor method has stronger adaptablty and hgher precson rate than K- nearest neghbor method. The mproved K- nearest neghbor method not only can declne the rates of mstake and mss, but also avod fallng nto local mnmum and beng nadequate for small samples. Therefore, the mproved K- nearest neghbor method has nvestgatve and applcatve values n the aspect of solder jont detecton. Table 2 The comparson of detecton methods Detecton method The mproved K-nearest neghbor method(k=3) AOI system K-nearest neghbor method(k=3) BP neural Net method Type Precson rate Mstake rate Mss rate Comprehensve Comprehensve Comprehensve Comprehensve 96.875% 10 99.286% 99.043% 93.75% 94.595% 96.428% 95.694% 90.625% 94.595% 97.857% 96.172% 96.875% 91.892% 98.571% 97.129% 0.714% 0.957% 6.25% 5.405% 2.143% 3.35% 5.405% 1.429% 2.392% 5.405% 2.857% 3.349% 0.478% 2.703% 0.479% 0.714% 0.957% Concluson The methods of mproved K- nearest neghbor, K- nearest neghbor, AOI system and BP neural net are compared to detect the solder jonts, the results are shown n table 1. The mproved K- nearest neghbor method has stronger adaptablty and hgher precson rate than K- nearest neghbor method. The mproved K- nearest neghbor method not only can declne the rates of mstake and mss, but also avod fallng nto local mnmum and beng nadequate for small samples. Therefore, the mproved K- nearest neghbor method has nvestgatve and applcatve values n the aspect of solder jont detecton. 656
Acknowledgements The Project of Laonng Provnce s Educaton Department(L2013225); Natonal Natural Scence Found Project of Chna(61272253). References [1] Qang G, Shanshan Z, Yang Z, et al. Detecton method of PCB component based on automatc optcal sttchng algorthm [J]. Crcut World, 2015, 41(4): 133-136. [2] Lu Y, Yu F. Automatc nspecton system of surface defects on optcal IR-CUT flter based on machne vson [J]. Optcs and Lasers n Engneerng, 2014, 55: 243-257. [3] Chen S H, Perng D B. Automatc optcal nspecton system for IC moldng surface[j]. Journal of Intellgent Manufacturng, 2014: 1-12. [4] Ln C S, Tzeng G A, Lay Y L, et al. An automatc optcal nspecton system for assembly and evaluaton of an optcal encoder [J]. J. Test. Eval, 2014, 42(4): 819-827. [5] Ma X, He X, Sh X. A varant of K nearest neghbor quantle regresson [J]. Journal of Appled Statstcs, 2015: 1-12. [6] Lu W, Shen Y, Chen S, et al. Effcent processng of k nearest neghbor jons usng mapreduce[j]. Proceedngs of the VLDB Endowment, 2012, 5(10): 1016-1027. [7] Steenwjk M D, Pouwels P J W, Daams M, et al. Accurate whte matter leson segmentaton by k nearest neghbor classfcaton wth tssue type prors (knn-ttps) [J]. NeuroImage: Clncal, 2013, 3: 462-469. [8] Yeslbudak M, Sagroglu S, Colak I. A new approach to very short term wnd speed predcton usng k-nearest neghbor classfcaton [J]. Energy Converson and Management, 2013, 69: 77-86. [9] Garca-Pneda O, MacDonald I R, L X, et al. Ol spll mappng and measurement n the Gulf of Mexco wth Textural Classfer Neural Network Algorthm (TCNNA) [J]. Selected Topcs n Appled Earth Observatons and Remote Sensng, IEEE Journal of, 2013, 6(6): 2517-2525. [10] L J, Cheng J, Sh J, et al. Bref ntroducton of back propagaton (BP) neural network algorthm and ts mprovement[m]//advances n Computer Scence and Informaton Engneerng. Sprnger Berln Hedelberg, 2012: 553-558. [11] Cao B Q, Lu J X, Wen B. Currency Characterstc Extracton and Identfcaton Research Based on PCA and BP Neural Network [J]. Journal of Convergence Informaton Technology, 2012, 7(2). [12] Jakat J S, Matad S S. PCB defect detecton based on pattern matchng and segmentaton algorthm [J]. Internatonal Journal of Engneerng and Innovatve Technology (IJEIT),2015,4(11):188-192. 657