Machine vision-based forging surface defect detection method and system

By combining local structural features and path consistency weights with an adaptive Gabor filter, the filtering direction and scale are dynamically adjusted, solving the detection blind zone and false alarm rate problems of traditional Gabor filters and achieving high-accuracy detection of surface defects in forgings.

CN121258993BActive Publication Date: 2026-04-07HANZHONG QUNFENG MACHINERY MFG
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-04
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

The fixed parameters of traditional Gabor filters result in detection blind spots and high false alarm rates, making it impossible to accurately identify minor defects on the surface of forgings.

Method used

An adaptive Gabor filter is used to construct boundary saliency weights by means of local structural anisotropy index, neighborhood gradient direction consistency and neighborhood mean. Combined with path consistency weights, the filtering direction and scale are dynamically adjusted to generate the final feature map for defect identification.

Benefits of technology

It effectively eliminates blind spots in detection, reduces false alarm rates, improves the accuracy and reliability of surface defect detection in forgings, and ensures the quality of forgings.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121258993B_ABST
    Figure CN121258993B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of image data processing, and more particularly to a forging surface defect detection method and system based on machine vision. The method comprises: acquiring a grayscale image of a forging surface to be detected; determining a boundary saliency weight; determining a path consistency weight; screening the boundary saliency weight and the path consistency weight to obtain a final weight; performing local adaptive threshold segmentation on the final feature map to obtain a binary image, and based on the connected regions in the binary image, performing defect recognition on the forging surface to be detected. By constructing the boundary saliency weight and the path consistency weight, the present application is respectively used for accurately positioning the defect edge and verifying the structural continuity, effectively suppresses the texture interference and reduces false alarms; by adaptive Gabor filtering, the response blind area problem of the traditional method is solved, and finally the two weights are fused to modulate the filtering response, thereby improving the accuracy of the forging surface defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image data processing, and in particular to a forging surface defect detection method and system based on machine vision. BACKGROUND

[0002] In the production and manufacturing process of forgings, due to the high-temperature and high-pressure processing technology, micro defects such as cracks, lines and scratches will inevitably occur on the surface of forgings. These defects may become stress concentration points and cause fatigue fracture or structural failure in subsequent use, affecting the safety and service life of forgings. In order to ensure the quality of forgings and improve production efficiency, it has become a key link to use machine vision technology to automatically detect the surface defects of forgings.

[0003] However, the surface of the forging is not an ideal smooth plane, but a complex natural texture formed by metal flow and surface oxidation. The local features of the complex natural texture, such as edges and lines, are highly similar to the features of the micro defects, thus constituting strong background interference for surface defect detection.

[0004] In order to accurately extract defect features from complex texture background, Gabor filter banks are often used in the prior art for processing. Due to its sensitivity to specific direction and frequency, Gabor filter has been widely used in texture analysis and edge detection.

[0005] However, the key parameters such as direction and scale of the traditional Gabor filter bank need to be set offline according to prior knowledge or the experience of the operator, and finally a static and discrete configuration is formed. When the actual defect direction or scale of the forging surface does not completely match the preset parameters, the response of the traditional Gabor filter will be significantly weakened, resulting in a response blind area and leading to missed detection of defects. At the same time, the traditional Gabor filter only relies on local pixel features for filter response calculation and cannot judge based on the overall structural consistency of the defect area, which is easy to misidentify normal texture similar to the local features of the defect in the complex texture background as a defect, resulting in a high false alarm rate in the detection process and reducing the accuracy of the forging surface defect. Ultimately, it affects the quality of forgings. SUMMARY

[0006] In order to solve the problem of detection blind area caused by the fixed parameters of the traditional Gabor filter and the high false alarm rate caused by the judgment of only local pixel features, thus reducing the accuracy of the forging surface defect and ultimately affecting the quality of the forgings, the present application provides a forging surface defect detection method and system based on machine vision.

[0007] In the first aspect, the present application provides a forging surface defect detection method based on machine vision, which adopts the following technical solution:

[0008] The forging surface defect detection method based on machine vision comprises: acquiring a gray image of a forging surface to be detected, calculating a structure tensor of the gray image, and obtaining a first eigenvalue, a second eigenvalue and a dominant direction of each pixel point based on the structure tensor; determining a local structure anisotropy index according to the first eigenvalue and the second eigenvalue; determining a boundary saliency weight according to the local structure anisotropy index, the consistency of gradient directions in a neighborhood, and the average of the local structure anisotropy index in the neighborhood; taking the dominant direction as the direction of adaptive Gabor filtering, determining the scale of adaptive Gabor filtering according to the local gray entropy, the first eigenvalue and the second eigenvalue, performing adaptive Gabor filtering on the gray image to obtain a dynamic filtering response; calculating the average of a plurality of dynamic filtering responses along a path in the dominant direction to obtain a path response; determining a path consistency weight according to the dynamic filtering response and the path response; screening the boundary saliency weight and the path consistency weight to obtain a final weight; multiplying the final weight by the dynamic filtering response to obtain a final feature map; performing local adaptive threshold segmentation on the final feature map to obtain a binary image, and performing defect recognition on the forging surface to be detected based on the connected regions in the binary image.

[0009] The local structure anisotropy index, the neighborhood gradient direction consistency and the neighborhood average are combined to construct a comprehensive evaluation model of the boundary saliency weight, which can effectively identify the real boundary features, suppress the interference of complex texture background, and improve the detection accuracy of defect boundaries; the dominant direction is taken as the adaptive Gabor filtering direction, the filtering scale is determined by combining the local gray entropy, the first eigenvalue and the second eigenvalue, the intelligent adjustment of the Gabor filtering parameters is realized, the response blind area problem caused by traditional fixed parameters is effectively solved, and it is ensured that the filter can adapt to defect features of different directions and scales; the path response and the path consistency weight are calculated to realize the evaluation of the overall structural consistency of the defect area, effectively distinguish the real defect and the background area similar to the local texture, and reduce the false alarm rate; the boundary saliency weight and the path consistency weight are fused to generate the final feature map combined with the dynamic filtering response, the comprehensive utilization of multi-dimensional features is realized, the accuracy and reliability of the forging surface defect detection are improved, and effective technical support is provided for forging quality control.

[0010] Further, after the gray image is acquired, the method further comprises: performing Gaussian smoothing processing on the gray image to suppress noise.

[0011] Further, the structure tensor is calculated by using a Sobel operator to calculate the gradient directions of the gray image in the x direction and the y direction. ​Gradient in the direction; the outer product of the gradient is Gauss weighted and averaged to obtain the structure tensor in a local window centered on each pixel.

[0012] Further, the local structure anisotropy index satisfies:

[0013] ; wherein, is the local structure anisotropy index of the pixel point , is the first eigenvalue of the pixel point , is the second eigenvalue of the pixel point , and is a hyperparameter.

[0014] The application constructs an evaluation model of the local structure anisotropy index by calculating the ratio of the difference and the sum of the first eigenvalue and the second eigenvalue, effectively reflects the directional features of the local structure of the pixel point, accurately distinguishes different types of local structure features such as linear structure, point structure and uniform area, provides reliable structure feature input for the calculation of the boundary saliency weight, and improves the distinguishing ability of the forging surface defects and background texture.

[0015] Further, the boundary saliency weight satisfies:

[0016] ; wherein, is the boundary saliency weight of the pixel point , is the local structure anisotropy index of the pixel point , is the consistency of the gradient direction in the neighborhood of the pixel point , is the side length of the neighborhood, is the neighborhood of the pixel point , is the local structure anisotropy index of the pixel point , and is a modified linear unit function.

