A printed circuit board defect detection method and system based on image recognition

Through technical means of multi-scale feature fusion and background texture suppression, the problem of background texture interference in printed circuit board detection is solved, more efficient defect detection and precise positioning is achieved, and the accuracy and robustness of the detection are improved.

CN119804490BActive Publication Date: 2025-08-08MEIZHOU CITY XING CHENG CIRCUIT BOARD CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510293006.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-13
Publication Date
2025-08-08
Estimated Expiration
2045-03-13

AI Technical Summary

Technical Problem

The existing printed circuit board defect detection methods based on image recognition are difficult to effectively distinguish background texture and defect characteristics, resulting in insufficient robustness and prone to false detection and missed detection.

Method used

Through technical means such as multi-scale feature fusion, background texture feature learning and suppression, adaptive threshold segmentation, and morphological optimization, including image preprocessing, scale feature fusion, background texture suppression, local statistical feature calculation, defect area refinement and classification positioning, the accuracy and robustness of detection are improved.

Benefits of technology

It effectively suppresses interference from complex background textures, improves the accuracy and robustness of defect detection of printed circuit boards, and achieves more efficient defect detection and precise positioning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119804490B_ABST
    Figure CN119804490B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of printed circuit board design technology, and in particular to a printed circuit board defect detection method and system based on image recognition. The method comprises the following steps: performing image preprocessing on an original PCB image to obtain a preprocessed PCB image; performing scale feature fusion on the preprocessed PCB image to obtain a multi-scale feature map; performing background texture feature learning on the multi-scale feature map to obtain a background suppression feature map; performing background texture suppression based on the background suppression feature map to obtain a significant defect map; and performing local statistical feature calculation based on the preprocessed PCB image and the significant defect map to obtain a local statistical feature map. The present invention effectively solves the problem of complex background texture interference and improves the accuracy and robustness of PCB defect detection through a series of technical means including multi-scale feature fusion, background texture feature learning and suppression, adaptive threshold segmentation, and morphological optimization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of printed circuit board design, and in particular to a printed circuit board defect detection method and system based on image recognition. Background Art

[0002] PCB circuits are becoming increasingly dense, making defect detection increasingly challenging and demanding. Traditional visual inspection methods are no longer sufficient for modern industrial production, leading to the emergence of automated optical inspection (AOI) technology based on image recognition. Early methods primarily relied on template matching, comparing the image to be inspected with a defect-free standard template and determining the presence of defects based on pixel differences. While this approach is simple and easy to implement, it is sensitive to image alignment and lighting variations, resulting in poor robustness and difficulty with complex background textures.

[0003] In PCB images, some background textures (such as pad edges and thin conductors) share similar texture features with defect features (such as open circuits, short circuits, and pinholes), making them difficult to distinguish. Different PCB designs, manufacturing processes, and lighting conditions all lead to variations in background texture, increasing the difficulty of detection. Most existing methods focus primarily on extracting defect features while neglecting to model and suppress complex background textures. This results in significant interference from background textures on defect detection. Due to the complexity and diversity of background textures, existing methods often lack robustness when dealing with different types of background textures, making them prone to false detections and missed detections. Summary of the Invention

[0004] Based on this, it is necessary to provide a printed circuit board defect detection method and system based on image recognition to solve at least one of the above technical problems.

[0005] To achieve the above objectives, a printed circuit board defect detection method based on image recognition includes the following steps:

[0006] Step S1: performing image preprocessing on the original PCB image to obtain a preprocessed PCB image; performing scale feature fusion on the preprocessed PCB image to obtain a multi-scale feature map;

[0007] Step S2: performing background texture feature learning on the multi-scale feature map to obtain a background suppression feature map; performing background texture suppression based on the background suppression feature map to obtain a significant defect map;

[0008] Step S3: Calculate local statistical features based on the pre-processed PCB image and the significant defect map to obtain a local statistical feature map; perform adaptive threshold calculation based on the local statistical feature map, and perform binary segmentation to obtain candidate defect areas;

[0009] Step S4: performing preliminary hole detection on the candidate defect regions to obtain preliminary hole regions; performing distance transformation calculation on the preliminary hole regions to obtain a distance transformation map; performing geodesic transformation calculation on the distance transformation map to obtain a geodesic distance map; constructing a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map; refining the defect region on the geodesic reconstruction map to obtain a refined defect region;

[0010] Step S5: classify the refined defect area to obtain defect category data; locate the defect based on the defect category data to obtain defect position and size data; integrate the defect information of the defect category data and the defect position and size data to obtain defect detection results to implement printed circuit board defect detection operations.

[0011] The present invention enhances image quality and consistency through image preprocessing, laying the foundation for subsequent processing; scale feature fusion combines the local texture information of wavelet transform and the global semantic information of deep learning to construct a more representative multi-scale feature map, thereby improving the robustness and accuracy of defect detection. By learning background texture features through the attention mechanism and guiding feature learning, the interference of complex background textures is effectively suppressed, the defect area is highlighted, and the final significant defect map makes the defects more significant, thereby improving the sensitivity of defect detection. The adaptive threshold calculation method based on local statistical features can dynamically adjust the segmentation threshold according to the characteristics of different areas, effectively overcoming the limitations of the fixed threshold method in complex backgrounds, improving the accuracy of defect segmentation, and obtaining more accurate candidate defect areas. Through a series of morphological operations, including noise removal, broken connection, hole detection, distance transformation, geodesic transformation and reconstruction, the defect area is effectively refined, the holes are filled, the edges are smoothed, the noise is removed, and ultimately more accurate defect shape and location information is obtained. Through feature extraction, classifier training and defect location, automatic classification and precise location of defects are achieved, and the category, location and size information of the defects are integrated, and finally structured defect detection results are output, providing effective data support for PCB production quality control. Therefore, the present invention provides a printed circuit board defect detection method based on image recognition, which solves the shortcomings of existing methods in dealing with complex background textures. Through a series of technical means such as multi-scale feature fusion, background texture feature learning and suppression, adaptive threshold segmentation, and morphological optimization, the problem of complex background texture interference is effectively solved, and the accuracy and robustness of PCB defect detection are improved. The invention method has important theoretical significance and practical application value, and provides effective technical support for quality control and efficiency improvement in the electronics manufacturing industry, so as to achieve more efficient and intelligent PCB defect detection.

[0012] Preferably, step S1 includes the following steps:

[0013] Step S11: performing image preprocessing on the original PCB image to obtain a preprocessed PCB image;

[0014] Step S12: performing multi-scale wavelet transform on the pre-processed PCB image to obtain multi-scale wavelet coefficients;

[0015] Step S13: Use a pre-trained deep convolutional neural network to extract deep features from the pre-processed PCB image to obtain a deep feature map;

[0016] Step S14: reconstructing the multi-scale wavelet coefficients to obtain a reconstructed wavelet feature map;

[0017] Step S15: performing feature map upsampling on the depth feature map according to the reconstructed wavelet feature map to obtain an upsampled depth feature map;

[0018] Step S16: performing feature fusion on the reconstructed wavelet feature map and the upsampled depth feature map to obtain a multi-scale feature map.

