Surface defect detection method and system for automobile parts

By using adaptive window size and gradient structure tensor matrix eigenvalue decomposition, combined with texture principal direction features and direction consistency features, the problem of texture interference in automotive parts inspection by traditional filtering algorithms is solved, and high-precision defect detection is achieved.

CN121767348APending Publication Date: 2026-03-31WUXI VGAGE MEASURING EQUIP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-25
Publication Date
2026-03-31

AI Technical Summary

Technical Problem

In the detection of surface defects in automotive parts, existing technologies and traditional filtering algorithms cannot adapt to the spatial heterogeneity of textures, resulting in the homogenization and annihilation of low-contrast defects such as weak scratches and shallow pits, or misjudgment as texture noise, leading to low detection accuracy.

Method used

An adaptive window size and gradient structure tensor matrix eigenvalue decomposition method is adopted, and combined with texture main direction features and direction consistency features, to calculate the comprehensive similarity weight. Defect detection is then performed using the Mask RCNN model.

Benefits of technology

It achieves precise suppression of highly directional process textures and complete preservation of real defects, improving the accuracy of detection results and reducing the false detection rate.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121767348A_ABST
    Figure CN121767348A_ABST
Patent Text Reader

Abstract

The invention relates to the field of image processing, in particular to a surface defect detection method and system for automobile parts, and the method comprises the steps: obtaining a preprocessed surface gray-scale map of the automobile parts; calculating the comprehensive similarity weight of the reference point and the target point based on the obtained texture direction difference, the obtained direction consistency difference and the obtained gray difference, calculating the filtering gray value of the target point based on the comprehensive similarity weight and the gray value of the target point, and traversing to obtain the filtering gray value of each pixel point of the surface gray-scale map; obtaining a texture suppression image, and training a preset defect detection model based on the texture suppression image to obtain a trained preset defect detection model; and inputting a to-be-detected texture suppression image into the trained preset defect detection model, and outputting a defect type. Through the technical scheme of the invention, the precision of a defect detection result can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing. In particular, it relates to a method and system for detecting surface defects in automotive parts. Background Technology

[0002] In modern automotive manufacturing, the surface quality of components directly affects the safety, reliability, and user experience of the entire vehicle. Key metal components such as engine blocks, transmission housings, and steering knuckles, as well as interior plastic parts like center consoles and door panels, commonly develop highly directional and regular surface textures such as brushed, frosted, or sandblasted finishes during precision machining. While these textures are normal manufacturing characteristics, they constitute complex structural background interference in machine vision inspection, with grayscale variations often comparable to, or even stronger than, actual defects.

[0003] Existing technical solutions generally employ traditional filtering algorithms with fixed parameters for background texture suppression. Their core flaw lies in their inability to adapt to the spatial heterogeneity of automotive component surface textures: in areas with uniform brushed textures, the fixed large window becomes overly smoothed due to a lack of local complexity awareness, resulting in the homogenization and annihilation of grayscale features of low-contrast defects such as subtle scratches and shallow pits; while in areas with brushed fractures, the fixed small window has limited suppression capability due to insufficient statistical samples, and residual strong texture interference is misjudged as defects, significantly increasing the false detection rate. More critically, such algorithms rely solely on grayscale differences to measure pixel similarity, ignoring the directional and structural features of the texture, leading to low accuracy in defect detection results. Summary of the Invention

[0004] To address the aforementioned technical problems, the present invention provides solutions in the following aspects.

[0005] In a first aspect, the present invention provides a method for detecting surface defects in automotive parts, comprising: acquiring a preprocessed grayscale image of the automotive parts; taking any pixel in the grayscale image as a target point to obtain a search window for the target point; constructing a neighborhood window centered on the target point and with a preset first length as the window size; calculating the gradient structure tensor matrix of the neighborhood window; performing eigenvalue decomposition on the gradient structure tensor matrix to obtain the texture main direction feature and direction consistency feature of the target point; taking any pixel in the search window as a reference point; calculating the texture direction difference between the reference point and the target point based on the texture main direction feature; calculating the direction consistency difference between the reference point and the target point based on the direction consistency feature; calculating the comprehensive similarity weight between the reference point and the target point based on the texture direction difference, the direction consistency difference, and the acquired grayscale difference; calculating the filtered grayscale value of the target point based on the comprehensive similarity weight and the grayscale value of the target point; traversing to obtain the filtered grayscale value of each pixel in the grayscale image to obtain a texture suppression image; training a preset defect detection model based on the texture suppression image to obtain a trained preset defect detection model; inputting the texture suppression image to be detected into the trained preset defect detection model, outputting the defect type, and completing the defect detection.