[0017] ​​​​​​​​​This invention achieves a comprehensive evaluation of boundary saliency weights by constructing a composite function that incorporates local anisotropy, gradient consistency, and neighborhood differences. It considers both the structural features of the pixel itself and the characteristics of its neighborhood environment, ensuring the accuracy of boundary recognition. The neighborhood average term reflects the overall structural characteristics of the local region, and the modified linear unit function ensures that a pixel only receives significant weight when its anisotropy index is higher than the neighborhood average, effectively suppressing interference from background textures. The introduction of gradient direction consistency further enhances the ability to recognize boundary features, effectively distinguishing between real boundaries and structural changes within textures, thus improving the accuracy and robustness of boundary detection.

[0018] Furthermore, the scale satisfies:

[0019] In the formula, For pixels The scale of adaptive Gabor filtering. This is the scale correction factor. For pixels Local gray-level entropy, For pixels The first eigenvalue, For pixels The second eigenvalue, This is the minimum filtering wavelength for Gabor filtering. For hyperparameters, It is a function for maximizing the value.

[0020] This invention achieves intelligent adjustment of the adaptive Gabor filter scale by constructing a composite function that includes gray-level entropy and eigenvalue ratio. It dynamically adjusts the filter scale based on the complexity of local gray-level changes and structural features, ensuring the filter's adaptability to different features. Gray-level entropy reflects the texture complexity of a local region, while the eigenvalue ratio reflects the directionality of the local structure. The combination of gray-level entropy and eigenvalue ratio allows scale adjustment to consider both texture complexity and structural directionality. A minimum wavelength constraint ensures that the filter scale is not too small, thus preventing loss of filtering effectiveness. This scale adjustment mechanism effectively solves the response blind zone problem caused by traditional fixed scales, enabling the Gabor filter to adapt to defect features at different scales, improving filtering performance and the accuracy of defect detection.

[0021] Furthermore, the path consistency weight satisfies:

[0022] In the formula, For pixels Path consistency weight, For pixels Path response, For pixels The dynamic filtering response, For pixels The maximum value among all pixels in the neighborhood of the dynamic filtering response. It is a very small positive number. It is the hyperbolic tangent function.

[0023] This invention achieves a scientific evaluation of path consistency weights by constructing a multiplication relationship between the path response and the dynamic filtering response, combined with neighborhood maximum value normalization. This effectively reflects the consistency of pixels within the overall structural path. The path response reflects the continuity along the dominant direction, while the dynamic filtering response reflects the local filtering effect. The product of the path response and the dynamic filtering response accurately reflects the comprehensive performance of pixels in terms of path continuity and local feature strength. Neighborhood maximum value normalization ensures a reasonable range for the weight values, and the hyperbolic tangent function constrains the range of weight values, improving the numerical stability of the calculation.

[0024] Furthermore, the final weight is obtained by taking the maximum value between the boundary saliency weight and the path consistency weight as the final weight.

[0025] Furthermore, the defect identification includes: performing morphological post-processing and connected component analysis on the connected regions in the binary image; and selecting connected regions that meet preset geometric conditions as the final detected defects, wherein the geometric conditions include minimum area, aspect ratio range, and circularity range.

[0026] Secondly, the present invention provides a machine vision-based forging surface defect detection system, which adopts the following technical solution:

[0027] The machine vision-based forging surface defect detection system includes a processor and a memory. The memory stores computer program instructions, which, when executed by the processor, implement the aforementioned machine vision-based forging surface defect detection method.

[0028] By adopting the above technical solution, the above-mentioned machine vision-based forging surface defect detection method is generated into a computer program and stored in a memory so that it can be loaded and executed by a processor. In this way, a terminal device can be made based on the memory and processor for convenient use.

[0029] The present invention has the following technical effects:

[0030] (1) Abandon the offline preset static parameters of the traditional Gabor filter, realize the adaptive adjustment of the filter direction and scale, take the dominant direction of the pixel point as the filtering direction, and ensure that any direction defects such as cracks and scratches of different angles can produce strong response; The local gray entropy reflecting the gray complexity of the region and the first and second eigenvalues reflecting the local structure change degree are used to dynamically determine the filtering scale, which can more accurately match the actual size of the defect, such as the small scale of fine lines and the large scale of long cracks, thereby solving the problem of weakened response caused by the mismatch between parameters and defect characteristics in traditional methods, effectively eliminating the detection blind area, and reducing the missed detection rate of weak defects such as cracks and lines.