[0019] The present invention effectively removes image noise through Gaussian filtering through image preprocessing, thereby improving the robustness of subsequent feature extraction; histogram equalization enhances image contrast, highlights detailed features in PCB images, and is beneficial to defect identification; scaling the image to a fixed size unifies the specifications of the input image, reduces the amount of calculation, and improves algorithm efficiency. Multi-scale wavelet transform decomposes the image into different frequency sub-bands, respectively capturing the contour information and detailed texture information of the image, realizing the extraction of multi-scale features of the PCB image, and providing rich feature representation for subsequent feature fusion. Using a pre-trained deep convolutional neural network to extract deep feature maps can effectively capture high-level semantic information and global features of PCB images, such as component layout, line direction, etc. These features help to distinguish defects from normal textures. Wavelet coefficient reconstruction recombines the coefficients after wavelet transformation into image form, retains multi-scale features, and expresses image information in a more intuitive way, which is convenient for fusion with deep feature maps. Feature map upsampling adjusts the size of the deep feature map to the same size as the reconstructed wavelet feature. Figure 1 This ensures the spatial alignment of the two feature maps, creating conditions for subsequent feature fusion. Feature fusion combines the local texture information of the wavelet feature map with the global semantic information of the depth feature map to form a more comprehensive multi-scale feature representation, improving the accuracy and robustness of defect detection.

[0020] Preferably, step S2 includes the following steps:

[0021] Step S21: constructing an attention module for background texture on the multi-scale feature map to obtain an attention weight map;

[0022] Step S22: performing attention-guided feature learning on the attention weight map and the multi-scale feature map to obtain a background suppression feature map;

[0023] Step S23: performing residual connection and feature fusion on the multi-scale feature map and the background suppression feature map to obtain a fused feature map;

[0024] Step S24: Perform nonlinear activation and normalization on the fused feature map to obtain a significant defect map.

[0025] The present invention generates an attention weight map by learning the background texture features in the multi-scale feature map through the attention module. The weight map highlights the background texture area and provides guidance for subsequent background suppression. The attention-guided feature learning uses the attention weight map to weight the multi-scale feature map, effectively suppressing the feature response of the background texture area and highlighting the features of the potential defect area, thereby improving the sensitivity of defect detection. The residual connection fuses the original multi-scale feature map with the background suppression feature map, retaining the original feature information, avoiding information loss, and enhancing the learning ability of the network; feature fusion further integrates the information of the two feature maps and improves the integrity of the feature representation. The nonlinear activation function ReLU introduces nonlinearity and enhances the expressive power of the model; the normalization operation maps the eigenvalues to a uniform range, improving the stability and robustness of the algorithm. The final significant defect map highlights the potential defect area and provides a reliable basis for subsequent defect segmentation.

[0026] Preferably, step S3 includes the following steps:

[0027] Step S31: determining the size of the local area according to the pre-processed PCB image and the significant defect map to obtain local area size data;

[0028] Step S32: performing local statistical feature calculation of a sliding window on the significant defect map according to the local area size data to obtain a local statistical feature map;

[0029] Step S33: performing adaptive threshold calculation based on the local statistical feature map to obtain an adaptive threshold map, wherein the local statistical feature map includes a local histogram, a local mean map, and a local standard deviation map;

[0030] Step S34: performing binary segmentation on the adaptive threshold map and the significant defect map to obtain candidate defect regions.

[0031] The present invention calculates the average size of connected areas based on the gradient information of the significant defect map, and determines the size of the local area in combination with the scaling factor. It can adaptively adjust the size of the local area to match defects of different sizes, thereby improving the adaptability of the algorithm to different defect types. The sliding window calculates the local histogram, mean and standard deviation, which can capture the statistical characteristics of the local area. These characteristics can effectively distinguish between the defect area and the background area, providing a basis for the subsequent adaptive threshold calculation. The adaptive threshold is calculated using the local histogram, mean and standard deviation, and the segmentation threshold can be dynamically adjusted according to the statistical characteristics of the local area, avoiding the limitations of the fixed threshold segmentation method and improving the accuracy of segmentation, especially in the case of complex background. Comparing the significant defect map with the adaptive threshold map and performing binary segmentation can effectively separate the potential defect area from the background, generate candidate defect areas, and provide input for subsequent morphological optimization.

[0032] Preferably, step S33 includes the following steps:

[0033] Step S331: performing local Otsu threshold calculation on the local histogram to obtain a local Otsu threshold list;

[0034] Step S332: converting the local Otsu threshold list into a threshold map according to the local region size data, and performing threshold smoothing to obtain a smoothed local Otsu threshold map;

[0035] Step S333: performing local contrast calculation based on the local mean map and the local standard deviation map to obtain a local contrast map;

[0036] Step S334: performing contrast normalization on the local contrast map to obtain a normalized local contrast map;

[0037] Step S335: Calculating the threshold adjustment weight using the normalized local contrast map to obtain a threshold adjustment weight map;

[0038] Step S336: Using the threshold adjustment weight map, threshold adjustment is performed on the smoothed local Otsu threshold map to obtain an adaptive threshold map.

[0039] By applying the Otsu algorithm to each local histogram, the present invention can obtain a series of local optimal thresholds. These thresholds preliminarily reflect the grayscale distribution characteristics of each local area, laying the foundation for the subsequent generation of an adaptive threshold map. Converting the local Otsu threshold list into a threshold map and performing Gaussian smoothing can effectively remove noise interference and make the threshold map smoother, thereby avoiding over-segmentation in the binary segmentation result and improving the stability of the segmentation. Calculating a local contrast map can reflect the texture characteristics of the local area of the image. Areas with high contrast usually correspond to defects or edge areas, which provides a basis for subsequent threshold adjustment based on contrast. Contrast normalization maps contrast values to between 0 and 1, eliminating the differences in contrast values between different areas and making the subsequent threshold adjustment weight calculation more standardized. Calculating the threshold adjustment weight using an exponential function can amplify the effect of contrast on the threshold, making the threshold adjustment amplitude larger in areas with high contrast (such as defect areas), thereby more accurately segmenting defects. The smoothed local Otsu threshold map is multiplied by the threshold adjustment weight map to obtain the final adaptive threshold map. This threshold map comprehensively considers the local grayscale distribution and local contrast information, and can more accurately reflect the boundary of the defect area, thereby improving the accuracy of binary segmentation.

[0040] Preferably, step S4 includes the following steps:

[0041] Step S41: removing noise from the candidate defect region to obtain a denoised candidate region; connecting the broken defects in the denoised candidate region to obtain a connected defect region;

[0042] Step S42: performing preliminary void detection on the defective area after connection to obtain a preliminary void area;

[0043] Step S43: performing distance transformation calculation on the preliminary hole area to obtain a distance transformation map;

[0044] Step S44: marking the hole boundary of the preliminary hole area to obtain a hole boundary map; performing geodesic transformation calculation on the distance transformation map using the hole boundary map as a marker to obtain a geodesic distance map;

[0045] Step S45: constructing a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map;

[0046] Step S46: performing region merging and filling on the geodesic reconstruction image and the connected defect region to obtain a filled defect region;

[0047] Step S47: performing edge smoothing on the filled defect area to obtain a smoothed defect area; performing region screening on the smoothed defect area to obtain a refined defect area.

[0048] The present invention effectively removes noise in candidate defect areas through median filtering, reducing false detections; morphological closing operations connect broken defect areas, making the defect areas more complete, which is beneficial for subsequent hole detection and defect refinement. Through connected region analysis and Euler number calculation, holes in the connected defect areas can be effectively identified and marked, providing target areas for subsequent distance transformation and geodesic transformation. Distance transformation calculates the distance from each pixel in the hole area to the nearest pixel in the non-hole area, converts the shape information of the hole into distance information, and provides basic data for subsequent geodesic transformation and reconstruction. The hole boundary marking accurately determines the outline of the hole; the geodesic transformation calculates the shortest path along the hole surface, which can more accurately describe the shape of the hole and provide key information for geodesic reconstruction. Geodesic reconstruction uses the geodesic distance map and distance transformation map to propagate the hole boundary information to the inside of the hole, effectively filling the hole area while retaining the original shape of the hole, providing more accurate shape information for the refinement of the defect area. Merging the geodesic reconstruction image with the connected defect region fills the voids, making the defect region more complete and preparing for subsequent edge smoothing and region filtering. Gaussian filtering smoothes the edges of the filled defect region, removing jagged edges and making the defect region's outline clearer. Region filtering removes areas that are too small, often representing noise or artifacts, thereby improving defect detection accuracy.

