PCBA board defect detection method and system based on image processing

By generating candidate region masks through Gaussian filtering, meshing, and the Otsu algorithm, and combining the Sobel operator and morphological closing operation to dynamically align solder joint templates, the problems of grayscale distortion and uneven allocation of computing resources in existing PCBA board defect detection are solved, achieving efficient and accurate defect detection.

CN120823430AInactive Publication Date: 2025-10-21广东德智矩阵科技有限公司
View PDF 0 Cites 22 Cited by

Patent Information

Application Number
CN202510743624.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-05
Publication Date
2025-10-21
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing PCBA board defect detection methods are prone to grayscale distribution distortion under the interference of complex surface reflections or shadows, resulting in blurred defect boundaries or insufficient contrast. Template matching strategies require frequent manual calibration. Traditional contour correction methods have difficulty distinguishing between real edges and noise interference, and uneven distribution of computing resources leads to low detection efficiency.

Method used

Noise is suppressed by using a Gaussian filter function. Candidate region masks are generated using grid grayscale change rate data and the Otsu algorithm. The gradient modulus is calculated by combining the Sobel operator. The edge structure is optimized by morphological closing operation and region growing algorithm. The defect region is identified by dynamically aligning the solder joint template.

Benefits of technology

It effectively reduces noise interference, improves the sensitivity of identifying minute defects, enhances robustness under complex lighting conditions, reduces misjudgments, achieves accurate positioning and classification of multiple types of defects, reduces computational complexity, and improves detection efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120823430A_ABST
    Figure CN120823430A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image detection, in particular to a PCBA board defect detection method and system based on image processing, and the method comprises the following steps: carrying out the meshing calculation of a gray scale deviation after a gray scale image is subjected to Gaussian filtering denoising, generating change rate data, carrying out the statistics of a frequency number, constructing a histogram, combining with an Otsu algorithm, and generating a candidate mask; extracting pixels based on a mask, calculating a gradient modulus, screening edge candidate points, carrying out gradient direction connection and morphological processing to generate a complete edge structure, expanding a connected domain through a region growing algorithm, aligning the connected domain with a template contour, and outputting defect coordinates. According to the method, the defect identification sensitivity is improved through combination of gray level image gridding processing and dynamic threshold calculation, a candidate mask is generated through grid gray level change rate statistics and an Otsu algorithm to avoid over-segmentation missing detection, and the contour precision is improved through combination of gradient modulus difference screening and morphological closed operation optimization. The region growing algorithm and template dynamic alignment reduce deformation misjudgment, and staged dimension reduction and feature enhancement reduce calculation complexity and solve resource waste.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image detection technology, and in particular to a method and system for detecting defects in a PCBA board based on image processing. Background Art

[0002] The field of image detection technology encompasses the acquisition, processing, and analysis of image information, aiming to identify, classify, and judge targets or features in images through machine vision systems or computer algorithms. Core areas within this technology include image preprocessing, target detection, feature extraction and comparison, image segmentation, and defect identification. Image detection is widely used in a variety of scenarios, including industrial automation, quality control, safety monitoring, and medical diagnosis. Specific industrial applications, such as surface defect identification, circuit board inspection, and product sorting, have become crucial for achieving intelligent manufacturing and automated quality inspection. This field emphasizes the precise identification of subtle differences in images, relying on the collaborative work of high-resolution imaging equipment and efficient image analysis algorithms to achieve highly reliable automated inspection.

[0003] Among them, PCBA defect detection methods refer to technical solutions for capturing and processing images of the assembled circuit board surface and component status during the printed circuit board assembly manufacturing process to identify potential defects. This topic primarily covers the use of image acquisition equipment to position the PCBA board and capture images, followed by grayscale difference analysis to identify defects such as missing components, offsets, incorrect polarity, or abnormal solder joints. This approach involves setting specific light source directions to enhance component feature boundaries, employing template matching strategies for standard image comparison analysis, implementing contour boundary correction to detect misalignment, and combining thresholds for pixel intensity changes within a region to identify anomalies. Through the synergistic effect of these technologies, differentiated defects on PCBA boards can be detected and classified.

[0004] Existing technologies rely on uniform light sources and fixed-angle imaging. This can easily lead to grayscale distortion caused by reflections or shadows on complex surfaces, resulting in blurred defect boundaries or insufficient contrast, impacting the reliability of subsequent feature extraction. Template matching strategies require a pre-defined standard image and are sensitive to positional deviations. When components exhibit slight displacement or deformation, matching failures can easily lead to missed defects, necessitating frequent manual calibration of template parameters and reducing the degree of automation in the inspection process. Traditional contour correction methods often rely on single-threshold segmentation, lacking dynamic analysis of local gradient changes and difficulty distinguishing true edges from noise. This can easily lead to missegmentation in areas with sticking solder joints or densely populated device clusters. Defect recognition utilizes static pixel intensity thresholds, failing to consider regional connectivity and morphological features. This lacks sensitivity to gradual defects such as cold solder joints and bubbles, leading to misjudgments and misclassifications. Existing methods often employ serial processing, failing to achieve coordinated optimization of feature extraction and classification decisions. In high-speed inspection scenarios, processing delays can occur due to uneven allocation of computing resources, hindering further improvements in inspection efficiency. Summary of the Invention

[0005] In order to solve the problem that the existing technology relies on uniform light source and fixed angle imaging, it is easy to produce grayscale distribution distortion under the interference of complex surface reflection or shadow, resulting in blurred defect boundaries or insufficient contrast, which affects the reliability of subsequent feature extraction. The template matching strategy requires pre-setting a standard image and is sensitive to position deviation. When there is slight displacement or deformation of the component, it is easy to miss the actual defect due to matching failure. Frequent manual calibration of template parameters is required, which reduces the degree of automation of the detection process. Traditional contour correction methods are mostly based on single threshold segmentation, lack dynamic analysis of local gradient changes, and have difficulty distinguishing between true edges and noise interference. They are prone to missegmentation in areas with solder joint adhesion or dense components. The defect recognition process uses a static pixel intensity threshold, does not consider regional connectivity and morphological characteristics, and is insufficiently sensitive to gradual defects such as cold solder joints and bubbles, which can easily lead to misjudgment or classification errors. Existing methods mostly use serial processing flows, fail to achieve coordinated optimization of feature extraction and classification decisions, and are prone to processing delays due to uneven allocation of computing resources in high-speed detection scenarios, which restricts the further improvement of detection efficiency. The embodiments of the present invention provide a PCBA board defect detection method and system based on image processing. The technical solution is as follows: On the one hand, a PCBA board defect detection method based on image processing is provided, the method comprising: S1: The original image of the PCBA board surface is acquired through an industrial camera and converted into a grayscale image. A Gaussian filter function is used to suppress noise. The pixel grayscale deviation is calculated in a grid array of equal size to generate grid grayscale change rate data. S2: Based on the grid grayscale change rate data, the frequency is counted to construct a normalized grayscale histogram, the change rate threshold is calculated using the Otsu algorithm, and the grids with grayscale change rates greater than the threshold are marked as candidate regions to obtain a binary mask of the candidate region; S3: extracting corresponding grayscale image pixels based on the binary mask of the candidate area, calculating the gradient modulus of the pixel points using the Sobel operator, and marking them as edge candidate points when the modulus exceeds a set multiple of the neighborhood average gradient modulus; S4: Based on the gradient direction data in the edge candidate point set, connect the pixel points with similar directions and adjacent spaces, complete the broken edges and remove isolated noise points through morphological closing operations, and generate complete edge structure data; S5: Extracting pixel features of the covered area based on the complete edge structure data, expanding the connected domain through a region growing algorithm, aligning and analyzing the expanded area with the contour data of the standard solder joint template, and outputting the coordinates of the defective area and contour marking data.

