Vision-based Inspection of PCB Soldering Defects

Vision-based inspection of printed circuit board (PCB) soldering defects was studied for preparing feature data and classifying the overall PCB soldering defects on a PCB prototype into different classes. The image data of overall PCB soldering defects on a PCB prototype was developed using an image sensor camera. Image data augmentation was conducted to enhance the dataset volume. Image pre-processing included image resizing, image colour conversion, and image denoising. Watershed-based image segmentation was performed in the image post-processing to segmented images; then, feature extraction was conducted using curvelet transform to prepare image feature data. The feature data as the statistical data include kurtosis, contrast, energy, homogeneity, and variance. These data were analysed, and the percentage difference of mean values of statistical data between image classes was calculated. Kurtosis had the highest percentage difference among the statistical data. In the comparison of the mean values, kurtosis obtained 4.97% difference for the class of good and medium condition; 17.02% difference for the good and bad condition; and 12.08% difference for the bad and medium condition. Through this analysis, kurtosis is considered more reliable data for the machine-learning based classification in this project. The extracted data can be applied in future studies to classify overall solder joint defects on a PCB prototype by artificial neural network in machine learning classification.


INTRODUCTION
Electronic devices are a fundamental need for citizens in this technological era as they can improve human lifestyles. The demand needs for the size of devices, cost-effectivity, higher density package, and higher performance (K. Pan et al. 2019;Song et al. 2019). Recently, technology use in printed circuit board (PCB) development has been investigated to determine the factors influencing passive component performance (K. Pan et al. 2019).
There are two classes of electronic component technology, which are Through Hole Technology (THT) components and Surface-Mount Devices (SMD). Different soldering procedures for surface-mounted components are gradually superseding soldering technology for throughhole components. However, the use of components with lead wire and soldering and soldering THT is still a better solution due to higher interconnection reliability (S. Maciej et al. 2021;Fonseka & Jayasinghe 2019).
Due to the simplicity of automating the SMD assembly process, electronic devices are being redesigned (or new ones are being designed) to minimise the product cost (S. Maciej et al. 2021).
Smaller packaging, smaller circuit boards, and smaller components are used in SMT to improve electronic packages (J. Smith et al. 2020). The miniaturisation of installation components is more challenging because smaller packages with higher lead counts necessitate more precise component placement (K. Pan et al. 2019). As such, eliminating defects using soldering technology has become a goal to reduce PCB defects (Haifeng Wang et al. 2019).
PCB board defect problem can be addressed by applying an automatic vision-based inspection system by obtaining the PCB images using machine vision apparatus such as a camera. The inspection and classification of the PCB defect can be categorised into two-image pre-processing stage and feature extraction technique. Image denoising is an essential process in the image pre-processing stage as it can 808 reconstruct a noisy image to a denoised image (Tian 2013). Every image consists of some noise contamination, and image denoising techniques can produce a denoised image, which ideally has no noise. Blurry effects can be obtained in the denoised image by applying most of the existing denoising methods (Malar et al. 2013). Noise elimination is required as the noise will impact the essential information of an image, which is important data in feature extraction of the image (Hamarneh et al. 2009). The noise is stationary and uncorrelated among pixels; sometimes, the variance of the noise is known. This research explored the manipulation of noise images and denoised images (Knaus et al. 2014).
According to Hamarneh et al. (2009), image denoising can be conducted by applying curvelet transform since it is a multiscale analysis and geometrical idea, which can accomplish the optimal rate of convergence by simple thresholding. Width, length, and anisotropy are the main variables of the curvelet. The length and width of curvelets inside the direction characteristics are related to the parabolic scaling law. The first generation of the curvelet transform can be used for picture fusion and image contrast enhancement, while the second generation of curvelets can be used for image denoising (B. Rajalingan et al. 2019). Fast discrete curvelet transform can be constructed by applying anisotropic law, wrapping, parabolic scaling, and tight framing. The application of fast discrete curvelet transform via wrapping is recommended as it is faster, simpler, and less redundant (Song et al. 2019). The utilisation of spatial grid allows the process of curvelet transform that is conducted in each scale and angles as curvelets in the frequency domain. Sub-band decomposition, smooth partitioning, and renormalisation, ridgelet analysis, and image reconstruction are the essential steps to conduct curvelet-based image denoising (Anandan et al. 2018) Image segmentation is an essential step in image postprocessing as image segmentation within similar classes consisting of related features can be accomplished by the image segmentation technique. Techniques for segmentation have been widely employed in various industries, including image processing. Image segmentation is the first necessary and critical step for later processes such as feature recognition; it is often used to determine the borders of objects in an image (S. Lou et al. 2021).
The utilisation of image gradient to carry out image segmentation can be accomplished by watershed-based segmentation. Images can be visualised into three dimensions by watershed transform, which include two spatial coordinates versus grey level. Watershed-based segmentation is a tropological interpretation segmentation method and can form closed boundaries for each segment area to ensure the segments are meaningful in the further process (Bloice et al. 2019). The watershed transform is a robust method based on mathematical morphology among several picture segmentation techniques (S. Lou et al. 2021).
Feature extraction is conducted to extract feature data of images after image segmentation. Important features in an image can be obtained, and feature data can be generated in a lower dimensionality space by utilising feature extraction techniques. There are three kinds of common visual features in image processing: colour, texture, and shape. Several feature extraction techniques exist, such as Gabor features and gradient features (Bloice et al. 2017).
The multiscale directional characteristics that allocate optimal nonadaptive sparse corresponding to objects with edges allow the curvelet transform to be applied as a feature extraction method (Guesmi et al. 2012). After carrying out feature extraction, the curve and line information from each expression frame can be illustrated as applying curveletbased transformation. Curvelet transform can also be applied in tasks comprising illustrated edge information (M. Alruwaili et al 2019).
This project proposes a vision-based inspection of PCB soldering defects instead of applying a contact-based method or supervised by a specialist. The objectives of this project are to develop a database of PCB soldering defects using an image sensor, apply watershed transform as an image segmentation method, and curvelet transform to conduct image denoising and feature extraction.