[0049] Preferably, step S43 includes the following steps:

[0050] Step S431: performing defect region inversion on the preliminary void region to obtain an inverted defect region;

[0051] Step S432: Calculating an initial distance map of the defective area after inversion using a pre-selected distance measurement method to obtain an initial distance map;

[0052] Step S433: normalizing the initial distance map to obtain a normalized distance map;

[0053] Step S434: performing distance map enhancement on the normalized distance map to obtain a distance transformation map.

[0054] The present invention inverts the preliminary hole area, converts the hole area into the background, and converts the background area into the foreground, which makes it possible to use a standard distance transformation algorithm to calculate the distance from each pixel to the nearest original hole area pixel, simplifying the calculation process. The initial distance map is calculated using the Euclidean distance metric method, which can accurately reflect the distance from each pixel to the nearest original hole area pixel, providing basic data for subsequent normalization and enhancement operations. Distance map normalization scales the distance value to between 0 and 1, eliminating the difference in distance values between different holes, making subsequent distance enhancement operations more standardized, and facilitating comparisons between different images. Distance map enhancement highlights the change in distance through power law transformation, making pixel values with larger distances more obvious, thereby enhancing the boundary information of the hole area, facilitating subsequent geodesic transformation and reconstruction, and improving the accuracy of defect area refinement.

[0055] Preferably, step S45 includes the following steps:

[0056] Step S451: constructing an initial reconstruction image according to the distance transformation image to obtain an initial reconstruction image;

[0057] Step S452: determining a dynamic threshold coefficient according to the geodesic distance map to obtain the dynamic threshold coefficient;

[0058] Step S453: traverse each pixel in the distance transformation map, and multiply the distance value of the corresponding pixel in the geodesic distance map by the dynamic threshold coefficient to obtain a dynamic threshold;

[0059] Step S454: performing pixel value comparison based on the distance transformation map and the dynamic threshold, and labeling the initial reconstructed image to obtain a labeled image;

[0060] Step S455: Perform morphological processing on the labeled image to obtain a geodesic reconstruction image.

[0061] This method replicates the distance transform map as the initial reconstruction map, providing initial data for subsequent iterative reconstruction operations and ensuring that the reconstructed image size is consistent with the original image. A dynamic threshold coefficient is determined based on the statistical properties of the geodesic distance map (mean and standard deviation), adaptively adjusting the sensitivity of the reconstruction process to ensure that the reconstruction result more closely matches the actual cavity shape. A dynamic threshold is calculated for each pixel, incorporating geodesic distance information into the reconstruction process and providing a basis for subsequent pixel value comparison and labeling. By comparing the distance transform map with the dynamic threshold and labeling the initial reconstruction map, geodesic distance information is propagated into the distance transform map, gradually constructing the reconstructed image and ensuring more accurate filling of cavity regions. A morphological closing operation smoothes the reconstruction result, removes minor noise and artifacts, and connects any broken regions, making the final geodesic reconstruction more complete and accurate, more accurately reflecting the shape and size of the cavity.

[0062] Preferably, step S5 includes the following steps:

[0063] Step S51: extracting features from the refined defect area to obtain a defect feature vector;

[0064] Step S52: performing lightweight classifier training based on the defect feature vector and the preset defect label to obtain a defect classifier;

[0065] Step S53: using a defect classifier to classify the defect feature vector to obtain defect category data;

[0066] Step S54: performing defect location according to the refined defect area and defect category data to obtain defect position and size data;

[0067] Step S55: Integrate the defect information of the defect category data and the defect position and size data to obtain the defect detection result.

[0068] By extracting multiple features from the refined defect region, including area, perimeter, circularity, Hu moment, grayscale mean, and grayscale standard deviation, this method comprehensively describes the geometric shape and grayscale characteristics of the defect, providing an effective feature representation for subsequent defect classification. Using a pre-labeled dataset to train a lightweight classifier (such as a Support Vector Machine (SVM) or random forest) effectively learns the mapping relationship between defect features and defect categories, enabling automatic classification of different defect types. Using the trained classifier to classify defect feature vectors, the refined defect region can be divided into different defect categories, such as open circuit, short circuit, and missing component, providing classification information for subsequent defect analysis and processing. Calculating the minimum bounding rectangle of the refined defect region accurately determines the defect's location coordinates and dimensions, providing precise positioning information for subsequent defect repair or other processing. Defect category, location, and dimension information are integrated to form the final defect detection result, which is then output in a structured manner, facilitating subsequent analysis, processing, and recording, thereby improving the practicality of defect detection.

[0069] Preferably, the present invention further provides a printed circuit board defect detection system based on image recognition, which is used to execute the printed circuit board defect detection method based on image recognition as described above. The printed circuit board defect detection system based on image recognition includes:

[0070] The multi-scale feature fusion module is used to perform image preprocessing on the original PCB image to obtain a preprocessed PCB image; and to perform scale feature fusion on the preprocessed PCB image to obtain a multi-scale feature map;

[0071] The background texture suppression module is used to learn background texture features on the multi-scale feature map to obtain a background suppression feature map; background texture suppression is performed based on the background suppression feature map to obtain a significant defect map;

[0072] The adaptive threshold segmentation module is used to calculate local statistical features based on the pre-processed PCB image and the significant defect map to obtain a local statistical feature map; adaptive threshold calculation is performed based on the local statistical feature map, and binary segmentation is performed to obtain candidate defect areas;

[0073] The morphological optimization module is used to perform preliminary void detection based on the candidate defect area to obtain a preliminary void area; perform distance transformation calculation on the preliminary void area to obtain a distance transformation map; perform geodesic transformation calculation on the distance transformation map to obtain a geodesic distance map; construct a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map; and refine the defect area on the geodesic reconstruction map to obtain a refined defect area.

[0074] The defect classification and positioning module is used to classify the refined defect area and obtain defect category data; locate the defect according to the defect category data and obtain defect position and size data; integrate the defect information of the defect category data and the defect position and size data to obtain the defect detection results. BRIEF DESCRIPTION OF THE DRAWINGS

[0075] Figure 1 The following is a flowchart of a printed circuit board defect detection method based on image recognition;

[0076] Figure 2 for Figure 1 Detailed implementation steps of step S3 in FIG.

[0077] Figure 3 for Figure 1 Detailed implementation steps of step S4 in FIG.

[0078] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION

[0079] The following is a clear and complete description of the technical method of the present invention in conjunction with the accompanying drawings. It is obvious that the embodiments described are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making any creative efforts are within the scope of protection of the present invention.

[0080] In addition, the accompanying drawings are merely schematic illustrations of the present invention and are not necessarily drawn to scale. Identical reference numerals in the figures denote identical or similar parts, and thus repetitive descriptions thereof will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor and / or microcontroller approaches.

[0081] It should be understood that although the terms "first," "second," and the like may be used herein to describe various elements, these elements should not be limited by these terms. These terms are used solely to distinguish one element from another. For example, a first element may be referred to as a second element, and similarly, a second element may be referred to as a first element, without departing from the scope of the exemplary embodiments. The term "and / or" as used herein includes any and all combinations of one or more of the listed associated items.