[0006] Preferably, the search window for obtaining the target point includes: constructing an initial evaluation window centered on the target point and with a preset second length as the window size; obtaining the gradient vector and gradient direction of any pixel in the initial evaluation window; calculating the magnitude of the gradient vector of any pixel, and using the standard deviation of the magnitudes of all pixels as the standard deviation of the gradient magnitude of the initial evaluation window; grouping pixels with consistent gradient directions in the initial window into a group, calculating the probability of any group of gradient directions appearing, and calculating the gradient direction entropy of the initial evaluation window based on the information entropy formula and the probability of any group of gradient directions appearing; calculating the first product of the standard deviation of the gradient magnitude and a preset first weighting coefficient; calculating the first difference between 1 and the preset first weighting coefficient, and calculating the second product of the first difference and the gradient direction entropy, and using the sum of the first product and the second product as the complexity score of the target point; obtaining the adaptive side length of the target point based on the complexity score, and constructing a search window for the target point centered on the target point and with the adaptive side length as the window size.

[0007] Preferably, obtaining the adaptive side length of the target point based on the complexity score includes: obtaining a preset maximum window side length and a preset minimum window side length, calculating a second difference between the preset maximum window side length and the preset minimum window side length; calculating a third difference between 1 and the complexity score, and calculating a third product of the second difference and the third difference, and using the sum of the preset minimum window side length and the third product as the adaptive side length of the target point.

[0008] Preferably, the texture direction difference includes: obtaining the texture main direction feature of the reference point by analogy with the calculation method of the texture main direction feature of the target point; calculating the first absolute difference between the texture main direction feature of the target point and the texture main direction feature of the reference point; calculating the fourth difference between the flat angle and the first absolute difference; selecting the minimum value between the first absolute difference and the fourth difference; and taking the ratio of the minimum value to the flat angle as the texture direction difference.

[0009] Preferably, the direction consistency difference includes: obtaining the direction consistency characteristics of the reference point by analogy with the calculation method of the direction consistency characteristics of the target point, and taking the absolute difference between the direction consistency characteristics of the target point and the direction consistency characteristics of the reference point as the direction consistency difference.

[0010] Preferably, obtaining the grayscale difference includes: obtaining the neighborhood window of the reference point by similarly constructing the neighborhood window of the target point, wherein the neighborhood window of the target point and the neighborhood window of the reference point have the same window size; for any position within the neighborhood window, calculating the square of the grayscale difference between the neighborhood window of the target point and the neighborhood window of the reference point at any position, and substituting the distance between any position and the center position of the neighborhood window into the Gaussian function to obtain the initial weight, calculating the fourth product of the initial weight at any position and the square of the grayscale difference, traversing to obtain the fourth product at each position in the neighborhood window, and using the sum of all fourth products as the grayscale difference between the target point and the reference point.

[0011] Preferably, the calculation of the comprehensive similarity weight between the reference point and the target point includes: calculating the first ratio of texture direction difference to preset texture filtering parameters, the second ratio of direction consistency difference to preset direction filtering parameters, and the third ratio of grayscale difference to preset grayscale filtering parameters; calculating the sum of the first ratio, the second ratio, and the third ratio, and using the negative exponent of the sum as the comprehensive similarity weight between the reference point and the target point.

[0012] Preferably, the calculation of the filtered grayscale value of the target point includes: traversing to obtain the comprehensive similarity weight between each pixel as a reference point and the target point; calculating the cumulative value of all comprehensive similarity weights; using the ratio of the comprehensive similarity weight between the reference point and the target point to the cumulative value as the normalized weight between the reference point and the target point; obtaining the initial grayscale value of the reference point based on the surface grayscale image; calculating the fifth product of the normalized weight and the initial grayscale value of the reference point; traversing to obtain the fifth product of each pixel in the search window; and using the cumulative value of all fifth products as the filtered grayscale value of the target point.

[0013] Preferably, the preset defect detection model is a Mask R-CNN model, which takes historical texture-suppressed images as input, uses the ground truth values ​​of defect categories, bounding box coordinates, and pixel-level segmentation masks of historical texture-suppressed images as labels, and uses the predicted values ​​of defect categories, bounding box coordinates, and pixel-level segmentation masks of historical texture-suppressed images as outputs to construct a training set; the loss function of the Mask R-CNN model is a multi-task loss function composed of classification loss, bounding box regression loss, and segmentation mask loss.