[0031] (2) Break through the limitation of traditional Gabor filter which only depends on local pixel features, introduce dual-dimension evaluation of path consistency weight and boundary saliency weight, path consistency weight evaluates the overall structural continuity of the defect area by calculating the average filtering response along the dominant direction path, such as cracks usually present continuous linear characteristics, while normal texture is usually discrete distribution; The boundary saliency weight combines the local structure anisotropy index and the consistency of the gradient direction of the neighborhood to strengthen the boundary difference between the defect and the background texture, effectively distinguishing defects with similar local features but different overall structures from normal textures, such as misjudging discrete textures formed by metal flow as cracks, reducing the false alarm rate caused by complex background interference.

[0032] (3) The product of the dynamic filtering response and the maximum weight generates the final feature map, which not only retains the sensitive capture of the local details of the defect by the adaptive Gabor filter, such as the gray change of weak scratches, but also amplifies the overall structural features of the defect through the weight, such as the continuous path of the crack and the linear trend of the line, so that the weak defect features that are originally hidden in complex textures are enhanced. Compared with the fuzzy feature map output by the traditional method, the contrast between the defect and the background in the final feature map is higher, providing a clearer feature basis for subsequent local adaptive threshold segmentation, and improving the detection sensitivity of subtle defects.

[0033] (4) After accurately identifying defects such as cracks and lines on the surface of forgings, unqualified products can be removed or repaired in a targeted manner to avoid these defects becoming stress concentration points in subsequent use, thereby preventing safety hazards such as fatigue fracture and structural failure; At the same time, the automatic detection process not only reduces the subjective error of manual judgment, but also improves the detection efficiency, which meets the quality control needs of large-scale production of forgings, and provides reliable quality assurance for forgings in fields with high safety requirements, such as aerospace and heavy machinery. BRIEF DESCRIPTION OF DRAWINGS

[0034] Figure 1 is the method flowchart of the forging surface defect detection method based on machine vision according to the embodiment of the application. DETAILED DESCRIPTION

[0035] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative efforts belong to the scope of the present application.

[0036] The embodiments of the present application disclose a forging surface defect detection method based on machine vision, referring to Figure 1 , comprising steps S01-S05:

[0037] S01: Obtain a gray image of a surface of a forging to be detected.

[0038] It should be noted that the forging surface will be attached with oxide scale due to high-temperature forging, metal oxidation and other processes, and the complex interlaced texture formed by metal flow will introduce random noise, and the local structure information of small defects such as fine cracks and short scratches is easy to be covered by background texture, which is difficult to distinguish directly. Therefore, in this step, the random noise is first suppressed by Gaussian smoothing to avoid noise interference with structure analysis; and then the structure dominant direction and anisotropy degree of each pixel neighborhood are obtained by structure tensor, to provide more accurate local structure basis for subsequent calculation.

[0039] A gray image of a surface of a forging to be detected is obtained by an industrial camera, and Gaussian smoothing is performed on the obtained gray image to suppress random noise; in order to accurately describe the structure information in the neighborhood of each pixel point, the structure tensor of the image is calculated, the gradients of each pixel point in the gray image in the direction and the direction are calculated by a gradient operator such as a Sobel operator, the structure tensor is a matrix, which is obtained by Gaussian weighted average of the outer product of the gradient components in a local window with the pixel point as the center and the size of , for example, For the pixel points located at the boundary, the local window may be partially out of the image range, resulting in no effective pixel value in part of the window, at this time, the mirror filling method is used to supplement the virtual pixel value out of the boundary: the pixel gray value of the corresponding position inside the boundary is copied to the symmetrical position outside the window with the image boundary as the axis of symmetry, to ensure that there are effective pixels in the whole local window to participate in the Gaussian weighted average calculation of the gradient outer product, avoiding the calculation deviation of the structure tensor eigenvalue and the dominant direction caused by boundary truncation; in order to quantify the structure dominant direction and the anisotropy degree of each local region, the structure tensor is subjected to eigenvalue decomposition to obtain the first eigenvalue and the second eigenvalue of the structure tensor of each pixel point, The direction of the feature vector corresponding to the first feature value is the dominant direction of the pixel in the local region.