[0082] To achieve this, please refer to Figures 1 to 3 A printed circuit board defect detection method based on image recognition comprises the following steps:

[0083] Step S1: performing image preprocessing on the original PCB image to obtain a preprocessed PCB image; performing scale feature fusion on the preprocessed PCB image to obtain a multi-scale feature map;

[0084] Step S2: performing background texture feature learning on the multi-scale feature map to obtain a background suppression feature map; performing background texture suppression based on the background suppression feature map to obtain a significant defect map;

[0085] Step S3: Calculate local statistical features based on the pre-processed PCB image and the significant defect map to obtain a local statistical feature map; perform adaptive threshold calculation based on the local statistical feature map, and perform binary segmentation to obtain candidate defect areas;

[0086] Step S4: performing preliminary hole detection on the candidate defect regions to obtain preliminary hole regions; performing distance transformation calculation on the preliminary hole regions to obtain a distance transformation map; performing geodesic transformation calculation on the distance transformation map to obtain a geodesic distance map; constructing a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map; refining the defect region on the geodesic reconstruction map to obtain a refined defect region;

[0087] Step S5: classify the refined defect area to obtain defect category data; locate the defect based on the defect category data to obtain defect position and size data; integrate the defect information of the defect category data and the defect position and size data to obtain defect detection results to implement printed circuit board defect detection operations.

[0088] In the embodiment of the present invention, reference Figure 1 FIG. 1 is a flow chart of the steps of the printed circuit board defect detection method based on image recognition according to the present invention. In this example, the printed circuit board defect detection method based on image recognition includes the following steps:

[0089] Step S1: performing image preprocessing on the original PCB image to obtain a preprocessed PCB image; performing scale feature fusion on the preprocessed PCB image to obtain a multi-scale feature map;

[0090] In the embodiment of the present invention, in the image preprocessing stage, the original PCB image is first subjected to Gaussian filtering for denoising, then subjected to histogram equalization for contrast enhancement, and finally scaled to a fixed size. In the scale feature fusion stage, the preprocessed image is first subjected to multi-scale wavelet transform, and the wavelet coefficients are reconstructed to obtain a reconstructed wavelet feature map; at the same time, a pre-trained ResNet-50 network is used to extract a depth feature map, and the map is upsampled to the same size as the wavelet feature map. Finally, the reconstructed wavelet feature map and the upsampled depth feature map are spliced in the channel dimension, and then 1 1. Convolution is used to perform feature fusion and obtain a multi-scale feature map.

[0091] Step S2: performing background texture feature learning on the multi-scale feature map to obtain a background suppression feature map; performing background texture suppression based on the background suppression feature map to obtain a significant defect map;

[0092] In the embodiment of the present invention, the attention module is used to learn the background texture features and generate an attention weight map. The attention weight map is multiplied with the multi-scale feature map to suppress the background texture and obtain a background suppression feature map. The multi-scale feature map and the background suppression feature map are residually connected and 1 1. Convolution fusion feature. Finally, the fused feature map is activated and normalized by ReLU to obtain the significant defect map.

[0093] Step S3: Calculate local statistical features based on the pre-processed PCB image and the significant defect map to obtain a local statistical feature map; perform adaptive threshold calculation based on the local statistical feature map, and perform binary segmentation to obtain candidate defect areas;

[0094] In this embodiment of the present invention, the local region size is calculated based on the gradient amplitude of the significant defect map. A sliding window is used to calculate the local histogram, local mean, and local standard deviation on the significant defect map to form a local statistical feature map. Based on the local statistical feature map, the initial threshold is calculated using the Otsu algorithm and adaptively adjusted based on the local mean and standard deviation to produce an adaptive threshold map. Finally, the significant defect map is compared with the adaptive threshold map and binarized to obtain candidate defect regions.

[0095] Step S4: performing preliminary hole detection on the candidate defect regions to obtain preliminary hole regions; performing distance transformation calculation on the preliminary hole regions to obtain a distance transformation map; performing geodesic transformation calculation on the distance transformation map to obtain a geodesic distance map; constructing a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map; refining the defect region on the geodesic reconstruction map to obtain a refined defect region;

[0096] In this embodiment of the present invention, candidate defect regions are subjected to median filtering for denoising and morphological closing operations to connect broken defects. Preliminary hole regions are detected through connected region analysis and Euler number calculation. A distance transform is performed on the preliminary hole regions to obtain a distance transform map. A geodesic transform is then performed to obtain a geodesic distance map. Geodesic reconstruction is performed using the distance transform map and the geodesic distance map to obtain a geodesic reconstruction map. Finally, the reconstructed map is merged with the connected defect regions, and Gaussian filtering and area screening are performed to obtain a refined defect region.

[0097] Step S5: classifying the refined defect area to obtain defect category data; locating the defect based on the defect category data to obtain defect position and size data; integrating the defect category data and the defect position and size data to obtain defect detection results, thereby achieving printed circuit board defect detection operations;

[0098] In this embodiment of the present invention, refined defect region features, including area, perimeter, circularity, Hu moment, grayscale mean, and grayscale standard deviation, are extracted to form a defect feature vector. A lightweight classifier (such as a support vector machine (SVM) or random forest) is trained using a pre-labeled dataset. The trained classifier is used to classify the defect feature vectors to obtain defect classification data. The minimum bounding rectangle (MBR) of each defect region is calculated to obtain its location and size information. Finally, the defect category, location, and size information are integrated to output the final defect detection result.

[0099] Preferably, step S1 includes the following steps:

[0100] Step S11: performing image preprocessing on the original PCB image to obtain a preprocessed PCB image;

[0101] Step S12: performing multi-scale wavelet transform on the pre-processed PCB image to obtain multi-scale wavelet coefficients;

[0102] Step S13: Use a pre-trained deep convolutional neural network to extract deep features from the pre-processed PCB image to obtain a deep feature map;

[0103] Step S14: reconstructing the multi-scale wavelet coefficients to obtain a reconstructed wavelet feature map;

[0104] Step S15: performing feature map upsampling on the depth feature map according to the reconstructed wavelet feature map to obtain an upsampled depth feature map;

[0105] Step S16: performing feature fusion on the reconstructed wavelet feature map and the upsampled depth feature map to obtain a multi-scale feature map.

[0106] In the embodiment of the present invention, the original PCB image is first read, which is usually an RGB color image or a grayscale image. The image data is read using the OpenCV library and converted into a NumPy array format. Subsequently, a Gaussian filter is applied to smooth the image to remove high-frequency noise and retain the edge information of the image. The convolution kernel size of the Gaussian filter is set to 5. 5, and the standard deviation is set to 1.5. Next, histogram equalization is performed to enhance the image contrast, making the grayscale distribution of the image more uniform and highlighting the details. Finally, in order to reduce the amount of calculation and unify the image size, the image is scaled to a fixed size, such as 512 512 pixels. The scaling algorithm uses bilinear interpolation to ensure image quality.

[0107] The PyWavelets library was used to perform a multiscale wavelet transform on the preprocessed PCB image. The 'db4' wavelet basis function was used for three-level decomposition, yielding wavelet coefficients for low-frequency and high-frequency subbands. The low-frequency subband primarily contains image contour information, while the high-frequency subband contains image detail and texture information. The wavelet coefficients obtained at each level of decomposition were stored as NumPy arrays for subsequent processing.

[0108] Load a pretrained deep convolutional neural network model, such as ResNet-50, which was trained on the ImageNet dataset and has powerful feature extraction capabilities. Use a deep learning framework such as TensorFlow or PyTorch to load the model. Remove the model's classification layer and feed the preprocessed PCB image into the model for forward propagation. Extract the output of the model's last convolutional layer as a deep feature map. This deep feature map captures high-level semantic information of the PCB image.

