Product defect visual prediction method and device based on X-ray

Through X-ray-based grayscale processing, adaptive median filtering and improved Canny algorithm combined with cluster analysis and entropy value judgment, the problems of low efficiency and low accuracy of product defect detection in existing technologies are solved, and automated product defect visualization measurement and detection are achieved.

CN120673173APending Publication Date: 2025-09-19ZHEJIANG CHINT INSTR & METER
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202510860056.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-25
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

The existing X-ray-based product defect detection method is inefficient and inaccurate, especially in accurately identifying tiny cracks and complex welded structures. It also relies on manual inspection, resulting in low efficiency and poor accuracy.

Method used

An X-ray-based product defect visualization prediction method is adopted. Edge detection is performed through grayscale processing, adaptive median filtering and improved Canny algorithm. Combined with cluster analysis and entropy judgment, defect areas are identified, and defect categories are predicted using a classification model. Finally, image correction and parameter measurement are performed.

Benefits of technology

It improves the accuracy and efficiency of defect detection, reduces false positives, realizes automated product defect visualization measurement and detection, reduces human intervention, and enhances the ability to identify complex welding structures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120673173A_ABST
    Figure CN120673173A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of machine vision and product defect visual prediction, in particular to a product defect visual prediction method and device based on X rays. According to the method, edge extraction and entropy-based analysis are utilized to enhance defect positioning, meanwhile, the challenges of image noise and non-uniform intensity change are solved, and in order to improve robustness, a self-adaptive threshold strategy combined with DBSCAN clustering is adopted to distinguish defects and noise. Therefore, the problems that in the prior art, the ratio of product defects is low, the visual prediction efficiency of edge blurring is low, and the accuracy is not high are solved. Compared with the prior art, noise reduction, edge detection and crack identification are enhanced. By integrating X-ray image processing, the method improves accuracy, reduces false positive and improves detection efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine vision and product defect visualization prediction, and in particular to an X-ray-based product defect visualization prediction method and device. Background Art

[0002] With the continuous advancement of industrialization, the visualization prediction and measurement of material and product defects, as well as welding technologies, are increasingly being used in manufacturing, as well as in the prediction and monitoring of product reliability and lifecycle degradation over the entire lifecycle. However, the health monitoring of materials and products throughout their lifecycles and the quality issues that arise in welded structures, such as cracks, pores, lack of fusion, voids, corrosion, delamination, deformation, separation, poor solder joint contact, partial weld leakage, and cold welds, seriously impact the safety and reliability of welded structures and product performance. To ensure product and welding quality, performance, stability, reliability, and safety, the visualization prediction, measurement, and visual inspection, prediction, and evaluation of product defects in welded structures and products have become an indispensable part, representing the future third digital industrial revolution.

[0003] In specific products, such as PCB (PCBA) processes and components, and PCB (PCBA) boards and components, defects such as cracks, voids, delamination, deformation, separation, bridging, open circuits in metal layers (wires, cores), fractures, dust, foreign matter and impurities, metal particles, looseness, corrosion degradation, and dislocation and damage to insulation layers can seriously affect the safety, reliability, stability, inherent performance, and failure prevention of solder joints, PCB (PCBA) boards, components, and processes. To ensure the quality, safety, reliability, stability, performance, and lifespan of PCB (PCBA) boards, components, and processes, visual prediction of product defects in PCB (PCBA) boards, components, and processes has become an indispensable component.

[0004] Traditional methods for visually predicting product defects include non-destructive testing (NDT) techniques such as ultrasonic testing, magnetic particle testing, penetrant testing, and X-ray testing. Ultrasonic testing is sensitive to internal cracks but is affected by reflection and attenuation in multi-layer structures. Magnetic particle testing and eddy current testing primarily detect surface defects, making them unsuitable for deep cracks. X-ray NDT is a non-contact method that uses contrast absorption to penetrate objects and reveal internal defects. Compared to other methods, it excels at efficiently and accurately detecting small and hidden cracks, making it an ideal choice for end-use testing. X-ray testing offers intuitive imaging, is sensitive to volumetric defects, accurately measures dimensions, and has no strict requirements for surface roughness. Furthermore, X-ray NDT technology offers advantages such as strong penetration, high image resolution, and the ability to penetrate deep into the material's internal structure. It is widely used for internal defect detection and quality control of metal materials. Currently, X-ray-based crack detection and assessment generally relies on manual visual inspection, which is not only inefficient and labor-intensive, but also often results inaccurate due to the eye's susceptibility to strong light damage and subjective factors. Existing X-ray imaging is an image output by the errors of various related factors. The image converted by the photoelectric analog-to-digital image has a large error compared with the original true value image. There is no calibration mechanism after image processing. It mainly relies on the accuracy of the hardware itself and human judgment, so that there is still a certain error between the image processing technology results and the actual situation. Therefore, the existing technology lacks technical solutions for the 3D measurement and reproduction of products and defects, such as type, shape, size, area, volume, etc., which seriously restricts the control, repair, improvement, production process improvement, product part design, maintenance and safety of products (parts).

[0005] As a key component of smart meters, terminal blocks connect power lines to the electrical system. During the manufacturing process, copper rods and sampling elements are welded together, replacing pre-buried screws. This welding process inevitably generates stress on the surface or inside the terminal. These stresses are gradually released, causing cracks, resulting in increased contact resistance, shortened lifespan or burnout of the meter, power measurement errors, and potential safety hazards. Therefore, detecting these defects is crucial for accurate power metering and system stability. Due to their small size, cracks formed on the terminals are very small. Although surface cracks can be identified visually, internal crack detection remains challenging due to low image contrast and blurred edges. As industrial production requires higher efficiency, traditional manual inspection can no longer meet the requirements.

[0006] In the power industry, electricity meters and metering automation terminals, instrument transformers, batteries, transformers and conductors, chips, IGBTs, BGAs, and other components are crucial to the power system. Their quality and reliability are directly linked to the accuracy of power metering and the proper operation of the power system. Defects such as cracks, voids, and delamination in solder joints, printed circuit boards (PCBAs), and components not only affect the service life and stability of electricity meters and metering automation terminals, batteries, instrument transformers, transformers, and conductors, leading to metering errors and even posing safety hazards. Traditional methods for visually predicting product defects such as cracks, voids, bubbles, and delamination in solder joints, printed circuit boards (PCBAs) and processes, instrument transformers and components, conductors, chips, IGBTs, BGAs, and other components rely primarily on manual visual inspection, which also suffers from low efficiency, high workload, and poor accuracy. With the continuous improvement of inspection efficiency and accuracy in industrial production, traditional manual inspection methods can no longer fully meet these requirements.

[0007] Advances in image processing and machine learning have improved defect identification through automated methods. Traditional image processing and machine learning offer alternatives through preprocessing, feature extraction, and pattern recognition. In their paper, "Automatic Defect Detection and Counting in Radiographic Weld Images," published in Computer Applications, M. Thiruganam, S. Anouncia, and S. Kantipudi proposed a method combining global and local thresholds, while N. Nacereddine, M. Zelmat, S., Belaifa, et al., published their paper, "Weld Defect Detection in Digital Image Processing of Industrial Radiography," in Transactions on Engineering Computing and Technology. They introduced contrast enhancement based on local pixel statistics. While these methods are effective for obvious defects, they can also cause minor cracks on wiring boards. Despite advances in image processing, detecting defects on complex weld surfaces remains challenging. Image noise and artifacts reduce accuracy, making it difficult for traditional methods to separate defects. Summary of the Invention

[0008] In light of this, the present invention provides an X-ray-based product defect visualization prediction method and device to address the low efficiency and accuracy of visual prediction of product defects, often due to low contrast and blurred edges, in existing technologies. Compared to traditional technologies, this method enhances noise reduction, edge detection, and crack identification. By integrating X-ray NDT with image processing, this method improves accuracy, reduces false positives, and increases detection efficiency.

[0009] In a first aspect, the present invention provides a product defect visualization prediction method based on X-rays, the method comprising: obtaining an X-ray image of a part to be tested; performing grayscale processing and denoising on the X-ray image to obtain a denoised grayscale image; performing edge detection on the denoised grayscale image using an improved Canny algorithm to obtain an edge-extracted binary image; performing boundary identification and cropping on the binary image to obtain a cropped binary sub-image; clustering the edge points of the binary sub-image, and determining the defect area according to the entropy value of each cluster; inputting parameter features of the defect area and the X-ray image into a classification model to predict the defect category; correcting the X-ray image based on the defect area and the defect category to obtain a corrected image; and performing parameter measurement and visualization on the corrected image.

[0010] In this method, the X-ray image is first converted into a grayscale image and subjected to denoising, thus preventing the impact of image noise on the detection results. An improved Canny algorithm is then used for edge detection, improving its adaptability and further enhancing detection accuracy. The binary image is then cropped to extract the sub-image containing the defect. Edge points are then clustered, and the defect area is determined based on the entropy of the clusters, thereby accurately detecting the defect area. The defect category is then determined based on the defect area and image features. The image is then corrected based on the defect area and defect category, allowing parameter measurement and visualization based on the corrected image. This method thus enables visual measurement and detection of product defects.

[0011] In addition, due to the influence of ambient light and the irregularities of the terminal surface, the image contains a large amount of noise, including salt and pepper noise, low contrast noise, and high-frequency noise. In order to minimize the interference of noise on subsequent crack detection, the original X-ray image is preprocessed. Through image filtering, a certain amount of noise interference can be removed while retaining the crack edge information, making the image extraction more stable. At the same time, edge extraction and entropy-based analysis are used to enhance defect positioning, while solving the challenges of image noise and non-uniform intensity changes. In order to improve robustness, an adaptive filtering strategy combined with clustering is adopted to distinguish defects from noise. As a result, the present invention solves the problems of low contrast and low efficiency and low accuracy of visual prediction of product defects in the prior art due to blurred edges. Compared with traditional technologies, it enhances noise reduction, edge detection and crack identification. By integrating X-ray image processing, the method improves accuracy, reduces false positives, and improves detection efficiency.

[0012] In an optional embodiment, the X-ray image is grayscale processed and denoised to obtain a denoised grayscale image, including: grayscale processing the X-ray image to obtain a grayscale image; adaptive median filtering is performed on the grayscale image to obtain an adaptive median filtered grayscale image; and Gaussian filtering is performed on the adaptive median filtered grayscale image to obtain a denoised grayscale image.

[0013] In the present invention, filtering is achieved by combining adaptive median filtering and Gaussian filtering. Different filtering methods undertake different denoising tasks, and work together to effectively suppress image noise and retain edge details. Among them, adaptive median filtering is mainly used to remove salt and pepper noise in the image, that is, isolated highlights or low highlights. When the window is gradually increased, it can more effectively smooth out isolated noise points in the image while retaining the detailed information of the edges in the image as much as possible. Therefore, adaptive median filtering retains the edge details of the image while eliminating salt and pepper noise. Gaussian filtering is used to further smooth the image after adaptive median filtering, mainly targeting random noise (such as Gaussian noise), which can more naturally eliminate random noise in the image and make the image smoother as a whole.