[0006] As a further solution of the present invention, the neighborhood adopts a fixed window size; The gradient directions are connected according to a direction difference tolerance and a spatial distance judgment criterion; The morphological closing operation uses a rectangular structure element, and the kernel size is set by a parameter; The region growing algorithm determines connectivity and growth boundaries based on a preset pixel feature similarity criterion, and stops growing when a threshold condition for region boundary feature change is met, configured according to the image source and device characteristics; The grid grayscale change rate data includes grid resolution, grayscale standard deviation matrix, and change rate distribution histogram. The candidate area binary mask specifically includes the binary segmentation threshold, the candidate area position index, and the number of mask connected areas. The edge candidate point set includes the gradient amplitude map, the neighborhood gradient mean multiple, and the candidate point coordinate set. The complete edge structure data includes the gradient direction histogram, the continuous edge chain code, and the morphological structure element size. The defect area coordinates and contour marking data specifically include the region growth bounding box, template matching degree, and the defect contour convex hull vertices.

[0007] As a further solution of the present invention, the specific steps of S1 include: S101: Use an industrial camera to obtain the original image of the PCBA board surface. Use brightness perception to convert the RGB image into a grayscale image. Perform a weighted combination of the RGB components of each pixel. Analyze a single-channel grayscale image matrix of the same size as the original image to obtain the grayscale image matrix value distribution result. S102: Based on the grayscale image matrix value distribution result, a Gaussian filter function is set and a convolution window is configured, a filter calculation is performed on adjacent pixel values ​​and a current pixel response value is determined, which is replaced with the grayscale value of the corresponding pixel in the original image to generate a Gaussian noise reduction grayscale matrix value; The Gaussian filter kernel size and standard deviation of the Gaussian filter function are set according to the real-time image noise level; S103: Divide the pixel grid according to the Gaussian noise reduction grayscale matrix value, calculate the ratio of the grayscale difference value to the center value in the grid, perform normalization processing, and obtain grid grayscale change rate data.

[0008] As a further solution of the present invention, the specific steps of S2 include: S201: Based on the grid grayscale change rate data, count the number of interval grids and calculate the corresponding frequency, perform normalization processing, record the ratio into the corresponding change rate interval, and generate a normalized frequency ratio distribution value; The normalized frequency ratio distribution value is a quantitative representation of the distribution of the grayscale change rate of the image, reflecting the texture characteristics of the image and the intensity of the grayscale change; S202: Based on the normalized frequency ratio distribution value, the Otsu algorithm is called to divide the interval and calculate the difference degree index when the current interval is used as the threshold division, and the interval boundary corresponding to the largest difference degree is selected as the change rate threshold to generate the Otsu grayscale change rate threshold interval boundary; S203: Using the Otsu grayscale change rate threshold interval limit as a screening basis, recording the grid positions exceeding the change rate threshold, extracting the image through the coordinate set, and obtaining a binary mask of the candidate area.

[0009] As a further solution of the present invention, the specific steps of S3 include: S301: Obtain the binary mask of the candidate region, extract the corresponding grayscale image pixels according to the mask coverage, use the Sobel operator to perform horizontal and vertical gradient detection on the pixels, and generate a gradient modulus matrix by synthesizing the gradient components; S302: Based on the gradient modulus matrix, traverse each pixel point and count the average of its neighborhood gradient modulus, compare the current pixel gradient intensity with the neighborhood average according to a preset multiple threshold, mark the pixel coordinates that meet the intensity relationship, and integrate the coordinate data to form a set of edge candidate points.

[0010] As a further solution of the present invention, the specific steps of S4 include: S401: Calculating the gradient direction difference between spatially adjacent pixels based on the pixel coordinates and gradient direction data in the edge candidate point set, screening pixel pairs whose direction differences meet the proximity condition, recording their coordinate correspondence, and generating a direction difference matching value; S402: calling the directional difference matching value, traversing the recorded pixel pair coordinates, and gradually marking adjacent connected units to fit a continuous edge segment set according to the spatial adjacency and directional consistency of the pixels, to generate a directional connectivity coefficient value; S403: Call the directional connectivity coefficient value, use the rectangular structure element to perform morphological closing operation, perform dilation and erosion processing on the broken areas whose position spacing is lower than the set pixel threshold in sequence, and remove isolated areas whose area is less than the set value to obtain complete edge structure data.

[0011] As a further solution of the present invention, the directional connectivity coefficient value is calculated using the formula: ; in, Represents the directional connectivity coefficient value, Representative The gradient direction difference between adjacent pixels is a dimensionless parameter after min-max normalization. Representative The pixel coordinate distance between pixels is a dimensionless parameter after min-max normalization. Representative The gradient value of the pixel with the largest gradient amplitude is a dimensionless parameter after min-max normalization. Representative The spatial distance deviation between pixels is a dimensionless parameter after min-max normalization. Represents the average value of the spatial distance deviation between adjacent pixels, which is a dimensionless parameter after min-max normalization. Represents the number of adjacent pixel pairs that meet the filtering criteria.

[0012] As a further solution of the present invention, the specific steps of S5 include: S501: Obtain a set of pixel coordinates of a coverage area in the complete edge structure data, extract regional pixel features, perform quantitative calculations on the gradient intensity and neighborhood contrast of the pixel points in the coordinate set, and generate a coverage area feature matrix; S502: Based on the coverage area feature matrix, a connected domain extension model is constructed using a region growing algorithm. A gradient intensity threshold is set as a growth termination condition. A gradient intensity peak point in the feature matrix is ​​selected as a seed point. The region is expanded by traversing eight neighboring pixels to generate an extended connected domain mask. The gradient intensity threshold is obtained by the statistical characteristics of the local area of ​​the image; S503: Calling the extended connected domain mask, combining it with the standard solder joint template contour data, calculating the Hausdorff distance between the mask edge points and the template contour by contour matching, screening the areas where the distance value exceeds the preset contour deviation threshold, and generating defect area coordinates and contour marking data; The contour deviation threshold is set by statistically modeling a batch of normal and abnormal solder joint samples.

[0013] As a further solution of the present invention, the gradient strength threshold is calculated using the formula: ; in, represents the gradient intensity threshold in the sth local area, Represents the total number of pixels in the sth local area, Represents the gradient strength of the i-th pixel in the s-th local area, Represents the average gradient intensity of the pixel points in the sth local area, Represents the neighborhood contrast value of the i-th pixel in the s-th local area, Represents the average neighborhood contrast of the pixel in the sth local area.