[0109] The multiscale wavelet coefficients were reconstructed using the PyWavelets library. An inverse wavelet transform was performed using the same wavelet basis function 'db4' and decomposition level. The reconstructed wavelet feature map, which contains the multiscale texture information of the PCB image, was stored as a NumPy array.

[0110] The depth feature map is upsampled using bilinear interpolation. The upsampled target size is the same as the wavelet feature map size. The upsampling operation expands the size of the depth feature map so that it is aligned with the wavelet feature map in the spatial dimension.

[0111] The reconstructed wavelet feature map and the upsampled depth feature map are concatenated along the channel dimension. This concatenated feature map contains the multi-scale wavelet features and depth semantic features of the PCB image. Subsequently, a 1×1 convolution is used to reduce the channel dimension of this concatenated feature map to reduce computational effort and fuse different types of features. The resulting multi-scale feature map is used for subsequent background texture feature learning.

[0112] Preferably, step S2 includes the following steps:

[0113] Step S21: constructing an attention module for background texture on the multi-scale feature map to obtain an attention weight map;

[0114] Step S22: performing attention-guided feature learning on the attention weight map and the multi-scale feature map to obtain a background suppression feature map;

[0115] Step S23: performing residual connection and feature fusion on the multi-scale feature map and the background suppression feature map to obtain a fused feature map;

[0116] Step S24: Perform nonlinear activation and normalization on the fused feature map to obtain a significant defect map.

[0117] In the embodiment of the present invention, the multi-scale feature map is input into the attention module. The attention module consists of two parallel convolution layers, and the convolution kernel size is 3 3, stride 1, and padding 'same'. The first convolutional layer outputs half the number of channels in the multi-scale feature map, while the second convolutional layer outputs 1 channel. ReLU activation is applied after each convolutional layer. The output of the second convolutional layer is activated using a sigmoid function to generate an attention weight map, which ranges from 0 to 1 and represents the saliency of the background texture at each pixel.

[0118] The attention weight map is element-wise multiplied with the multi-scale feature map. This operation assigns attention weights to the multi-scale feature map, suppressing features in background texture areas while enhancing features in potential defect areas. The multiplication result is then fed into a 3×3 convolutional layer with a stride of 1 and 'same' padding, resulting in the same number of output channels as the multi-scale feature map. The result is then activated using a ReLU function to produce a background suppression feature map.

[0119] The multi-scale feature map and the background suppression feature map are element-wise added together to implement a residual connection. Residual connections help preserve the original feature information and avoid the vanishing gradient problem. The result of the addition is then passed through a 1×1 convolutional layer with a stride of 1 and a padding of 'same'. The number of output channels is the same as the multi-scale feature map. This convolutional layer fuses the features after the residual connection to produce a fused feature map.

[0120] The fused feature map is input into the ReLU activation function, introducing nonlinearity and enhancing the model's expressive power. The activated feature map is then normalized. Using the Min-Max normalization method, the pixel values of the feature map are scaled to a range between 0 and 1, resulting in the final saliency defect map. This saliency defect map highlights potential defect areas and suppresses background texture interference, providing a foundation for subsequent defect segmentation.

[0121] Preferably, step S3 includes the following steps:

[0122] Step S31: determining the size of the local area according to the pre-processed PCB image and the significant defect map to obtain local area size data;

[0123] Step S32: Calculating the local statistical features of the sliding window of the significant defect map according to the local area size data to obtain a local statistical feature map;

[0124] Step S33: performing adaptive threshold calculation based on the local statistical feature map to obtain an adaptive threshold map, wherein the local statistical feature map includes a local histogram, a local mean map, and a local standard deviation map;

[0125] Step S34: performing binary segmentation on the adaptive threshold map and the significant defect map to obtain candidate defect regions.

[0126] As an example of the present invention, refer to Figure 2 As shown, in this example, step S3 includes:

[0127] Step S31: determining the size of the local area according to the pre-processed PCB image and the significant defect map to obtain local area size data;

[0128] In an embodiment of the present invention, the pre-processed PCB image and the significant defect map are analyzed to determine the size of the local area. Taking into account the diversity of PCB defect sizes, a statistical method based on the significant defect map is used to determine the size of the local area. First, the gradient amplitude map of the significant defect map is calculated. Then, the connected areas of the pixels whose gradient amplitude is greater than a preset threshold (for example, 0.1) are counted. The average size of these connected areas is calculated and used as the initial value of the local area size. In order to adapt to the characteristics of different PCB images, the initial value is multiplied by a scaling factor (for example, 1.5) to obtain the final local area size data. The local area size data is in pixels, for example, 15 15 pixels.

[0129] Step S32: Calculating the local statistical features of the sliding window of the significant defect map according to the local area size data to obtain a local statistical feature map;

[0130] In an embodiment of the present invention, a sliding window operation is performed on the significant defect map using the local area size. The sliding step size is set to 1 pixel. For each pixel in the window, the local histogram, local mean, and local standard deviation are calculated. The local histogram divides the pixel values into 256 gray levels and counts the number of pixels at each gray level. The local mean calculates the average value of all pixel values in the window. The local standard deviation calculates the standard deviation of all pixel values in the window. The local histogram, local mean, and local standard deviation of each window are stored as a local statistical feature map. The size of the local statistical feature map is the same as that of the significant defect map, and each pixel position corresponds to a feature vector containing local histogram, local mean, and local standard deviation information.

[0131] Step S33: performing adaptive threshold calculation based on the local statistical feature map to obtain an adaptive threshold map, wherein the local statistical feature map includes a local histogram, a local mean map, and a local standard deviation map;

[0132] In an embodiment of the present invention, for each pixel position in the local statistical feature map, the adaptive threshold is calculated using its corresponding local histogram, local mean and local standard deviation. First, the local histogram is threshold segmented using the Otsu algorithm to obtain an initial threshold. Then, the initial threshold is adjusted according to the local mean and local standard deviation. The adjustment formula is: `T=T0+α*(μ-β*σ)`, where T0 is the initial threshold, μ is the local mean, σ is the local standard deviation, and α and β are preset parameters, for example, α=0.5, β=1.0. The adaptive threshold of each pixel position is stored as an adaptive threshold map, the size of which is the same as the significant defect map.

[0133] Step S34: performing binary segmentation on the adaptive threshold map and the significant defect map to obtain candidate defect regions;

[0134] In this embodiment of the present invention, a significant defect map is compared with an adaptive threshold map. If the value of a pixel in the significant defect map is greater than or equal to its corresponding adaptive threshold, the pixel is marked as 1; otherwise, it is marked as 0. The marking result is stored as a binary image, namely, a candidate defect region. In the candidate defect region, pixels with a value of 1 represent potential defect areas, and pixels with a value of 0 represent background areas.

[0135] Preferably, step S33 includes the following steps:

[0136] Step S331: performing local Otsu threshold calculation on the local histogram to obtain a local Otsu threshold list;

[0137] Step S332: converting the local Otsu threshold list into a threshold map according to the local region size data, and performing threshold smoothing to obtain a smoothed local Otsu threshold map;

[0138] Step S333: performing local contrast calculation based on the local mean map and the local standard deviation map to obtain a local contrast map;

[0139] Step S334: performing contrast normalization on the local contrast map to obtain a normalized local contrast map;

[0140] Step S335: Calculating the threshold adjustment weight using the normalized local contrast map to obtain a threshold adjustment weight map;

[0141] Step S336: Using the threshold adjustment weight map, threshold adjustment is performed on the smoothed local Otsu threshold map to obtain an adaptive threshold map.