[0014] In an optional embodiment, the grayscale image is subjected to adaptive median filtering to obtain a grayscale image after adaptive median filtering, including: calculating the maximum value, minimum value and median value of the pixel values ​​of the grayscale image in the initial filtering window; judging whether the median value and the current pixel value are both between the minimum value and the maximum value; when the median value is between the minimum value and the maximum value and the current pixel value is not between the minimum value and the maximum value, replacing the current pixel value with the median value; when the median value is between the minimum value and the maximum value and the current pixel value is between the minimum value and the maximum value, retaining the current pixel value; when the median value is not between the minimum value and the maximum value, increasing the size of the initial filtering window, repeating the steps of calculating the maximum value, the minimum value and the median value, and judging the median value and the current pixel value, until the initial filtering window is increased to a preset maximum window.

[0015] In the present invention, when judging whether the median replaces the current pixel, a judgment condition is added on whether the current pixel value is within the median range. This improvement can more accurately preserve cracks, voids, delaminations and intermittent weld edges, and reduce the loss of details caused by over-smoothing. Among them, in the X-ray image of the electric meter, the noise distribution is uneven, which makes the fixed window size inappropriate, that is, it may not be able to completely remove the noise, and may also cause blurred edges. To solve this problem, an adaptive median filter is used, which dynamically adjusts the window size according to the statistical characteristics of the local area. This method improves the efficiency of noise removal while preserving edge details.

[0016] In an optional embodiment, an improved Canny algorithm is used to perform edge detection on the denoised grayscale image to obtain a binary image with edge extraction, including: using a simplified Sobel operator to calculate the gradient amplitude and gradient direction of each pixel in the denoised grayscale image; quantizing the gradient direction of each pixel to obtain a quantized gradient direction; performing non-maximum suppression on the pixel points in the quantized gradient direction based on the gradient amplitude to remove non-edge points to obtain a gradient amplitude image; determining a double threshold by using the gradient amplitude and a maximum inter-class variance method, and determining edge points, weak edge points, and non-edge points in the gradient amplitude image based on the relationship between the gradient amplitude and the double threshold; performing hysteresis connection on the gradient amplitude image after the edge point classification using a neighborhood check greater than the threshold range to classify the weak edge points as edge points or non-edge points to obtain a binary image with edge extraction.

[0017] In this invention, a simplified Sobel operator is used to optimize computational complexity and reduce calculation time, making it particularly suitable for the rapid processing of large-scale X-ray images. By quantizing the gradient direction to five standard directions (0°, 45°, 90°, -45°, and -90°), the impact of noise on edge direction detection is reduced, and the consistency of edge directions is improved, which facilitates the visualization and prediction of product defects in complex texture images and reduces errors. The use of a wide range of neighborhood checks in the hysteresis connection helps preserve true edges and reduces the probability of isolated weak edge points being suppressed, thereby improving edge continuity and integrity while balancing computational complexity and accuracy.

[0018] In an optional embodiment, the binarized image is subjected to boundary identification and cropping to obtain a cropped binarized sub-image, including: counting the number of pixel values ​​in each row and each column in the binarized image; determining an initial boundary of the binarized image based on a relationship between a preset threshold and the number of pixel values ​​in each row and a relationship between a preset threshold and the number of pixel values ​​in each column; determining a final boundary based on a relationship between an average pixel value of the initial boundary and an average pixel value of a preset range; and cropping the binarized image using the final boundary as a cropping boundary to obtain a cropped binarized sub-image.

[0019] In this method, an initial boundary is first determined based on the sum of pixel values, and then the final boundary is determined based on the average pixel value, finding the location where the mean value drops significantly. This allows the sub-image containing the defect to be cropped from the binary image, effectively removing boundary noise in the X-ray image caused by complex multi-layer solder structures, PCB boards, mutual inductors, and components, while also ignoring the interference of solder structure edges on subsequent defect identification.

[0020] In an optional embodiment, the edge points of the binary sub-image are clustered, and the defect area is determined based on the entropy value of each cluster, including: clustering the edge points in the binary sub-image using a density-based clustering algorithm to obtain multiple clusters, the density-based clustering algorithm including DBSCAN clustering; calculating the entropy value of each cluster based on the area and number of points of each cluster, and determining the defect area based on the minimum entropy value.

[0021] This method uses geometric feature extraction and analysis to accurately identify the actual area and number of defects, further improving the accuracy of product defect visualization prediction. By combining geometric features with morphological analysis to identify defects, it provides accurate and reliable product defect visualization prediction results. Its adaptive nature eliminates the need for human intervention throughout the detection process, enabling automated detection and improving detection efficiency. Furthermore, the use of the DBSCAN clustering algorithm enhances the ability to distinguish defect backgrounds.

[0022] In an optional embodiment, the entropy value of each cluster is calculated based on the area and number of points of each cluster, and the defect area is determined based on the minimum entropy value, including: calculating the area of ​​each cluster based on the coordinates of the edge points in each cluster; calculating the entropy value of each cluster based on the area of ​​each cluster, the number of edge points in each cluster and the total number of clusters; and determining the position of the defect in the X-ray image to be detected based on the coordinates of the cluster with the minimum entropy value.

[0023] In the present invention, an entropy value measurement is defined by comprehensively considering the area and number of edge points of the defect. The smaller the entropy value, the greater the possibility of being a defect. The entropy value measurement can more accurately distinguish defects from other noise points when processing complex welds or device surfaces and interiors, improve the reliability and accuracy of product defect visualization predictions, and effectively reduce the risk of false detection and missed detection. Specifically, entropy reflects the product of the area of ​​the region and the number of edge points. A higher entropy indicates that the region contains richer edge information, thereby increasing the possibility of it becoming a crack region. Compared with other noise points, defective regions usually have larger areas and more edge points, resulting in lower entropy values. Based on the calculated entropy value, the cluster with the smallest entropy is selected as the crack cluster. This improves the accuracy and robustness of detection.

[0024] In an optional embodiment, the parameter features of the defect area and the X-ray image are input into a classification model to predict the defect category, including: performing logical contrast correction processing on the X-ray image using a preset correction rule set to obtain a processed X-ray image; extracting the grayscale distribution features of the processed X-ray image; extracting the texture parameters of the processed X-ray image using a grayscale co-occurrence matrix; constructing a feature vector with the defect area, grayscale distribution features and texture parameters; and inputting the feature vector into the classification model to predict the defect category.

[0025] In an optional embodiment, parameter measurement and visualization are performed on the corrected image, including: measuring the shape, size, area and volume of the corrected image and the defect area; and performing visualization based on the shape, size, area and volume.

[0026] In a second aspect, the present invention provides an X-ray-based product defect visualization prediction device, the device comprising: an image acquisition module for acquiring an X-ray image of a welding part to be inspected; a grayscale and denoising processing module for performing grayscale processing and denoising on the X-ray image to obtain a denoised grayscale image; an edge detection module for performing edge detection on the denoised grayscale image using an improved Canny algorithm to obtain an edge-extracted binary image; a cropping module for performing boundary identification and cropping on the binary image to obtain a cropped binary sub-image; a crack determination module for clustering the edge points of the binary sub-image and determining the defect area according to the entropy value of each cluster; a category prediction module for inputting the parameter features of the defect area and the X-ray image into a classification model to predict the defect category; a correction module for correcting the X-ray image based on the defect area and the defect category to obtain a corrected image; and a measurement and visualization module for performing parameter measurement and visualization on the corrected image.

[0027] In a third aspect, the present invention provides a computer device comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to thereby execute the X-ray-based product defect visualization prediction method of the above-mentioned first aspect or any corresponding embodiment thereof.

[0028] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the X-ray-based product defect visualization prediction method of the above-mentioned first aspect or any corresponding embodiment thereof.

[0029] In a fifth aspect, the present invention provides a computer program product comprising computer instructions for causing a computer to execute the X-ray-based product defect visualization prediction method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0031] Figure 1 is a flow chart of a method for visually predicting product defects according to an embodiment of the present invention;

[0032] Figure 2 is a flowchart of another method for visually predicting product defects according to an embodiment of the present invention;

[0033] Figure 3 is a schematic diagram of an X-ray image of a surface of a welding structure in an electric energy meter according to an embodiment of the present invention;

[0034] Figure 4 is a three-dimensional distribution diagram of grayscale visualization before denoising (original noise) according to an embodiment of the present invention;

[0035] Figure 5 is a visualized three-dimensional distribution graph of grayscale after denoising according to an embodiment of the present invention;

[0036] Figure 6 is a binarized image extracted from edges according to an embodiment of the present invention;

[0037] Figure 7 is a schematic diagram of a labeling result according to an embodiment of the present invention;

[0038] Figure 8 1 is a schematic diagram of images of qualified chips and unqualified chips (chips with cold solder joints and broken gold wires) after correction according to an embodiment of the present invention;

[0039] Figure 9 1 is a schematic diagram of images of a qualified BGA and an unqualified BGA (BGA with solder voids) after correction according to an embodiment of the present invention;

[0040] Figure 10 Schematic diagram of images of a qualified crystal oscillator and an unqualified crystal oscillator (a crystal oscillator with cracks in the thyristor and broken wires) after correction according to an embodiment of the present invention;

[0041] Figure 11is a structural block diagram of a device for visually predicting product defects according to an embodiment of the present invention;

[0042] Figure 12 1. A schematic diagram of a workflow of a method for enhancing defect localization of a terminal of a sampling component of a smart meter based on entropy and edge extraction and fusion of DBSCAN clustering according to an embodiment of the present invention;

[0043] Figure 13 is a schematic diagram of image samples of a data set of sampling component terminals of a smart meter according to an embodiment of the present invention;

[0044] Figure 14 1 is a schematic diagram of experimental results of crack detection on terminals of sampling components of a smart meter according to an embodiment of the present invention;

[0045] Figure 15 is a schematic diagram of the results of ablation research and comparison of terminals of sampling components of smart meters according to an embodiment of the present invention;

[0046] Figure 16 is a comparative schematic diagram of different crack detection methods for terminals of sampling components of a smart meter according to an embodiment of the present invention;

[0047] Figure 17 Schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0048] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, 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 creative efforts shall fall within the scope of protection of the present invention.

[0049] According to an embodiment of the present invention, an embodiment of a method for visually predicting product defects is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0050] In this embodiment, a product defect visualization prediction method based on X-ray is provided, which can be used for electronic devices such as computers, mobile phones, tablet computers, smart meters, smart terminals, PCB (PCBA) boards, components, mutual inductors, transformers, wires, silicon wafers, etc. Figure 1 FIG. 1 is a flow chart of a method for visually predicting product defects according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0051] Step S101: Acquire an X-ray image of the part to be tested. Specifically, this detection method can be used to visually predict product defects in the welding parts of an electric energy meter. It can also detect defects such as cracks, delamination, voids, deformation, separation, bridging, open circuits in metal layers (wires, cores), short circuits, cold welds, poor solder joints, fractures, dust, foreign matter and impurities, metal particles, looseness, dislocation, and damaged insulation layers in PCB (PCBA) boards, components, mutual inductors, transformers, wires, silicon wafers, etc. For example, in an electric energy meter, cracks and voids may exist on or within the welding surface of the terminal blocks of its components. Among them, the copper rod of the terminal of the electric energy meter and the sampling element are fixed with welding hard connection instead of embedded screws. Welding cracks will appear on the surface or inside of the sampling element welding hard connection and the terminal. The cracks generated at the weld of the sampling element welding hard connection and the terminal include through cracks, internal cracks and holes. In addition, the defects detected also include PCB (PCBA) board cracking, invisible cracks and delamination on components on the PCB (PCBA) board such as diodes, transistors, capacitors, resistors, transformers, mutual inductors, silicon wafers, MCU, CPU, GPU, NPU, IGBT, IGBT, MOSFET, GTO, inductors, SOP, QFP, BGA, CSP, CSP, POP devices, batteries, mutual inductors, transformers and wires, and solder joints. The X-ray images of these parts can be used to detect cracks, voids, discontinuous welds, separations, bridges, open circuits, short circuits, cold welds, cold solder joints, fractures, dust, foreign matter and impurities, metal particles, looseness, dislocation, and damage to the insulation layer. The X-ray images of PCBs (PCBAs), transformers, and components such as diodes, capacitors, resistors, transformers, transformers, silicon wafers, MCUs, CPUs, GPUs, NPUs, IGBTs, IGBTs, MOSFETs, GTOs, inductors, SOPs, QFPs, BGAs, CSPs, CSPs, POPs, batteries, and cables can also be used to detect cracks and delaminations, voids, fractures, deformations, separations, bridges, open circuits, short circuits, cold welds, cold solder joints, fractures, dust, foreign matter and impurities, metal particles, looseness, dislocation, and damage to the insulation layer. Therefore, defect detection can be achieved by acquiring X-ray images of these parts.