[0014] On the other hand, a PCBA board defect detection system based on image processing is provided. The PCBA board defect detection system based on image processing is used to perform the above-mentioned PCBA board defect detection method based on image processing. The system includes: The image acquisition module is used to obtain the original image through the industrial camera, convert the RGB to grayscale space, use the Gaussian filter function for convolution noise reduction, divide the grid array into equal-sized grids, calculate the grayscale standard deviation within the grid, generate grid grayscale change rate data, and pass it to the area screening module; The region screening module is used to construct a normalized histogram from the grid grayscale change rate data, calculate the threshold using the Otsu algorithm, screen the grid cells exceeding the threshold, extract the corresponding pixel coordinates to generate a candidate region pixel set, and pass it to the edge detection module; The edge detection module is used to perform coordinate mapping on the pixel set of the candidate area, calculate the partial derivatives in the x / y direction using the Sobel operator, calculate the gradient modulus, compare the neighborhood average modulus, generate a set of edge candidate points, and pass the data to the edge optimization module; An edge optimization module is used to connect adjacent pixels within a set angle based on the gradient direction data of the edge candidate point set, perform dilation and erosion operations using morphological closing operations, generate complete edge structure data, and pass it to the defect analysis module; The defect analysis module is used to match the complete edge structure data with the standard template in terms of contour curvature, calculate the Hausdorff distance, start the region growing algorithm when the threshold is exceeded, and generate the coordinates of the defect area and contour marking data.

[0015] The beneficial effects brought about by the technical solution provided by the embodiment of the present invention include at least: Through grayscale image gridding and dynamic threshold calculation, the traditional uniform processing is transformed into local feature analysis, effectively reducing noise interference and improving the sensitivity of detecting small defects. A grid grayscale change rate statistics and frequency normalization method, combined with the Otsu algorithm, are used to adaptively generate candidate region masks, avoiding the over-segmentation and missed detection problems caused by manually setting fixed thresholds and enhancing robustness in complex lighting scenarios. A candidate edge point screening strategy based on gradient modulus differences suppresses pseudo-edge interference by comparing neighborhood gradients. Combining gradient direction consistency constraints with morphological closing operation optimization, this strategy achieves continuity restoration of broken edges and noise filtering, improving contour extraction accuracy. A region growing algorithm and a dynamic alignment mechanism for standard solder joint templates, through the synergistic effect of connected domain expansion and contour matching, reduce misjudgments caused by positional offset or deformation in traditional template matching, while achieving accurate localization and classification of multiple defect types. The overall process utilizes staged data dimensionality reduction and feature enhancement to maintain detection efficiency while reducing computational complexity, addressing the resource waste associated with global processing in traditional methods. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 It is a schematic diagram of the workflow of the present invention; Figure 2 It is a system flow chart of the present invention. DETAILED DESCRIPTION

[0017] The technical solution of the present invention is described below in conjunction with the accompanying drawings.

[0018] In the embodiments of the present invention, words such as "exemplarily" and "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as an "exemplary" in the present invention should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of the word "exemplary" is intended to present concepts in a concrete manner. Furthermore, in the embodiments of the present invention, "and / or" can mean both or either of the two.

[0019] In the embodiments of the present invention, the terms "image" and "picture" may sometimes be used interchangeably. It should be noted that, when the distinction is not emphasized, the meanings they convey are the same. The terms "of," "corresponding," and "corresponding" may sometimes be used interchangeably. It should be noted that, when the distinction is not emphasized, the meanings they convey are the same.

[0020] In the embodiments of the present invention, sometimes a subscript such as W1 may be written as a non-subscript such as W1. When the difference is not emphasized, the meanings to be expressed are the same.

[0021] In order to make the technical problems, technical solutions and advantages to be solved by the present invention clearer, a detailed description will be given below with reference to the accompanying drawings and specific embodiments.

[0022] See also Figure 1 The embodiment of the present invention provides a PCBA board defect detection method based on image processing. The processing flow of the method may include the following steps: S1: The original image of the PCBA board surface is acquired through an industrial camera and converted into a grayscale image. A Gaussian filter function is used to suppress noise. The pixel grayscale deviation is calculated in a grid array of equal size to generate grid grayscale change rate data. S2: Based on the grid grayscale change rate data, the frequency is counted to construct a normalized grayscale histogram, and the change rate threshold is calculated using the Otsu algorithm. The grids with grayscale change rates greater than the threshold are marked as candidate regions, and a binary mask of the candidate region is obtained; S3: Extract the corresponding grayscale image pixels based on the binary mask of the candidate area, calculate the gradient modulus of the pixel points using the Sobel operator, and mark them as edge candidate points when the modulus exceeds the set multiple of the neighborhood average gradient modulus; S4: Based on the gradient direction data in the edge candidate point set, connect the pixels with similar directions and spatial proximity, complete the broken edges and remove isolated noise points through morphological closing operations, and generate complete edge structure data; S5: Extract pixel features of the covered area based on the complete edge structure data, expand the connected domain through the region growing algorithm, align and analyze the expanded area with the contour data of the standard solder joint template, and output the defect area coordinates and contour marking data.

[0023] The grid grayscale change rate data includes grid resolution, grayscale standard deviation matrix, and change rate distribution histogram. The candidate region binary mask specifically includes the binary segmentation threshold, candidate region position index, and the number of mask connected regions. The edge candidate point set includes the gradient amplitude map, neighborhood gradient mean multiples, and candidate point coordinate set. The complete edge structure data includes the gradient direction histogram, continuous edge chain code, and morphological structure element size. The defect region coordinates and contour marking data specifically include the region growth bounding box, template matching degree, and defect contour convex hull vertices.

[0024] Specifically, the steps of S1 are: S101: Use an industrial camera to obtain the original image of the PCBA board surface. Use brightness perception to convert the RGB image into a grayscale image. Perform a weighted combination of the RGB components of each pixel. Analyze a single-channel grayscale image matrix of the same size as the original image to obtain the grayscale image matrix value distribution result. To obtain the original image of the PCBA board surface through an industrial camera, the industrial camera must first be initialized and calibrated to ensure the clarity and consistency of image acquisition. During this process, the camera exposure time, gain parameters, and image size must be set. For example, the exposure time is set to 2000 microseconds, the gain value is set to 1.5, and the image acquisition size is set to 1920×1080. After the image acquisition is completed, the image is read pixel by pixel and the RGB three-channel components are extracted for each pixel. Each pixel contains three color channels: red, green, and blue, and the component value range is 0 to 255. After obtaining the RGB three components, the brightness perception method is used to convert them into a single-channel grayscale value. This method is achieved by weighted summing the R, G, and B components. The specific operation is to multiply the red component of each pixel by 0.299, the green component by 0.587, and the blue component by 0.114. The three results are then added and rounded off. For example, when the pixel R=120, G=130, and B=140, the corresponding grayscale value is: ; The above operations are performed on each pixel in the image one by one, and finally a grayscale image matrix of equal size is obtained. The matrix is ​​in single-channel form and is represented as a two-dimensional array structure. For example, if the image size is 1920×1080, the grayscale matrix size is also 1920×1080. The grayscale value corresponding to each pixel will be used as the input data set for subsequent analysis. In this process, analyzing the grayscale value distribution means performing statistical analysis operations on the grayscale values ​​in the matrix, such as calculating indicators such as mean, variance, extreme value, and frequency distribution to reflect the brightness change of the image in space. The lower grayscale value range is defined as 0 to 85, representing the dark area, the medium range is defined as 86 to 170, representing the normal brightness area, and the higher range is defined as 171 to 255, representing the bright area. This grayscale partitioning facilitates targeted filtering and local feature enhancement in subsequent steps.