[0142] In an embodiment of the present invention, the local histogram corresponding to each pixel position in the local statistical feature map is traversed. For each local histogram, the Otsu algorithm is applied to calculate the optimal segmentation threshold. The Otsu algorithm determines the optimal threshold by maximizing the between-class variance. The Otsu thresholds calculated for each local histogram are stored in a list to obtain a local Otsu threshold list.

[0143] The local Otsu threshold list is converted into a threshold map of the same size as the significant defect map. The threshold of each pixel position corresponds to the Otsu threshold calculated from its local histogram. In order to remove noise and obtain a smoother threshold map, the threshold map is smoothed using Gaussian filtering. The Gaussian kernel size is set to the same as the local region size (e.g. 15 15), the standard deviation is set to 1 / 3 of the local region size (e.g. 5), and the smoothed local Otsu threshold map is obtained.

[0144] The local contrast map is calculated using the local mean map and the local standard deviation map. The local contrast at each pixel is defined as the local standard deviation divided by the local mean: `C = σ / μ`, where C is the local contrast, σ is the local standard deviation, and μ is the local mean. To avoid division by zero errors, C is set to 0 when μ is 0.

[0145] Normalize the local contrast map. Use the Min-Ma× normalization method to scale the local contrast value to between 0 and 1: `C' = (C-Cmin) / (Cma×-Cmin)`, where C' is the normalized local contrast, C is the original local contrast, and Cmin and Cma× are the minimum and maximum values in the local contrast map, respectively.

[0146] Calculate the threshold adjustment weight map based on the normalized local contrast map. The threshold adjustment weight is defined as an exponential function of the normalized local contrast: `W = e × p(γ * C')`, where W is the threshold adjustment weight, C' is the normalized local contrast, and γ is a parameter that controls the magnitude of the weight change, for example, γ = 2.0.

[0147] Multiply the smoothed local Otsu threshold map by the threshold adjustment weight map element-by-element to obtain the final adaptive threshold map: `T = T0 * W`, where T is the adaptive threshold, T0 is the smoothed local Otsu threshold, and W is the threshold adjustment weight. Each pixel value in the adaptive threshold map represents the segmentation threshold at that pixel location.

[0148] Preferably, step S4 includes the following steps:

[0149] Step S41: removing noise from the candidate defect region to obtain a denoised candidate region; connecting the broken defects in the denoised candidate region to obtain a connected defect region;

[0150] Step S42: performing preliminary void detection on the defective area after connection to obtain a preliminary void area;

[0151] Step S43: performing distance transformation calculation on the preliminary hole area to obtain a distance transformation map;

[0152] Step S44: marking the hole boundary of the preliminary hole area to obtain a hole boundary map; performing geodesic transformation calculation on the distance transformation map using the hole boundary map as a marker to obtain a geodesic distance map;

[0153] Step S45: constructing a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map;

[0154] Step S46: performing region merging and filling on the geodesic reconstruction image and the connected defect region to obtain a filled defect region;

[0155] Step S47: performing edge smoothing on the filled defect area to obtain a smoothed defect area; performing region screening on the smoothed defect area to obtain a refined defect area.

[0156] As an example of the present invention, refer to Figure 3 As shown, in this example, step S4 includes:

[0157] Step S41: removing noise from the candidate defect region to obtain a denoised candidate region; connecting the broken defects in the denoised candidate region to obtain a connected defect region;

[0158] In the embodiment of the present invention, median filtering is applied to the candidate defect area to remove noise. The median filter kernel size is set to 3 3. Subsequently, the morphological closing operation is used to connect the broken defect areas. The closing operation is a combination of dilation and erosion operations, which can effectively connect the broken areas and fill small holes. Structural element selection 5 5 rectangular structuring elements.

[0159] Step S42: performing preliminary void detection on the defective area after connection to obtain a preliminary void area;

[0160] In this embodiment of the present invention, a connected region analysis is performed on the defective areas after connection. The area and Euler number of each connected region are calculated. The Euler number is defined as the number of objects in the connected region minus the number of holes. If the Euler number of a connected region is less than 1, it is considered to contain a hole and is marked as a hole region. All pixels marked as hole regions are merged to obtain a preliminary hole region.

[0161] Step S43: performing distance transformation calculation on the preliminary hole area to obtain a distance transformation map;

[0162] In this embodiment of the present invention, a distance transform is performed on the preliminary hole region. The distance from each pixel in the hole region to the nearest pixel in the non-hole region is calculated using the Euclidean distance metric. The calculated distance values are stored as a distance transform map, where each pixel's value represents its distance to the nearest pixel in the non-hole region.

[0163] Step S44: marking the hole boundary of the preliminary hole area to obtain a hole boundary map; performing geodesic transformation calculation on the distance transformation map using the hole boundary map as a marker to obtain a geodesic distance map;

[0164] In this embodiment of the present invention, a morphological gradient operation is used to extract the boundaries of the preliminary hole region. The morphological gradient is defined as the dilation operation minus the erosion operation. A 3×3 rectangular structuring element is selected as the structuring element. The extracted boundary is marked as the hole boundary map. Using the hole boundary map as a marker, a geodesic transformation is performed on the distance transform map. The geodesic transformation calculates the shortest geodesic distance from each pixel on the hole boundary to every other boundary pixel, that is, the shortest path along the hole surface.

[0165] Step S45: constructing a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map;

[0166] In this embodiment of the present invention, a geodesic reconstruction image is constructed using a distance transform map and a geodesic distance map. Using the geodesic distance map as a marker, geodesic reconstruction is performed on the distance transform map. The geodesic reconstruction operation iteratively propagates values from the marker image into the distance transform map until a steady state is reached. The reconstructed image preserves the shape of the original hole and fills the area within it.

[0167] Step S46: performing region merging and filling on the geodesic reconstruction image and the connected defect region to obtain a filled defect region;

[0168] In the embodiment of the present invention, a logical OR operation is performed on the geodesic reconstruction image and the connected defect area to merge the two areas. The merged area includes the connected defect area and the filled hole area.

[0169] Step S47: performing edge smoothing on the filled defect area to obtain a smoothed defect area; performing region screening on the smoothed defect area to obtain a refined defect area;

[0170] In the embodiment of the present invention, Gaussian filtering is applied to the defect area after filling to perform edge smoothing. The Gaussian kernel size is set to 5 5, and the standard deviation is set to 1. Then, region screening is performed based on the area of the connected regions. Connected regions with an area smaller than a preset threshold (e.g., 10 pixels) are removed and considered noise. The resulting connected regions are the refined defect regions.

[0171] Preferably, step S43 includes the following steps:

[0172] Step S431: performing defect region inversion on the preliminary void region to obtain an inverted defect region;

[0173] Step S432: Calculating an initial distance map of the defective area after inversion using a pre-selected distance measurement method to obtain an initial distance map;

[0174] Step S433: normalizing the initial distance map to obtain a normalized distance map;

[0175] Step S434: performing distance map enhancement on the normalized distance map to obtain a distance transformation map.

[0176] In this embodiment of the present invention, the initial hole region is binary-inverted. In the initial hole region, pixels with a value of 1 represent the hole region, and pixels with a value of 0 represent the background region. After the inversion, pixels with a value of 0 represent the hole region, and pixels with a value of 1 represent the background region. This step facilitates the subsequent distance transform calculation.

[0177] Perform a distance transform on the inverted defect region. Use the exact Euclidean distance metric. Calculate the Euclidean distance from each pixel in the inverted defect region to the nearest non-zero pixel (i.e., the pixel in the original hole region). Store the calculated distance values in the initial distance map. Each pixel in the initial distance map represents its Euclidean distance to the nearest pixel in the original hole region.