METHODOLOGY AND EXPERIMENTAL SETUP
The methodology applied in this project is shown in Figure 1, which includes image acquisition, image data augmentation, image pre-processing, and post-processing techniques. The PCB prototype of the project was prepared with a sample of solder joint defects, as shown in Figure 2. The defects included solder bridging, insufficiently applied solder, excessively applied solder, and missing solder. The quantity of the inspected solder joint defects of the PCB prototype determined the respective category of the overall solder joint defect condition; the categories are good, medium, and bad condition. If the solder joints were satisfying or less than three solder joints consisting of FIGURE 2. Sample PCB prototype with various solder joint defects. excessively applied solder, the PCB prototype was rated as a good condition since the circuit connection would not be affected by excessively applied solder. However, it would have been a waste of applied solder. The defects in solder joints presented in Figure 2 are between four and nine on the PCB prototype; as such, it would be rated as a medium condition since the prototype is not functioning. And a bad condition of the PCB prototype can be identified if more than ten solder joints have defects. Examples of each condition of overall solder joint defects are shown in Table 1 Image data augmentation is a required step in image processing as a new dataset can be generated by expanding the existing dataset within the image augmentation technique (Amoda et al. 2013). It is often used in deep learning image processing to increase data and avoid overfitting. The main purpose of image augmentation is to obtain more and a variety of datasets. The new dataset needs to contain the essential information of the existing datasets and detect new incoming images under various conditions (Gan & Zailah 2019). The generated new datasets can enhance the model accuracy of the machine learning context, and the trained FIGURE 3. Samples of augmented images dataset. models will be more robust to unseen data (Amoda et al. 2013). Ten original images from each class were collected in this project, and image data augmentation was utilised to obtain a new variety of images dataset. Random rotation, reflection, and random translation with set limitations were applied as image data augmentation of the project. New image data were saved in a folder created after the augmentation options. Fifty images were prepared in each dataset class, which included 10 original images and 40 augmented images. A total of 150 pieces of images dataset were obtained in three-class variations as the image dataset of this project. The augmented image samples are shown in Figure 3.