[0025] Table 1 Pixel gray value calculation table

[0026] As shown in Table 1, the grayscale value distribution of 9 example pixels obtained by the brightness perception method is shown. This matrix can be used for subsequent filtering operations and grid division analysis.

[0027] S102: Based on the grayscale image matrix value distribution result, a Gaussian filter function is set and a convolution window is configured. A filter calculation is performed on adjacent pixel values ​​and a current pixel response value is determined. The current pixel response value is replaced with the grayscale value of the corresponding pixel in the original image to generate a Gaussian noise reduction grayscale matrix value. The Gaussian filter kernel size and standard deviation of the Gaussian filter function are set according to the real-time image noise level; When performing a Gaussian filter on a grayscale image matrix, the image noise level must first be assessed. The noise level can be determined by calculating the standard deviation σ of the image's grayscale values. If σ is less than or equal to 15, the image noise is low, and a smaller filter kernel, such as a 3×3 Gaussian kernel, is suitable. If σ is between 16 and 30, the image noise is moderate, and a 5×5 filter kernel is suitable. If σ is greater than 30, the image noise is high, and a larger 7×7 filter kernel is required. Regarding the selection of filter kernel size and standard deviation σ, assuming the image standard deviation σ is 18, a 5×5 filter kernel with a standard deviation of 1.0 is suitable.

[0028] After setting the filter kernel, for each pixel in the image, the pixels surrounding it are extracted as a neighborhood window. A window centered on a pixel is extracted, and the spatial distance and grayscale difference between each pixel's grayscale value and the center pixel are calculated. A weight is then assigned to each pixel. By weightedly summing the response values ​​of each pixel, the resulting Gaussian filtered image is obtained.

[0029] For example, in a 5×5 filter window, the grayscale value of the central pixel is 110. After weighted accumulation of the grayscale values ​​of the surrounding 24 pixels and the difference between the central pixel and the grayscale value, the total sum is 2640, and the total weight is 24. The response value is: ; When performing this calculation, all neighboring pixels are processed once and updated to new response values, completing the Gaussian filtering of the entire grayscale image matrix and obtaining the grayscale matrix value after noise reduction.

[0030] S103: Divide the pixel grid according to the Gaussian noise reduction grayscale matrix value, calculate the ratio of the grayscale difference value to the center value in the grid, perform normalization processing, and obtain grid grayscale change rate data; When performing pixel grid division on a Gaussian denoised grayscale image, the image can be divided into multiple small grid areas, for example, each grid area is 32×32 pixels. In each grid, the average grayscale value of the pixels within it is first calculated as the center value C of the grid. Next, the difference between the grayscale value of each pixel and the center value C is calculated, and the rate of change is calculated based on the difference. The formula for calculating the rate of change is as follows: ; in, Indicates the first The rate of change of pixels relative to the average grayscale value of the grid, Indicates the first The gray value of a pixel, Represents the average grayscale value of the pixels in the grid, which is used as the center grayscale value of the grid.

[0031] In order to facilitate analysis, the change rate data is further normalized to obtain the normalized change rate , the formula is as follows: ; in, Indicates the The normalized rate of change of pixels, Indicates the The original rate of change of pixels relative to the grid grayscale average, Indicates the minimum value of the original pixel change rate in the current grid area. Indicates the maximum value of the raw pixel change rate in the current grid area.

[0032] For example, if the rate of change of a grid is 0.25, the minimum change rate is 0.05, the maximum rate of change If is 0.35, the normalized rate of change is: ; This normalization process helps eliminate the influence of grayscale differences between grids, allowing the rates of change in different regions to be compared on the same scale. When the average rate of change in a grid region is greater than 0.25, it is marked as a high-variability region; when the average rate of change is less than 0.1, it is marked as a stable region. This method effectively identifies high-variability and stable regions in the image, providing a basis for further image analysis and processing.

[0033] Specifically, the steps of S2 are: S201: Based on the grid grayscale change rate data, the number of interval grids is counted and the corresponding frequency is calculated. After normalization, the ratio is recorded into the corresponding change rate interval to generate a normalized frequency ratio distribution value; The normalized frequency ratio distribution value is a quantitative representation of the distribution of the grayscale change rate of the image, reflecting the texture characteristics of the image and the intensity of the grayscale change; Based on the initial input processing of the image, taking a 100×100 pixel single-channel grayscale image as an example, the image is first divided into grid areas of equal size according to 10×10 pixels, forming a total of 100 grids. Next, each grid area is assigned a number such as G1 to G100 to facilitate subsequent data management and positioning operations. In each grid, the grayscale values ​​of the 100 pixels contained therein are extracted from left to right and from top to bottom, and stored in the memory as a one-dimensional array. During the execution process, the pixel values ​​are obtained by pixel-by-pixel scanning and recorded in the array P. For example, for grid G12, its grayscale value is , then perform grayscale difference operation on adjacent pixel pairs in the array, that is, take the absolute value of the difference between each pair of adjacent pixels and form a difference array D. For example, for the first 10 pixel values, we get , perform an averaging operation on the array and get the mean rate of change of grid G12 as , repeat this operation for 100 grids to form the grid mean set M, as , then the change rate interval is determined to be 0~10 according to the maximum change range and divided into 5 equal width sub-intervals, namely , then traverse the mean of each grid in the entire set M, determine which specific interval its value falls into and add 1 to the corresponding interval count. For example, if there are 25 values ​​in M ​​that fall in the interval [0, 2), 30 in [2, 4), 20 in [4, 6), 15 in [6, 8), and 10 in [8, 10], then the interval frequency is , by calculating the total number of grids , perform normalization calculation on each frequency divided by the total, and perform ratio calculation operations in sequence , and get the ratio set: , where each element represents the proportion of grids in the corresponding interval whose grayscale changes are within this range. The data is saved in the form of an array V, which is the frequency ratio distribution result of the image at different change rates.