[0052] Before acquiring X-ray images, the part to be tested can be cleaned as necessary. When acquiring X-ray images, X-ray equipment can be used, and appropriate shooting angles, exposure times, and parameter settings can be selected to ensure the clarity and contrast of the acquired X-ray images, thereby avoiding the impact of unclear X-ray images on the test results.

[0053] Step S102: Grayscale processing and denoising are performed on the X-ray image to obtain a denoised grayscale image. Grayscale processing of the X-ray image removes color information from the image, simplifying subsequent processing steps, such as edge detection. It also reduces image data size and improves subsequent processing speed. Furthermore, image noise can affect detection accuracy. Therefore, a correlation filtering algorithm can be used to denoise the image during detection.

[0054] In step S103, an improved Canny algorithm is used to perform edge detection on the denoised grayscale image to obtain a binary image with edge extraction. Specifically, the Canny algorithm, as an edge detection algorithm, can reliably detect edges in an image through steps such as gradient calculation, non-maximum suppression, dual thresholds, and hysteresis connection. For example, the Canny algorithm in the related art uses a fixed dual threshold. When the grayscale differences between different regions of the X-ray image are large, the fixed dual threshold cannot be adjusted according to the grayscale distribution of the image. Therefore, the traditional Canny algorithm can be improved to increase its adaptability, thereby further improving the subsequent detection accuracy.

[0055] Step S104: Boundary identification and cropping are performed on the binarized image to obtain a cropped binarized sub-image. Specifically, the acquired X-ray image represents an overall image of the weld. To more accurately identify defective areas, pixel value analysis can be used to crop the image and further extract the image containing the defect. For example, statistical analysis can be performed on the pixel values ​​of each row and column in the binarized image to determine the actual edge of the image containing the defect. The image can then be cropped to remove the area outside the edge to obtain a cropped binarized sub-image.

[0056] Step S105: Cluster the edge points of the binarized sub-image and determine the defect area based on the entropy value of each cluster. Specifically, when clustering the binarized sub-image, the edge points extracted from the image can be clustered. The calculated entropy value of the cluster can reflect the purity of the edge points in each cluster. The distribution of edge points also reflects the distribution of defects such as cracks to a certain extent. Therefore, the calculated entropy value can be used to screen and determine the defect area.

[0057] Step S106: Input the defect area and the parameter features of the X-ray image into a classification model to predict the defect category. Specifically, in order to more accurately identify defects in the product, after determining the defect area, the defect category can be predicted based on the defect area, i.e., the defect location, and the relevant parameter features of the X-ray image, using a classification model. The classification model can use a support vector machine or a neural network, or a statistical analysis method such as regression analysis. In addition, before using the classification model, the selected support vector machine or neural network framework can be trained. After the classification model is trained, the defect area and parameter features can be directly input into the classification model to obtain the defect category. The defect categories here include cracks and delamination, voids, fractures, deformations, separations, bridges, open circuits in metal layers (wires, cores), short circuits, cold welds, poor welds, fractures, dust, foreign matter and impurities, metal particles, looseness, dislocations, and damage to the insulation layer. The specific categories can be determined based on the defects that may exist in the product.

[0058] Step S107: Correcting the X-ray image based on the defect region and the defect category to obtain a corrected image. Specifically, when correcting the X-ray image, the defect region may be corrected based on the defect region and the specifically predicted defect category to more clearly and accurately display the defect region. For example, this may be achieved by adjusting the grayscale value of the defect region, increasing the contrast of the defect region, or highlighting the defect region to obtain a corrected X-ray image.

[0059] Step S108: Parameter measurement and visualization are performed on the corrected image. Specifically, when measuring the corrected image, relevant parameters can be measured based on the defect area in the corrected image and the X-ray image to visualize the product and its defects. For example, parameters such as shape, size, area, and volume can be measured.

[0060] The product defect visualization prediction method provided by an embodiment of the present invention first converts the X-ray image into a grayscale image and performs denoising processing on it, thereby avoiding the influence of image noise on the detection results. It then uses an improved Canny algorithm for edge detection, improving its adaptability and further improving detection accuracy. The binary image is then cropped to extract the sub-image containing the defect. The edge points are then clustered and the defect area is determined based on the entropy value of the cluster, thereby achieving accurate detection of the defect area. The defect category is then determined based on the defect area and image features, and the image is corrected based on the defect area and defect category so that parameter measurement and visualization can be performed based on the corrected image. As a result, this method achieves visual measurement and detection of product defects.

[0061] In this embodiment, a product defect visualization prediction method based on X-rays is provided. The process includes the following steps:

[0062] Step S201: Obtain an X-ray image of the welding part to be inspected. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.

[0063] Step S202: performing grayscale processing and denoising on the X-ray image to obtain a denoised grayscale image.

[0064] Specifically, the above step S202 includes:

[0065] Step S2021: Grayscale processing is performed on the X-ray image to obtain a grayscale image. Specifically, the grayscale processing can be implemented using relevant techniques, such as a maximum value method, an average method, or a weighted average method. Through grayscale processing, a grayscale image containing pixel grayscale values ​​(hereinafter referred to as pixel values) is obtained.

[0066] Step S2022, performing adaptive median filtering on the grayscale image to obtain a grayscale image after adaptive median filtering; specifically, the adaptive median filtering algorithm can remove salt and pepper noise in the image, and achieve smoothing of the image while maintaining edge details.

[0067] In an optional implementation, the above step S2022 includes:

[0068] Step a1: Calculate the maximum, minimum, and median values ​​of the grayscale image's pixel values ​​within an initial filtering window. The initial filtering window may have a predefined size, such as W = 3. After determining the initial filtering window, calculate the maximum, minimum, and median values ​​of all pixel values ​​within the grayscale image within the initial filtering window.

[0069] Step a2: Determine whether the median and the current pixel value are both between the minimum and maximum values. Specifically, after calculating the maximum, minimum, and median values ​​in the initial filter window, the three values ​​can be compared to determine whether the median is greater than the minimum and less than the maximum. Each pixel value in the initial filter window is then compared with the maximum and minimum values. The pixel value of each pixel in the initial filter window is used as the current pixel value to determine whether it is greater than the minimum and less than the maximum. When determining the median, the median value can be determined first, and the current pixel value can be determined only after the median value is determined.

[0070] Step a3, when the median is between the minimum value and the maximum value and the current pixel value is not between the minimum value and the maximum value, the current pixel value is replaced with the median; specifically, when it is determined that the median is greater than the minimum value and less than the maximum value, but the current pixel value is not between the minimum value and the maximum value, that is, the current pixel value is less than the minimum value or greater than the maximum value, the current pixel value is replaced with the median, that is, the current pixel value is replaced with the median.

[0071] Step a4: When the median is between the minimum value and the maximum value and the current pixel value is between the minimum value and the maximum value, the current pixel value will be retained; specifically, if it is determined that the median is greater than the minimum value and less than the maximum value, and the current pixel value is also greater than the minimum value and less than the maximum value, the current pixel value can be kept unchanged and the next pixel value in the window is used as the current pixel value for comparison with the maximum value and the minimum value.

[0072] Step a5: When the median is not between the minimum and maximum values, the size of the initial filter window is increased, and the steps of calculating the maximum, minimum, and median, and judging the median and the current pixel value are repeated until the initial filter window is increased to the preset maximum window size. Specifically, when it is determined that the median is not between the minimum and maximum values, that is, the median is less than the minimum value or greater than the maximum value, the size of the initial filter window needs to be increased, and then the maximum, minimum, and median are recalculated for the increased window, and the size of the pixel value, maximum, minimum, and median in the increased window is judged. If the median is still not between the minimum and maximum values, the process is repeated until the size of the initial filter window is increased to the preset maximum window size. When increasing the window size, it can be increased in the manner of W=W+2.

[0073] Based on the above steps, the mathematical expression of adaptive median filtering is as follows:

[0074] I(i,j)=Median(n(k))

[0075] Among them, k is the total number of pixels in the window, n is the sorted gray value sequence, i is the horizontal coordinate of the pixel, and j is the vertical coordinate of the pixel.

[0076] The adaptive median filtering algorithm employed in this embodiment provides an improved image denoising algorithm. Specifically, it optimizes the adaptive median filtering algorithm to better meet the needs of visual defect prediction for products such as welded structures, PCBs, transformers, and components. Compared to traditional adaptive median filtering algorithms that remove noise by increasing the window size based on a fixed rule, this embodiment introduces a more flexible dynamic adjustment mechanism. When the initial filter window fails to effectively remove noise, the window size is adaptively increased based on the noise level, ensuring a better balance between noise removal and edge detail preservation. However, traditional filtering methods can easily lead to loss of edge information. This embodiment adds a criterion for determining whether the current pixel value falls within the median range when determining whether to replace the current pixel with the median. This improvement more accurately preserves cracks, voids, delaminations, and intermittent weld edges, reducing detail loss caused by oversmoothing. Furthermore, the filtering process in traditional methods lacks flexibility and relies on a fixed threshold. By adjusting the filtering conditions, this embodiment allows the filtering process to adapt to the actual noise distribution characteristics in the image, thus adapting to the noise in the X-ray image.

[0077] Step S2023: Gaussian filtering is performed on the grayscale image after the adaptive median filtering to obtain a denoised grayscale image. Specifically, Gaussian filtering uses a Gaussian function to simulate a filter of arbitrary shape to remove noise or other unnecessary information from an image, thereby optimizing image quality. During the visual defect prediction process for products such as soldered structures, PCBs, transformers, and components, noise and artifacts may appear in the image due to the light source characteristics and complex imaging environment of X-ray imaging technology, affecting subsequent edge detection. The principle of Gaussian filtering is as follows: First, a weight coefficient is calculated for each surrounding pixel relative to the central pixel using a Gaussian function. Then, the value of each surrounding pixel is multiplied by its corresponding weight coefficient. Finally, all these products are added together and divided by the sum of all weight coefficients. The result is the new value of the central pixel after Gaussian filtering. This process can be implemented using a convolution kernel, where each element in the kernel represents the distance from the central pixel. Pixels closer in distance have a greater weight. The advantage of Gaussian filtering is that it effectively smooths images and reduces noise while preserving edges.