[0014] Secondly, the present invention also provides a surface defect detection system for automotive parts, comprising: a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the above-described surface defect detection method for automotive parts is implemented.

[0015] The present invention has the following effects: This invention elevates filtering decisions from surface grayscale similarity to a deeper level of local texture structure similarity, achieving precise suppression of highly directional process textures (such as brushed and matte finishes) on automotive parts while fully preserving true defects. It quantifies texture complexity using gradient amplitude standard deviation and directional entropy, dynamically allocating adaptive window sizes. In textured defect areas with disordered textures, the window shrinks to prevent defect pixels from being smoothed out by normal texture smoothing, while in background areas with uniform textures, the window expands to fully integrate periodic fluctuations and achieve background homogenization. Simultaneously, it integrates differences in the main texture direction and differences in directional consistency to construct a comprehensive similarity weight. This ensures that the filtering operation only produces a strong smoothing effect in normal areas with continuous texture direction and orderly structure, while exponentially attenuating the weight in areas with abrupt changes in texture direction or disordered structure caused by defects. This physically blocks the diffusion of background texture energy to defect areas. It effectively solves the problem of traditional methods easily smoothing or over-enhancing texture noise in low-contrast defects such as micro-scratches and brush breaks against strong texture backgrounds, improving the accuracy of surface defect detection results for automotive parts. Attached Figure Description

[0016] Figure 1 This is a flowchart of a surface defect detection method for automotive parts according to an embodiment of the present invention. Detailed Implementation

[0017] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.

[0018] The specific embodiments of the present invention will now be described in detail with reference to the accompanying drawings.

[0019] Reference Figure 1 A method for detecting surface defects in automotive parts includes steps S1-S4, as detailed below: S1: Obtain the preprocessed grayscale image of the automotive parts, take any pixel in the grayscale image as the target point, and obtain the search window for the target point.

[0020] In one embodiment, a high-resolution industrial area array camera, combined with uniform backlighting or a coaxial light source, is used to acquire RGB (Red, Green, Blue) images of the automotive component surface to ensure uniform image illumination. The surface RGB images are then converted to grayscale to obtain an initial surface grayscale image.

[0021] The initial surface grayscale image is preprocessed to obtain a surface grayscale image. The preprocessing includes: The initial surface grayscale image is uniformly scaled to a standard size of 1024×1024 pixels using a bilinear interpolation algorithm. This size achieves a balance between ensuring the resolution of defect details and computational efficiency, while eliminating scale differences caused by the offset of the part's placement on the conveyor belt or the fluctuation of the camera's shooting distance. This provides a scale consistency guarantee for subsequent texture analysis based on a fixed window size.

[0022] Based on prior geometric knowledge of components (such as contour templates exported from models, fixed position constraints of production line tooling fixtures, or contour fitting based on edge detection), the effective area containing the surface to be inspected is accurately extracted through template matching or mask segmentation technology. This effectively eliminates interference from non-detection targets such as conveyor belts, fixture reflections, and shadows, and avoids background noise from misleading the texture complexity assessment and filtering operations.

[0023] Linear normalization of the grayscale dynamic range is applied to the effective area, adjusting the grayscale value dynamic range to the standard range of 0 to 255. This eliminates the overall brightness drift caused by the uniformity of illumination within the same batch or the attenuation / replacement of the light source between different batches, ensuring that the texture contrast and the grayscale features of defects are comparable in the time dimension.

[0024] At this point, a preprocessed surface grayscale image can be obtained. Any pixel in the surface grayscale image is taken as the target point. An initial evaluation window is constructed with the target point as the center and a preset second length as the window size. The gradient vector and gradient direction of any pixel in the initial evaluation window are obtained.