[0034] S202: Based on the normalized frequency ratio distribution value, the Otsu algorithm is called to divide the interval and calculate the difference degree index when the current interval is used as the threshold division. The interval boundary corresponding to the largest difference degree is selected as the change rate threshold to generate the Otsu grayscale change rate threshold interval boundary; Based on the obtained ratio array V=[0.25, 0.30, 0.20, 0.15, 0.10], first take out the frequency ratio represented by each element in V and use it as the weight for subsequent calculations. Then set the midpoint values ​​of the corresponding intervals to 1, 3, 5, 7, and 9, respectively, to form coordinate pairs, such as (1, 0.25), (3, 0.30), (5, 0.20), (7, 0.15), and (9, 0.10). Then try to use each feasible split point position as the potential threshold position. For example, when the split point is the second position, the first two elements constitute one group, and the next three groups constitute another class. Perform the accumulation operation of the normalized frequency ratio, and the sum of the weights of the first class is , and the sum of the class weights is , respectively multiply the midpoint value of each interval by its corresponding ratio, and calculate the weighted average of the two categories before and after. The weighted average of the front category is , weighted average of the latter classes ; Then calculate the overall mean Then, according to the Otsu judgment formula, the inter-class variance calculation process is performed , substitute the split positions from k=1 to k=4 into the process and record the results each time, and finally find the one that makes The segmentation position corresponding to the largest k value is taken as the optimal threshold point. If the final result reaches the maximum when k=3, the interval boundary corresponding to the segmentation point at this time is selected as 6, which is the key demarcation threshold for subsequent image processing.

[0035] S203: Using the Otsu grayscale change rate threshold interval as a screening basis, recording the grid positions that exceed the change rate threshold, extracting the image through the coordinate set, and obtaining a binary mask of the candidate region; After obtaining the threshold interval limit of 6, traverse the previously numbered grids and take the average value of each grid Compare directly with threshold 6, if it meets , then mark the current grid as a candidate area, record its upper left corner coordinates in set C, use the grid number as the index during the traversal process, and calculate the upper left corner coordinate point by combining the image size and grid size. For example, grid No. 33 is the 4th row and 3rd column area, then the upper left corner coordinates are (x=20, y=30). If the average value is 6.3, then (20, 30) is stored in the coordinate set C. Repeat the above process to obtain the coordinate points that meet the conditions to form a set , take out the coordinate points of the set one by one and perform the mask initialization operation, that is, construct a 100×100 pixel binary matrix, set the 10×10 pixel area value corresponding to each recorded coordinate position to 1, and the remaining positions to 0. For example, the coordinate point (20, 30) represents the grid area of ​​the 3rd column and 4th row, then assign the values ​​1 to the positions in the row interval [30~39] and the column interval [20~29] in the matrix. In this way, traverse the entire set C in turn and finally generate a complete candidate area mask map.

[0036] Specifically, the steps of S3 are: S301: Obtain a binary mask of the candidate region, extract corresponding grayscale image pixels according to the mask coverage, use the Sobel operator to perform horizontal and vertical gradient detection on the pixels, and generate a gradient modulus matrix by synthesizing the gradient components; During execution, the candidate region is first binarized to generate a binary mask. Regions with a median value of 1 in the mask represent the target region to be processed. Next, an edge detection algorithm is used to grayscale the image based on the shape characteristics of the target region. Grayscale conversion converts the color information of each pixel in the image into a grayscale value, reducing computational complexity. During processing, a 3×3 sliding window is used to traverse the candidate region. The center point of each window is surrounded by eight neighboring points. The grayscale values ​​of these neighboring points are calculated to form a local grayscale distribution matrix.

[0037] Then, the Sobel operator is applied to perform edge detection on the region. The specific operation is to use the horizontal and vertical Sobel convolution kernels to convolve with the grayscale value in the 3×3 window respectively, and calculate the horizontal and vertical gradient components: ; ; Then, the gradient modulus is calculated by To evaluate edge strength: ; This process is performed in the entire candidate area to generate a complete gradient modulus matrix, in which each element corresponds to the gradient modulus value of the corresponding pixel in the image. Through this matrix, the edge features in the image can be further analyzed.

[0038] S302: Based on the gradient modulus matrix, traverse each pixel point and calculate the mean of its neighborhood gradient modulus, compare the current pixel gradient intensity with the neighborhood mean according to a preset multiple threshold, mark the pixel coordinates that meet the intensity relationship, and integrate the coordinate data to form a set of edge candidate points.

[0039] After obtaining the gradient modulus matrix, we need to traverse each pixel in the image. For each pixel, extract the 3×3 neighborhood area centered on itself and calculate the mean of the gradient modulus values ​​of the pixels in the neighborhood. The specific operation is to read the gradient modulus values ​​of the 9 pixels in the neighborhood. .

[0040] Sum these 9 values ​​and calculate the mean: ; Next, the gradient modulus value of the current pixel and neighborhood mean Compare. If Greater than the preset multiplier The calculated critical value marks the point as an edge candidate point. The calculation method is: ; in, is the mean value of the pixel gradient modulus in the candidate area, is the standard deviation. For example, if the mean gradient modulus in a region is , standard deviation , then the multiplication coefficient for: ; Then, the gradient modulus value of the current pixel is compared with the calculated threshold. For example, if the gradient modulus of the current pixel is , you need to judge: .

[0041] because The point is marked as an edge candidate point. After screening in this way, a set of edge candidate point coordinates that meet the conditions is generated.

[0042] Table 2 Gradient modulus and edge detection threshold data table

[0043] As shown in Table 2, by setting the dynamic coefficient , realizing the identification of edge pixels. The result shows that when the gradient modulus value is higher than the neighborhood mean, the pixel is at the edge of the target contour, and the coordinates that meet the conditions are selected into the edge candidate point set for subsequent edge connection processing.

[0044] Specifically, the steps of S4 are: S401: Based on the pixel coordinates and gradient direction data in the edge candidate point set, calculate the gradient direction difference between spatially adjacent pixels, select pixel pairs whose direction differences meet the proximity condition, record their coordinate correspondence, and generate a direction difference matching value; Based on the pixel coordinates and gradient direction data in the edge candidate point set, the two-dimensional spatial coordinate data of the edge candidate point is first obtained. The coordinate value can be expressed as the position of the pixel point in the image matrix, such as point A (x1, y1) and point B (x2, y2). Then, for each pixel point, its gradient direction data is extracted. The data can be obtained by calculating the grayscale difference of the pixel in the x-axis and y-axis directions to obtain the gradient vector, and then the inverse tangent function is used to calculate the gradient direction data. Get angle information. For example, for point A, if its gradient values ​​in the x and y directions are 、 , then , and store its angle in the form of degrees in the data field of the pixel point. Next, traverse the 8 connected pixels in the neighborhood of the edge point and calculate the gradient direction difference between it and the current pixel. Specifically, by calculating the absolute difference of the direction angles of adjacent pixels, such as the direction angle of point A is 26.57° and the direction angle of the adjacent point B is 24.00°, then the direction difference is 2.57°. On this basis, judge each direction difference and set the direction consistency threshold to 5°. If the difference between a certain pixel pair is less than 5°, then the pixel pair is counted into the condition set and its coordinate correspondence is recorded as (A, B). The traversal judgment and matching recording process of the direction difference between the edge candidate pixels in the entire image is gradually completed. As shown in Table 3, the pixel pairs with a direction angle difference less than 5° are all valid pairs. The coordinate relationship set of all pixel pairs that meet the direction consistency is obtained to form a direction difference matching value.