IMAGE PRE-PROCESSING
The prepared images dataset needed to undergo image pre-processing before image post-processing. Image preprocessing was started by image resizing as the images needed to be resized to 500*500 pixels. Resizing into smaller pixels is not encouraged to ensure the necessary information from images can be analysed easily. Then, image denoising was carried out to minimise noise contamination in the images. Image denoising was started by adding noise to the grayscale images to form noisy images. Noisy variance can define as a noisy image, and the noise variance in this project was set as a sigma value equal to ten. The sigma value is needed to manipulate variables by multiplying the normally distributed random numbers. The noisy image can only be formed as the obtained value is added to the original image. After obtaining noisy images, normalisation of curvelet is needed to compute, and curvelet transform needs to be applied on the noisy image for having curvelet decomposition to obtain sub-band images and acquire curvelet coefficients. A digital curvelet transform can be identified, as shown in Eq.
(1). The input of Cartesian arrays with t1>0 and t2<n is represented as f[t1,t2] in the equation, curvelet coefficients are represented as And the Reisz is represented as in the equation (Song et al. 2019). Next, the sub-bands images must undergo hard thresholding in the loop of the curvelet coefficient, which acts as detailed information. The curvelet coefficients then need to perform the inverse curvelet transform after hard thresholding for reconstructing the image into the required denoised image (Anandan et al. 2018

IMAGE PRE-PROCESSING
The prepared images dataset needed to undergo image pre-processing before image post-processing. Image pre-processing was started by image resizing as the images needed to be resized to 500*500 pixels. Resizing into smaller pixels is not encouraged to ensure the necessary information from images can be analysed easily. Then, image denoising was carried out to minimise noise contamination in the images. Image denoising was started by adding noise to the grayscale images to form noisy images. Noisy variance can define as a noisy image, and the noise variance in this project was set as a sigma value equal to ten. The sigma value is needed to manipulate variables by multiplying the normally distributed random numbers. The noisy image can only be formed as the obtained value is added to the original image. After obtaining noisy images, normalisation of curvelet is needed to compute, and curvelet transform needs to be applied on the noisy image for having curvelet decomposition to obtain sub-band images and acquire curvelet coefficients. A digital curvelet transform can be identified, as shown in Eq. (1). The input of Cartesian arrays with t1>0 and t2<n is represented as f[t1,t2] in the equation, curvelet coefficients are represented as " ( , , )And the Reisz is represented as +,,,-" in the equation (Song et al. 2019). Next, the sub-bands images must undergo hard thresholding in the loop of the curvelet coefficient, which acts as detailed information. The curvelet coefficients then need to perform the inverse curvelet transform after hard thresholding for reconstructing the image into the required denoised image (Anandan et al. 2018). (1)

Image Segmentation
Watershed-based image segmentation technique was applied in the image post-processing of this project as it is stable and able to detect continuous boundaries in the image segments. Figure 4 shows the watershed-based segmentation process starting from conducting morphological transformation on the denoised image by subtracting background form, removing smaller features than the structuring element, and adjusting image intensity. The level of grey thresholding of the image was acquired to conduct image binarisation. After the image was binarised, distance transform was computed to acquire the distance from every pixel to the nearest nonzero-valued pixel as a negative value for transforming the object marker as a background marker into catchment basins. The extended maxima pixels and background pixels can be forced to be the only local minima in the image within the conducted image modification. Watershed transform was computed as segmentation method, and label function was applied to convert the segments of solder joints image into the specified colourmap. Feature extraction was conducted to obtain more precise feature data. A standard watershed segmentation algorithm applies topographical distance in the discrete case for digital images and can be described using Eq. (2), Eq. (3), and Eq. (4). In Eq. (2), the lower slope is represented as LS(p), with the maximum slope that connects pixel p in the input image f with its neighbours of lower altitude. The set of neighbours is represented as N(p), and the Euclidean distance between p and q is represented as d(p,q). The right-hand side in Eq. (2) is required to be zero as p = q. Thus, the slope value can be lower as p represents a local minimum [16].
Meanwhile, Eq. (3) represents the cost to move from pixel p to q. In the case of presenting a path = ( 8 , … , -) from p_0 = p_l to p_l = q, Eq. (4) represents the topographical distance along π between the two pixels, p and q. The minimum topographic distance of all paths relating to p and q is represented as I Q ( , ) in Eq. (4). By relating to the equation explanation, catchment basin CB( S ) of a local minimum m_i is explained as a set of pixels containing smaller topographic distances to the m_i local minimum than any other local minimum. The set of pixels that do not belong to any catchment basin are the watershed pixels (Garg et al. 2012).
Image Segmentation Watershed-based image segmentation technique was applied in the image post-processing of this project as it is stable and able to detect continuous boundaries in the image segments. Figure 4 shows the watershed-based segmentation process starting from conducting morphological transformation on the denoised image by subtracting background form, removing smaller features than the structuring element, and adjusting image intensity. The level of grey thresholding of the image was acquired to conduct image binarisation. After the image was binarised, distance transform was computed to acquire the distance from every pixel to the nearest nonzero-valued pixel as a negative value for transforming the object marker as a background marker into catchment basins. The extended maxima pixels and background pixels can be forced to be the only local minima in the image within the conducted image modification. Watershed transform was computed as segmentation method, and label function was applied to convert the segments of solder joints image into the specified colourmap. Feature extraction was conducted to obtain more precise feature data. (1) A standard watershed segmentation algorithm applies topographical distance in the discrete case for digital images and can be described using Eq. (2), Eq. (3), and Eq. (4). In Eq. (2), the lower slope is represented as LS(p), with the maximum slope that connects pixel p in the input image f with its neighbours of lower altitude. The set of neighbours is represented as N(p), and the Euclidean distance between p and q is represented as d(p,q). The right-hand side in Eq.
(2) is required to be zero as p = q. Thus, the slope value can be lower as p represents a local minimum The prepared images dataset needed to undergo image pre-processing before image post-processing. Image pre-processing was started by image resizing as the images needed to be resized to 500*500 pixels. Resizing into smaller pixels is not encouraged to ensure the necessary information from images can be analysed easily. Then, image denoising was carried out to minimise noise contamination in the images. Image denoising was started by adding noise to the grayscale images to form noisy images. Noisy variance can define as a noisy image, and the noise variance in this project was set as a sigma value equal to ten. The sigma value is needed to manipulate variables by multiplying the normally distributed random numbers. The noisy image can only be formed as the obtained value is added to the original image. After obtaining noisy images, normalisation of curvelet is needed to compute, and curvelet transform needs to be applied on the noisy image for having curvelet decomposition to obtain sub-band images and acquire curvelet coefficients. A digital curvelet transform can be identified, as shown in Eq. (1). The input of Cartesian arrays with t1>0 and t2<n is represented as f[t1,t2] in the equation, curvelet coefficients are represented as " ( , , )And the Reisz is represented as +,,,-" in the equation (Song et al. 2019). Next, the sub-bands images must undergo hard thresholding in the loop of the curvelet coefficient, which acts as detailed information. The curvelet coefficients then need to perform the inverse curvelet transform after hard thresholding for reconstructing the image into the required denoised image (Anandan et al. 2018). (1)

Image Segmentation
Watershed-based image segmentation technique was applied in the image post-processing of this project as it is stable and able to detect continuous boundaries in the image segments. Figure 4 shows the watershed-based segmentation process starting from conducting morphological transformation on the denoised image by subtracting background form, removing smaller features than the structuring element, and adjusting image intensity. The level of grey thresholding of the image was acquired to conduct image binarisation. After the image was binarised, distance transform was computed to acquire the distance from every pixel to the nearest nonzero-valued pixel as a negative value for transforming the object marker as a background marker into catchment basins. The extended maxima pixels and background pixels can be forced to be the only local minima in the image within the conducted image modification. Watershed transform was computed as segmentation method, and label function was applied to convert the segments of solder joints image into the specified colourmap. Feature extraction was conducted to obtain more precise feature data. A standard watershed segmentation algorithm applies topographical distance in the discrete case for digital images and can be described using Eq. (2), Eq. (3), and Eq. (4). In Eq. (2), the lower slope is represented as LS(p), with the maximum slope that connects pixel p in the input image f with its neighbours of lower altitude. The set of neighbours is represented as N(p), and the Euclidean distance between p and q is represented as d(p,q). The right-hand side in Eq. (2) is required to be zero as p = q. Thus, the slope value can be lower as p represents a local minimum [16].
Meanwhile, Eq. (3) represents the cost to move from pixel p to q. In the case of presenting a path = ( 8 , … , -) from p_0 = p_l to p_l = q, Eq. (4) represents the topographical distance along π between the two pixels, p and q. The minimum topographic distance of all paths relating to p and q is represented as I Q ( , ) in Eq. (4). By relating to the equation explanation, catchment basin CB( S ) of a local minimum m_i is explained as a set of pixels containing smaller topographic distances to the m_i local minimum than any other local minimum. The set of pixels that do not belong to any catchment basin are the watershed pixels Meanwhile, Eq. (3) represents the cost to move from pixel p to q. In the case of presenting a path from p_0 = p_l to p_l = q, Eq. (4) represents the topographical distance along π between the two pixels, p and q. The minimum topographic distance of all paths relating to p and q is represented as in Eq. (4). By relating to the equation explanation, catchment basin CB(of a local minimum m_i is explained as a set of pixels containing smaller topographic distances to the m_i local minimum than any other local minimum. The set of pixels that do not belong to any catchment basin are the watershed pixels (Garg et al. 2012).
(2) segmentation distance in the an be described . In Eq. (2), the S(p), with the l p in the input altitude. The set N(p), and the is represented as 2) is required to ue can be lower ].