[0025] The magnitude of the gradient vector at any pixel is calculated, and the standard deviation of the magnitudes of all pixels is used as the standard deviation of the gradient magnitude in the initial evaluation window. The standard deviation of the gradient magnitude is a statistical measure of the drastic change in grayscale within a local area. Its calculation process is as follows: First, the gradient vector of each pixel is obtained using first-order differential operators such as the Sobel operator. The magnitude of the gradient vector reflects the instantaneous rate of change of grayscale at that point in space. Then, within the initial evaluation window centered on the target pixel (for example, the window size is set to 5x5), the dispersion of the gradient magnitudes of all pixels is statistically analyzed and quantified in the form of standard deviation. The core significance of the standard deviation of the gradient magnitude lies in its focus not only on the intensity of grayscale changes but also on the non-uniformity of these changes. A high standard deviation indicates the simultaneous presence of pixels with strong gradients (such as edges or defect boundaries) and weak gradients (such as smooth areas) within the window, resulting in high-frequency abrupt changes. Conversely, a low standard deviation indicates a uniform distribution of gradient magnitudes within the region, often representing a smooth, regular texture.

[0026] Pixels with consistent gradient directions in the initial window are grouped together. The probability of any gradient direction appearing in any group is calculated. The gradient direction entropy of the initial evaluation window is then calculated based on the information entropy formula and the probability of any gradient direction appearing in any group. Gradient direction entropy is a statistical indicator that quantifies the degree of disorder in the distribution of gradient directions within a local region from an information theory perspective. The core significance of gradient direction entropy lies in capturing the directional regularity of texture: when the gradient direction entropy approaches 0, it indicates that the gradient directions of most pixels in the initial evaluation window are highly concentrated in a single interval; when the gradient direction entropy increases significantly, it reflects that the directional distribution tends to be uniform or exhibits a multi-peak distribution.

[0027] It's important to explain that gradient directional entropy and gradient magnitude standard deviation are crucially complementary: gradient directional entropy focuses on whether the direction is ordered, while gradient magnitude standard deviation focuses on whether the change is drastic. For example, a uniformly brushed area may have a high gradient magnitude (due to alternating light and dark textures) but low directional entropy (consistent direction), while a fine scratch may have a gradual change in gradient magnitude but a sudden increase in directional entropy (abrupt direction). The joint decision-making of these two factors can effectively distinguish between regions with strong texture but regularity and regions with weak texture but disorder, providing a dual criterion for adaptive window size allocation that combines grayscale intensity and structural regularity, avoiding misjudgments caused by a single indicator.

[0028] Calculate the first product of the standard deviation of the gradient magnitude and a preset first weighting coefficient; calculate the first difference between 1 and the preset first weighting coefficient, and calculate the second product of the first difference and the gradient direction entropy. The sum of the first and second products is used as the complexity score of the target point. It should be explained that the standard deviation of the gradient magnitude and the gradient direction entropy used to calculate the complexity score are both normalized using the maximum and minimum values.

[0029] It should be explained that the preset first weighting coefficient is used to quantitatively adjust the relative contribution weights of the gradient magnitude standard deviation (reflecting the drasticness of gray-level changes) and gradient direction entropy (reflecting the degree of directional disorder) in the comprehensive complexity score. The value of the preset first weighting coefficient directly determines the algorithm's sensitivity preference for two types of texture features: intensity abrupt changes and directional disorder. When the preset first weighting coefficient approaches 1, the decision mechanism is highly dependent on the discreteness of gray-level changes, which is suitable for scenarios where defects are mainly manifested as gray-level jumps but directional continuity (such as the contrast between light-colored pits on a dark background). When the preset first weighting coefficient approaches 0, the algorithm focuses on capturing the irregularity of the directional field, which is more suitable for detecting defects that cause abrupt changes in texture direction but have gradual gray-level changes (such as vertical cross scratches and wire breaks).

[0030] For example, in this embodiment, the preset first weighting coefficient is set to 0.5, which means that the two types of indicators are given equal weights, forming a balanced comprehensive evaluation strategy. It is worth noting that the preset first weighting coefficient is not fixed. In engineering practice, it should be optimized in a targeted manner according to the prior knowledge of the texture of the parts to be inspected. For example, for brushed surfaces with strong directionality, the preset first weighting coefficient can be appropriately reduced to 0.3 to 0.4 to enhance the discrimination power of directional features.

[0031] Obtain the preset maximum window side length and the preset minimum window side length, calculate the second difference between the preset maximum window side length and the preset minimum window side length; calculate the third difference between 1 and the complexity score, and calculate the third product of the second difference and the third difference. Use the sum of the preset minimum window side length and the third product as the adaptive side length of the target point.