[0178] Normalize the initial distance map. Use the Min-Ma× normalization method to scale the distance values to between 0 and 1. The normalization formula is: `D' = (D - Dmin) / (Dma× - Dmin)`, where D' is the normalized distance value, D is the original distance value, and Dmin and Dma× are the minimum and maximum values in the initial distance map, respectively.

[0179] The normalized distance map is enhanced to highlight distance variations. This enhancement is performed using a power-law transformation, using the formula: `D'' = D'^γ`, where D'' is the enhanced distance value, D' is the normalized distance value, and γ is a parameter controlling the degree of enhancement, for example, γ = 2.0. The enhanced distance values are stored as the final distance transformation map. In the distance transformation map, larger pixel values indicate greater distance from the original hole region. This enhancement step facilitates subsequent geodesic transformation and reconstruction, improving the refinement of the defect region.

[0180] Preferably, step S45 includes the following steps:

[0181] Step S451: constructing an initial reconstruction image according to the distance transformation image to obtain an initial reconstruction image;

[0182] Step S452: determining a dynamic threshold coefficient according to the geodesic distance map to obtain the dynamic threshold coefficient;

[0183] Step S453: traverse each pixel in the distance transformation map, and multiply the distance value of the corresponding pixel in the geodesic distance map by the dynamic threshold coefficient to obtain a dynamic threshold;

[0184] Step S454: performing pixel value comparison based on the distance transformation map and the dynamic threshold, and labeling the initial reconstructed image to obtain a labeled image;

[0185] Step S455: Perform morphological processing on the labeled image to obtain a geodesic reconstruction image.

[0186] In the embodiment of the present invention, the distance transform map is copied and used as the initial reconstruction map. The size and content of the initial reconstruction map are exactly the same as those of the distance transform map. Subsequent operations will modify the initial reconstruction map to ultimately obtain a geodesic reconstruction map.

[0187] Analyze the geodesic distance map and determine the dynamic threshold coefficient. Calculate the mean μ and standard deviation σ of the geodesic distance map. The dynamic threshold coefficient is defined as: `k = 1 - α * (σ / μ)`, where α is a parameter that controls the coefficient size, for example, α = 0.5. This coefficient is used to control the sensitivity of geodesic reconstruction.

[0188] Traverse each pixel in the distance transformation map. For each pixel, multiply the distance value of its corresponding position in the geodesic distance map by the dynamic threshold coefficient k to obtain the dynamic threshold of the pixel.

[0189] Traverse each pixel in the initial reconstructed image. Compare the distance value of the corresponding pixel in the distance transform image with a dynamic threshold. If the value in the distance transform image is greater than the dynamic threshold, set the value of the corresponding pixel in the initial reconstructed image to the value of the corresponding pixel in the geodesic distance image. Otherwise, keep the value of the corresponding pixel in the initial reconstructed image unchanged. This results in a labeled image where some pixels have values from the geodesic distance map and others from the distance transform image.

[0190] A morphological closing operation is performed on the labeled image. A 3×3 rectangular structuring element is selected. This closing operation smoothes the reconstruction, removes small noise and artifacts, and connects broken areas. The result is the final geodesic reconstruction image. This geodesic reconstruction accurately describes the shape and size of the void and fills the area within the void, providing a foundation for subsequent refinement of the defect area.

[0191] Preferably, step S5 includes the following steps:

[0192] Step S51: extracting features from the refined defect area to obtain a defect feature vector;

[0193] Step S52: performing lightweight classifier training based on the defect feature vector and the preset defect label to obtain a defect classifier;

[0194] Step S53: using a defect classifier to classify the defect feature vector to obtain defect category data;

[0195] Step S54: performing defect location according to the refined defect area and defect category data to obtain defect position and size data;

[0196] Step S55: Integrate the defect information of the defect category data and the defect position and size data to obtain the defect detection result.

[0197] In this embodiment of the present invention, a series of features are extracted for each refined defect region to form a defect feature vector. The extracted features include: 1. Area: the number of pixels in the defect region; 2. Perimeter: the number of pixels at the defect region's boundary; 3. Circularity: 4π * area / perimeter squared; 4. Hu moments: seven invariant moments that describe the shape characteristics of the defect region; 5. Grayscale mean: the average grayscale value of pixels within the defect region (based on a preprocessed PCB image); 6. Grayscale standard deviation: the standard deviation of the grayscale values of pixels within the defect region (based on a preprocessed PCB image). These features are combined into a vector, which serves as the feature vector for the defect region.

[0198] Using a pre-prepared dataset containing various PCB defect types, we extracted defect feature vectors and annotated each defect region with a pre-set defect label, such as open, short, missing component, or rat bite. Using this labeled data, we trained a lightweight classifier, such as a support vector machine (SVM) or random forest. The SVM used a radial basis kernel (RBF) with a penalty coefficient C set to 1.0. The random forest used 100 decision trees with a maximum depth of 10. During training, we used 5-fold cross-validation for model selection and parameter optimization.

[0199] Use a defect classifier to classify the defect feature vector. The classifier outputs a defect category label for each defect region, such as open circuit, short circuit, missing component, or rat bite. The classification results are stored as defect category data.

[0200] For each refined defect area, calculate the coordinates of the upper left corner, width, and height of its minimum bounding rectangle. This minimum bounding rectangle accurately defines the location and size of the defect area. The center coordinates, width, and height of the defect area, along with the corresponding defect category label, are stored as defect location and size data.

[0201] Defect category data, location, and size data are combined to form the final defect detection results. Defect detection results are output in a table or JSON format, including each defect's category, location coordinates, width, height, and other information, facilitating subsequent defect analysis and processing.

[0202] Preferably, the present invention further provides a printed circuit board defect detection system based on image recognition, which is used to execute the printed circuit board defect detection method based on image recognition as described above. The printed circuit board defect detection system based on image recognition includes:

[0203] The multi-scale feature fusion module is used to perform image preprocessing on the original PCB image to obtain a preprocessed PCB image; and to perform scale feature fusion on the preprocessed PCB image to obtain a multi-scale feature map;

[0204] The background texture suppression module is used to learn background texture features on the multi-scale feature map to obtain a background suppression feature map; background texture suppression is performed based on the background suppression feature map to obtain a significant defect map;

[0205] The adaptive threshold segmentation module is used to calculate local statistical features based on the pre-processed PCB image and the significant defect map to obtain a local statistical feature map; adaptive threshold calculation is performed based on the local statistical feature map, and binary segmentation is performed to obtain candidate defect areas;

[0206] The morphological optimization module is used to perform preliminary void detection based on the candidate defect area to obtain a preliminary void area; perform distance transformation calculation on the preliminary void area to obtain a distance transformation map; perform geodesic transformation calculation on the distance transformation map to obtain a geodesic distance map; construct a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map; and refine the defect area on the geodesic reconstruction map to obtain a refined defect area.

[0207] The defect classification and positioning module is used to classify the refined defect area and obtain defect category data; locate the defect according to the defect category data and obtain defect position and size data; integrate the defect information of the defect category data and the defect position and size data to obtain the defect detection results.

[0208] The present invention is therefore intended to be illustrative and non-restrictive in all respects, with the scope of the invention being defined by the appended claims rather than the foregoing description, and all changes that come within the meaning and range of equivalents of the application documents are intended to be embraced within the present invention.

[0209] The foregoing description is intended only to provide specific embodiments of the present invention, which will enable those skilled in the art to understand and implement the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not intended to be limited to the embodiments shown herein, but is to be construed in the widest possible manner consistent with the principles and novel features disclosed herein.