[0045] Table 3 Pixel pairs whose direction difference satisfies the conditions

[0046] As shown in Table 3, pixel pairs with direction differences less than the threshold of 5° are recorded into the set, completing the generation of direction difference matching values.

[0047] S402: calling the direction difference matching value, traversing the recorded pixel pair coordinates, and gradually marking the adjacent connected units to fit the continuous edge segment set according to the spatial adjacency and direction consistency of the pixels, and generating the direction connectivity coefficient value; After the direction difference matching value is generated, the recorded pixel pairs are traversed and processed. Starting from each pair of starting coordinates, it is confirmed whether they have spatial connectivity. The basis for determining spatial connectivity is whether the current pixel and the target pixel are in an 8-connected neighborhood. For example, pixel A (120, 98) and pixel B (121, 98) meet the horizontal adjacent relationship, and the coordinate difference satisfies Δx = 1, Δy = 0, belonging to the 8-connected relationship. After confirming the connectivity, the direction consistency is further confirmed. The direction consistency standard still uses the 5° threshold to determine the direction difference. If the direction difference Δθ = |θ If 1-θ2|<5°, the current pixel is marked as part of a continuous edge segment, and its connection is constructed into an edge segment unit. Its path and order are recorded, and it continues to expand to the connected neighborhood of pixel B, looking for the next matching pixel point C that satisfies the direction difference of less than 5°. If the direction difference between point C (122, 99) and point B is 1.80°, which meets the requirement, it is added to the edge segment. Repeat this operation until there are no matching points, forming a complete continuous edge segment. Record the connection relationship in each edge segment, and calculate the directional connectivity coefficient value for each edge segment using the formula: ; in, Represents the directional connectivity coefficient value, Representative The gradient direction difference between adjacent pixels is a dimensionless parameter after min-max normalization. Representative The pixel coordinate distance between pixels is a dimensionless parameter after min-max normalization. Representative The gradient value of the pixel with the largest gradient amplitude is a dimensionless parameter after min-max normalization. Representative The spatial distance deviation between pixels is a dimensionless parameter after min-max normalization. Represents the average value of the spatial distance deviation between adjacent pixels, which is a dimensionless parameter after min-max normalization. Represents the number of adjacent pixel pairs that meet the filtering criteria.

[0048] For a certain edge segment, suppose it includes 5 pairs of valid pixel pairs. After normalization and conversion into dimensionless parameters, the azimuth angle differences are Δθ=[0.538, 0, 1, 0.143, 0.929], the pixel spacing d=[1, 0, 1, 0, 1], the corresponding gradient values ​​g=[0, 1, 0.6, 0.4, 0.8], and the spatial deviation δ=[1, 0, 0.5, 0.25, 0.75]. The average deviation is calculated. , substitute the data into the calculation: ; ; = ; The result shows that the edge segment has high directional connectivity. After the calculation process is completed, the directional connectivity coefficient value of each edge segment is recorded separately to form a directional connectivity dataset.

[0049] S403: Call the directional connectivity coefficient value, use the rectangular structure element to perform morphological closing operation, perform dilation and erosion processing on the broken areas whose position spacing is lower than the set pixel threshold, and remove isolated areas whose area is less than the set value to obtain complete edge structure data.

[0050] After calling the above directional connectivity coefficient value, the edge segments are screened. First, the directional connectivity normalization threshold is set to 0.75, and the edge segments with directional connectivity coefficients not less than the normalization threshold are retained. The spatial spacing between edge segments is identified, and the Euclidean distance between the end pixel of each edge segment and the starting pixel of other edge segments is calculated. , if the end point of edge segment 1 is (150, 200) and the starting point of edge segment 2 is (152, 201), we can calculate Pixels, if the fracture judgment threshold is set to 3 pixels, then the two edge segments are considered to constitute fracture segments, and they are closed. The closing process uses a rectangular structure element to perform morphological operations, and the structure element size is set to 3×3. First, the dilation operation is performed to expand the pixel range of the edge segment so that the originally close edge segments are connected. Then the corrosion operation is performed to restore the original shape of the edge segment to avoid edge blurring caused by expansion. At the same time, isolated pixel blocks are cleared to determine whether their area is less than 10 pixels. If the area is less than 10 pixels, they are deleted. For example, if the area of ​​a connected edge segment in a certain area is 8 pixels, it is marked as an invalid area and removed. Finally, the complete edge structure data with strong continuity and high directional consistency is retained to complete the structural integration process of the edge image.

[0051] Specifically, the steps of S5 are: S501: Obtain a pixel coordinate set of the coverage area in the complete edge structure data, extract regional pixel features, perform quantitative calculations on the gradient intensity and neighborhood contrast of the pixel points in the coordinate set, and generate a coverage area feature matrix; When obtaining the pixel coordinate set of the coverage area in the complete edge structure data, the original weld image is first converted into a binary edge image through the image edge detection method. Then, it is divided into small grids of 25×25 pixels. The edge connectivity in each grid is checked in turn. The grid area with closed edges is extracted as the candidate area, and the coordinates of each pixel in it are recorded to form a coordinate array. , and then take each pixel in the area as the center point, construct its 3×3 neighborhood grayscale window, and execute the Sobel operator to perform convolution operations in the x and y directions for each pixel to obtain the horizontal gradient value and longitudinal gradient value , and then according to Calculate gradient strength , for example, the grayscale difference of the image is 、 The pixel has a gradient strength of , then call the neighborhood pixel grayscale array such as: ; The grayscale value of the central pixel is 130. The absolute value of the difference between the grayscale value of the neighboring pixels and the grayscale value of the central pixel is calculated and averaged to obtain the neighborhood contrast: , generating a data vector at each pixel location , the vectors together constitute the coverage area feature matrix. If there are 150 pixels in the area, the matrix dimension is 150×4, which is used for subsequent connected domain recognition operations.

[0052] S502: Based on the coverage area feature matrix, a connected domain extension model is constructed using a region growing algorithm. A gradient intensity threshold is set as a growth termination condition. The gradient intensity peak point in the feature matrix is ​​selected as a seed point. The region is expanded by traversing the eight-neighborhood pixels to generate an extended connected domain mask. Using the coverage area feature matrix formed in paragraph S501, we first need to perform statistical calculations on the pixel gradient intensity in the local area and record the number of pixels in each area. , pixel gradient intensity in the region Contrast with neighborhood , and calculate the mean 、 For example, for region 1, which has 150 pixels, the average gradient strength is 35, and the average neighborhood contrast is 12, the gradient strength threshold is calculated using the formula: ; in, represents the gradient intensity threshold in the sth local area, Represents the total number of pixels in the sth local area, Represents the gradient strength of the i-th pixel in the s-th local area, Represents the average gradient intensity of the pixel points in the sth local area, Represents the neighborhood contrast value of the i-th pixel in the s-th local area, Represents the average neighborhood contrast of the pixel in the sth local area.

