A surface defect detection method and system for automobile parts
Patent Information
- Application Number
- CN202610222987.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-25
- Publication Date
- 2026-09-18
- Estimated Expiration
- 2046-02-25
AI Technical Summary
[0003]现有技术方案普遍采用固定参数的传统滤波算法进行背景纹理抑制,其核心缺陷在于无法适应汽车零部件表面纹理的空间异质性:在拉丝均匀纹理区域,固定大窗口因缺乏局部复杂度感知而过度平滑,导致微弱划痕、浅凹坑等低对比度缺陷的灰度特征被均质化湮灭;而在拉丝断裂区域,固定小窗口因统计样本不足而抑制能力有限,残留的强纹理干扰被误判为缺陷,显著推高误检率
本发明通过将滤波决策从表层灰度相似性提升至局部纹理结构相似性的深层判别,实现了对汽车零部件表面强方向性工艺纹理(如拉丝、磨砂)的精准抑制与真实缺陷的完整保留,利用梯度幅值标准差与方向熵量化纹理复杂度,动态分配自适应窗口尺寸,在纹理紊乱的缺陷区域收缩窗口以规避缺陷像素被正常纹理平滑淹没,在纹理均匀的背景区域扩张窗口以充分融合周期性起伏实现背景均质化;同时融合纹理主方向差异与方向一致性差异构建综合相似度权重,使滤波操作仅在纹理走向连续且结构有序的正常区域产生强平滑效应,而对缺陷引起的纹理方向突变或结构紊乱区域实施权重指数级衰减,从而在物理层面阻断了背景纹理能量向缺陷区域的扩散。有效解决了传统方法在强纹理背景下易将微划痕、拉丝断裂等低对比度缺陷误平滑或过度增强纹理噪声的问题,提高汽车零部件的表面缺陷检测结果的精度。
Smart Images

Figure CN121767348B_ABST
Abstract
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 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 method for detecting surface defects in automotive parts, characterized in that, include: 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; A neighborhood window is constructed with the target point as the center and a preset first length as the window size. The gradient structure tensor matrix of the neighborhood window is calculated. The gradient structure tensor matrix is decomposed by eigenvalue to obtain the texture main direction feature and direction consistency feature of the target point. Using any pixel in the search window as a reference point, the texture direction difference between the reference point and the target point is calculated based on the main texture direction feature. The direction consistency difference between the reference point and the target point is calculated based on the direction consistency feature. The comprehensive similarity weight between the reference point and the target point is calculated based on the texture direction difference, the direction consistency difference, and the obtained grayscale difference. The filtered grayscale value of the target point is calculated based on the comprehensive similarity weight and the grayscale value of the reference point. The filtered grayscale value of each pixel in the surface grayscale image is obtained by traversing the image to obtain the texture suppression image. The preset defect detection model is trained based on the texture suppression image to obtain the trained preset defect detection model. The texture-suppressed image to be detected is input into a pre-trained defect detection model, which outputs the defect category, bounding box coordinates, and pixel-level segmentation mask to complete the defect detection.
2. The method for surface defect detection of automotive parts according to claim 1, characterized in that, The search window for obtaining the target point includes: 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. Calculate the magnitude of the gradient vector at any pixel, and use the standard deviation of the magnitudes of all pixels as the standard deviation of the gradient magnitude in the initial evaluation window; 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 calculated based on the information entropy formula and the probability of any gradient direction appearing in any group. Calculate the first product of the standard deviation of the gradient magnitude and the 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. Use the sum of the first product and the second product as the complexity score of the target point. The adaptive side length of the target point is obtained based on the complexity score, and a search window for the target point is constructed with the target point as the center and the adaptive side length as the window size.
3. The method for surface defect detection of automotive parts according to claim 2, characterized in that, The adaptive side length of the target point obtained based on complexity scoring includes: Get the preset maximum window side length and the 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 and third differences. Use 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 automotive parts according to claim 1, characterized in that, The texture direction differences include: Similarly, the main texture direction feature of the reference point is obtained by calculating the main texture direction feature of the target point. The first absolute difference between the main texture direction feature of the target point and the main texture direction feature of the reference point is calculated, and 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 used as the texture direction difference.
5. A method for detecting surface defects in automotive parts according to claim 1, characterized in that, The differences in directional consistency include: Similarly, the direction consistency characteristics of the reference point are obtained by calculating the direction consistency characteristics of the target point. The absolute difference between the direction consistency characteristics of the target point and the direction consistency characteristics of the reference point is taken as the direction consistency difference.
6. The method for surface defect detection of automotive parts according to claim 1, characterized in that, Obtaining the grayscale difference includes: Similarly, the neighborhood window of the reference point is obtained using the same method as 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. 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.
7. The method for surface defect detection of automotive parts according to claim 1, characterized in that, The calculation of the comprehensive similarity weight between the reference point and the target point includes: 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.
8. A method for detecting surface defects in automotive parts according to claim 1, characterized in that, The filtered grayscale value of the target point is calculated as follows: Iterate through each pixel to obtain the comprehensive similarity weight between the reference point and the target point. Calculate the cumulative value of all comprehensive similarity weights. Use 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. The initial grayscale value of the reference point is obtained based on the surface grayscale image. The fifth product of the normalized weight and the initial grayscale value of the reference point is calculated. The fifth product of each pixel in the search window is obtained by traversing the search window. The accumulated value of all fifth products is used as the filtered grayscale value of the target point.
9. A method for detecting surface defects in automotive parts according to claim 1, characterized in that, The preset defect detection model is a Mask RCNN model, which takes historical texture-suppressed images as input, the true values of defect categories, bounding box coordinates, and pixel-level segmentation masks of historical texture-suppressed images as labels, and 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 RCNN model is a multi-task loss function composed of classification loss, bounding box regression loss, and segmentation mask loss.
10. A surface defect detection system for automotive parts, characterized in that, include: A processor and a memory, the memory storing computer program instructions that, when executed by the processor, implement a surface defect detection method for automotive parts according to any one of claims 1-9.
Citation Information
Patent Citations
Quality detection method for constructional engineering concrete prefabricated part
CN119205763A
Textile cloth cover defect intelligent detection method based on machine vision
CN121458718A