PCB defect detection method based on image processing

By adopting an image-based method in PCB defect detection, combining diffusion model and discrete wavelet transformation technology, only normal sample data sets are used for training, the problems of deep learning models in defect type generalization ability and computing resource consumption are solved, and efficient small sample learning and detection accuracy are achieved.

CN119919399AActive Publication Date: 2025-05-02JILIN UNIVERSITY

Patent Information

Application Number
CN202510396836.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-01
Publication Date
2025-05-02
Estimated Expiration
2045-04-01

Smart Images

  • Figure CN119919399A_ABST
    Figure CN119919399A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of defect detection, and relates to a PCB defect detection method based on image processing, which comprises the following steps: collecting defect-free PCB image data, and making a data set; loss functions are set for the reconstructed subnet and the segmented subnet respectively, the data set is used for training to obtain the trained reconstructed subnet and the segmented subnet, and the trained reconstructed subnet adopts a diffusion model to carry out noise removal on to-be-detected image data subjected to preprocessing and data enhancement step by step according to time steps to obtain a reconstructed image. And decomposing the reconstructed image into a low-frequency component and a high-frequency component through discrete wavelet transform, inputting the low-frequency component into the trained segmentation subnet, comparing the low-frequency component with the to-be-detected image data, and distinguishing a defect part. According to the method, the number of used samples is far smaller than that of other target detection model samples, discrete wavelet transform is utilized, high-frequency components are extracted for back diffusion denoising, the reasoning speed is increased, and the segmentation and defect detection precision is improved through the extracted low-frequency components.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of defect detection, and in particular relates to a PCB defect detection method based on image processing. Background Art

[0002] With the rapid development of the electronics industry, PCB (printed circuit board) manufacturing technology is evolving towards high density, miniaturization and complex functions, which puts higher requirements on PCB quality inspection. PCB defect detection plays a vital role in ensuring product performance, reliability and safety. However, with the increasing complexity of PCB design, traditional inspection methods face many challenges.

[0003] At present, PCB defect detection technology mainly includes manual visual inspection, automatic optical inspection, automatic X-ray inspection and electrical testing. In recent years, with the vigorous development of deep learning technology, defect detection methods based on deep learning models such as Convolutional Neural Networks (CNN) have gradually attracted widespread attention. Deep learning models have powerful feature extraction and pattern recognition capabilities, can automatically learn complex image features, do not rely on traditional artificial feature design, and perform well when processing large-scale data. This has made the potential of deep learning in PCB defect detection widely recognized. However, although deep learning methods have made certain progress in the field of PCB defect detection, there are still many shortcomings. The performance of deep learning models is highly dependent on large-scale, high-quality annotated data sets. However, in PCB defect detection, high-quality defect data is often scarce, especially for some rare defect types, it is difficult to collect enough samples. PCB defects are usually manifested as minor structural changes, such as minor solder joint damage, minor line breaks, etc. Deep learning models are effective when processing larger targets, but there are still difficulties in detecting minor defects. Since deep learning models usually perform detection on feature maps of larger scales, they may ignore subtle details on smaller scales, resulting in unsatisfactory detection of small defects. In addition, the feature extraction process of convolutional neural networks usually involves multi-layer downsampling operations, which may further lose key information of small defects, making it difficult for the model to accurately locate and identify these small defects in the context of high-density and complex circuits. In particular, YOLO, which is often used in existing PCB defect detection, has weak detection capabilities for small defects and is prone to missed detection. Deep learning models usually rely on specific defect types in the training data for learning, so when faced with defect types that do not appear or appear less frequently in the training set, the model's generalization ability is weak. The training of deep learning models usually requires a lot of computing resources, especially when the network structure is complex or the amount of data is large, the training time and hardware costs increase significantly. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a PCB defect detection method based on image processing, so as to solve the problem that the generalization ability of the model is weak when facing defect types that do not appear or appear rarely in the training set, and the training of deep learning models usually requires a large amount of computing resources.