[0040] S02: Determine the significance weights of the boundary.

[0041] It should be noted that the core difference between surface defects in forgings, such as the edges of micro-cracks and isolated short scratches, and the background texture lies in the abrupt change in local structural anisotropy. The anisotropy index cannot effectively distinguish between defect boundaries and texture boundaries, such as the natural texture edges of oxide scale. Furthermore, the gradient direction of defect edges is usually more uniform, and the consistency of gradient direction has a significant impact on the recognizability of defect edges. Therefore, this step calculates the difference between the anisotropy index and the neighborhood average to highlight abrupt changes, and combines this with gradient direction consistency to enhance edge realism, constructing boundary saliency weights to accurately capture the characteristics of defect edges and isolated short defects.

[0042] The local structural anisotropy index is determined based on the first eigenvalue and the second eigenvalue.

[0043] Specifically, the local structural anisotropy index satisfies:

[0044] ;

[0045] In the formula, For pixels Local structural anisotropy index, For pixels The first eigenvalue, For pixels The second eigenvalue, For example, hyperparameters. This is used to avoid numerical calculation errors caused by a denominator of zero in the formula.

[0046] Based on the local structure anisotropy index, the consistency of gradient directions within the neighborhood, and the mean of the local structure anisotropy index within the neighborhood, the boundary saliency weight is determined, and the size of the neighborhood is [missing information]. ,in, , This is a preset magnification factor; for example, its value range is... The neighborhood is set based on the following principle: to ensure that the neighborhood window can cover a sufficient area of ​​the local structure and the surrounding background, effectively distinguish the difference between the anisotropy index of the local structure and the surrounding environment, and avoid misjudgment of boundary salience due to the neighborhood being too small.

[0047] Specifically, the boundary significance weights satisfy:

[0048] ;

[0049] In the formula, For pixels Boundary significance weights, For pixels The local structural anisotropy index is higher at defect edges and isolated defects, but lower inside long defects and large areas of background texture. For pixels Consistency of gradient direction within the neighborhood Let be the side length of the neighborhood. For pixels The neighborhood, For pixels Local structural anisotropy index, To correct the linear unit function, i.e. .

[0050] in, Represents pixels The degree of anisotropy of the structure within a neighborhood reflects the strength of the directionality of the surface structure of the forging in that region. Background textures of forgings, such as interlaced patterns formed by metal rheology and oxide scale-covered areas, are mostly chaotic isotropic structures with weak directionality. The value is close to 0, while the defect edges, such as crack edges and scratch boundaries, are linear continuous structures, exhibiting strong anisotropy and obvious directionality. The value is significantly high; therefore, the larger the value, the more pronounced the structural directionality in the region. For example, the greater the difference between the linear structure at the crack edge and the surrounding uniform texture, the better. The larger it is, the smaller it is, and vice versa. Represents pixels The consistency of gradient directions within a neighborhood measures the continuity of the region's edges. Forging defects, such as fine cracks and short scratches, have continuous linear edges with highly uniform gradient directions. For example, if a crack extends along the metal rheological direction, the edge gradient is perpendicular to the crack's direction. In contrast, the gradient directions of background texture edges, such as natural fractures in oxide scale and metal grain boundaries, are chaotic. Therefore, the larger this value, the more uniform the gradient direction in the region, conforming to the linear continuity of defect edges, and the more likely a chaotic gradient, rather than a textured gradient, is to be a true defect edge. The larger it is, the smaller it is, and vice versa. Represents pixels The degree to which the anisotropy index is higher than the average level of its neighborhood is only retained as abrupt change features. Forging background textures, such as the local structure of large-area metal rheological regions, show a uniform distribution of anisotropy index values, with the difference close to 0 (set to 0 by the corrected linear unit function). However, defect edges or isolated defects, such as small scratches or micro-hair lines, have local structure anisotropy index values ​​much higher than the surrounding background, with a positive and large difference. Therefore, the larger the value, the more significant the structural difference between the pixel and the surrounding background texture, and the more likely it is to be a defect edge or isolated defect. The larger it is, the smaller it is, and vice versa.