[0078] The Gaussian filtering process involves applying a Gaussian filter to the image after adaptive median filtering. For example, a 3×3 convolution kernel with a standard deviation σ of 2 can be selected. The image is then convolved with the selected Gaussian kernel. During the convolution operation, the Gaussian kernel is used to calculate the weighted average of the pixels in its neighborhood, centered at each pixel, to obtain a new pixel value. This entire process traverses all pixels in the image, completing the Gaussian filtering process.

[0079] The formula of the Gaussian function can be expressed as:

[0080]

[0081] Where x and y represent the horizontal and vertical positions of the pixel in the image, respectively, and σ is the standard deviation, which determines the width of the Gaussian function.

[0082] In this embodiment, filtering is achieved through a combination of adaptive median filtering and Gaussian filtering. Different filtering methods perform different denoising tasks, working together to effectively suppress image noise while preserving edge detail. Adaptive median filtering is primarily used to remove salt-and-pepper noise (i.e., isolated highlights or dims) from images. Its characteristic is that it adapts to varying noise densities by adjusting the filter window size. For each pixel, the adaptive median filter dynamically calculates the minimum, maximum, and median values ​​within the window and, based on these statistics, decides whether to retain the current pixel value or replace it with the median value. As the window size increases, it can more effectively smooth out isolated noise points in the image while preserving edge detail as much as possible. Therefore, adaptive median filtering removes salt-and-pepper noise while preserving edge detail. Gaussian filtering, on the other hand, further smooths the image after adaptive median filtering, primarily targeting random noise (such as Gaussian noise). Gaussian filtering applies a convolution kernel based on a Gaussian distribution to perform a weighted average of the pixels surrounding each pixel, with closer pixels receiving a higher weight and farther pixels receiving a lower weight. This can more naturally eliminate random noise in the image while making the image smoother overall.

[0083] Step S203, performing edge detection on the denoised grayscale image using an improved Canny algorithm to obtain a binary image with edge extraction;

[0084] Specifically, the above step S203 includes:

[0085] In step S2031, a simplified Sobel operator is used to calculate the gradient magnitude and gradient direction of each pixel in the denoised grayscale image. The conventional Canny algorithm uses a standard Sobel operator to calculate the gradient magnitude and gradient direction, which is computationally complex and requires a longer computation time. This embodiment uses a simplified Sobel operator to optimize computational complexity, reduce computation time, and is particularly suitable for rapid processing of large-size X-ray images.

[0086] Specifically, the simplified Sobel operator is expressed as follows:

[0087]

[0088] Where S xis the gradient operator of the image in the x direction, S y is the gradient operator of the image in the y direction.

[0089] When calculating the gradient magnitude and gradient direction, we can first use a simplified Sobel operator as the convolution kernel to perform a convolution operation on the image to obtain an approximate gradient value, and then further calculate the gradient magnitude and gradient direction.

[0090] Specifically, the approximate gradient value D of each pixel x and D y Calculated using the following formula:

[0091] D x =I*S x

[0092] D y =I*S y

[0093] Where I represents the input image and * represents the convolution operation.

[0094] Furthermore, the gradient magnitude M(x,y) and gradient direction θ(x,y) can be calculated using the following formula:

[0095]

[0096] Step S2032: quantize the gradient direction of each pixel to obtain a quantized gradient direction. The gradient direction θ is quantized into five directions: 0°, 45°, 90°, -45°, and -90°. The specific quantization process includes: for each pixel, calculating the absolute difference between its gradient direction θ and the five standard directions of 0°, 45°, 90°, -45°, and -90°, and selecting the standard direction with the smallest difference as the quantized gradient direction θ. q .

[0097] The mapping function formula of the quantization process is:

[0098] θ q (x,y)=argmin θ{0°,45°,90°,-45°,-90°} |θ-θ(x,y)|

[0099] In this embodiment, by quantizing the gradient direction into five standard directions, namely 0°, 45°, 90°, -45°, and -90°, the influence of noise on edge direction detection can be reduced, the consistency of edge direction can be improved, which is beneficial to crack detection in complex texture images and reduces errors.

[0100] Step S2033, based on the gradient amplitude, non-maximum suppression is performed on the pixel points in the quantized gradient direction to remove non-edge points and obtain a gradient amplitude image; wherein, non-maximum suppression is specifically performed on the gradient direction θ q On the θ axis, only the pixel with the largest gradient amplitude is retained, and the remaining pixel points (non-edge points) are suppressed, that is, the non-edge points are removed. The specific implementation process of the non-maximum suppression includes: for each pixel, check along θ q The gradient magnitude of the previous and next pixel points in the direction. If the gradient magnitude M of the current pixel point is greater than the gradient magnitude of the previous and next pixel points, the pixel point is retained, otherwise it is suppressed as a non-edge point.

[0101] Step S2034: Determine a dual threshold using the gradient magnitude and the maximum inter-class variance method. Based on the relationship between the gradient magnitude and the dual threshold, determine edge points, weak edge points, and non-edge points in the gradient magnitude image. Specifically, when determining the dual threshold, the maximum inter-class variance method (Otsu) can be used to calculate the global threshold T of the gradient magnitude image. The specific calculation process can be implemented with reference to related technologies and will not be described in detail here. After calculating the global threshold, the adaptive dual threshold can be calculated using the following formula:

[0102] low=0.05×a×T

[0103] high=2.5×low

[0104] Where low represents the low threshold, high represents the high threshold, and a is a scaling factor used to adjust the threshold, which is used to scale the global threshold T calculated by the Otsu method.

[0105] After calculating the dual thresholds, the calculated gradient magnitude can be compared with the dual thresholds to classify edge points. Pixels with gradient magnitudes greater than the high threshold are marked as edge points, pixels with gradient magnitudes less than the low threshold are marked as non-edge points, and pixels with gradient magnitudes between the low and high thresholds are considered weak edge points.

[0106] In this embodiment, the Otsu method is used to calculate the global threshold during dual-threshold calculation, and this serves as the basis for adjusting the dual thresholds. In practical applications, the grayscale distribution of X-ray images is affected by many factors, such as material thickness, density, and imaging conditions, which can lead to significant grayscale differences between different areas. Compared to the traditional Canny algorithm, which uses fixed preset high and low thresholds, this adaptive method can better adjust according to the image's grayscale distribution.

[0107] Step S2035, using a neighborhood check greater than a threshold range to perform hysteresis connection on the gradient amplitude image after the edge point classification, classify the weak edge points as edge points or non-edge points, and obtain a binary image of edge extraction. Among them, the neighborhood check greater than the threshold range can be a neighborhood check greater than the 3×3 range in the related art. For example, a 9×9 large-scale neighborhood check can be used. By using a large-scale neighborhood check in the hysteresis connection, it helps to retain the real edge and reduce the probability of isolated weak edge points being suppressed, thereby improving the continuity and integrity of the edge. Specifically, when using a 9×9 large-scale neighborhood check, the specific hysteresis connection can be expressed by the following formula:

[0108]

[0109] In the formula, count0 represents the number of non-edge points in a 9×9 neighborhood centered on the weak edge pixel, count1 represents the number of strong edge points in a 9×9 neighborhood centered on the weak edge pixel, flag is a flag matrix used to mark the pixel status, and r and c represent the horizontal and vertical coordinates of the current pixel, respectively. i and j represent the horizontal and vertical offsets relative to the current pixel, respectively. The values ​​of i and j range from -8 to 8, representing a 9×9 neighborhood centered on the current pixel (r, c). Within this neighborhood, each offset corresponds to an adjacent pixel position. By traversing i and j, the number of non-edge points (count0) and strong edge points (count1) in the neighborhood surrounding the current weak edge point (r, c) can be counted.

[0110] The pixel status in the flag matrix (flag) indicates whether the pixel is an edge point, specifically status 0 or 1. 0 indicates a non-edge point, while 1 indicates an edge point. During the hysteresis connection process, weak and strong edge points are also considered. Strong edge points are pixels with more pronounced edge features, while weak edge points are pixels with gradient values ​​between a high threshold and a low threshold. The flag matrix (flag) is generated during the execution of the modified Canny algorithm and identifies the status of each pixel in the image. Specifically, during the Canny edge detection process, after double threshold processing, pixels are classified into three categories: ① Strong edge points: Pixels with gradient values ​​above the high threshold are directly marked as 1. ② Weak edge points: Pixels with gradient values ​​between the high and low thresholds are also temporarily marked as 1, but require further evaluation through hysteresis connection. ③ Non-edge points: Pixels with gradient values ​​below the low threshold are marked as 0. The flag matrix (flag) is a two-dimensional matrix of the same size as the input image, with each element corresponding to a pixel. The value of each position in the matrix indicates whether the pixel at that position is an edge point. This matrix is ​​generated during the Canny edge detection process and is constructed in the double threshold processing and hysteresis connection stages. Hysteresis connection will decide whether to retain weak edge points as edge points based on the number of strong edge points in the neighborhood, and ultimately adjust the value in the flag matrix. Each element of the flag matrix flag can be determined by the following logic: First, in the double threshold stage, the value in the flag matrix (0 or 1) is initialized by comparing the gradient amplitude with the high and low thresholds. Then, in the hysteresis connection processing stage, the flag matrix is ​​further updated based on the number of strong edge points in the neighborhood, and the weak edge points that meet the conditions are converted to strong edge points (1), otherwise they remain as non-edge points (0).

[0111] The above formula is used to count the number of edge points around the weak edge point within a 9×9 pixel range. If the number of strong edge points is greater than the number of non-edge points, that is, count1 is greater than count0, then the point is retained as an edge point, otherwise it is suppressed as a non-edge point. Thus, through the hysteresis connection, the further classification of the weak edge points in the above step S2034 is achieved, that is, in order to determine whether a weak edge point should be retained as an edge point, it is necessary to check the neighborhood features around it. If the number of strong edge points count1 is greater than the number of non-edge points count0, it means that the edge features are more obvious in this local area. Therefore, if count1 is greater than count0, it means that in the neighborhood of the weak edge point, the strong edge point dominates, so the weak edge point is retained as an edge point.

[0112] Step S204 : performing boundary recognition and cropping on the binarized image to obtain a cropped binarized sub-image.

[0113] Specifically, the above step S204 includes:

[0114] Step S2041: Count the number of pixel values ​​in each row and column of the binary image. The specific counting process can be implemented using the following formula:

[0115]

[0116] Where CPC represents the number of pixel values ​​in each column, RPC represents the number of pixel values ​​in each row, canny_edges(i,j) represents the pixel value at position (i,j) in the binary edge image, and height and width represent the height and width of the image, respectively.

[0117] Step S2042 determines the initial boundary of the binary image based on the relationship between a preset threshold and the number of pixel values ​​in each row, and between the preset threshold and the number of pixel values ​​in each column. Specifically, when determining the initial boundary, the number of pixel values ​​in each row and column can be compared with the preset thresholds. For example, the image can be scanned from the left side of the image to the right. Each time a column is scanned, the number of pixel values ​​in that column is compared with the preset threshold. If the number is less than the preset threshold, the image is scanned rightward until a column with a number of pixel values ​​greater than the preset threshold is found, which is then used as the left boundary. The image is then scanned from the right side of the image to the left, finding the first column with a number greater than the preset threshold as the right boundary. The image is then scanned downward from the top, comparing the number of pixel values ​​in each scanned row with the preset threshold. A row with a number greater than the preset threshold is found as the upper boundary. Finally, the image is scanned from the bottom up, finding the first row with a number greater than the preset threshold as the lower boundary. Thus, the left boundary, right boundary, upper boundary, and lower boundary together constitute the initial boundary of the binary image. In practical applications, the preset threshold may be set to 10, and in other embodiments, it may also be set to other values.