[0032] It should be explained that in areas with high texture complexity (such as areas with broken textures), the complexity score approaches 1, and the adaptive window size shrinks to near the preset minimum window size; for example, this embodiment uses 15 pixels. The physical significance of the small window is to limit the spatial range of the filtering operation, thereby effectively avoiding the risk of smoothing normal texture pixels with defective pixels. Conversely, in uniform areas with low texture complexity (such as areas with regular, uniform textures), the complexity score approaches 0, and the adaptive window size expands to near the preset maximum window size; for example, this embodiment uses 51 pixels. The large window enhances the smoothing ability for periodic texture fluctuations by increasing the statistical sample size: in normal texture areas with consistent direction and regular grayscale changes, a large number of pixels within the large window have highly similar texture features, and after weighted averaging, the micro-texture contrast can be significantly reduced, achieving background homogenization.

[0033] S2: Construct a neighborhood window centered on the target point and with a preset first length as the window size. Calculate the gradient structure tensor matrix of the neighborhood window. Perform eigenvalue decomposition on the gradient structure tensor matrix to obtain the main texture direction features and direction consistency features of the target point.

[0034] In one embodiment, a neighborhood window is constructed with the target point as the center and a preset first length as the window size. For example, the preset first length is 7 in this embodiment. Within the neighborhood window, the gradient vector of each pixel is first calculated based on first-order differential operators such as the Sobel operator, and then a gradient structure tensor matrix is ​​constructed to suppress noise and enhance the robustness of direction estimation.

[0035] Eigenvalue decomposition of the gradient structure tensor matrix yields the principal direction feature and the orientation consistency feature. The principal direction feature physically represents the direction where local texture energy is most concentrated. For directional textures such as brushed or frosted textures, the principal direction feature exhibits a smooth and continuous change in normal areas, while abrupt changes occur at defects such as scratches and breaks. The orientation consistency feature quantifies the degree of order in the local orientation field through the relative differences in eigenvalues.

[0036] S3: Using any pixel in the search window as a reference point, calculate the texture direction difference between the reference point and the target point based on the main texture direction feature, calculate the direction consistency difference between the reference point and the target point based on the direction consistency feature, calculate the comprehensive similarity weight between the reference point and the target point based on the texture direction difference, direction consistency difference, and the obtained grayscale difference, calculate the filtered grayscale value of the target point based on the comprehensive similarity weight and the grayscale value of the target point, traverse to obtain the filtered grayscale value of each pixel in the surface grayscale image, obtain the texture suppression image, and train the preset defect detection model based on the texture suppression image to obtain the trained preset defect detection model.

[0037] In one embodiment, any pixel in the search window is used as a reference point, where there may be cases where the reference point and the target point are the same. The texture direction difference between the reference point and the target point is calculated based on the main texture direction feature, and the direction consistency difference between the reference point and the target point is calculated based on the direction consistency feature.

[0038] The calculation process for texture direction difference is as follows: the texture direction feature of the reference point is obtained by analogy with the calculation method of the texture direction feature of the target point; the first absolute difference between the texture direction feature of the target point and the texture direction feature of the reference point is calculated; the fourth difference between the flat angle and the first absolute difference is calculated; the minimum value between the first absolute difference and the fourth difference is selected; the ratio of the minimum value to the flat angle is taken as the texture direction difference.

[0039] It needs to be explained that the physical meaning of the difference in texture direction lies in capturing the spatial continuity of the texture field: in the texture areas of normal brushed, frosted and other processes, the texture direction of adjacent pixels shows a smooth gradient, and the difference in texture direction is close to 0, indicating that the texture direction is highly consistent; however, when there are defects such as scratches, brush breaks or pits, the edge of the defect will destroy the regularity of the original texture, causing a sudden change in the local texture direction field. For example, when a vertical scratch is orthogonal to a horizontal brushed texture, the direction at the brush break is discontinuous, which significantly increases the difference in direction.

[0040] This characteristic makes texture direction difference a discriminative feature for distinguishing between "normal texture undulations" and "real defects". Introducing texture direction difference can more accurately identify pixel pairs with similar gray levels but abrupt changes in direction (defects) and different gray levels but continuous directions (normal textures). It is highly sensitive to texture direction difference when calculating filter weights, ensuring that smoothing operation only occurs in normal background areas with highly consistent texture directions, while texture direction disorder caused by defects is completely preserved due to the sharp decay of weights.

[0041] The calculation process for the directional consistency difference is as follows: the directional consistency characteristics of the reference point are obtained by analogy with the calculation method of the directional consistency characteristics of the target point, and the absolute difference between the directional consistency characteristics of the target point and the directional consistency characteristics of the reference point is taken as the directional consistency difference.