[0053] Substituting into the formula: ; Assume that the gradient intensities of three representative pixels are 33, 36, and 39, and the corresponding neighborhood contrasts are 11, 13, and 14, respectively. Then: First pixel: ; Second pixel: ; 3rd pixel: ; Taking the average value: , the actual sum of 150 pixels should be averaged, and the final threshold value of the region is about 8.2. Then scan the gradient value of each pixel in the feature matrix, and select the pixel with a gradient strength greater than that of its eight neighboring pixels as the seed point for region expansion. For example, if the gradient value of a pixel is 40, the gradient value of its eight neighboring pixels is , then the point is the gradient peak, which is used as the starting point. The surrounding unvisited pixels are retrieved in turn according to the eight-neighborhood access strategy. The gradient intensity of each neighboring point is compared with the current threshold. If the gradient value is greater than or equal to the set threshold and has not been processed, it is marked as an expansion area and used as the expansion center point of a new round. If it does not meet the requirements, it is skipped. The cycle is executed until there are no more pixels that meet the conditions. Finally, the mask matrix is ​​output, and its dimension is the same as the original Figure 1 The positions with a value of 1 in the mask represent the connected areas after expansion, and the positions with a value of 0 are non-region pixels.

[0054] S503: Calling the extended connected domain mask, combining it with the standard solder joint template contour data, and using contour matching to calculate the Hausdorff distance between the mask edge points and the template contour, screening the areas where the distance value exceeds the preset contour deviation threshold, and generating the defect area coordinates and contour marking data; After completing the region growing and generating the mask map, the mask edge points need to be compared one by one according to the edge contour data of the standard solder joint template. First, the regional edge points with a value of 1 in the mask map are extracted. , and then extract its ideal edge point from the solder joint template contour , for each mask edge point, calculate the shortest Euclidean distance to the template edge point. The farthest shortest distance is the Hausdorff distance, which is expressed as: ; For example, the mask point (105, 58) and the template point (100, 60) have a distance of If the threshold is set to 5, the point is considered to deviate from the normal contour. The point coordinate set with a deviation of 5 pixels is stored, and then the outer contour dot matrix of the defect area is formed based on the point set contour closing operation. The coordinates and contour index data of the defect area are stored as the final output result. The setting of the deviation threshold is obtained through large sample analysis. It is assumed that the maximum deviation of the edge of 100 groups of normal samples is concentrated between [2.1, 4.5] pixels. The deviation of 85% of the abnormal solder joints exceeds 5.5 pixels. Therefore, setting a threshold of 5 pixels can effectively define the abnormal area.

[0055] Table 4: Example of statistical table for solder joint image processing:

[0056] As shown in Table 4, the key parameters of the three coverage areas in the image processing process are given. Area 1 corresponds to the coverage area. In area 2, multiple features are higher, so the expansion area is larger. The deviation value in area 3 is larger, which is consistent with the judgment logic of the presence of defect features.

[0057] like Figure 2 As shown in the figure, the PCBA board defect detection system based on image processing includes: The image acquisition module is used to obtain the original image through the industrial camera, convert the RGB to grayscale space, use the Gaussian filter function for convolution noise reduction, divide the grid array into equal-sized grids, calculate the grayscale standard deviation within the grid, generate grid grayscale change rate data, and pass it to the area screening module; The region screening module is used to construct a normalized histogram from the grid grayscale change rate data, calculate the threshold using the Otsu algorithm, screen the grid cells that exceed the threshold, extract the corresponding pixel coordinates to generate a candidate region pixel set, and pass it to the edge detection module; The edge detection module is used to perform coordinate mapping on the pixel set of the candidate area, calculate the partial derivatives in the x / y direction through the Sobel operator, calculate the gradient modulus, compare the neighborhood average modulus, generate a set of edge candidate points, and pass the data to the edge optimization module; The edge optimization module is used to connect adjacent pixels within a set angle based on the gradient direction data of the edge candidate point set, perform dilation and corrosion operations using morphological closing operations, generate complete edge structure data, and pass it to the defect analysis module; The defect analysis module is used to match the contour curvature of the complete edge structure data with the standard template, calculate the Hausdorff distance, start the region growing algorithm when the threshold is exceeded, and generate the coordinates of the defect area and contour marking data.

[0058] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.

Claims

1. A PCBA board defect detection method based on image processing, characterized in that: The following steps are involved: S1: The original image of the PCBA board surface is acquired through an industrial camera and converted into a grayscale image. A Gaussian filter function is used to suppress noise. The pixel grayscale deviation is calculated in a grid array of equal size to generate grid grayscale change rate data. S2: Based on the grid grayscale change rate data, the frequency is counted to construct a normalized grayscale histogram, the change rate threshold is calculated using the Otsu algorithm, and the grids with grayscale change rates greater than the threshold are marked as candidate regions to obtain a binary mask of the candidate region; S3: extracting corresponding grayscale image pixels based on the binary mask of the candidate area, calculating the gradient modulus of the pixel points using the Sobel operator, and marking them as edge candidate points when the modulus exceeds a set multiple of the neighborhood average gradient modulus; S4: Based on the gradient direction data in the edge candidate point set, connect the pixel points with similar directions and adjacent spaces, complete the broken edges and remove isolated noise points through morphological closing operations, and generate complete edge structure data; S5: Extracting pixel features of the covered area based on the complete edge structure data, expanding the connected domain through a region growing algorithm, aligning and analyzing the expanded area with the contour data of the standard solder joint template, and outputting the coordinates of the defective area and contour marking data.

2. The PCBA board defect detection method based on image processing according to claim 1, characterized in that: The neighborhood adopts a fixed window size; The gradient directions are connected according to a direction difference tolerance and a spatial distance judgment criterion; The morphological closing operation uses a rectangular structure element, and the kernel size is set by a parameter; The region growing algorithm determines connectivity and growth boundaries based on a preset pixel feature similarity criterion, and stops growing when a threshold condition for region boundary feature change is met, configured according to the image source and device characteristics; The grid grayscale change rate data includes grid resolution, grayscale standard deviation matrix, and change rate distribution histogram. The candidate area binary mask specifically includes the binary segmentation threshold, the candidate area position index, and the number of mask connected areas. The edge candidate point set includes the gradient amplitude map, the neighborhood gradient mean multiple, and the candidate point coordinate set. The complete edge structure data includes the gradient direction histogram, the continuous edge chain code, and the morphological structure element size. The defect area coordinates and contour marking data specifically include the region growth bounding box, template matching degree, and the defect contour convex hull vertices.

3. The PCBA board defect detection method based on image processing according to claim 1, characterized in that: The specific steps of S1 include: S101: Use an industrial camera to obtain the original image of the PCBA board surface. Use brightness perception to convert the RGB image into a grayscale image. Perform a weighted combination of the RGB components of each pixel. Analyze a single-channel grayscale image matrix of the same size as the original image to obtain the grayscale image matrix value distribution result. S102: Based on the grayscale image matrix value distribution result, a Gaussian filter function is set and a convolution window is configured, a filter calculation is performed on adjacent pixel values ​​and a current pixel response value is determined, which is replaced with the grayscale value of the corresponding pixel in the original image to generate a Gaussian noise reduction grayscale matrix value; The Gaussian filter kernel size and standard deviation of the Gaussian filter function are set according to the real-time image noise level; S103: Divide the pixel grid according to the Gaussian noise reduction grayscale matrix value, calculate the ratio of the grayscale difference value to the center value in the grid, perform normalization processing, and obtain grid grayscale change rate data.