[0118] Step S2043, determine the final boundary based on the relationship between the average pixel value of the initial boundary and the average pixel value of the preset range; specifically, the initial boundary determined above can roughly determine the initial boundary of the binary sub-image, and on this basis, it can be further cropped to a position where the pixel value drops rapidly and tends to be flat. Further refine the cropping boundary. When determining the final boundary, first set the step size m_threshold of the cropping boundary, then scan to the right from the left boundary, calculate the average pixel value of each column, find the position where the mean value drops significantly and determine it as the new left boundary left_boundary. Specifically, set the average pixel value within the step size range and compare it with the average pixel value at the initial boundary. If the average pixel value within a certain range is significantly lower than 0.125 times the average pixel value of the preliminary boundary, then determine the position as the final boundary position. The final left boundary calculation formula is as follows:

[0119]

[0120] Wherein, j represents the current scanning position, k represents the offset within the step range, and the step m_threshold can be set to 12 in this embodiment.

[0121] Similarly, starting from the right boundary, scan leftward, starting from the top boundary, scanning downward, and starting from the bottom boundary, scanning upward. Calculate the average pixel value for each column or row, find the location where the average value drops significantly, and determine it as the new boundary. Thus, the final boundary is determined by the final left boundary, final right boundary, final top boundary, and final bottom boundary.

[0122] In step S2044, the binarized image is cropped using the final boundary as a cropping boundary to obtain a cropped binarized sub-image. Specifically, after determining the final boundary, the binarized image is cropped using it as the cropping boundary. This allows the sub-image containing the defect to be cropped from the binarized image, effectively removing boundary noise in the X-ray image caused by complex multi-layer solder structures, and ignoring interference with subsequent defect identification caused by edges of solder structures, PCBs, transformers, and components.

[0123] Step S205 : clustering the edge points of the binary sub-image, and determining the defect area according to the entropy value of each cluster.

[0124] Specifically, the above step S205 includes:

[0125] In step S2051, a density-based clustering algorithm is used to cluster the edge points in the binary sub-image to obtain multiple clusters. In this density-based clustering algorithm, as long as the density (number of objects or data points) of a neighboring area exceeds a certain threshold during clustering, it is added to a cluster that is close to it. This algorithm does not require the number of clusters to be specified in advance, but can automatically determine the shape and number of clusters based on the distribution of data points. In practical applications, algorithms such as DBSCAN (Density-Based Spatial Clustering of Applications with Noise), OPTICS (Ordering Points To Identify the Clustering Structure), and DENCLUE (Density-Based Clustering in Spatial Databases with Noise) can be used for clustering.

[0126] In this embodiment, DBSCAN is used to perform cluster analysis. The cluster analysis process specifically includes:

[0127] First, edge points are extracted from the binarized sub-image, and the coordinates of all edge points are obtained. Specifically, the edge points can be obtained by edge detection in step S203, for example, by determining the edge points whose value is 1 in the marker matrix. After the edge points are obtained, their coordinates can be recorded to obtain a point set.

[0128] The extracted edge point coordinates are then normalized. Normalization can eliminate scale differences in the data, so that different features have the same weight when clustering. The normalization process is specifically implemented using the following formula:

[0129]

[0130] In the formula, x′ and y′ represent the standardized horizontal and vertical coordinates, respectively, x and y represent the original horizontal and vertical coordinates, respectively, μ x and μ y Represent the mean of the horizontal and vertical axes, σ x and σ y represent the standard deviation of the horizontal and vertical axes respectively.

[0131] Finally, set the parameters for the DBSCAN algorithm, including the neighborhood radius ε and the minimum number of points, MinPts. The neighborhood radius ε determines the neighborhood range of a point, and the minimum number of points, MinPts, determines the density threshold of a cluster. For example, in DBSCAN density clustering, the neighborhood radius ε can be set to 8, and the minimum number of points, MinPts, can be set to 5. After setting the parameters, use the DBSCAN algorithm to cluster the normalized edge points. Based on the set ε and MinPts, the algorithm divides the edge points into different clusters based on density and distribution, and also marks out noise points.

[0132] Step S2052 : calculating the entropy value of each cluster according to the area and number of points of each cluster, and determining the defect area according to the minimum entropy value.

[0133] Specifically, the above step S2052 includes:

[0134] Step b1: Calculate the area of ​​each cluster based on the coordinates of the edge points in each cluster. Specifically, when calculating the area of ​​each cluster, polygon fitting can be performed based on the coordinates of the edge points within the cluster, and the area of ​​each cluster can be calculated using the polygon area. The area of ​​each cluster can be calculated using the following formula:

[0135]

[0136] In the formula, (x i ,y i) is the coordinate of the i-th pixel, and (x n+1 ,y n+1 )=(x1,y1), that is, the first point and the last point coincide, forming a closed polygon.

[0137] Step b2: Calculate the entropy of each cluster based on the area of ​​each cluster, the number of edge points in each cluster, and the total number of clusters; wherein the number of edge points in each cluster represents the number of points. Specifically, the entropy of each cluster is calculated using the following formula:

[0138]

[0139] Among them, p i It represents the product of the area of ​​the ith cluster and the number of points, and n is the total number of clusters.

[0140] Step b3, determine the position of the defect in the X-ray image to be detected based on the coordinates of the cluster with the smallest entropy value. According to the above entropy calculation formula, the entropy value is determined by the area and number of points of the cluster when calculating the entropy value, so the entropy value reflects the distribution of edge points within the cluster. In addition, since defects such as cracks usually have a larger area and more edge points, the smaller the entropy value, the larger the product of the area and the number of points of the cluster, and the higher the possibility that the cluster is a defect. According to the calculated entropy value, the cluster with the smallest entropy value is selected as the defect cluster. In addition, after confirming that the selected cluster is a defect cluster through geometric features, i.e., area and number of points analysis, the position of the defect is marked on the original image, i.e., the X-ray image. For example, the corresponding position of the selected defect cluster in the original image can be framed out based on the coordinates of the selected defect cluster.

[0141] Step S206: Input the parameter features of the defect area and the X-ray image into a classification model to predict the defect category.

[0142] Specifically, the above step S206 includes:

[0143] Step S2061, use the preset correction rule set to perform logical contrast correction processing on the X-ray image to obtain a processed X-ray image; specifically, the preset correction rule set can be formulated based on factors such as the characteristics of the X-ray image, imaging device parameters, and the desired correction effect. For example, if the grayscale value of a certain area of ​​the image is lower than the threshold T1, and the grayscale difference between the area and the adjacent area is greater than the difference threshold D1, then the grayscale value of the area is specifically adjusted (such as adding a fixed value A1). Among them, for the X-ray image, it can be expressed as I(x, y), x and y respectively represent the horizontal and vertical coordinates of the image on the two-dimensional plane, and the value range of the image can be determined according to the specific image data format. For example, for a grayscale image, the value range may be [0, 255]. Further, the process of performing logical contrast correction processing on the X-ray image can be expressed as C(I(x, y), R), where R represents the preset correction rule set. Thus, the processed X-ray image is expressed as I corrected (x, y) = C(I(x, y), R).

[0144] Step S2062: extract the grayscale distribution characteristics of the processed X-ray image; specifically, the grayscale histogram can be used to count the grayscale distribution characteristics of the pixels. When determining the grayscale histogram, the grayscale value range can be set to [0, G], and then the number of pixels in each grayscale value interval is counted to obtain the grayscale histogram H = [h0, h1…h G ].

[0145] In step S2063, texture parameters of the processed X-ray image are extracted using a gray-level co-occurrence matrix (GLCM). Specifically, texture parameters such as contrast C, correlation R, energy E, and entropy H can be calculated using the gray-level co-occurrence matrix (GLCM). The specific calculation method can be implemented with reference to related technologies and will not be further described here.

[0146] Step S2064: construct a feature vector using the defect area, grayscale distribution characteristics, and texture parameters.

[0147] Step S2065: Input the feature vector into the classification model to predict the defect category. Specifically, the trained model is M, and the feature vector is input. After that, the model outputs the probability distribution of image type P = [p0, p1…p n ], where n is the number of defect categories, P i It represents the probability that the defect belongs to the i-th type, and the type with the highest probability is the predicted defect category or defect type.

[0148] Step S207: Correct the X-ray image based on the defect area and the defect category to obtain a corrected image. Specifically, the corrected image can be represented as I final (x, y) = I (x, y) + f (P), where f (P) represents the correction function used during correction.

[0149] Step S208: Parameter measurement and visualization are performed on the corrected image.

[0150] Specifically, the above step S208 includes:

[0151] Step S2081 , measuring the shape, size, area and volume of the corrected image and the defective area.

[0152] Among them, when measuring the shape, the image contour C can be extracted by edge detection algorithm (such as Canny edge detection) i ,y i )|i=1.2…m}, where i represents the coordinates of the pixel points on the contour. Then calculate the geometric features of the contour. For example, calculate the perimeter L of the contour. For discrete contour points, the length of the broken line can be used to approximate the calculation. Thus, the perimeter Furthermore, to describe the compactness of the shape, the shape factor S can be calculated f For a circle, the shape factor is 1, and the more irregular the shape, the greater the S f If the area of ​​the area enclosed by the outline is recorded as A, the calculation formula for the shape factor of different shapes is In addition, shape description based on moments can also be performed. In the moment of the image, the zero-order moment M0 can be used to calculate the area, and the first-order moments M10 and M01 are used to calculate the centroid coordinates (x c ,y c ), Second-order moments and higher-order moments can be used to describe the direction, eccentricity, and other characteristics of a shape. For example, the second-order central moment u 20 、u 02 and u 11 The main axis direction and eccentricity of the image can be combined to describe the shape in more detail.

[0153] When measuring dimensions, you can first measure the dimensions at the pixel scale, and then convert the measured dimensions to the physical scale. When measuring dimensions at the pixel scale, for simple shapes, such as rectangles, find the boundary pixels of the image in the horizontal and vertical directions, and set the minimum x coordinate of the horizontal boundary pixels as x. min , the maximum x coordinate is x max , the minimum y coordinate of the vertical boundary pixel is y min , the maximum y coordinate is ymax , then the size of the image in pixel scale is (x max -x min +1,y max -y min +1), where 1 is added because the boundary pixels are included. For irregular shapes, edge pixel points are obtained by edge detection, and the maximum span of edge pixel points in each direction is calculated to approximate the size. When performing size conversion under physical scale, if the actual physical size corresponding to each pixel is known (for example, obtained through the parameters of the imaging device), it is set as (s x , s y )(unit is mm / pixel, etc.), then the size in physical scale is (x max -x min +1)s x ,(y max -y min +1)s y ).