I(L) ,L) )
(2) ents the cost to of presenting a l to p_l = q, Eq. istance along π between the two pixels, p and q. The minimum topographic distance of all paths relating to p and q is represented as I Q ( , ) in Eq. (4). By relating to the equation explanation, catchment basin CB( S ) of a local minimum m_i is explained as a set of pixels containing smaller topographic distances to the m_i local minimum than any other local minimum. The set of pixels that do not belong to any catchment basin are the watershed pixels (Garg et al. 2012). (4)

FEATURE EXTRACTION
The segmented image needed to undergo curvelet-based feature extraction to collect the image's feature data. Curvelet decomposition can extract the texture feature of an image and obtain statistical features such as energy and entropy (Anandan et al. 2018;Nandhini et al. 2016). Curvelet sub-band images can utilise these features to represent an image. Thus, curvelet transform was applied in this project to acquire the texture feature of the solder joint defects, and the process of curvelet-based feature extraction is shown in Figure 4. The feature extraction method was performed using a curvelet toolbox (Curvelab). The feature extraction started by applying forward curvelet transform defined in Eq.
(1) on the segmented image for acquiring curvelet decomposition. This type of transformation is required to set for a real-valued curvelet to obtain the curvelet coefficient since a complex-valued curvelet can only provide an image of curvelet decomposition. The curvelet decomposition of this project was set to three scales; the first scale consists of approximation coefficients, the second and third scales consist of detailed coefficients of the image. Extraction of a detailed coefficient in the second scale was carried out after accomplishing the stated setting since the detailed coefficients in the second scale are the needed coefficients in this project. The second scale of curvelet decomposition comprises 16 orientation images or so-called sub-bands images. Statistical data can be derived from these images, which represent the feature data of each orientation image. The chosen statistical data include homogeneity, variance, kurtosis, contrast, and energy (Cahaya et al. 2017). A grey-level co-occurrence matrix (GLCM) was applied for acquiring the mentioned statistical data. These data were saved in an Excel file for a further classification process.

