Weld defect intelligent detection method based on machine vision
By constructing distance metric functions for local grayscale profile deviation degree and local gradient structure disorder degree, the problem of distinguishing between benign heterogeneous points and malignant defect points in existing weld inspection is solved, thereby improving the accuracy and reliability of weld defect detection.
Patent Information
- Application Number
- CN202511663681.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-13
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2045-11-13
AI Technical Summary
In existing weld defect detection methods, Euclidean distance cannot effectively distinguish between benign heterogeneous points and malignant defect points, resulting in a high rate of missed detection and making it difficult to meet the needs of efficient, safe and automated weld inspection.
Weld defect identification is performed by constructing distance metrics functions for local grayscale profile deviation and local gradient structure disorder, combined with Euclidean distance.
It improves the accuracy of weld defect detection, reduces misjudgment and missed detection of benign gray-scale heterogeneous points, and achieves highly reliable online monitoring and intelligent evaluation.
Smart Images

Figure CN121095262A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition technology, and in particular to an intelligent detection method for weld defects based on machine vision. Background Technology
[0002] In modern manufacturing, welding, as a key process for joining metal materials, is widely used in high-end equipment manufacturing fields such as aerospace, rail transportation, automobile manufacturing, and pressure vessels. The stability and reliability of weld quality directly affect the safety and service life of product structures; therefore, weld quality inspection and evaluation are indispensable parts of industrial production. Traditional weld inspection methods mainly include manual visual inspection, radiographic testing (RT), and ultrasonic testing (UT). These methods can detect defects inside or on the surface of welds to some extent, but they suffer from low inspection efficiency, high cost, reliance on human experience for inspection results, and poor repeatability. In addition, radiographic testing poses radiation safety hazards and cannot meet the needs of intelligent production lines for efficient, safe, and automated weld inspection.
[0003] With the rapid development of machine vision and image processing technologies, automatic weld defect detection methods based on image recognition have become a mainstream research and application direction. These methods typically utilize industrial cameras to acquire weld surface images and analyze image grayscale, texture, and morphological features through algorithms to achieve automatic weld defect identification. Among these methods, unsupervised clustering-based detection techniques have good universality and automation characteristics due to the elimination of manual annotation. Their basic principle is to input the grayscale value and spatial location of each pixel as features into the clustering algorithm, and use distance metrics to determine the similarity between pixels. However, existing methods generally use traditional Euclidean distance as a similarity metric between pixels. This distance only considers pixel grayscale and coordinate differences and cannot reflect the structural continuity and gradient direction order of the grayscale distribution on the weld surface. Because the welding process generates microscopic textures and weld wave structures caused by normal processes, these areas appear as benign heterogeneous points with significant grayscale changes in the image. Real defects (such as porosity, slag inclusions, or cracks) also exhibit abrupt grayscale changes, making it difficult for clustering algorithms to distinguish between the two. This results in defect features being submerged by normal weld textures and a high rate of missed detections. Therefore, how to construct a distance metric model with structure awareness during weld image clustering to improve the separability of weld defects and normal texture regions has become a pressing technical problem in the field of intelligent weld image detection. Summary of the Invention
[0004] In view of this, the present invention aims to propose an intelligent detection method for weld defects based on machine vision, so as to solve the problem that the Euclidean distance in the existing weld defect detection cannot distinguish between benign heterogeneous points and malignant defect points, resulting in missed detection.
[0005] To achieve the above objectives, the technical solution of the present invention is implemented as follows: A machine vision-based intelligent detection method for weld defects, the method comprising: Step S1: Obtain the basic grayscale feature dataset of pixels by acquiring and preparing features from the weld area image; Step S2: Obtain the local grayscale profile divergence by performing trend prediction and comparison on the local grayscale profile of the pixel; Step S3: Obtain the disorder of the local gradient structure by performing unit vector aggregation analysis on the gradient directions of the pixel's neighborhood; Step S4: Obtain the distance metric function for structure perception by multiplicatively modulating the local gray-scale profile deviation degree and the local gradient structure disorder degree; Step S5: Obtain weld defect identification results by performing cluster analysis on the distance metric function of structure perception.
[0006] Furthermore, the step of acquiring and preparing the basic grayscale feature dataset of pixels by collecting and preparing the image of the weld area includes: The process involves vertically acquiring at least one high-resolution digital grayscale image of the weld area of the workpiece to be inspected using an industrial area array camera installed on the production line. A fixed light source is used for illumination during the vertical image acquisition process. After preprocessing the acquired grayscale image, basic grayscale feature data of each pixel is extracted from the image. The basic grayscale feature data includes the two-dimensional position coordinates of the pixel in the image and the corresponding grayscale value. The two-dimensional position coordinates and grayscale values of all pixels constitute the basic grayscale feature dataset of the pixels.
[0007] Furthermore, the step of obtaining the local grayscale profile divergence by performing trend prediction and comparison on the local grayscale profile of pixels includes: By performing hierarchical statistical processing on the grayscale data of the pixel neighborhood, the grayscale feature parameters of the inner and outer rings are obtained; by performing trend prediction and deviation calculation on the grayscale feature parameters, the local grayscale profile deviation factor is obtained.
[0008] Furthermore, the step of obtaining inner and outer ring grayscale feature parameters by performing hierarchical statistical processing on the grayscale data of the pixel neighborhood includes: For any target pixel in the basic grayscale feature dataset, define the inner ring neighborhood range and the outer ring neighborhood range, divide the neighborhood range of the target pixel according to the inner ring neighborhood range and the outer ring neighborhood range, and obtain the inner ring neighborhood and outer ring neighborhood of the target pixel. The average gray value of the pixels in the inner ring neighborhood of the target pixel is used as the inner ring gray value feature parameter of the target pixel; the average gray value of the pixels in the outer ring neighborhood of the target pixel is used as the outer ring gray value feature parameter of the target pixel.
[0009] Furthermore, the step of obtaining the local grayscale profile deviation by performing trend prediction and deviation calculation on grayscale feature parameters includes: For any target pixel in the pixel base grayscale feature dataset, the calculation result of the inner ring grayscale feature parameter of the target pixel being twice the outer ring grayscale feature parameter of the target pixel is taken as the theoretical environment predicted grayscale value of the target pixel; the absolute value of the calculation result of subtracting the grayscale value of the target pixel from the theoretical environment predicted grayscale value of the target pixel is taken as the local grayscale profile deviation of the target pixel.
[0010] Furthermore, the step of obtaining the local gradient structure disorder by performing unit vector aggregation analysis on the gradient directions of the pixel's neighborhood includes: By performing gradient calculation on the grayscale data of the weld image, a pixel gradient vector dataset is obtained. Then, by normalizing the gradient vector dataset, unit direction vector data of the pixels is obtained. Finally, by aggregating and summing the neighborhood unit direction vector data, the disorder factor of the local gradient structure is obtained.
[0011] Furthermore, the step of performing gradient calculation processing on the grayscale data of the weld image to obtain a pixel gradient vector dataset, and then performing direction normalization processing on the gradient vector dataset to obtain pixel unit direction vector data, includes: For any target pixel in the pixel basic grayscale feature dataset, the horizontal gradient component and vertical gradient component of the target pixel are obtained by calculating the grayscale change rate of the target pixel in the horizontal and vertical directions, respectively. The horizontal and vertical gradient components of the target pixel are combined to obtain the gradient vector of the target pixel, and the magnitude of the gradient vector of the target pixel is calculated. Divide the gradient vector of the target pixel by the magnitude of the gradient vector to obtain the unit direction vector of the target pixel. When the magnitude of the gradient vector is zero, the range direction vector of the target pixel is defined as the zero vector.
[0012] Furthermore, the step of obtaining the local gradient structure disorder by aggregating and summing the neighborhood unit direction vector data includes: Set a square neighborhood radius; for any target pixel in the basic grayscale feature dataset, extract the unit direction vector data of all pixels within the neighborhood based on the square neighborhood radius, with the target pixel as the center; perform vector summation on the unit direction vectors of all pixels within the neighborhood, calculate the magnitude of the vector summation result, and normalize the magnitude with the number of pixels in the neighborhood to obtain the neighborhood gradient direction consistency ratio; subtract the neighborhood gradient direction consistency ratio from the constant 1 as the local gradient structure disorder of the target pixel.
[0013] Furthermore, the step of obtaining a structure-aware distance metric function by multiplicatively modulating the local grayscale profile divergence and the local gradient structure disorder includes: For any two target pixels in the pixel basic grayscale feature dataset, calculate the Euclidean distance based on the grayscale value and two-dimensional position coordinates of the two target pixels to obtain the original distance metric value of the two target pixels. The difference between the local grayscale profile divergence and the difference between the local gradient structure disorder of the two target pixels are calculated respectively. The absolute values of the two differences are added to a constant 1 respectively as the modulation terms of the two types of structural attributes. The original distance metric value is multiplied sequentially by the modulation terms of the two types of structural attributes to obtain the structure-aware distance metric function value of the two target pixels.
[0014] Furthermore, the step of obtaining weld defect identification results through cluster analysis of the structure-aware distance metric function includes: The neighborhood radius parameter and the minimum neighborhood sample number parameter of the clustering algorithm are set, and the structure-aware distance metric function is used as the distance calculation standard of the clustering algorithm. Density reachability analysis is performed on all pixels in the pixel basic grayscale feature dataset, and pixels that meet the density reachability condition are clustered to form multiple pixel clusters. The number of pixels in the clusters is filtered by size, and clusters with a number of pixels less than the minimum neighborhood sample number parameter are removed as noise clusters. The clusters retained after size filtering are output as weld defect regions to obtain the weld defect identification results.
[0015] Compared with the prior art, the present invention has the following advantages: This invention presents a machine vision-based intelligent weld defect detection method. By introducing a local grayscale profile deviation factor and a local gradient structure disorder factor, it structurally improves the traditional Euclidean distance-based weld image clustering metric. This allows distance calculation to reflect not only pixel grayscale and spatial location differences but also the local grayscale continuity and gradient direction consistency of the weld surface. Through this structure-aware distance metric, the algorithm naturally widens the distance between real defect points and normal weld texture points in the feature space, thereby enhancing cluster separation and achieving high-precision identification of defects such as micropores, slag inclusions, and cracks on the weld surface. In practical industrial inspection scenarios, this invention significantly reduces misjudgments and missed detections caused by benign grayscale heterogeneous points such as normal weld waves and solidification textures, ensuring stable identification capabilities even under complex process conditions. This method requires no additional hardware sensors; by modeling and adaptively modulating the grayscale structure and gradient direction at the algorithm level, it balances detection accuracy and real-time performance, providing a highly reliable image analysis solution for online monitoring and intelligent evaluation of welding quality. Attached Figure Description
[0016] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an undue limitation of the invention. In the drawings: Figure 1 This is a flowchart illustrating a machine vision-based intelligent detection method for weld defects according to an embodiment of the present invention. Detailed Implementation
[0017] The present invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0018] See Figure 1 This is a flowchart of a machine vision-based intelligent detection method for weld defects provided in Embodiment 1 of the present invention. Figure 1 As shown, a machine vision-based intelligent detection method for weld defects may include: Step S1: Obtain the basic grayscale feature dataset of pixels by acquiring and preparing features from the image of the weld area.
[0019] This step aims to obtain basic data for subsequent analysis. First, an industrial area array camera installed on the production line is used to perform a vertical image acquisition process on the weld area of the workpiece to be inspected, acquiring at least one high-resolution digital grayscale image. A fixed light source is used for illumination during the vertical image acquisition process. After preprocessing the acquired grayscale image, basic grayscale feature data of each pixel is extracted from the image. The basic grayscale feature data includes the two-dimensional position coordinates of the pixel in the image and the corresponding grayscale value, and the two-dimensional position coordinates and grayscale values of all pixels constitute the pixel basic grayscale feature dataset.
[0020] This completes the acquisition of the basic grayscale feature dataset of pixels by collecting and preparing features from images of the weld area.
[0021] Step S2: Obtain the local grayscale profile deviation by performing trend prediction and comparison on the local grayscale profile of the pixel.
[0022] The fundamental problem with existing weld defect detection technologies lies in the algorithm's inability to distinguish whether a grayscale anomaly belongs to normal weld texture (benign heterogeneous point) or a true defect (malignant defect point). A pixel's attributes should not be determined solely by its grayscale value, but rather by its structural relationship with its surrounding local environment. Specifically, a benign heterogeneous point, even if its grayscale value forms local peaks or valleys, is still part of the continuous and smooth evolution of the grayscale profile in its region; conversely, a malignant defect point disrupts this local grayscale continuity, representing a structural singularity. It is necessary to quantify the degree to which the grayscale value of any pixel conforms to the grayscale change trend constituted by its local environment. This step achieves this by constructing a grayscale prediction model based on the local environment: first, analyzing the grayscale distribution pattern of the environment surrounding a pixel, and based on this pattern, predicting the theoretical grayscale value of the pixel under defect-free conditions; then, by comparing the difference between the actual grayscale value and the theoretical grayscale value of the pixel, an index quantifying its degree of anomaly can be obtained. The smaller the value of this indicator, the more it conforms to the local structural rules, and the higher the probability that it is a benign point; the larger the value of this indicator, the more it disrupts the local structural rules, and the greater the suspicion that it is a malignant defect point.
[0023] In summary, this invention first performs hierarchical statistical processing on the grayscale data of the pixel neighborhood to obtain inner and outer ring grayscale feature parameters. Specifically, for any target pixel in the basic grayscale feature dataset, an inner ring neighborhood range and an outer ring neighborhood range are defined. In this embodiment, the inner ring neighborhood range is defined as the range within a radius of 2 pixels of the target pixel, and the outer ring neighborhood range is defined as the range 3 to 4 pixels away from the target pixel. The neighborhood range of the target pixel is divided according to the inner and outer ring neighborhood ranges to obtain the inner and outer ring neighborhoods of the target pixel. The average grayscale value of the pixels in the inner ring neighborhood of the target pixel is used as the inner ring grayscale feature parameter of the target pixel; the average grayscale value of the pixels in the outer ring neighborhood of the target pixel is used as the outer ring grayscale feature parameter of the target pixel.
[0024] After obtaining the outer ring grayscale feature parameters of the target pixel, the local grayscale profile deviation factor is obtained by performing trend prediction and deviation calculation on the grayscale feature parameters. Specifically, for any target pixel in the basic grayscale feature dataset, the calculation result of twice the inner ring grayscale feature parameters of the target pixel and the outer ring grayscale feature parameters of the target pixel is used as the theoretical environment predicted grayscale value of the target pixel; the absolute value of the calculation result of subtracting the theoretical environment predicted grayscale value of the target pixel from its grayscale value is used as the local grayscale profile deviation of the target pixel.
[0025] In one implementation, assume the first The inner ring grayscale feature parameters of each pixel are: ;No. The outer ring grayscale feature parameters of each pixel are: ;No. The grayscale value of each pixel is Then the first The expression for calculating the local grayscale profile divergence of a pixel is:
[0026] in, Indicates the first Local grayscale profile divergence of individual pixels; Indicates the first The grayscale value of each pixel; Indicates the first Inner ring grayscale feature parameters of each pixel; Indicates the first Outer ring grayscale feature parameters of each pixel; This indicates absolute value calculation.
[0027] It should be noted that the calculation of local grayscale profile deviation is achieved by defining inner and outer ring neighborhood ranges to collect contextual information around the target pixel. On the actual weld surface, whether it's a smooth weld area or an undulating area with a fish-scale pattern, the surface morphology should be a continuous transition at the microscale. This physical continuity is directly reflected in the image as a smooth change in the grayscale profile. The inner and outer ring grayscale feature parameters capture the average grayscale level at two levels from the target pixel, from far to near. The difference between the two quantifies the rate of grayscale change as it approaches the center from the periphery, i.e., the trend of the local grayscale profile. For example, on the slope of a weld wave, this difference will be a stable small value; while when crossing the edge of a bright weld wave, this difference will be a large positive value. Secondly, the core expression of the formula... Mathematically equivalent to Assuming the weld surface structure is continuous, the grayscale value of the target pixel should be the grayscale level of its nearest neighbor (represented by the inner ring), superimposed with the variation trend carried over from the outermost environment (from the outer ring to the inner ring). .therefore, This constitutes the theoretical environmental prediction value for the grayscale value of the target pixel. This prediction value reflects the grayscale that the target pixel should exhibit under conditions of no structural abrupt changes or defects. Finally, by calculating the absolute difference between the actual grayscale value and this environmental prediction value, the formula yields the local grayscale profile deviation of the pixel. For a benign heterogeneous point produced by a normal welding process, such as a tiny protrusion on a weld bead, although its grayscale value may be higher than the surrounding area, it is still part of the smooth transition of the entire weld bead surface, so its grayscale value will be very close to the environmental prediction value, and the calculated local grayscale profile deviation value will be very small. However, for a malignant defect point, such as a tiny black pore, it is a break in the physical structure on the originally continuous weld surface. Its extremely low grayscale value differs from the higher theoretical value predicted by the surrounding bright and normal weld area, which will result in a large local grayscale profile deviation value.
[0028] Thus, the process of obtaining the local grayscale profile deviation by trend prediction and comparison of local grayscale profiles of pixels is completed.
[0029] Step S3: Obtain the disorder of the local gradient structure by performing unit vector aggregation analysis on the gradient directions of the neighborhood of the pixel.
[0030] The local grayscale profile deviation constructed in step S2 effectively identifies pixels whose grayscale values deviate significantly from the local profile trend. However, the local grayscale profile deviation has a deeper problem in solving this problem: it cannot effectively distinguish between ordered and disordered grayscale abrupt changes. In actual weld images, some structures formed by normal processes, such as clear boundaries between weld waves, will also have pixels with high profile deviation values due to drastic grayscale changes. This is similar to the profile deviation values of disordered abnormal points caused by defects (such as porosity and slag inclusions). However, these two types of points are fundamentally different in physical structure: the local structure of the former (such as the edge of a weld wave) is regular and directional; while the local structure of the latter (such as porosity) is chaotic. Therefore, to completely solve the problem of distinguishing between benign and malignant heterogeneous points, a second judgment criterion must be introduced to quantify the degree of disorder in the microstructure within the neighborhood of a pixel. Because the gradient field of an image in a structurally ordered region is regular, with its gradient vectors having consistent or smoothly transitioning directions; conversely, a structurally disordered defective region will disrupt its surrounding gradient field, causing the gradient vectors to become chaotic. This step aims to design an index that can accurately measure the consistency of this local gradient field orientation distribution.
[0031] In summary, this invention first performs gradient calculation on the grayscale data of the weld image to obtain a pixel gradient vector dataset, and then performs direction normalization on the gradient vector dataset to obtain the pixel unit direction vector data. Specifically, for any target pixel in the basic grayscale feature dataset, the horizontal gradient component and vertical gradient component of the target pixel are obtained by calculating the grayscale change rate of the target pixel in the horizontal and vertical directions, respectively. The horizontal gradient component and vertical gradient component of the target pixel are combined to obtain the gradient vector of the target pixel, and the magnitude of the gradient vector of the target pixel is calculated. The gradient vector of the target pixel is divided by the magnitude of the gradient vector to obtain the unit direction vector of the target pixel. When the magnitude of the gradient vector is zero, the range direction vector of the target pixel is defined as the zero vector.
[0032] After obtaining the unit direction vector data of the pixel, the local gradient structure disorder is obtained by aggregating and summing the neighboring unit direction vector data. Specifically, a square neighborhood radius is set. In this embodiment, the square neighborhood radius is set to 5. The square neighborhood radius value can be adjusted according to the actual scenario and is not required. For any target pixel in the pixel basic grayscale feature dataset, the unit direction vector data of all pixels within the neighborhood range are extracted based on the target pixel as the center and the square neighborhood radius. The unit direction vectors of all pixels within the neighborhood range are vector summed, and the magnitude of the vector summation result is calculated. The magnitude is normalized with the number of pixels in the neighborhood to obtain the neighborhood gradient direction consistency ratio. The result of subtracting the neighborhood gradient direction consistency ratio from the constant 1 is taken as the local gradient structure disorder of the target pixel.
[0033] In one implementation, assume the first The unit direction vector of each pixel is ;No. The set of square neighboring pixels of a pixel is The neighborhood radius of a square neighborhood is Then the first The expression for calculating the disorder of the local gradient structure of a pixel is:
[0034] in, Indicates the first The disorder of the local gradient structure of each pixel; Indicates the first Unit direction vector of each pixel; Indicates the first A set of square neighborhood pixels of 1 pixel; This represents the neighborhood radius of the square neighborhood.
[0035] It should be noted that the formula calculates the unit gradient vector of all pixels within the square neighborhood of the target pixel. The focus of the analysis shifts from the magnitude of the gradient to its direction. In weld images, the gradient direction directly reflects the direction of the most dramatic grayscale change, which is closely related to the microscopic geometric orientation of the weld surface. By normalizing the gradient vector, the influence of gradient magnitude changes caused by uneven illumination or contrast differences is eliminated, allowing the factor to focus more purely on the orderliness of the structure itself. Secondly, the core part of the formula lies in the vector summation of all unit gradient vectors in the neighborhood. If the structure of a region is highly ordered, such as on a regular, straight weld edge, then the gradient directions of all pixels in its neighborhood will be basically consistent, all perpendicular to the edge line. At this time, all unit vectors are almost in the same direction, and the magnitude of their vector sum will approach the sum of the magnitudes of all unit vectors, that is, the total number of pixels in the neighborhood. Finally, the formula is obtained by... This ratio normalizes the magnitude of the vector sum to the range of 0 to 1. This ratio quantifies the overall consistency of the gradient directions; the closer the value is to 1, the more consistent the directions. Based on this, through... The calculation yielded a local gradient structure disorder assessment. This design makes the local gradient structure disorder assessment value positively correlated with the structure's disorder degree. For the aforementioned ordered anomaly points (such as weld bead edges), since the gradient directions are highly consistent, this ratio is close to 1, and the final calculated local gradient structure disorder assessment value will approach 0. However, for a disordered anomaly point (such as a pore), the gradient vectors in its neighborhood will point towards the pore center from all directions. These unit vectors with different directions will largely cancel each other out when the vector sum is performed, resulting in a magnitude of the vector sum that is much smaller than the value of the pore. Since this ratio is close to 0, the final calculated local gradient structure disorder evaluation value will approach 1. In this way, the local gradient structure disorder evaluation successfully provides a decisive basis for distinguishing the two types of high-value local grayscale profile divergence points that could not be distinguished in step S2, and accurately quantifies the orderliness of the local structure of the pixel.
[0036] This completes the process of obtaining the disorder of the local gradient structure by performing unit vector aggregation analysis on the gradient directions of the pixel's neighborhood.
[0037] Step S4: Obtain the distance metric function for structure perception by multiplicatively modulating the local grayscale profile deviation degree and the local gradient structure disorder degree.
[0038] Steps S2 and S3 have calculated two key optimization factors for each pixel in the image. Now, these two factors need to be effectively integrated into the traditional Euclidean distance metric function so that when calculating the distance between two pixels, it comprehensively considers their spatial location, original grayscale differences, and newly constructed structural attribute differences. When two pixels exhibit significant differences in any structural attribute, the probability of them belonging to the same class (especially the defect class) is extremely low; therefore, their calculated distance should be significantly amplified. Conversely, when two pixels are highly similar in structural attributes, their original distance is not penalized by amplification, thus maintaining their relative closeness. Through this differentiated distance modulation, the distance between malignant defect points and all benign points in the feature space can be effectively increased, thereby enhancing their separability in subsequent clustering.
[0039] In summary, after obtaining the local grayscale profile divergence and local gradient structure disorder of a pixel, this invention, for any two target pixels in the basic grayscale feature dataset, calculates the Euclidean distance based on the grayscale values and two-dimensional position coordinates of the two target pixels to obtain the original distance metric values of the two target pixels; calculates the difference in local grayscale profile divergence and the difference in local gradient structure disorder of the two target pixels respectively, and uses the calculation results of adding the absolute values of the two differences to a constant 1 as the modulation terms of the two types of structural attributes; and multiplies the original distance metric values by the modulation terms of the two types of structural attributes in sequence to obtain the structure-aware distance metric function values of the two target pixels.
[0040] Thus, the distance metric function for obtaining structure perception is completed by multiplicatively modulating the local gray-scale profile deviation degree and the local gradient structure disorder degree.
[0041] Step S5: Obtain weld defect identification results by performing cluster analysis on the distance metric function of structure perception.
[0042] In this embodiment, the DBSCAN algorithm, mentioned in the background section, is used to cluster pixels. First, two core parameters of the algorithm need to be set: the neighborhood radius and the minimum number of neighborhood samples constituting the core point. The minimum number of neighborhood samples can be set based on the minimum effective size of the defect to be detected. For example, to detect a tiny defect consisting of at least 10 pixels, the minimum number of neighborhood samples can be set to 10. The neighborhood radius parameter is selected based on the numerical characteristics of the distance metric in step S4. As analyzed earlier, the design of the structure-aware distance metric ensures that the calculated distance between pairs of neighboring pixels with the same physical origin (e.g., two neighboring points belonging to the same defect) is numerically much smaller than the calculated distance between pairs of pixels with different physical origins (e.g., a malignant defect point and a benign heterogeneous point). In the numerical simulation of this embodiment, the structure-aware distance metric values of neighboring defect points of the same type are typically in the tens, while the structure-aware distance metric values between dissimilar points are in the thousands. Therefore, the neighborhood radius parameter can be set as a threshold that can effectively define these two types of distances. In this embodiment, the neighborhood radius is set to 500.
[0043] After setting the neighborhood radius parameter and the minimum number of neighborhood samples parameter for the clustering algorithm, the structure-aware distance metric function is used as the distance calculation standard for the clustering algorithm. Density reachability analysis is performed on all pixels in the pixel basic grayscale feature dataset, and pixels that meet the density reachability condition are clustered together to form multiple pixel clusters.
[0044] After the clustering process is completed, post-processing analysis is performed on all pixel clusters output by the algorithm to complete the final defect determination. Through structure-aware distance measurement, truly malignant defect points have been specifically clustered in the feature space. Therefore, only a size filter based on the minimum defect size needs to be applied to all pixel clusters generated by the DBSCAN algorithm. Any cluster with fewer pixels than the preset minimum neighborhood sample number is considered to be caused by random noise and is not considered. For the remaining clusters after size filtering, the design of this invention ensures that only clusters composed of truly malignant defect points will form stably. This is because in step S4, the structure-aware distance measurement between all benign points (whether smooth points or ordered anomalous points) and malignant defect points is systematically amplified, causing them to fail to meet the density attainability condition of the DBSCAN algorithm and be grouped into the same core cluster. Therefore, any independent cluster remaining after size filtering can be directly determined as a defect region.
[0045] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A machine vision-based intelligent detection method for weld defects, characterized in that, The method includes: Step S1: Obtain the basic grayscale feature dataset of pixels by acquiring and preparing features from the weld area image; Step S2: Obtain the local grayscale profile divergence by performing trend prediction and comparison on the local grayscale profile of the pixel; Step S3: Obtain the disorder of the local gradient structure by performing unit vector aggregation analysis on the gradient directions of the pixel's neighborhood; Step S4: Obtain the distance metric function for structure perception by multiplicatively modulating the local gray-scale profile deviation degree and the local gradient structure disorder degree; Step S5: Obtain weld defect identification results by performing cluster analysis on the distance metric function of structure perception.
2. The intelligent detection method for weld defects based on machine vision according to claim 1, characterized in that, The process of acquiring and preparing basic grayscale feature datasets of pixels by collecting and preparing images of the weld area includes: The process involves vertically acquiring at least one high-resolution digital grayscale image of the weld area of the workpiece to be inspected using an industrial area array camera installed on the production line. A fixed light source is used for illumination during the vertical image acquisition process. After preprocessing the acquired grayscale image, basic grayscale feature data of each pixel is extracted from the image. The basic grayscale feature data includes the two-dimensional position coordinates of the pixel in the image and the corresponding grayscale value. The two-dimensional position coordinates and grayscale values of all pixels constitute the basic grayscale feature dataset of the pixels.
3. The intelligent detection method for weld defects based on machine vision according to claim 1, characterized in that, The step of obtaining the local grayscale profile divergence by trend prediction and comparison of local grayscale profiles of pixels includes: By performing hierarchical statistical processing on the grayscale data of the pixel neighborhood, the grayscale feature parameters of the inner and outer rings are obtained; by performing trend prediction and deviation calculation on the grayscale feature parameters, the local grayscale profile deviation factor is obtained.
4. The intelligent detection method for weld defects based on machine vision according to claim 3, characterized in that, The step involves performing hierarchical statistical processing on the grayscale data of the pixel's neighborhood to obtain the grayscale feature parameters of the inner and outer rings, including: For any target pixel in the basic grayscale feature dataset, define the inner ring neighborhood range and the outer ring neighborhood range, divide the neighborhood range of the target pixel according to the inner ring neighborhood range and the outer ring neighborhood range, and obtain the inner ring neighborhood and outer ring neighborhood of the target pixel. The average gray value of the pixels in the inner ring neighborhood of the target pixel is used as the inner ring gray value feature parameter of the target pixel; the average gray value of the pixels in the outer ring neighborhood of the target pixel is used as the outer ring gray value feature parameter of the target pixel.
5. The intelligent detection method for weld defects based on machine vision according to claim 3, characterized in that, The process of obtaining local grayscale profile deviation by performing trend prediction and deviation calculation on grayscale feature parameters includes: For any target pixel in the pixel base grayscale feature dataset, the calculation result of the inner ring grayscale feature parameter of the target pixel being twice the outer ring grayscale feature parameter of the target pixel is taken as the theoretical environment predicted grayscale value of the target pixel; the absolute value of the calculation result of subtracting the grayscale value of the target pixel from the theoretical environment predicted grayscale value of the target pixel is taken as the local grayscale profile deviation of the target pixel.
6. The intelligent detection method for weld defects based on machine vision according to claim 1, characterized in that, The method of obtaining the disorder of the local gradient structure by performing unit vector aggregation analysis on the gradient directions of the pixel's neighborhood includes: By performing gradient calculation on the grayscale data of the weld image, a pixel gradient vector dataset is obtained. Then, by normalizing the gradient vector dataset, the unit direction vector data of the pixels is obtained. Finally, by aggregating and summing the neighborhood unit direction vector data, the disorder of the local gradient structure is obtained.
7. The intelligent detection method for weld defects based on machine vision according to claim 6, characterized in that, The process involves performing gradient calculation on the grayscale data of the weld image to obtain a pixel gradient vector dataset, and then performing direction normalization on the gradient vector dataset to obtain unit direction vector data for each pixel, including: For any target pixel in the pixel basic grayscale feature dataset, the horizontal gradient component and vertical gradient component of the target pixel are obtained by calculating the grayscale change rate of the target pixel in the horizontal and vertical directions, respectively. The horizontal and vertical gradient components of the target pixel are combined to obtain the gradient vector of the target pixel, and the magnitude of the gradient vector of the target pixel is calculated. Divide the gradient vector of the target pixel by the magnitude of the gradient vector to obtain the unit direction vector of the target pixel. When the magnitude of the gradient vector is zero, the range direction vector of the target pixel is defined as the zero vector.
8. The intelligent detection method for weld defects based on machine vision according to claim 6, characterized in that, The step of obtaining the disorder of the local gradient structure by aggregating and summing the neighborhood unit direction vector data includes: Set a square neighborhood radius; for any target pixel in the basic grayscale feature dataset, extract the unit direction vector data of all pixels within the neighborhood based on the square neighborhood radius, with the target pixel as the center; perform vector summation on the unit direction vectors of all pixels within the neighborhood, calculate the magnitude of the vector summation result, and normalize the magnitude with the number of pixels in the neighborhood to obtain the neighborhood gradient direction consistency ratio; subtract the neighborhood gradient direction consistency ratio from the constant 1 as the local gradient structure disorder of the target pixel.
9. The intelligent detection method for weld defects based on machine vision according to claim 1, characterized in that, The method of obtaining a structure-aware distance metric function by multiplicatively modulating the local gray-scale profile divergence and the local gradient structure disorder includes: For any two target pixels in the pixel basic grayscale feature dataset, calculate the Euclidean distance based on the grayscale value and two-dimensional position coordinates of the two target pixels to obtain the original distance metric value of the two target pixels. The difference between the local grayscale profile divergence and the difference between the local gradient structure disorder of the two target pixels are calculated respectively. The absolute values of the two differences are added to a constant 1 respectively as the modulation terms of the two types of structural attributes. The original distance metric value is multiplied sequentially by the modulation terms of the two types of structural attributes to obtain the structure-aware distance metric function value of the two target pixels.
10. The intelligent detection method for weld defects based on machine vision according to claim 1, characterized in that, The method of obtaining weld defect identification results through cluster analysis of the distance metric function of structure perception includes: The neighborhood radius parameter and the minimum neighborhood sample number parameter of the clustering algorithm are set, and the structure-aware distance metric function is used as the distance calculation standard of the clustering algorithm. Density reachability analysis is performed on all pixels in the pixel basic grayscale feature dataset, and pixels that meet the density reachability condition are clustered to form multiple pixel clusters. The number of pixels in the clusters is filtered by size, and clusters with a number of pixels less than the minimum neighborhood sample number parameter are removed as noise clusters. The clusters retained after size filtering are output as weld defect regions to obtain the weld defect identification results.
Citation Information
Patent Citations
Steel die welding defect detection method and system based on machine vision
CN115100171A
Memory bank damage rapid detection method based on machine vision
CN116664559A
Construction engineering steel structure welding quality detection method
CN117635604A
Non-standard industrial product defect detection method based on image processing
CN118608525A
Road surface defect intelligent identification method and system based on machine vision
CN119205784A
Cited By
Titanium frame container welding seam quality detection method and system
CN121353279A
Titanium frame container weld quality detection method and system
CN121353279B
Surface oxidation detection method and system for overhead stranded wire
CN121540717A
Corn kernel crushing identification method based on multi-feature fusion
CN121564494A