[0154] When measuring the area, you can use the pixel counting method or the integral method. When using the pixel counting method, you can determine the image area R by using methods such as region growing algorithm and threshold segmentation, and then count the pixels. For a given image area R (such as the corrected image area or defect area), count the number of pixels N in the area. If the actual physical area corresponding to each pixel is A p (For example, if the pixel is a square with side length s, then A p =s 2 ), then the image area A=NxA p When measuring by integration, the image is regarded as a two-dimensional function I(x, y). For a closed image region R, its boundary is ЭR. According to Green's formula, the area A can be expressed as In actual digital images, they need to be discretized before use, for example, by performing approximate calculations by summing boundary pixels.

[0155] For three-dimensional imaging, image volume can also be measured, which can be done using the slice superposition method. When measuring, the image data is treated as a two-dimensional digital matrix, and each element in this matrix corresponds to the pixel value at a specific position in the image. The image is then preprocessed, first normalized to ensure that the range of pixel values ​​is in the appropriate range for subsequent calculations. For example, if the pixel value range is 0-4095, the formula is used Normalize it to the range of 0-1, where I(x,y) is the original pixel value and I norm(x,y) is the normalized pixel value. Noise is then removed by filtering, such as using a Gaussian filter. By setting an appropriate filter kernel size and standard deviation, random noise interference in the image can be reduced.

[0156] Furthermore, the image requires geometric calibration. This can be done by using parameters such as the pixel size of the detector used to acquire the image to build a geometric model. Assuming the pixel sizes are p and p (in millimeters per pixel), the actual physical location (X, Y) corresponding to a point (x, y) in the image can be calculated using X = x × p and Y = y × p. This step helps to link the image pixel coordinates to the actual physical space, which is critical for subsequent accurate measurement of object dimensions.

[0157] If there is a series of two-dimensional slice images of three-dimensional imaging {I1, I2, ... I n}, first calculate the area A1, A2, ... A of each slice image according to the above two-dimensional image area measurement method n If the spacing between slices is d (in millimeters, etc.), the volume V of the three-dimensional image can be approximately expressed as In addition, if the voxel (three-dimensional pixel) representation of the three-dimensional image can be obtained through the reconstruction algorithm, the volume can also be calculated by voxel counting, which is similar to the two-dimensional pixel counting method, counting the number of voxels and multiplying it by the actual physical volume corresponding to each voxel.

[0158] In addition, the center of mass coordinate method or the boundary coordinate method can also be used to measure the image position. Among them, the center of mass coordinate method is calculated by calculating the moment to obtain the center of mass. As mentioned above, the moment of the image is calculated. The zero-order moment M0 can be used to calculate the area, and the first-order moments M10 and M01 are used to calculate the center of mass coordinates (x c ,y c ),in The centroid coordinates can be used as the position of the image in the plane, and the unit is pixel coordinates. If you want to convert it to physical coordinates, you should also convert it according to the actual physical size of each pixel. When calculating the boundary coordinate method, first determine the bounding box coordinates of the image, that is, find the minimum and maximum coordinates (x and y) of the boundary pixel points of the image in the horizontal and vertical directions. min ,y min ) and (x max ,y max ). Then take the center coordinates of this bounding box Indicates the image location.

[0159] Step S2082: Visualize based on the shape, size, area, and volume. Specifically, after measuring the shape, size, area, and volume, the product's tested part and the corresponding defects can be accurately and clearly displayed.

[0160] In an embodiment of the present invention, an improved Canny algorithm is used for edge detection. Adaptive median filtering and Gaussian filtering are first used as a combined filter for denoising, making full use of redundant information in the image to weaken or remove noise and retain edge details. Secondly, a simplified Sobel operator is used to calculate the approximate gradient value and gradient direction of each pixel in the image, and quantization processing is performed based on the approximate gradient value and gradient direction, effectively reducing errors and improving the accuracy and speed of product defect visualization prediction. Finally, valid edge points are selected through non-maximum suppression and adaptive dual thresholds, and a large-scale neighborhood check is introduced for hysteresis connection, further improving the accuracy and continuity of edge detection and ensuring the integrity of product defect visualization prediction results.

[0161] In this embodiment of the present invention, cluster analysis using the DBSCAN algorithm combined with the results from the Canny algorithm effectively identifies and separates defects from noise points. Geometric feature extraction and analysis accurately identify the actual area and number of defects, further improving the accuracy of product defect visualization prediction. By combining geometric features with morphological analysis to identify defects, accurate and reliable product defect visualization prediction results are provided. The adaptive nature of the system eliminates the need for human intervention throughout the entire detection process, enabling automated detection and improving detection efficiency.

[0162] In this embodiment of the present invention, an entropy metric is defined by comprehensively considering the defect area and the number of edge points. A smaller entropy value indicates a greater likelihood of a defect. This entropy metric can more accurately distinguish defects from other noise points when processing complex weld surfaces, improving the reliability and accuracy of product defect visualization predictions and effectively reducing the risk of false and missed detections.

[0163] As a specific application example of the embodiment of the present invention, take the defect as a welding structure in an electric energy meter as an example, such as Figure 2 As shown in the figure, the product defect visualization prediction method can be implemented using the following process:

[0164] S01: Obtain an X-ray image of the surface of the welding structure in the electric energy meter, perform grayscale processing on the obtained X-ray image, and obtain a grayscale image containing pixel grayscale values; wherein the obtained image is as follows: Figure 3 shown.

[0165] S02: Use adaptive median filtering and Gaussian filtering as a combination filter to perform denoising on the grayscale image data. The grayscale visualization 3D distribution map before denoising and the grayscale visualization 3D distribution map after denoising are shown as follows: Figure 4 and Figure 5 As shown in the figure, it can be seen that after the adaptive median filter and Gaussian filter processing, the noise in the image is effectively suppressed and the edge details are well preserved. Figure 4 , Figure 5The noise is significantly reduced and the image becomes smoother.

[0166] S03: Using the improved Canny algorithm to perform edge detection on the denoised image, the edge detection process includes: calculating the direction and amplitude of the gradient of the denoised image, quantizing the gradient direction, performing non-maximum suppression, and using the Otsu method to determine the adaptive double threshold for large-scale neighborhood hysteresis connection. The edge-extracted binary image obtained by edge detection is as follows: Figure 6 shown.

[0167] S04: Identify the actual edge of the welding structure in the X-ray image through a pixel value analysis method and cut it out to obtain a binary sub-image containing the defect.

[0168] S05: Perform cluster analysis on the binarized sub-image using a density-based clustering algorithm DBSCAN.

[0169] S06: Calculate the entropy value of each cluster, select the cluster with the minimum entropy value as the defect cluster and mark it in the X-ray image. The final marking result is as follows: Figure 7 shown.

[0170] S07: Inputting the parameter features of the defect area and the X-ray image into a classification model to predict the defect category.

[0171] S08: Correcting the X-ray image based on the defect area and the defect category to obtain a corrected image.

[0172] S09: Parameter measurement and visualization of the corrected image. The corrected images of qualified chips and unqualified chips (chips with cold solder joints and broken gold wires) are as follows: Figure 8 As shown, Figure 8 The upper left part is a qualified chip 44 , and the lower left part, upper right part and lower right part are defective unqualified chips, which specifically include cold solder wires 41 , broken gold wires 42 and micro-defective chips 43 .

[0173] The corrected images of qualified BGA and unqualified BGA (BGA with solder voids) are as follows Figure 9 shown. Figure 9 The left half is a qualified BGA 53, and the right half is a failed BGA 52. The failed BGA includes a GBA cavity 51 (the white circle is a cavity).

[0174] The images of qualified crystal oscillators and unqualified crystal oscillators (crystal oscillators with thyristor cracks and wire breakage) after correction are as follows Figure 10 shown. Figure 10In the figure, the upper part shows two qualified crystal oscillators 48, and the lower part shows two unqualified crystal oscillators 50. In the two crystal oscillators on the left, 49 indicates the position of the bonding wires. The bonding wires of the qualified crystal oscillator on the upper left side are normal, while the bonding wires of the unqualified crystal oscillator on the lower left side are broken (the grayish-white color indicates a break feature). In the two crystal oscillators on the right side, 47 indicates the position of the crystal silicon solder joints. The silicon solder joints of the qualified crystal oscillator on the upper right side are normal, while the silicon solder joints of the unqualified crystal oscillator on the lower right side are broken (the bright lines indicate break lines in the silicon solder joints).

[0175] As a specific application example of the present invention, X-ray images are used to detect cracks in the terminal connector of a smart meter. Figure 12 As shown in the figure, it includes image acquisition, preprocessing, crack extraction, and defect identification. First, image preprocessing removes noise. Edge detection extracts key features. Then, DBSCAN clustering and entropy analysis are applied to accurately locate the terminal area and further identify and extract cracks.

[0176] Step A: X-ray image preprocessing.

[0177] Due to the influence of ambient light and irregularities in the terminal surface, the image contains a large amount of noise, including salt and pepper noise, low-contrast noise, and high-frequency noise. To minimize the interference of noise on subsequent crack detection, the original X-ray image is preprocessed. Image filtering can remove certain noise interference while retaining crack edge information, thereby making image extraction more stable. Taking into account the characteristics of terminal X-ray images, this embodiment uses a filter that combines adaptive median filtering and Gaussian filtering to effectively remove interference.

[0178] The median filter is a nonlinear low-pass filter that removes impulse noise by defining a window in the image space.

[0179] The current pixel value is replaced by the median value of the adjacent pixels. However, in meter X-ray images, the noise distribution is uneven, making a fixed window size inappropriate—it may not completely remove the noise and may also cause blurred edges. To address this problem, this embodiment uses adaptive median filtering, which dynamically adjusts the window size based on the statistical characteristics of the local area. This method improves noise removal efficiency while preserving edge details. The specific process of adaptive median filtering is as follows:

[0180] 1) Define the initial filter window size as W = 3 in the image. For each pixel (r, y), calculate the minimum value Zmin, maximum value maz and median value Zmed of all pixel values ​​in the window and determine whether the condition zmin≤Zmed is satisfied. <zmax。

[0181] 2) If the condition is met, keep the current pixel value, otherwise replace it with the median value zmed.