[0042] It should be explained that the difference in directional consistency, by quantifying the degree of deviation in the texture order of the neighborhood windows where the target point and the reference point are located, provides a key criterion for the filtering algorithm to perceive the stability of the texture structure. In a uniform normal texture area (such as a regularly brushed surface), the target point and the reference point have similar high directional consistency feature values ​​due to the high consistency of the texture direction, and their difference is close to zero, indicating that the texture structure in this area is stable and reliable, and suitable for strong smoothing to suppress background undulations; however, at the defect boundary, the normal texture area and the defect disturbance area form a sharp contrast, resulting in a significant increase in the difference in directional consistency.

[0043] The calculation process for grayscale difference is as follows: the neighborhood window of the reference point is obtained in the same way as the construction method of the neighborhood window of the target point. The neighborhood window of the target point and the neighborhood window of the reference point have the same window size.

[0044] For any position within the neighborhood window, calculate the square of the grayscale difference between the neighborhood window of the target point and the neighborhood window of the reference point at any position. Substitute the distance between any position and the center position of the neighborhood window into the Gaussian function to obtain the initial weight. Calculate the fourth product of the initial weight at any position and the square of the grayscale difference. Iterate through each position in the neighborhood window to obtain the fourth product. The sum of all fourth products is taken as the grayscale difference between the target point and the reference point.

[0045] It needs to be explained that the grayscale difference is compared through the Gaussian weighted neighborhood window structure. The core physical meaning is that the Gaussian weights are distributed with an exponential decay around the center pixel. This not only strengthens the dominant role of the core area of ​​the neighborhood window in similarity judgment, but also naturally suppresses the interference of edge noise and small texture perturbations. It can robustly identify normal areas with the same texture direction but with small translations or lighting gradients, thus achieving strong smoothing suppression in backgrounds with regular brushed or frosted textures.

[0046] In step S2, the directional consistency feature obtained through eigenvalue decomposition has a value range between 0 and 1. Furthermore, in step S3, the ratio of the minimum value to the flat angle is used as the texture direction difference, ensuring that the texture direction difference value also falls within the range of 0 to 1. The grayscale difference of each pixel in the surface grayscale image is obtained by traversing the image, and the grayscale difference is normalized using maximum and minimum value normalization, ensuring that the grayscale difference value also falls within the range of 0 to 1.

[0047] Calculate the first ratio of texture direction difference to preset texture filtering parameters, the second ratio of direction consistency difference to preset direction filtering parameters, and the third ratio of grayscale difference to preset grayscale filtering parameters respectively; calculate the sum of the first ratio, the second ratio, and the third ratio, and use the negative exponent of the sum as the comprehensive similarity weight between the reference point and the target point.

[0048] It should be explained that the comprehensive similarity weighting integrates three dimensions: grayscale difference, texture direction difference, and direction consistency difference. This elevates the filtering algorithm decision-making in existing technologies from a shallow discrimination based on similar grayscale values ​​(smoothing only) to a deeper level based on similar local texture structures (smoothing only). The core physical significance lies in its ability to accurately identify the inherent regularity of textures rather than surface grayscale fluctuations. By setting relatively small preset texture filtering and preset direction filtering parameters, it is highly sensitive to minute differences in texture features, ensuring that high weights are applied only to normal background areas with continuous texture direction and orderly structure (such as regular string patterns). In areas where defects cause abrupt changes in texture direction or structural disorder (such as scratches crossing string patterns), even a slight increase in texture direction difference or direction consistency difference leads to an exponential decrease in weights. This causes defective pixels to rely primarily on their own weight and a few similar abnormal pixels for weighted averaging, thus completely preserving the original features of low-contrast defects such as micro-scratches. For example, the preset grayscale filtering parameter is 0.3, the preset texture filtering parameter is 0.2, and the preset direction filtering parameter is 0.1. Specific values ​​can be set by those skilled in the art based on experience.

[0049] The algorithm iterates through each pixel to obtain its comprehensive similarity weight with the target point when used as a reference point. It calculates the cumulative value of all comprehensive similarity weights and uses the ratio of the comprehensive similarity weight between the reference and target points to the cumulative value as the normalized weight between the reference and target points. Based on the surface grayscale image, it obtains the initial grayscale value of the reference point. It calculates the fifth product of the normalized weight and the initial grayscale value of the reference point. It iterates through each pixel in the search window to obtain the fifth product, and uses the cumulative value of all fifth products as the filtered grayscale value of the target point. When the target and reference points are the same pixel, the normalized weight between the target and reference points is one-tenth of the cumulative value. In this case, the fifth product is the product of one-tenth of the cumulative value and the grayscale value of the target point.