Claims

1. A printed circuit board defect detection method based on image recognition, characterized in that: The following steps are involved: Step S1: performing image preprocessing on the original PCB image to obtain a preprocessed PCB image; Perform scale feature fusion on the pre-processed PCB image to obtain a multi-scale feature map; Step S2 is specifically as follows: Step S21: constructing an attention module for background texture on the multi-scale feature map to obtain an attention weight map; Step S22: performing attention-guided feature learning on the attention weight map and the multi-scale feature map to obtain a background suppression feature map; Step S23: performing residual connection and feature fusion on the multi-scale feature map and the background suppression feature map to obtain a fused feature map; Step S24: performing nonlinear activation and normalization on the fused feature map to obtain a significant defect map; Step S3 is specifically as follows: Step S31: determining the size of the local area according to the pre-processed PCB image and the significant defect map to obtain local area size data; Step S32: Calculating the local statistical features of the sliding window of the significant defect map according to the local area size data to obtain a local statistical feature map; Step S33: performing adaptive threshold calculation based on the local statistical feature map to obtain an adaptive threshold map, wherein the local statistical feature map includes a local histogram, a local mean map, and a local standard deviation map, wherein step S33 is specifically as follows: Step S331: performing local Otsu threshold calculation on the local histogram to obtain a local Otsu threshold list; Step S332: converting the local Otsu threshold list into a threshold map according to the local region size data, and performing threshold smoothing to obtain a smoothed local Otsu threshold map; Step S333: performing local contrast calculation based on the local mean map and the local standard deviation map to obtain a local contrast map; Step S334: performing contrast normalization on the local contrast map to obtain a normalized local contrast map; Step S335: Calculating the threshold adjustment weight using the normalized local contrast map to obtain a threshold adjustment weight map; Step S336: using the threshold adjustment weight map to perform threshold adjustment on the smoothed local Otsu threshold map to obtain an adaptive threshold map; Step S34: performing binary segmentation on the adaptive threshold map and the significant defect map to obtain candidate defect regions; Step S4: performing preliminary hole detection on the candidate defect regions to obtain preliminary hole regions; performing distance transformation calculation on the preliminary hole regions to obtain a distance transformation map; performing geodesic transformation calculation on the distance transformation map to obtain a geodesic distance map; constructing a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map; refining the defect region on the geodesic reconstruction map to obtain a refined defect region; Step S5: classify the refined defect area to obtain defect category data; Defect location is performed based on defect category data to obtain defect position and size data; The defect information is integrated on the defect category data as well as the defect location and size data to obtain the defect detection results to realize the printed circuit board defect detection operation.

2. The printed circuit board defect detection method based on image recognition according to claim 1, characterized in that: Step S1 includes the following steps: Step S11: performing image preprocessing on the original PCB image to obtain a preprocessed PCB image; Step S12: performing multi-scale wavelet transform on the pre-processed PCB image to obtain multi-scale wavelet coefficients; Step S13: Use a pre-trained deep convolutional neural network to extract deep features from the pre-processed PCB image to obtain a deep feature map; Step S14: reconstructing the multi-scale wavelet coefficients to obtain a reconstructed wavelet feature map; Step S15: performing feature map upsampling on the depth feature map according to the reconstructed wavelet feature map to obtain an upsampled depth feature map; Step S16: performing feature fusion on the reconstructed wavelet feature map and the upsampled depth feature map to obtain a multi-scale feature map.

3. The printed circuit board defect detection method based on image recognition according to claim 1, characterized in that: Step S4 includes the following steps: Step S41: removing noise from the candidate defect region to obtain a denoised candidate region; connecting the broken defects in the denoised candidate region to obtain a connected defect region; Step S42: performing preliminary void detection on the defective area after connection to obtain a preliminary void area; Step S43: performing distance transformation calculation on the preliminary hole area to obtain a distance transformation map; Step S44: marking the hole boundary of the preliminary hole area to obtain a hole boundary map; performing geodesic transformation calculation on the distance transformation map using the hole boundary map as a marker to obtain a geodesic distance map; Step S45: constructing a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map; Step S46: performing region merging and filling on the geodesic reconstruction image and the connected defect region to obtain a filled defect region; Step S47: performing edge smoothing on the filled defect area to obtain a smoothed defect area; performing region screening on the smoothed defect area to obtain a refined defect area.

4. The printed circuit board defect detection method based on image recognition according to claim 3, characterized in that: Step S43 includes the following steps: Step S431: performing defect region inversion on the preliminary void region to obtain an inverted defect region; Step S432: Calculating an initial distance map of the defective area after inversion using a pre-selected distance measurement method to obtain an initial distance map; Step S433: normalizing the initial distance map to obtain a normalized distance map; Step S434: performing distance map enhancement on the normalized distance map to obtain a distance transformation map.

5. The printed circuit board defect detection method based on image recognition according to claim 3, characterized in that: Step S45 includes the following steps: Step S451: constructing an initial reconstruction image according to the distance transformation image to obtain an initial reconstruction image; Step S452: determining a dynamic threshold coefficient according to the geodesic distance map to obtain the dynamic threshold coefficient; Step S453: traverse each pixel in the distance transformation map, and multiply the distance value of the corresponding pixel in the geodesic distance map by the dynamic threshold coefficient to obtain a dynamic threshold; Step S454: performing pixel value comparison based on the distance transformation map and the dynamic threshold, and labeling the initial reconstructed image to obtain a labeled image; Step S455: Perform morphological processing on the labeled image to obtain a geodesic reconstruction image.

6. The printed circuit board defect detection method based on image recognition according to claim 1, characterized in that: Step S5 includes the following steps: Step S51: extracting features from the refined defect area to obtain a defect feature vector; Step S52: performing lightweight classifier training based on the defect feature vector and the preset defect label to obtain a defect classifier; Step S53: using a defect classifier to classify the defect feature vector to obtain defect category data; Step S54: performing defect location according to the refined defect area and defect category data to obtain defect position and size data; Step S55: Integrate the defect information of the defect category data and the defect position and size data to obtain the defect detection result.

7. A printed circuit board defect detection system based on image recognition, characterized in that: For executing the printed circuit board defect detection method based on image recognition according to claim 1, the printed circuit board defect detection system based on image recognition comprises: The multi-scale feature fusion module is used to perform image preprocessing on the original PCB image to obtain a preprocessed PCB image; and to perform scale feature fusion on the preprocessed PCB image to obtain a multi-scale feature map; The background texture suppression module is used to learn background texture features on the multi-scale feature map to obtain a background suppression feature map; background texture suppression is performed based on the background suppression feature map to obtain a significant defect map; The adaptive threshold segmentation module is used to calculate local statistical features based on the pre-processed PCB image and the significant defect map to obtain a local statistical feature map; adaptive threshold calculation is performed based on the local statistical feature map, and binary segmentation is performed to obtain candidate defect areas; The morphological optimization module is used to perform preliminary void detection based on the candidate defect area to obtain a preliminary void area; perform distance transformation calculation on the preliminary void area to obtain a distance transformation map; perform geodesic transformation calculation on the distance transformation map to obtain a geodesic distance map; construct a geodesic reconstruction map using the geodesic distance map and the distance transformation map to obtain a geodesic reconstruction map; and refine the defect area on the geodesic reconstruction map to obtain a refined defect area. The defect classification and positioning module is used to classify the refined defect area and obtain defect category data; locate the defect according to the defect category data and obtain defect position and size data; integrate the defect information of the defect category data and the defect position and size data to obtain the defect detection results.

Citation Information

Patent Citations

  • Wire harness defect detection method and system based on visual identification

    CN119090874A