[0182] 3) If the condition in step 2 is not met, increase the window size W=W+2 and repeat steps 1 and 2 until the window size reaches the predefined maximum value. The mathematical expression of adaptive median filtering is: (same as the formula in step a5 of the above embodiment:

[0183] I(i,j)=Median(n(k))

[0184] Where k is the total number of pixels in the window, n is the sorted grayscale sequence, i is the horizontal coordinate of the pixel, and j is the vertical coordinate of the pixel. In X-ray images, low-contrast areas are often covered by noise, especially at the terminal edges where the surface is relatively smooth. To improve this situation, Gaussian filtering can effectively remove uniformly distributed background noise while improving the clarity of the image. Specifically, after performing adaptive median filtering, a 3x3 window is selected and the standard deviation σ is set to 2. The image is then processed with Gaussian filtering after denoising. The pixel value is updated by performing convolution and using a Gaussian kernel to calculate the weighted average of each pixel and its neighboring pixels. The Gaussian filter formula is expressed as:

[0185]

[0186] Where x and y represent the horizontal and vertical positions of the pixel in the image, and σ is the standard deviation, which determines the width of the Gaussian function. After applying adaptive median and Gaussian filtering, the noise in the image is significantly reduced while preserving edge details. Figure 14 and Figure 15 shows the 3D visualization of the X-ray grayscale image before and after filtering, where Figure 14 represents the original noisy image, Figure 15 Showing the denoising results, with sharper edges and smoother surfaces.

[0187] Step B: X-ray image edge extraction.

[0188] Because electricity meters have multi-layer structures, terminal edges are affected by background variations, resulting in inconsistent contrast when using traditional edge extraction methods. When background contrast increases, traditional methods may misclassify crack edges as weak edges, leading to their loss. To address this issue, this embodiment incorporates the characteristics of X-ray images and extracts terminal edges based on grayscale projection distribution.

[0189] After X-ray image preprocessing, an improved Sobel operator is used to effectively extract edges, balancing computational complexity and accuracy. In order to estimate the gradient magnitude and direction of each pixel, the following convolution kernel is used to calculate the horizontal and vertical gradients:

[0190]

[0191] Among them S x and S y Denotes the gradient operator in the x and y directions respectively. By performing convolution, the x and y direction gradients (D x , D y ,), followed by the gradient magnitude M and gradient direction θ.

[0192] D x =I*S x

[0193] D y =I*S y

[0194]

[0195] To discretize θ, the gradient direction is assigned to one of five angles: 0, 45°, 90°, -45°, and -90°. The absolute difference between the direction of each pixel and these five angles is calculated, and the closest match is selected:

[0196] θ q (x,y)=argmin θ{0°,45°,90°,-45°,-90°] |θ-θ(x,y)|

[0197] Along the gradient direction θ q , only the pixels with the highest gradient magnitude are retained, while other pixels are suppressed. For each pixel, the gradient values ​​of the adjacent pixels are compared; if the current pixel has the highest gradient, it is retained as an edge, otherwise it is suppressed. The Otsu method is then applied to determine the global threshold T of the gradient magnitude image. The two thresholds are calculated as follows:

[0198] low=0.05×a×T

[0199] high=2.5×low

[0200] Where a is a scaling factor. Pixels with gradients above a high threshold are classified as edges, while pixels below a low threshold are suppressed.

[0201] In order to redefine the discontinuous edges in the X-ray image, a 9x9 neighborhood is applied for post-processing to ensure accurate edge preservation. The number of strong and weak edges in the adjacent area is calculated as follows:

[0202]

[0203] Where count0 and count1 represent the number of non-edge points in the neighborhood. If count1>count0, the weak edge is retained, otherwise the weak edge is suppressed.

[0204] Step C, crack initiation detection.

[0205] In industrial inspection, X-ray images of electric energy meters show that the terminals occupy a small portion of the image, while the background occupies the majority. While the background is irrelevant to the analysis, crack defects in the terminals are the primary focus. Because terminals are typically located in the center, their edge characteristics differ from those of other areas. To improve segmentation efficiency and reduce the interference of false defects, this embodiment utilizes the geometric and algebraic characteristics of the endpoints to accurately determine their edges. The background is then removed to extract the sub-image containing the crack.

[0206] To obtain the size of the binary edge image, calculate the number of pixel values ​​in each column and each row. The formula for calculating the number of pixel values ​​in an image column and row is as follows:

[0207]

[0208] Where CPC represents the number of pixel values ​​in each column, and RPC represents the number of pixels in each row. canny_edges(i, j) represents the pixel value at position (i, i) in the binary edge image. height and width represent the height and width of the image, respectively.

[0209] Based on the distribution of edge pixels in the terminal, a threshold, Traek, is set to preliminarily determine the actual boundary. By counting the edge pixels in each column, the first column exceeding Traek is determined as the left boundary, while the last column exceeding Traek is determined as the right boundary. Similarly, the number of edge pixels in each row is counted to determine the upper and lower boundaries.

[0210] Wherein, j represents the current scanning position, k represents the offset within the step range, and the step m_threshold can be set to 12 in this embodiment.

[0211] To further optimize boundary selection and improve crack extraction accuracy, an adaptive boundary clipping step size (Ssean) based on edge pixel density was introduced. A scanning process was performed from the outer edge of the image toward the inner region, and the average number of pixels within the sliding window was calculated. When the average value significantly decreased by more than 12.5% ​​of the initial boundary average pixel count, the corresponding location was defined as the final boundary. The left boundary was determined as follows:

[0212]

[0213] Among them L bonkmy Indicates the index of the left boundary, s scan represents the adaptive scanning step, j is the current scanning position, k is the offset within the step, R threshold is the adaptive boundary threshold.

[0214] This adaptive boundary selection method effectively removes terminal edge noise and enhances craek region extraction. Similarly, the right, top, and bottom boundary scans are performed, and the average pixel value of each column or row is calculated. Boundaries are set where significant dips occur, allowing precise cropping of the sub-image containing the crack. This step reduces boundary noise in the terminal's multi-layer structure and minimizes interference in crack detection.

[0215] After binarization, DBSCAN clustering is applied for crack analysis. Edge pixel coordinates are extracted and normalized to ensure consistent weights in the clusters, as described below:

[0216]

[0217] where x′ and y′ represent the normalized horizontal and vertical coordinates, respectively, x and y are the original coordinates, μ x : and μ y is the horizontal mean, vertical coordinate, and σ x and σ y is their standard deviation.

[0218] Subsequently, DBSCAN clustering is performed on the standardized crack edge pixels to distinguish different crack candidate regions. The core parameters of the DBSCAN algorithm include the neighborhood radius ∈ and the minimum number of points MinPts. The parameter ∈ defines the neighborhood range of the point, while MinPts determines the density threshold for clustering. During the crack extraction process, further improvements are needed to select the most likely crack region to ensure that the extracted region is aligned with the actual crack characteristics. To achieve this, the area of ​​each cluster region is first calculated, and then the polygonal area of ​​the crack region is calculated based on the coordinates of the edge points:

[0219]

[0220] Where (x i ,y i ) represents the coordinates of the i-th pixel, (x n+1 ,y n+1 )=(x i ,y i ), which means that the first and last points intersect to form a closed polygon. To further analyze the distribution of edges within the crack region, the entropy of each cluster is calculated to evaluate the concentration of edge points. The entropy is defined as follows:

[0221]

[0222] where p i represents the product of the area and the number of edge points in the i-th cluster, and n is the total number of clusters.

[0223] Entropy reflects the product of the area of ​​a region and the number of edge points. A higher entropy indicates that the region contains more edge information, increasing its likelihood of being a crack region. Compared to other noise points, crack regions typically have larger areas and more edge points, resulting in lower entropy values. Based on the calculated entropy value, the cluster with the lowest entropy is selected as the crack cluster.

[0224] After the crack region is determined based on the geometric feature analysis, the identified crack image is marked at the original location. A bounding box corresponding to the selected crack region is drawn in the original X-ray image.

[0225] In step D, the parameter features of the defect area and the X-ray image are input into a classification model to predict the defect category.

[0226] Step E: Correcting the X-ray image based on the defect area and the defect category to obtain a corrected image; specifically, the corrected image can be expressed as I final (x, y) = I (x, y) + f (P), where f (P) represents the correction function used during correction.

[0227] Step F: Parameter measurement and visualization of the corrected image.

[0228] In addition, to evaluate the effectiveness of the proposed method, X-ray images of smart meters were collected using an X-ray machine (X6600B) provided by Holmo Technology Co., Ltd. These images contain noise and show non-uniform intensity variations, such as Figure 13 The image samples of the smart meter energy sampling component dataset are shown. Figure 13 The left picture is the collected image sample of the mutual inductor. Figure 13 The image on the right shows a sample image of a relay circuit breaker terminal block; the dashed box highlights a crack defect in the terminal connector. Ablation experiments were also performed to analyze the impact of key steps in the method. All experiments were conducted on a computer equipped with a 2.60 GHz CPU, 32 GB of RAM, and a 64-bit Windows 10 operating system. The software was implemented using MATLAB.

[0229] As shown in Table 1 below, the present invention is for Example Figure 3 The cracks in the meter sampling element are shown. Figure 8 、 Figure 9 、 Figure 10 The prediction, correction, and visualization recognition rates of cracks, voids, cold solder joints, and welding cracks in chips, BGAs, and crystal oscillators are compared with the defect recognition results reflected in product images using the existing Faster R-CNN deep learning network.

[0230] Table 1

[0231]

[0232]

[0233] It can be seen from Table 1 that the prediction recognition, correction recognition and visualization recognition rates of this embodiment are all improved. The recognition rate for smart meter defects was 89.4%, which increased to 95.8% after correction. The recognition accuracy increased to 98.5% after measurement and visualization. The recognition rate for chip solder joint defects was 93.7%, with an accuracy of 97.6% and 98.7% after correction. The recognition rate for chip wire break defects was 87.3%, with an accuracy of 98.3% and 99.6% after correction. The recognition rate for BGA solder void defects was 91.3%, with an accuracy of 97.5% and 98.3% after correction. The recognition rate for crystal oscillator crack defects was 87.9%, with an accuracy of 95.2% and 98.4% after correction. The image recognition was assessed using existing indicators such as intersection over union (IoU), mean average precision (mAP), precision, and recall. The accuracy of prediction, correction, measurement, and visualization for image shape, area, length, width, depth, volume, and position (defect location) was significantly higher than that of existing technologies. Meet the needs of online intelligent and automated real-time detection.

[0234] In an optional embodiment, to quantitatively evaluate the performance of the crack detection method, four evaluation metrics are used: precision, recall, F1 score, and IoU, which evaluate the accuracy of the detected crack area with the pixel-level ground truth.

[0235] Recall (R) represents the ratio of correctly predicted detection frames to actual ground-truth frames among all the detection frames predicted by the model. It reflects the model's ability to detect real objects (avoiding missed detections). Recall is expressed using the following formula:

[0236]

[0237] TP (True Positive) indicates the number of correctly detected targets. FN (False Negative) indicates the number of missed targets.

[0238] The accuracy P (precision) represents the proportion of correct detection frames (positive samples) among all the detection frames predicted by the model. It reflects the reliability of the model's prediction of positive samples (avoiding false positives). The accuracy is expressed as follows:

[0239]

[0240] FP (False Positive) indicates the number of targets that are falsely detected by the model (detection boxes that are "created out of thin air" or "wrongly matched").

[0241] The F1 score is the harmonic mean of Precision and Recall and is given by:

[0242]

[0243] The higher the F1 score, which ranges from 0 to 1, the better the crack detection performance.

[0244] Additionally, the IoU (Intersection Over Union) is used to evaluate the overlap between the detected crack area and the ground truth:

[0245]

[0246] Among them, R pred represents the predicted crack area, R gt Indicates the true crack area on the bottom surface. The loU value ranges from 0 to 1, with higher values ​​indicating better spatial alignment between the detected crack and the actual crack. To determine whether a crack is correctly identified, an area-based criterion is applied: a crack is considered successfully detected if at least 50% of the detected crack pixels overlap with the ground truth pixels.

[0247] To evaluate the effectiveness of the proposed method, experiments were conducted on a dataset containing 200 X-ray images with detected cracks. Table 2 shows the parameter settings for the proposed crack detection method, which produces the best detection results on the dataset. The experimental results were comprehensively evaluated using the aforementioned evaluation metrics.

[0248] Table 2

[0249]

[0250] Figure 14 Figure 1 shows experimental results for crack detection using the proposed method. A selection of experimental results is shown, with the first row displaying the DBSCAN clustering results for different cracks, with each color representing a different cluster. The second row displays the crack detection results. These results demonstrate that the proposed method can effectively detect cracks of varying lengths and locations, demonstrating its effectiveness.

[0251] This example further uses ablation experiments to evaluate the impact of each module on crack detection performance. Figure 15 shown. Figure 15 The upper left figure shows the results of the complete method, accurately identifying cracks while suppressing false detections. Figure 15The upper right figure shows the result without preprocessing, where noise is misclassified as ascracks due to the lack of contrast enhancement and denoising, thereby increasing false positives. Figure 15 The lower left corner shows the result without edge extraction, which leads to incomplete crack shape and misclassification of background structure. Figure 15 The lower right figure presents the results without entropy depreciation, which causes all cluster regions to be marked as ascracks, reducing detection reliability. These results show that each module plays a crucial role in improving accuracy and robustness.

[0252] This example further compares the MNGLV and BBox methods with the method used in this example. The MNGLV method is a crack detection technique based on maximum neighborhood grayscale variation, which enhances crack regions by analyzing local grayscale variations. The BBox method uses adaptive threshold segmentation and morphological reconstruction to identify defect regions in X-ray images.

[0253] like Figure 16 As shown in Table 3 below, the MNGLV method failed to effectively remove noise, resulting in noise being misclassified as cracks. While the BBox method demonstrated better noise removal capabilities, it often misidentified connections between cracks and terminals as cracks, failing to fully extract the cracks. Although the BBox method exhibited faster execution time, the method of this embodiment achieved a higher F1 score, demonstrating superior detection performance. In contrast, the proposed method accurately identified and expanded cracks, achieving high accuracy and completeness in crack detection while maintaining a balance between precision and computational efficiency.

[0254] Table 3

[0255]

[0256]

[0257] A comparison of different crack detection methods shows that this embodiment reduces false positives compared to traditional methods. It is effective for industrial detection of small-scale defects in complex electrical components. Future work will focus on improving computational efficiency and expanding applicability to various defect detection tasks. The proposed method utilizes edge extraction and entropy-based analysis to enhance defect localization while addressing the challenges of image noise and non-uniform intensity variations. To improve robustness, an adaptive thresholding strategy combined with DBSCAN clustering is used to distinguish cracks from noise. Experimental evaluation shows that the proposed method effectively detects cracks of different sizes and locations with higher accuracy and robustness than traditional methods.

[0258] Moreover, this visualization processing provides a basis for high-precision inspection, measurement, prediction and evaluation of product images, internal structures, quality and process defects, as well as product (parts) control, repair, improvement, production (including welding) process improvement, product and parts design, maintenance and safety, ensuring the integrity, continuity, safety, stability, performance and life of materials and products (parts), improving the efficiency and effectiveness of the entire life cycle of products and parts, especially enabling the detection and measurement of minor defects or hidden defects in existing technologies, improving the quality foundation, and providing basic support and technical leadership for metering and billing in modern power supply service systems, electricity-carbon-network integration, digital power grids and new power systems.

[0259] This embodiment also provides an X-ray-based product defect visualization prediction device, which is used to implement the above-mentioned embodiments and preferred embodiments. Details already described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0260] This embodiment provides a product defect visualization prediction device based on X-rays, such as Figure 11 Shown, including:

[0261] An image acquisition module 81 is used to acquire an X-ray image of the welding part to be inspected;

[0262] A grayscale and denoising processing module 82 is configured to perform grayscale processing and denoising on the X-ray image to obtain a denoised grayscale image;

[0263] An edge detection module 83 is configured to perform edge detection on the denoised grayscale image using an improved Canny algorithm to obtain a binary image with edge extraction;

[0264] A cropping module 84 is configured to perform boundary recognition and cropping on the binary image to obtain a cropped binary sub-image;

[0265] a crack determination module 85 for clustering the edge points of the binary sub-image and determining the defect area according to the entropy value of each cluster;

[0266] A category prediction module 86 is configured to input the parameter features of the defect area and the X-ray image into a classification model to predict the defect category;

[0267] a correction module 87, configured to correct the X-ray image based on the defect area and the defect category to obtain a corrected image;

[0268] The measurement and visualization module 88 is used to perform parameter measurement and visualization on the corrected image.

[0269] The further functional description of each of the above modules is the same as that of the above corresponding embodiments and will not be repeated here.

[0270] The embodiment of the present invention also provides a computer device having the above Figure 11 The X-ray-based product defect visualization prediction device shown.

[0271] See also Figure 17 , Figure 17 is a structural diagram of a computer device provided by an optional embodiment of the present invention, such as Figure 17 As shown, the computer device includes: one or more processors 10, memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components utilize different buses to communicate with each other and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in the memory or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Equally, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 17 A processor 10 is taken as an example.

[0272] The processor 10 may be a central processing unit, a network processor, or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic, or any combination thereof.

[0273] The memory 20 stores instructions that can be executed by at least one processor 10, so as to enable at least one processor 10 to execute the method shown in the above embodiment.

[0274] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created based on the use of a computer device for displaying a small program landing page, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.

[0275] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid-state drive; the memory 20 may also include a combination of the above types of memory.

[0276] The computer device further includes a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0277] The embodiment of the present invention also provides a computer-readable storage medium. The above-mentioned method according to the embodiment of the present invention can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the method shown in the above embodiment is implemented.

[0278] A portion of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the form in which the computer program instruction exists in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc. Accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium that can be accessed by the computer.

[0279] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A product defect visualization prediction method based on X-ray, characterized in that: The method comprises: Acquiring an X-ray image of the part to be tested; performing grayscale processing and denoising on the X-ray image to obtain a denoised grayscale image; Using an improved Canny algorithm to perform edge detection on the denoised grayscale image to obtain a binary image with edge extraction; Performing boundary recognition and cropping on the binarized image to obtain a cropped binarized sub-image; Clustering the edge points of the binary sub-image, and determining the defect area according to the entropy value of each cluster; Inputting the parameter features of the defect area and the X-ray image into a classification model to predict the defect category; Correcting the X-ray image based on the defect area and the defect category to obtain a corrected image; Perform parameter measurements and visualization on the rectified images.

2. The method according to claim 1, characterized in that Performing grayscale processing and denoising on the X-ray image to obtain a denoised grayscale image includes: performing grayscale processing on the X-ray image to obtain a grayscale image; Performing adaptive median filtering on the grayscale image to obtain a grayscale image after adaptive median filtering; Gaussian filtering is performed on the grayscale image after the adaptive median filtering to obtain a denoised grayscale image.

3. The method according to claim 2, characterized in that Performing adaptive median filtering on the grayscale image to obtain a grayscale image after adaptive median filtering, comprising: Calculating the maximum, minimum and median values ​​of the pixel values ​​of the grayscale image in the initial filtering window; Determine whether the median value and the current pixel value are both between the minimum value and the maximum value; When the median value is between the minimum value and the maximum value and the current pixel value is not between the minimum value and the maximum value, replacing the current pixel value with the median value; When the median value is between the minimum value and the maximum value and the current pixel value is between the minimum value and the maximum value, the current pixel value will be retained; When the median is not between the minimum and maximum values, the size of the initial filtering window is increased, and the steps of calculating the maximum, minimum and median values, and judging the median value and the current pixel value are repeated until the initial filtering window is increased to the preset maximum window.

4. The method according to claim 1, wherein An improved Canny algorithm is used to perform edge detection on the denoised grayscale image to obtain a binary image with edge extraction, including: Using a simplified Sobel operator to calculate the gradient magnitude and gradient direction of each pixel in the denoised grayscale image; Quantify the gradient direction of each pixel to obtain the quantized gradient direction; Based on the gradient amplitude, non-maximum suppression is performed on the pixel points in the quantized gradient direction to remove non-edge points, thereby obtaining a gradient amplitude image; Determining a dual threshold value by using the gradient amplitude and the maximum inter-class variance method, and determining edge points, weak edge points, and non-edge points in the gradient amplitude image based on the relationship between the gradient amplitude and the dual threshold value; A neighborhood check greater than a threshold range is used to perform hysteresis connection on the gradient magnitude image after the edge point classification, and the weak edge points are classified as edge points or non-edge points to obtain a binary image of edge extraction.

5. The method according to claim 1, wherein Boundary recognition and cropping are performed on the binarized image to obtain a cropped binarized sub-image, including: Counting the number of pixel values ​​in each row and column of the binary image; Determining an initial boundary of the binary image according to a relationship between a preset threshold and the number of pixel values ​​in each row and a relationship between a preset threshold and the number of pixel values ​​in each column; determining a final boundary based on a relationship between an average pixel value of the initial boundary and an average pixel value of a preset range; The binarized image is cropped using the final boundary as a cropping boundary to obtain a cropped binarized sub-image.

6. The method according to claim 4, characterized in that Clustering the edge points of the binary sub-image and determining the defect area according to the entropy value of each cluster, including: Clustering the edge points in the binary sub-image using a density-based clustering algorithm to obtain a plurality of clusters, wherein the density-based clustering algorithm includes DBSCAN clustering; The entropy value of each cluster is calculated according to the area and number of points of each cluster, and the defect area is determined according to the minimum entropy value.

7. The method according to claim 6, characterized in that The entropy value of each cluster is calculated based on the area and number of points of each cluster, and the defect area is determined based on the minimum entropy value, including: Calculate the area of ​​each cluster based on the coordinates of the edge points in each cluster; The entropy value of each cluster is calculated based on the area of ​​each cluster, the number of edge points in each cluster, and the total number of clusters; The position of the defect in the X-ray image to be detected is determined according to the coordinates of the cluster with the smallest entropy value.

8. The method according to claim 1, characterized in that Input the parameter features of the defect area and the X-ray image into the classification model to predict the defect category, including: Performing logical contrast correction processing on the X-ray image using a preset correction rule set to obtain a processed X-ray image; Extracting grayscale distribution features of the processed X-ray image; The texture parameters of the processed X-ray image are extracted using gray-level co-occurrence matrix; Constructing a feature vector from the defect area, grayscale distribution characteristics and texture parameters; The feature vector is input into the classification model to predict the defect category.

9. The method according to claim 1, characterized in that Perform parameter measurements and visualization on the rectified image, including: Measure the shape, size, area, and volume of corrected images and defect areas; Visualization is performed based on the shape, size, area, and volume.

10. A product defect visualization prediction device based on X-ray, characterized in that: The device comprises: An image acquisition module is used to acquire an X-ray image of the welding part to be inspected; A grayscale and denoising processing module, configured to perform grayscale processing and denoising on the X-ray image to obtain a denoised grayscale image; An edge detection module is used to perform edge detection on the denoised grayscale image using an improved Canny algorithm to obtain a binary image with edge extraction; A cropping module, configured to perform boundary recognition and cropping on the binary image to obtain a cropped binary sub-image; a crack determination module, configured to cluster the edge points of the binary sub-image and determine the defect area according to the entropy value of each cluster; A category prediction module, configured to input the parameter features of the defect area and the X-ray image into a classification model to predict the defect category; a correction module, configured to correct the X-ray image based on the defect area and the defect category to obtain a corrected image; The measurement and visualization module is used to measure and visualize the parameters of the rectified image.

Citation Information

Cited By

  • Automatic processing method and system for graphic annotation

    CN121236344A

  • Real-time microdefect identification method and system based on intelligent control production

    CN121304555A

  • A real-time micro-defect identification method and system based on intelligent control production

    CN121304555B