[0005] The present invention is achieved in this way. A PCB defect detection method based on image processing, the method comprising: S1: Collect defect-free PCB board image data, preprocess and enhance the PCB board image data, and make a data set; S2: Loss functions are set for the reconstruction subnet and the segmentation subnet respectively, and the trained reconstruction subnet and segmentation subnet are obtained by training using the data set. The trained reconstruction subnet uses a diffusion model to gradually remove noise from the preprocessed and data enhanced image data to obtain a reconstructed image according to time steps. The reconstructed image is decomposed into low-frequency components and high-frequency components by discrete wavelet transform. The low-frequency components are input into the trained segmentation subnet and compared with the preprocessed and data enhanced image data to be detected, and the defective parts are distinguished.

[0006] Furthermore, in the process of training with the data set, the defects are added as noise to the PCB board image data according to the time step in the reconstruction subnet for forward diffusion processing until the PCB board image data is completely converted into pure noise data; the pure noise data is subjected to reverse diffusion processing, and the noise is gradually removed according to the time step to obtain a reconstructed image; the loss function of the reconstruction subnet is for: ,in and There are two different time steps. Is a label indicating whether the sample is abnormal, 0 represents a normal sample, 1 represents an abnormal sample, is at the time step The real noise added, is at the time step The real noise added, is the reconstruction subnetwork at time step The predicted noise, is the reconstruction subnetwork at time step Predicted noise.

[0007] Furthermore, the loss function of the segmentation subnet is for: , in is the true anomaly mask of the input image, is the anomaly mask predicted by the segmentation subnet, To smooth the L1 loss function, is the focal loss function, It is a hyperparameter used to balance the importance of L1 loss function and focal loss function. The true anomaly mask refers to the image area with noise.

[0008] Furthermore, the total loss function of the reconstruction subnet and the segmentation subnet is for: , Reduce the total loss function through training The value of makes the output of the segmentation subnet close to the true anomaly mask.

[0009] Furthermore, the discrete wavelet transform includes convolving the input reconstructed image in the horizontal direction and the vertical direction using a low-pass wavelet filter and a high-pass wavelet filter respectively to obtain a low-frequency component and a high-frequency component.

[0010] Furthermore, the high-frequency component is fed back to the reverse diffusion process, and the reverse diffusion process removes the fed-back high-frequency component as noise to be removed.

[0011] Compared with the prior art, the present invention has the following beneficial effects: the present invention only needs to use a data set of normal samples for training, avoiding the difficulty of collecting defect data and the problem of sample imbalance. The number of samples used in the present invention is far less than that of other target detection models, and small sample learning can be achieved while maintaining high accuracy. The present invention uses discrete wavelet transform to extract high-frequency components for back-diffusion denoising, thereby improving the inference speed and improving the accuracy of segmentation and defect detection by extracting low-frequency components. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 A flow chart of a method provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0013] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0014] See also Figure 1 As shown, the present invention provides a PCB defect detection method based on image processing, the method comprising: S1: Collect defect-free PCB board image data, preprocess and enhance the PCB board image data, and make a data set; The present invention uses a normal, defect-free PCB board as a sample to collect image data.

[0015] S2: Loss functions are set for the reconstruction subnet and the segmentation subnet respectively, and the trained reconstruction subnet and segmentation subnet are obtained by training using the data set. The trained reconstruction subnet uses a diffusion model to gradually remove noise from the preprocessed and data enhanced image data to obtain a reconstructed image according to time steps. The reconstructed image is decomposed into low-frequency components and high-frequency components by discrete wavelet transform. The low-frequency components are input into the trained segmentation subnet and compared with the preprocessed and data enhanced image data to be detected, and the defective parts are distinguished.