[0050] It needs to be explained that the filtered grayscale value is essentially an intelligent reconstruction result based on the similarity of local texture structure: in normal texture areas (such as regularly brushed surfaces), the pixels around the target point share a consistent texture direction and a highly ordered orientation field, and obtain a significant normalized contribution coefficient through comprehensive similarity weights; the weighted averaging process is essentially a fusion of information for pixel groups with the same texture pattern, averaging the periodic alternation of light and dark micro-undulations into uniform grayscale, thereby effectively reducing the contrast of background texture.

[0051] By traversing the surface grayscale image pixel by pixel, the filtered grayscale value of each pixel is obtained. The filtered grayscale value is then used as the new grayscale value of any pixel to obtain a new grayscale image, which is the texture-suppressed image.

[0052] A pre-trained defect detection model is obtained by training a pre-trained defect detection model based on texture-suppressed images. The pre-trained defect detection model is a Mask R-CNN (Mask Region-based Convolutional Neural Network) model. It takes historical texture-suppressed images as input, uses the ground truth values ​​of defect categories, bounding box coordinates, and pixel-level segmentation masks of historical texture-suppressed images as labels, and uses the predicted values ​​of defect categories, bounding box coordinates, and pixel-level segmentation masks of historical texture-suppressed images as outputs to construct a training set. The loss function of the Mask R-CNN model is a multi-task loss function composed of classification loss, bounding box regression loss, and segmentation mask loss.

[0053] For example, the Mask RCNN model uses the Adam (Adaptive Moment Estimation) optimizer with an initial learning rate of 0.001. The learning rate is reduced to one-tenth of the original rate every 50 iterations, for a total of 200 iterations. The network parameters are optimized using the gradient descent algorithm until the model converges on the validation set, thus completing the training of the preset defect detection model.

[0054] S4: Input the texture-suppressed image to be detected into the pre-trained pre-defined defect detection model, and output the defect category, bounding box coordinates, and pixel-level segmentation mask to complete the defect detection.

[0055] The system includes a processor and a memory, the memory storing computer program instructions, which, when executed by the processor, implement a surface defect detection method for automotive parts according to the first aspect of the present invention.

[0056] The system also includes other components well known to those skilled in the art, such as communication buses and communication interfaces, the settings and functions of which are known in the art and will not be described in detail here.

[0057] It should be noted that those skilled in the art can make various modifications and improvements without departing from the inventive concept, and these all fall within the scope of protection of this invention. Therefore, the scope of protection of this patent should be determined by the appended claims.

Claims

1. A surface defect detection method for an automobile component, characterized by, The method comprises the following steps: acquire a surface gray image of pretreated automobile parts, take any pixel point in the surface gray image as a target point, and obtain a search window of the target point; construct a neighborhood window with the target point as the center and a preset first length as the window size, calculate a gradient structure tensor matrix of the neighborhood window, perform eigenvalue decomposition on the gradient structure tensor matrix to obtain a texture main direction feature and a direction consistency feature of the target point; take any pixel point in the search window as a reference point, calculate a texture direction difference between the reference point and the target point based on the texture main direction feature, calculate a direction consistency difference between the reference point and the target point based on the direction consistency feature, calculate a comprehensive similarity weight between the reference point and the target point based on the texture direction difference, the direction consistency difference and the acquired gray difference, calculate a filtered gray value of the target point based on the comprehensive similarity weight and the gray value of the reference point, traverse to obtain a filtered gray value of each pixel point in the surface gray image, obtain a texture suppression image, train a preset defect detection model based on the texture suppression image to obtain a trained preset defect detection model; input the texture suppression image to be detected into the trained preset defect detection model, output a defect category, a bounding box coordinate and a pixel-level segmentation mask, and complete defect detection.