[0051] S03: Determine the path consistency weight.

[0052] It should be noted that long defects on the surface of forgings, such as long cracks and extended scratches, have structural features that are continuously distributed along a specific direction. However, traditional fixed-parameter Gabor filters cannot adapt to the direction of defects in different regions. For example, cracks may extend along the metal rheological direction. Furthermore, scale differences, such as the different widths of coarse and fine cracks, can easily lead to response blind zones due to parameter mismatch. Simultaneously, discrete texture points may produce spurious responses, requiring path continuity verification to eliminate interference. Therefore, this step first generates an accurate response through a dual dynamic adaptive Gabor filter based on direction and scale, and then calculates the path response consistency along the dominant structural direction, constructing path consistency weights to capture the continuous structural features of long defects.

[0053] Using the dominant direction as the direction of adaptive Gabor filtering, the scale of adaptive Gabor filtering is determined based on the local gray-level entropy, the first feature value, and the second feature value. Adaptive Gabor filtering is then applied to the gray-level image to obtain a dynamic filtering response.

[0054] Specifically, the scale satisfies:

[0055] ;

[0056] In the formula, For pixels The scale of adaptive Gabor filtering. This is a scaling correction factor, for example, with a value range of [value range missing]. , For pixels Local gray-level entropy, For pixels The first eigenvalue, For pixels The second eigenvalue, This refers to the minimum filtering wavelength for Gabor filtering, exemplarily 1 to 3 pixels. For hyperparameters, It is a function for maximizing the value.

[0057] in, The overall correction coefficient represents the dynamic scale and is used to adapt to the basic texture coarseness of forgings made of different materials, such as the different texture densities of stainless steel forgings and carbon steel forgings. Represents pixels The degree of disorder in the grayscale distribution on the surface of the forging within the neighborhood, i.e., texture complexity, is significant. In areas with dense oxide scale, such as surfaces not cleaned after high-temperature forging, the grayscale is chaotic with high local grayscale entropy. Conversely, in metallic luster areas with less oxide scale and more uniform grayscale, local grayscale entropy is low. If a high local grayscale entropy value is filtered using a small wavelength, the oxide scale texture will be over-refined, generating numerous false responses. In such cases, a large wavelength filter is needed to ignore texture details and focus on the defect structure. Therefore, the larger this value, the more complex the texture in that area, requiring a larger wavelength to cover the complete structural features and avoid over-refining the texture through filtering. The larger it is, the greater it becomes; conversely, the smaller it is, the greater it becomes. Represents pixels The degree of weakening of structural anisotropy within the neighborhood: In the metallic luster region of a forging, there is no oxide scale or defect structure, and it is close to isotropy, so this ratio is close to 1. However, in defect areas, such as cracks, the structure has strong anisotropy, and this ratio is close to 0. If a small wavelength filter is used in the metallic luster region, it is easy to misjudge small grayscale fluctuations as defects. In this case, a large wavelength filter is needed to suppress fluctuation interference. Therefore, the larger this value is, the closer the structure in that region is to the metallic luster region. In this case, a larger wavelength adaptation is needed to avoid missing large-scale continuous defects. The larger it is, the greater it becomes; conversely, the smaller it is, the greater it becomes.

[0058] The mean of multiple dynamic filter responses along the path along the dominant direction is calculated to obtain the path response.

[0059] Specifically, from pixels Start moving forward in the dominant direction and in the opposite direction of the dominant direction. Step by step, the mean of the dynamic filtered response values ​​of all the pixels passed through is denoted as the path response. .