[0016] In the process of training with the dataset, the defects are added as noise to the PCB image data in the reconstruction subnet according to the time step for forward diffusion processing until the PCB image data is completely converted into pure noise data; the pure noise data is subjected to reverse diffusion processing, and the noise is gradually removed according to the time step to obtain the reconstructed image; the loss function of the reconstruction subnet is for: ,in and There are two different time steps. Is a label indicating whether the sample is abnormal, 0 represents a normal sample, 1 represents an abnormal sample, is at the time step The real noise added, is at the time step The real noise added, is the reconstruction subnetwork at time step The predicted noise, is the reconstruction subnetwork at time step Predicted noise.

[0017] The forward diffusion process is described by the following formula: , in, To control the noise intensity at each time step, represents a normal distribution, It is image data at time steps, is the image data of the previous step, is the identity matrix, It is the output of each step of the forward diffusion process.

[0018] After multiple diffusion steps, the image data will become pure noise, i.e. In the back diffusion process, the image is reconstructed by gradually removing the noise. This process usually uses the following back diffusion formula: , in, and are the mean and standard deviation predicted by the neural network, which are used to generate The image at time step.

[0019] The noise in the above process uses Simplex noise as a defect added to the image data. The present invention adds noise to a defect-free qualified product sample to simulate unknown defects. The area where the noise is added is used as a real abnormality mask.

[0020] The present invention minimizes the loss function of the reconstructed subnet Train the reconstruction subnetwork.

[0021] Loss function for segmentation subnet for: , in is the true anomaly mask of the input image, is the anomaly mask predicted by the segmentation subnet, To smooth the L1 loss function, is the focal loss function, It is a hyperparameter used to balance the importance of L1 loss function and focal loss function. The real anomaly mask refers to the image area with noise.

[0022] By minimizing the loss function of the segmentation subnet Train the segmentation subnet.

[0023] During the training process, the reconstruction subnet and the segmentation subnet are not trained separately. For the entire network, the total loss function of the reconstruction subnet and the segmentation subnet is established. for: , Reduce the total loss function through training The value of makes the output of the segmentation subnet close to the true anomaly mask.

[0024] A discrete wavelet transform layer is set between the reconstruction subnet and the segmentation subnet to perform discrete wavelet transform on the reconstructed image output by the reconstruction subnet. The purpose is to decompose the reconstructed image of the input two-dimensional data into low-frequency subbands and high-frequency subbands. The input reconstructed image is convolved with a wavelet low-pass filter and a wavelet high-pass filter to obtain low-frequency components and high-frequency components respectively. For each direction, including the horizontal direction and the vertical direction, one filter (wavelet low-pass filter or wavelet high-pass filter) is first applied, and then another filter is applied. This will produce four subbands: low-frequency-low-frequency (LL), low-frequency-high-frequency (LH), high-frequency-low-frequency (HL), and high-frequency-low-frequency (HH). Low-frequency-low-frequency (LL) is the main component of the input data and contains most of the information of the image. It is obtained by convolving the input reconstructed image with the wavelet low-pass filter in the horizontal and vertical directions. The remaining high-frequency components mainly contain some noise and edge information.

[0025] In the present invention, low-frequency information is selected and sent to the segmentation subnet to filter high-frequency noise, which is more conducive to the segmentation subnet to compare the enhanced image and distinguish the defective part.

[0026] For the decomposed high-frequency information, which is mainly composed of noise, the high-frequency components are fed back to the reverse diffusion process, and the reverse diffusion process removes the fed-back high-frequency components as the noise to be removed. After such feedback, the denoising effect of the reconstructed subnet can be increased. The reverse diffusion formula becomes the following form: , is the high-frequency-high-frequency component at time step t-1, is the high-frequency-low-frequency component of the t-1 time step, is the low-frequency-high-frequency component at the t-1 time step.

[0027] During the training process, the input of the segmentation subnet is divided into two parts: the output of the reconstruction subnet and the image data of the PCB board with defects added. The anomaly score of each area is obtained by comparing the difference between the two. The greater the difference between the two, the higher the anomaly score.