DATABASE
The images of solder joint conditions of the PCB prototype were captured using a smartphone camera (OppoA92). Ten images per each category of overall solder joint conditions were collected, categorised as good condition, medium condition, and bad condition; additional 40 augmented images were obtained from each defect category.

PRE-PROCESSED IMAGE
Image pre-processing started with image resizing and colour conversion. The resulting image after resizing and colour conversion is shown in Fig. 5. The image was resized to 500*500 pixels and successfully converted into a grayscale image. The essential information of the image, the solder joints, can still be seen clearly, but reflection is present on the solder joints since the surface of specular solder joints was smooth. Reflection is considered a type of noisy contamination in image processing as it can affect the accuracy of feature data.
In order to minimise the reflection of solder joints in the image, curvelet-based image denoising was carried out. Figure 6 shows the image comparison between the original, noisy, and denoised images. As shown in the figure, the image was denoised successfully as the denoised image contains less noisy contamination (reflection on the solder joints) compared with the original image. The SNR (signalto-noise ratio) was measured on the noisy and denoised images compared to the original image. In image processing, SNR characterises the quality of an image. The SNR values are shown in Table 2. The noisy image has a lower SNR value than the denoised image, indicating that the image was successfully denoised by the proposed image denoising technique.  Several steps needed to be carried out to complete the proposed watershed-based segmentation method, which includes morphological transformation, adjustment of image intensity, image binarisation, computation of distance transform, background marker, and watershed transform as segmentation method. Figure 7 shows the resulting image of a few processes, in which Figure 7(a) is the image after conducting morphological transform. The shape of the objects still can be seen, but the background is darker as the  Figure 7(b) represents the resulting image after adjusting the image intensity. The image intensity was adjusted successfully since the objects in the image are clearer and easier to analyse than those in the image after morphological transform. The image was further processed by image binarisation, and the resulting image is shown in Figure  7(c). The image is binarised as the objects are black while the background is white. Black spots of various sizes are present around the solder joints due to the formation of oily dirt after soldering on the PCB prototype.
Then, the image underwent distance transform and background marker. Watershed transform was applied for segmenting objects in the image. Figure 8(a) shows the resulting image after conducting watershed transform: the essential objects, namely all the solder joints, are segmented from the background successfully. Several segmented solder joints do not have a complete circular shape as the reflection of solder joints is not eliminated completely from the image but only minimised. Image fusion was conducted to obtain a coloured segmented image with the remaining texture of the original image, as shown in Figure 8(b). Further feature extraction can be used to obtain the essential feature data within this step. The proposed watershed-based segmentation technique was conducted successfully as the solder joints are segmented from the background. Feature extraction in this project was conducted using curvelet transform to obtain the feature data of the image. After conducting curvelet decomposition, the detailed coefficients can be obtained in each orientation of the second scale in the decomposed image. Feature extraction is required to be carried out in the orientations for acquiring the statistical data. Two images of sample orientations are shown in Figure 9. The shape and edge of the objects are shown in each orientation to represent the detailed coefficients, which consists of different coarse scales. Based on Figure 9, the image of orientation 5 consists of a finer texture compared with orientation 2. Different coarse scales in different orientations can bring various values of feature data to form the statistical data.
The acquired statistical data from the detailed coefficients of the 16 orientations images were saved in an Excel file. The acquired sample data of each class of PCB prototype is graphically visualised in Figure 10, Figure 11, and Figure 12. These statistical data include contrast, energy, homogeneity, kurtosis, and variance for 16 orientation images of scale 2 in a decomposed image. The graph pattern analysis of the statistical data in the figures shows that the energy and homogeneity data are nearly constant in each orientation. Meanwhile, kurtosis presents different values in different image orientations and classes. As depicted in the graph pattern, kurtosis can easily differentiate the different image classes as the highest and lowest values are quite different.
The obtained statistical data were subjected to further analysis to validate the data performance of this project. The average value of each statistical data for the orientations in each image dataset for the PCB prototype was calculated and listed in Table 3. The percentage differences of the statistical data between classes of images were then calculated from the mean values and presented in Table 4. Kurtosis obtained the highest percentage of difference compared to other statistical data of the image classes. Kurtosis achieved a 4.97% difference in the mean value for the comparison of good and medium condition, 17.02% difference for the comparison of good and bad condition, and 12.08% difference for the comparison of bad and medium conditions. Thus, the analysis indicates that kurtosis is a more reliable statistical data for image classification.  The project was successfully completed as the statistical data have been duly collected and analysed. The percentage difference of the mean value of statistical data between image classes was calculated, whereby kurtosis obtained the highest percentage difference in the comparison among three classes of dataset compared with other statistical data. Kurtosis achieved a 4.97% difference of mean value in the comparison of good and medium conditions, 17.02% difference in the comparison of good and bad conditions, and 12.08% difference in the comparison of bad and medium conditions. Kurtosis is more reliable data for the classifier of machine learning. In addition, watershed-based image segmentation, curvelet-based image denoising, and feature extraction were also implemented in this project. Future work could include the utilisation of the prepared data to classify the images into different classes of overall solder joints defects. The application of machine vision equipment in this project can further improve the image quality as the lighting source and camera in the machine vision system can capture a clearer image with less noise.