[0060] The path consistency weight is determined based on the dynamic filtering response and the path response.

[0061] Specifically, the path consistency weights satisfy:

[0062] ;

[0063] In the formula, For pixels Path consistency weight, For pixels Path response, For pixels The dynamic filtering response, For pixels The maximum value among all pixels in the neighborhood of the dynamic filtering response. It is a very small positive number. It is the hyperbolic tangent function.

[0064] in, Represents pixels The synergistic strength between the dynamic filtering response and the average response along the dominant path reflects the consistency between the response of that pixel and the responses of other pixels along the path. Long defects in forgings, such as long cracks and scratches extending along the metal rheological direction, have the characteristic of continuous distribution along a specific direction, meaning that the dynamic filtering responses of all pixels along the path are highly consistent and the product value is large. In contrast, background textures, such as oxide scale and grain boundaries, are discretely distributed, meaning that the responses along the path are chaotic and the product value is small. Therefore, the larger this value is, the more unified the structural response of that pixel is with that of other pixels along the path, and the more it conforms to the characteristic of long defects being continuously distributed along a specific direction. The larger it is, the smaller it is; conversely, the smaller it is. Its function is to the product term Normalization is performed because in industrial settings, deviations in the angle of forging placement and fluctuations in workshop lighting can cause local brightness differences in images. For example, areas closer to the light source may have a higher absolute response value, while areas farther from the light source may have a lower response value. Without normalization, high responses in bright areas may lead to misjudging textures as defects, or low responses in dark areas may cause missed detection of real defects. Therefore, normalization unifies the response magnitude, eliminates the influence of differences in the absolute value of dynamic filtering responses in different areas, and ensures the stability of path consistency weight calculation and comparability between different areas.

[0065] S04: Filter the boundary saliency weight and the path consistency weight to obtain the final weight.

[0066] It should be noted that the boundary saliency weight can accurately capture defect edges and isolated short defects, such as small scratches and tiny hairline cracks, while the path consistency weight is sensitive to long defects with complete shapes, such as long cracks and extended scratches. Therefore, this step adopts a maximum value fusion strategy to select the final weight, and then uses the final weight to modulate the dynamic filtering response to generate a final feature map that can comprehensively highlight various defects and suppress background textures.

[0067] Specifically, the final weight is obtained as follows:

[0068] The maximum value between the boundary saliency weight and the path consistency weight is taken as the final weight.

[0069] The final weights are multiplied by the dynamic filtering response to obtain the final feature map.

[0070] S05: Perform local adaptive threshold segmentation on the final feature map to obtain a binary image, and identify defects on the surface of the forging to be detected based on the connected regions in the binary image.

[0071] It should be noted that in industrial field inspection, deviations in the placement angle of forgings and fluctuations in ambient lighting, such as changes in workshop lighting intensity, can easily lead to uneven local brightness in the image. If global thresholding is used, textures in bright areas may be misidentified as defects due to local brightness differences, or true defects in dark areas may be missed. Furthermore, binarization may leave residual noise points, such as spurious responses from oxide scale debris, and small non-defect connected components, such as texture clusters. Therefore, this step employs a local adaptive thresholding method to achieve accurate binarization, and through morphological post-processing and connected component geometric filtering, finally outputs information such as the location and size of the true defects.

[0072] Specifically, the defect identification includes:

[0073] Morphological post-processing and connected component analysis are performed on the connected regions in the binary image;

[0074] Connected regions that meet preset geometric conditions are selected as the final detected defects. These geometric conditions include minimum area, aspect ratio range, and circularity range. For example, minimum area ≥ 5 pixels, aspect ratio ≤ 10, and circularity ≥ 0.2. Then, the location, size, and other information of the defects are output to complete the machine vision-based surface defect detection of forgings.

[0075] This invention also discloses a machine vision-based forging surface defect detection system, including a processor and a memory. The memory stores computer program instructions, which, when executed by the processor, implement the machine vision-based forging surface defect detection method according to this invention.