4. The PCBA board defect detection method based on image processing according to claim 3, characterized in that: The specific steps of S2 include: S201: Based on the grid grayscale change rate data, count the number of interval grids and calculate the corresponding frequency, perform normalization processing, record the ratio into the corresponding change rate interval, and generate a normalized frequency ratio distribution value; The normalized frequency ratio distribution value is a quantitative representation of the distribution of the grayscale change rate of the image, reflecting the texture characteristics of the image and the intensity of the grayscale change; S202: Based on the normalized frequency ratio distribution value, the Otsu algorithm is called to divide the interval and calculate the difference degree index when the current interval is used as the threshold division, and the interval boundary corresponding to the largest difference degree is selected as the change rate threshold to generate the Otsu grayscale change rate threshold interval boundary; S203: Using the Otsu grayscale change rate threshold interval limit as a screening basis, recording the grid positions exceeding the change rate threshold, extracting the image through the coordinate set, and obtaining a binary mask of the candidate area.

5. The PCBA board defect detection method based on image processing according to claim 4, characterized in that: The specific steps of S3 include: S301: Obtain the binary mask of the candidate region, extract the corresponding grayscale image pixels according to the mask coverage, use the Sobel operator to perform horizontal and vertical gradient detection on the pixels, and generate a gradient modulus matrix by synthesizing the gradient components; S302: Based on the gradient modulus matrix, traverse each pixel point and count the average of its neighborhood gradient modulus, compare the current pixel gradient intensity with the neighborhood average according to a preset multiple threshold, mark the pixel coordinates that meet the intensity relationship, and integrate the coordinate data to form a set of edge candidate points.

6. The PCBA board defect detection method based on image processing according to claim 5, characterized in that: The specific steps of S4 include: S401: Calculating the gradient direction difference between spatially adjacent pixels based on the pixel coordinates and gradient direction data in the edge candidate point set, screening pixel pairs whose direction differences meet the proximity condition, recording their coordinate correspondence, and generating a direction difference matching value; S402: calling the directional difference matching value, traversing the recorded pixel pair coordinates, and gradually marking adjacent connected units to fit a continuous edge segment set according to the spatial adjacency and directional consistency of the pixels, to generate a directional connectivity coefficient value; S403: Call the directional connectivity coefficient value, use the rectangular structure element to perform morphological closing operation, perform dilation and erosion processing on the broken areas whose position spacing is lower than the set pixel threshold in sequence, and remove isolated areas whose area is less than the set value to obtain complete edge structure data.

7. The PCBA board defect detection method based on image processing according to claim 6, characterized in that: The directional connectivity coefficient value is calculated using the formula: ; in, Represents the directional connectivity coefficient value, Representative The gradient direction difference between adjacent pixels is a dimensionless parameter after min-max normalization. Representative The pixel coordinate distance between pixels is a dimensionless parameter after min-max normalization. Representative The gradient value of the pixel with the largest gradient amplitude is a dimensionless parameter after min-max normalization. Representative The spatial distance deviation between pixels is a dimensionless parameter after min-max normalization. Represents the average value of the spatial distance deviation between adjacent pixels, which is a dimensionless parameter after min-max normalization. Represents the number of adjacent pixel pairs that meet the filtering criteria.

8. The PCBA board defect detection method based on image processing according to claim 6, characterized in that: The specific steps of S5 include: S501: Obtain a set of pixel coordinates of a coverage area in the complete edge structure data, extract regional pixel features, perform quantitative calculations on the gradient intensity and neighborhood contrast of the pixel points in the coordinate set, and generate a coverage area feature matrix; S502: Based on the coverage area feature matrix, a connected domain extension model is constructed using a region growing algorithm. A gradient intensity threshold is set as a growth termination condition. A gradient intensity peak point in the feature matrix is ​​selected as a seed point. The region is expanded by traversing eight neighboring pixels to generate an extended connected domain mask. The gradient intensity threshold is obtained by the statistical characteristics of the local area of ​​the image; S503: Calling the extended connected domain mask, combining it with the standard solder joint template contour data, calculating the Hausdorff distance between the mask edge points and the template contour by contour matching, screening the areas where the distance value exceeds the preset contour deviation threshold, and generating defect area coordinates and contour marking data; The contour deviation threshold is set by statistically modeling a batch of normal and abnormal solder joint samples.

9. The PCBA board defect detection method based on image processing according to claim 8, characterized in that: The gradient strength threshold is calculated using the formula: ; in, represents the gradient intensity threshold in the sth local area, Represents the total number of pixels in the sth local area, Represents the gradient strength of the i-th pixel in the s-th local area, Represents the average gradient intensity of the pixel points in the sth local area, Represents the neighborhood contrast value of the i-th pixel in the s-th local area, Represents the average neighborhood contrast of the pixel in the sth local area.

10. The PCBA board defect detection system based on image processing is characterized by: The system is used to implement the PCBA board defect detection method based on image processing according to any one of claims 1 to 9, and the system includes: The image acquisition module is used to obtain the original image through the industrial camera, convert the RGB to grayscale space, use the Gaussian filter function for convolution noise reduction, divide the grid array into equal-sized grids, calculate the grayscale standard deviation within the grid, generate grid grayscale change rate data, and pass it to the area screening module; The region screening module is used to construct a normalized histogram from the grid grayscale change rate data, calculate the threshold using the Otsu algorithm, screen the grid cells exceeding the threshold, extract the corresponding pixel coordinates to generate a candidate region pixel set, and pass it to the edge detection module; The edge detection module is used to perform coordinate mapping on the pixel set of the candidate area, calculate the partial derivatives in the x / y direction using the Sobel operator, calculate the gradient modulus, compare the neighborhood average modulus, generate a set of edge candidate points, and pass the data to the edge optimization module; An edge optimization module is used to connect adjacent pixels within a set angle based on the gradient direction data of the edge candidate point set, perform dilation and erosion operations using morphological closing operations, generate complete edge structure data, and pass it to the defect analysis module; The defect analysis module is used to match the complete edge structure data with the standard template in terms of contour curvature, calculate the Hausdorff distance, start the region growing algorithm when the threshold is exceeded, and generate the coordinates of the defect area and contour marking data.

Citation Information

Cited By

  • Quick judgment method for side-scan sonar image view field target doubt

    CN120976725A

  • Method for detecting pollutants in high-purity quartz sand based on image recognition

    CN120997832A

  • Multi-source data feature extraction and fusion method and system for power grid infrastructure construction

    CN121030695A

  • High-precision edge extraction method based on automatic image processing

    CN121095587A

  • Box-type substation spraying quality detection method based on image processing

    CN121190474A