2. The method for surface defect detection of an automobile component according to claim 1, wherein The method comprises the following steps: construct an initial evaluation window with the target point as the center and a preset second length as the window size, obtain a gradient vector and a gradient direction of any pixel point in the initial evaluation window; calculate the module length of the gradient vector of any pixel point, and take the standard deviation of the module lengths of all pixel points as the gradient amplitude standard deviation of the initial evaluation window; group the pixel points with consistent gradient directions in the initial window, count the probability of occurrence of the gradient direction of any group, calculate the gradient direction entropy of the initial evaluation window according to the information entropy formula and the probability of occurrence of the gradient direction of any group; calculate the first product of the gradient amplitude standard deviation and a preset first weighting coefficient, calculate the first difference between 1 and the preset first weighting coefficient, and calculate the second product of the first difference and the gradient direction entropy, and take the sum of the first product and the second product as the complexity score of the target point; obtain the adaptive side length of the target point based on the complexity score, and construct the search window of the target point with the target point as the center and the adaptive side length as the window size.

3. The method for surface defect detection of an automobile component according to claim 2, wherein The method comprises the following steps: obtain a preset maximum window side length and a preset minimum window side length, and calculate the second difference between the preset maximum window side length and the preset minimum window side length; calculate the third difference between 1 and the complexity score, and calculate the third product of the second difference and the third difference, and take the sum of the preset minimum window side length and the third product as the adaptive side length of the target point.

4. The method for surface defect detection of an automobile component according to claim 1, wherein The texture direction difference comprises the following steps: obtain the texture main direction feature of the reference point according to the calculation method of the texture main direction feature of the target point, calculate the first absolute difference between the texture main direction feature of the target point and the texture main direction feature of the reference point, and calculate the fourth difference between the flat angle and the first absolute difference, and select the minimum value between the first absolute difference and the fourth difference; take the ratio of the minimum value and the flat angle as the texture direction difference.

5. The method for surface defect detection of automotive parts as claimed in claim 1 wherein, The direction consistency difference comprises the following steps: The direction consistency feature of the target point is obtained according to the same method, and the absolute difference between the direction consistency feature of the target point and the direction consistency feature of the reference point is taken as the direction consistency difference.

6. The method for surface defect detection of an automobile component according to claim 1, wherein The gray difference includes: The neighborhood window of the target point is obtained according to the same method, and the neighborhood window of the target point and the neighborhood window of the reference point have the same window size; For any position in the neighborhood window, the square of the gray difference value of any position in the neighborhood window of the target point and the neighborhood window of the reference point is calculated, the distance between any position and the center position of the neighborhood window is substituted into the Gaussian function to obtain the initial weight, the fourth product of the initial weight and the square of the gray difference value of any position is calculated, and the fourth product of each position in the neighborhood window is obtained by traversal, and the sum of all fourth products is taken as the gray difference between the target point and the reference point.

7. The method for surface defect detection of an automobile component according to claim 1, wherein The calculation of the comprehensive similarity weight of the reference point and the target point includes: The first ratio of the texture direction difference and the preset texture filtering parameter, the second ratio of the direction consistency difference and the preset direction filtering parameter, and the third ratio of the gray difference and the preset gray filtering parameter are calculated respectively. The sum value of the first ratio, the second ratio and the third ratio is calculated, and the negative exponential value of the sum value is taken as the comprehensive similarity weight of the reference point and the target point.

8. The method for surface defect detection of an automobile component according to claim 1, wherein The calculation of the filtered gray value of the target point includes: The comprehensive similarity weight of each pixel point as the reference point and the target point is obtained by traversal, the accumulation value of all comprehensive similarity weights is calculated, the ratio of the comprehensive similarity weight of the reference point and the target point to the accumulation value is taken as the normalized weight of the reference point and the target point. The initial gray value of the reference point is obtained based on the surface gray image, the fifth product of the normalized weight and the initial gray value of the reference point is calculated, the fifth product of each pixel point in the search window is obtained by traversal, and the accumulation value of all fifth products is taken as the filtered gray value of the target point.

9. The method for surface defect detection of an automobile component according to claim 1, wherein The preset defect detection model is a Mask RCNN model, a set of training sets is constructed by taking the historical texture suppressed image as input, taking the true value of the defect category, the true value of the bounding box coordinate and the true value of the pixel-level segmentation mask of the historical texture suppressed image as label, and taking the predicted value of the defect category, the predicted value of the bounding box coordinate and the predicted value of the pixel-level segmentation mask of the historical texture suppressed image as output. The loss function of the Mask RCNN model is a multi-task loss function composed of a classification loss, a bounding box regression loss and a segmentation mask loss.

10. A surface defect detection system for automotive parts, characterized by, It includes: A processor and a memory, the memory stores computer program instructions, when the computer program instructions are executed by the processor, a surface defect detection method for automobile parts according to any one of claims 1-9 is realized.