[0076] 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.

[0077] The above are all preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Therefore, all equivalent changes made in accordance with the structure, shape and principle of the present invention should be covered within the scope of protection of the present invention.

Claims

1. A machine vision-based method for detecting surface defects in forgings, characterized in that, include: Acquire a grayscale image of the surface of the forging to be inspected, calculate the structure tensor of the grayscale image, and obtain the first feature value, second feature value, and dominant direction of each pixel based on the structure tensor; The local structural anisotropy index is determined based on the first and second eigenvalues; The boundary significance weights are determined based on the local structural anisotropy index, the consistency of gradient directions in the neighborhood, and the mean of the local structural anisotropy index in the neighborhood. The dominant direction is used as the direction of adaptive Gabor filtering. The scale of adaptive Gabor filtering is determined based on local gray-level entropy, the first eigenvalue, and the second eigenvalue. Adaptive Gabor filtering is then applied to the gray-level image to obtain the dynamic filtering response. The mean of multiple dynamic filter responses along the dominant direction is calculated to obtain the path response; The path consistency weight is determined based on the dynamic filtering response and the path response. The final weights are obtained by filtering the boundary significance weights and path consistency weights; The final weights are multiplied by the dynamic filtering response to obtain the final feature map; The final feature map is subjected to local adaptive threshold segmentation to obtain a binary image, and defects on the surface of the forging to be detected are identified based on the connected regions in the binary image. The boundary significance weights satisfy: ; In the formula, For pixels Boundary significance weights, For pixels Local structural anisotropy index, For pixels Consistency of gradient direction within the neighborhood Let be the side length of the neighborhood. For pixels The neighborhood, For pixels Local structural anisotropy index, To correct the linear unit function; Scale requirements are met: In the formula, For pixels The scale of adaptive Gabor filtering. This is the scale correction factor. For pixels Local gray-level entropy, For pixels The first eigenvalue, For pixels The second eigenvalue, This is the minimum filtering wavelength for Gabor filtering. For hyperparameters, It is a function for maximizing the value; Path consistency weights satisfy: In the formula, For pixels Path consistency weight, For pixels Path response, For pixels The dynamic filtering response, For pixels The maximum value among all pixels in the neighborhood of the dynamic filtering response. It is the hyperbolic tangent function.

2. The machine vision-based method for detecting surface defects in forgings according to claim 1, characterized in that, After obtaining the grayscale image, the following is also included: Gaussian smoothing is applied to grayscale images to suppress noise.

3. The machine vision-based method for detecting surface defects in forgings according to claim 1, characterized in that, Computing the structure tensor includes: Using the Sobel operator, the grayscale image is calculated. direction and Gradient in direction; Within a local window centered on each pixel, the structure tensor is obtained by Gaussian weighted averaging of the outer product of the gradients.

4. The machine vision-based method for detecting surface defects in forgings according to claim 1, characterized in that, The local structural anisotropy index satisfies: ; In the formula, For pixels Local structural anisotropy index, For pixels The first eigenvalue, For pixels The second eigenvalue, This is a hyperparameter.

5. The machine vision-based method for detecting surface defects in forgings according to claim 1, characterized in that, The final weights are obtained as follows: The maximum value between the boundary saliency weight and the path consistency weight is used as the final weight.

6. The machine vision-based method for detecting surface defects in forgings according to claim 1, characterized in that, Defect identification, including: Morphological post-processing and connected component analysis are performed on connected regions in binary images; Connected regions that meet preset geometric conditions are selected as the final detected defects. These geometric conditions include minimum area, aspect ratio range, and circularity range.

7. A machine vision-based forging surface defect detection system, characterized in that, include: The processor and memory, wherein the memory stores computer program instructions, which, when executed by the processor, implement the machine vision-based forging surface defect detection method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Forging defect detection method based on deep learning

    CN113393439A

  • Method and system for detecting surface defects of titanium alloy forge piece

    CN118379286A