[0028] When actually used for detection, the input of the segmentation subnet includes: the output of the reconstruction subnet and the image data of the PCB board to be detected. By comparing the difference between the two, the abnormal score of each area is obtained. The greater the difference between the two, the higher the abnormal score, thus separating the defective part. Defect detection of PCB boards is achieved.

[0029] When actually used for detection, the original image captured by the industrial camera is divided into four sub-images containing only one PCB board to be detected. The four sub-images are sent to the reconstruction subnet separately. The reconstruction subnet only performs reverse diffusion processing, removes noise from the input PCB board image data to obtain a reconstructed image, and inputs it into the segmentation subnet to obtain the detection result.

[0030] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A PCB defect detection method based on image processing, characterized in that: The method includes: S1: Collect defect-free PCB board image data, preprocess and enhance the PCB board image data, and make a data set; S2: Loss functions are set for the reconstruction subnet and the segmentation subnet respectively, and the trained reconstruction subnet and segmentation subnet are obtained by training using the data set. The trained reconstruction subnet uses a diffusion model to gradually remove noise from the preprocessed and data enhanced image data according to time steps to obtain a reconstructed image. The reconstructed image is decomposed into low-frequency components and high-frequency components by discrete wavelet transform. The low-frequency components are input into the trained segmentation subnet to compare with the image data to be detected, and the defective parts are distinguished.

2. The PCB defect detection method based on image processing according to claim 1 is characterized in that: In the process of training with the data set, the defects are added as noise to the PCB board image data according to the time step in the reconstruction subnet for forward diffusion processing until the PCB board image data is completely converted into pure noise data; the pure noise data is subjected to reverse diffusion processing, and the noise is gradually removed according to the time step to obtain a reconstructed image; the loss function of the reconstruction subnet is for: ,in and There are two different time steps. Is a label indicating whether the sample is abnormal, 0 represents a normal sample, 1 represents an abnormal sample, is at the time step The real noise added, is at the time step The real noise added, is the reconstruction subnetwork at time step The predicted noise, is the reconstruction subnetwork at time step Predicted noise.

3. The PCB defect detection method based on image processing according to claim 2 is characterized in that: The loss function of the segmentation subnet is for: , in is the true anomaly mask of the input image, is the anomaly mask predicted by the segmentation subnet, To smooth the L1 loss function, is the focal loss function, It is a hyperparameter used to balance the importance of L1 loss function and focal loss function. The true anomaly mask refers to the image area with noise.

4. The PCB defect detection method based on image processing according to claim 3 is characterized in that: The total loss function of the reconstruction subnet and the segmentation subnet for: , Reduce the total loss function through training The value of makes the output of the segmentation subnet close to the true anomaly mask.

5. The PCB defect detection method based on image processing according to claim 2 is characterized in that: The discrete wavelet transform includes convolving the input reconstructed image in the horizontal direction and the vertical direction using a low-pass wavelet filter and a high-pass wavelet filter respectively to obtain a low-frequency component and a high-frequency component.

6. The PCB defect detection method based on image processing according to claim 5 is characterized in that: The high-frequency component is fed back to the back diffusion process, and the back diffusion process removes the fed-back high-frequency component as noise to be removed.

Citation Information

Patent Citations

  • Board card defect category identification method, device and equipment and readable storage medium

    CN114240926A

  • Defect detection CT image reconstruction method and system fusing FBP algorithm and IR algorithm

    CN117218220A

  • Image anomaly detection method based on self-supervised learning and diffusion generation model

    CN118037711A

  • Image shadow removal method based on wavelet non-uniform diffusion model

    CN118134800A

  • Aluminum foil package infrared sealing image defect detection method based on self-supervised learning

    CN118297937A

Cited By

  • Multi-platform-oriented large PCB vector diagram cloud intelligent processing method

    CN120953082A

  • Multi-platform-oriented large pcb vector diagram cloud intelligent processing method

    CN120953082B

  • PCB multi-type defect detection method and device based on frequency domain perception enhancement, storage medium and program product

    CN121962145A