Forging surface defect detection method and system based on machine vision
By combining boundary saliency 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 caused by the fixed parameters of traditional Gabor filters, and improving the accuracy and reliability of surface defect detection of forgings.
Patent Information
- Application Number
- CN202511813106.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-04
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2045-12-04
AI Technical Summary
The fixed parameters of traditional Gabor filters lead to detection blind spots and high false alarm rates, affecting the accuracy and quality of surface defect detection in forgings.
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.
It effectively eliminates blind spots in detection, reduces false alarm rates, improves the accuracy and reliability of surface defect detection in forgings, ensures forging quality, and adapts to defect characteristics of different directions and scales.
Smart Images

Figure CN121258993A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image data processing technology, and in particular to a method and system for detecting surface defects in forgings based on machine vision. Background Technology
[0002] During the manufacturing process of forgings, due to the high temperature and high pressure processing technology, minor defects such as cracks, hairline cracks, and scratches inevitably occur on the surface of the forgings. These defects may become stress concentration points, which may lead to fatigue fracture or structural failure in subsequent use, affecting the safety and life of the forgings. In order to ensure the quality of forgings and improve production efficiency, the use of machine vision technology for automated detection of surface defects of forgings has become a key link.
[0003] However, the surface of forgings is not an ideal smooth plane, but generally has complex natural textures formed by metal rheology, surface oxidation, etc. The local features of complex natural textures in the image, such as edges and lines, are highly similar to the features of weak defects, thus constituting a strong background interference for surface defect detection.
[0004] In order to accurately extract defect features from complex texture backgrounds, Gabor filter banks are often used in existing technologies. Due to their sensitivity to specific directions and frequencies, Gabor filters are widely used in texture analysis and edge detection.
[0005] However, key parameters such as the direction and scale of traditional Gabor filter banks need to be set offline based on prior knowledge or operator experience, resulting in a static and discrete configuration. When the direction or scale of the actual defects on the forging surface does not perfectly match the preset parameters, the response of traditional Gabor filters will be significantly weakened, creating a response blind zone and leading to missed defects. At the same time, traditional Gabor filters rely solely on local pixel features for filtering response calculation and cannot combine the overall structural consistency of the defect area for judgment. This makes it easy to misidentify normal textures similar to the local features of defects in complex texture backgrounds as defects, resulting in a high false alarm rate during the detection process. This reduces the accuracy of forging surface defects and ultimately affects the quality of the forging. Summary of the Invention
[0006] To address the issues of detection blind spots caused by the fixed parameters of traditional Gabor filters and the high false alarm rate resulting from relying solely on local pixel features, which reduces the accuracy of forging surface defect detection and ultimately affects forging quality, this invention provides a machine vision-based method and system for detecting forging surface defects.
[0007] In a first aspect, the present invention provides a machine vision-based method for detecting surface defects in forgings, employing the following technical solution: A machine vision-based method for detecting surface defects in forgings includes: acquiring a grayscale image of the surface of the forging to be detected; calculating the structure tensor of the grayscale image; and obtaining a first feature value, a second feature value, and a dominant direction for each pixel based on the structure tensor; determining a local structural anisotropy index based on the first feature value and the second feature value; determining a boundary saliency weight 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; and using the dominant direction as the direction of an adaptive Gabor filter, and determining the boundary saliency weight based on the local grayscale entropy, the first feature value, and the second feature value. The feature value is used to determine the scale of the adaptive Gabor filter. An adaptive Gabor filter is applied to the grayscale image to obtain a dynamic filter response. The mean of multiple dynamic filter responses along the dominant direction is calculated to obtain the path response. Based on the dynamic filter response and the path response, a path consistency weight is determined. The boundary saliency weight and the path consistency weight are filtered to obtain the final weight. The final weight is multiplied by the dynamic filter response to obtain the final feature map. Local adaptive threshold segmentation is performed on the final feature map to obtain a binary image. Based on the connected regions in the binary image, defect identification is performed on the surface of the forging to be inspected.
[0008] This invention constructs a comprehensive evaluation model for boundary saliency weights by combining local structural anisotropy index, neighborhood gradient direction consistency, and neighborhood mean. This model effectively identifies true boundary features, suppresses interference from complex textured backgrounds, and improves the detection accuracy of defect boundaries. By using the dominant direction as the adaptive Gabor filtering direction and combining local gray-level entropy, the first eigenvalue, and the second eigenvalue to determine the filtering scale, intelligent adjustment of Gabor filtering parameters is achieved. This effectively solves the response blind zone problem caused by traditional fixed parameters, ensuring that the filter can adapt to defect features of different directions and scales. By calculating path response and path consistency weights, the overall structural consistency of the defect region is evaluated, effectively distinguishing between real defects and background regions with similar local textures, reducing the false alarm rate. By fusing boundary saliency weights and path consistency weights and combining them with dynamic filtering response to generate the final feature map, comprehensive utilization of multi-dimensional features is achieved, improving the accuracy and reliability of forging surface defect detection and providing effective technical support for forging quality control.
[0009] Furthermore, after acquiring the grayscale image, the method further includes: performing Gaussian smoothing on the grayscale image to suppress noise.
[0010] Further, calculating the structure tensor includes: using the Sobel operator to calculate the grayscale image in... direction and The gradient in the direction; within a local window centered on each pixel, the outer product of the gradient is Gaussian-weighted averaged to obtain the structure tensor.
[0011] Furthermore, 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.
[0012] This invention constructs an evaluation model for the local structural anisotropy index by calculating the ratio of the difference between the first and second eigenvalues to the sum of the eigenvalues. This model effectively reflects the directional characteristics of the local structure of pixels, accurately distinguishes different types of local structural features such as linear structures, point structures, and uniform regions, provides reliable structural feature input for calculating boundary saliency weights, and improves the ability to distinguish between surface defects and background textures of forgings.
[0013] Furthermore, the boundary saliency 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.
[0014] 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.
[0015] Furthermore, the scale satisfies: 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.
[0016] 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.
[0017] Furthermore, the path consistency weight satisfies: 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.
[0018] 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.
[0019] 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.
[0020] 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.
[0021] Secondly, the present invention provides a machine vision-based forging surface defect detection system, which adopts the following technical solution: 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.
[0022] 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.
[0023] The present invention has the following technical effects: (1) Abandoning the offline preset static parameters of traditional Gabor filters, the filter direction and scale are adaptively adjusted. The dominant direction of the pixel is used as the filtering direction to ensure that a strong response can be generated for defects in any direction, such as cracks and scratches at different angles. The filtering scale is dynamically determined by the local gray-level entropy that reflects the gray-level complexity of the region and the first and second feature values that reflect the intensity of local structural changes. This more accurately matches the actual size of the defect, such as the small scale of fine hairline cracks and the large scale of long cracks. This solves the problem of reduced response caused by the mismatch between parameters and defect features in traditional methods, effectively eliminates the detection blind zone, and reduces the missed detection rate of weak defects such as cracks and hairline cracks.
[0024] (2) Breaking through the limitations of traditional Gabor filters that rely solely on local pixel features, a dual-dimensional evaluation of path consistency weight and boundary saliency weight is introduced. The path consistency weight evaluates the overall structural continuity of the defect region by calculating the mean of the filter response along the dominant direction path. For example, cracks usually exhibit continuous linear characteristics, while normal textures are mostly discrete. The boundary saliency weight combines the local structural anisotropy index and the neighborhood gradient direction consistency to strengthen the boundary difference between defects and background textures, effectively distinguishing defects with similar local features but different overall structures from normal textures. For example, it can misjudge discrete textures formed by metal rheology as cracks, reducing the false alarm rate caused by complex background interference.
[0025] (3) The final feature map is generated by multiplying the dynamic filtering response and the final weight. This not only retains the adaptive Gabor filtering's sensitivity to capturing local details of defects, such as the grayscale changes of weak scratches, but also amplifies the overall structural features of defects through weights, such as the continuous path of cracks and the linear trend of hairline cracks. This enhances the weak defect features that were originally covered in complex textures. Compared with the blurred feature map output by traditional methods, the final feature map has a higher contrast between defects and background, providing a clearer feature basis for subsequent local adaptive threshold segmentation and improving the detection sensitivity of subtle defects.
[0026] (4) After accurately identifying defects such as cracks and hairline on the surface of forgings, unqualified products can be removed in time or targeted repairs can be carried out 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 automated inspection process not only reduces the subjective error of manual judgment, but also improves the inspection efficiency, adapts to the quality control needs of large-scale forging production, and provides reliable forging quality assurance for fields with high safety requirements, such as aerospace and heavy machinery. Attached Figure Description
[0027] Figure 1 This is a flowchart of the method for detecting surface defects in forgings based on machine vision, according to an embodiment of the present invention. Detailed Implementation
[0028] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0029] This invention discloses a machine vision-based method for detecting surface defects in forgings, referring to... Figure 1 This includes steps S01-S05: S01: Obtain a grayscale image of the surface of the forging to be inspected.
[0030] It should be noted that the surface of forgings is covered with oxide scale due to high-temperature forging and metal oxidation processes, and the complex interwoven textures formed by metal rheology introduce random noise. Furthermore, the local structural information of minute defects, such as fine cracks and short scratches, is easily masked by the background texture, making them difficult to distinguish directly. Therefore, this step first requires Gaussian smoothing to suppress random noise and avoid noise interference with structural analysis; then, the dominant structural direction and anisotropy degree of each pixel's neighborhood are obtained through the structure tensor, providing a more accurate basis for subsequent calculations regarding local structure.
[0031] Grayscale images of the forging surface to be inspected are acquired using an industrial camera. Gaussian smoothing is applied to the acquired grayscale images to suppress random noise. To accurately describe the structural information within the neighborhood of each pixel, the structure tensor of the image is calculated. The Sobel gradient operator and other gradient operators are used to calculate the gradient of each pixel within the grayscale image. direction and The gradient in the direction, the structure tensor is a The matrix is formed by centering each pixel on a matrix of size 1. The gradient components are obtained by taking a Gaussian weighted average of their outer products within a local window, as exemplified. For pixels located at the boundary, their local window may partially extend beyond the image range, resulting in some positions within the window lacking effective pixel values. In this case, a mirror filling method is used to supplement the virtual pixel values that extend beyond the boundary: using the image boundary as the axis of symmetry, the pixel grayscale values at the corresponding positions inside the boundary are copied to the symmetrical positions outside the window. This ensures that all effective pixels within the entire local window participate in the Gaussian weighted average calculation of the gradient outer product, avoiding the calculation deviation between the structural tensor eigenvalues and the dominant direction caused by boundary truncation. To quantify the dominant structural direction and anisotropy of each local region, the structural tensor is decomposed into eigenvalues to obtain the first eigenvalue of the structural tensor for each pixel. With the second eigenvalue , The direction of the feature vector corresponding to the first feature value is the dominant direction of the pixel in the local region.
[0032] S02: Determine the significance weights of the boundary.
[0033] 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.
[0034] The local structural anisotropy index is determined based on the first eigenvalue and the second eigenvalue.
[0035] Specifically, 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, For example, hyperparameters. This is used to avoid numerical calculation errors caused by a denominator of zero in the formula.
[0036] 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, , The magnification factor is a preset value; for example, its range is [value range missing]. 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.
[0037] Specifically, the boundary significance weights satisfy: ; 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. .
[0038] 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 coverage 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.
[0039] S03: Determine the path consistency weight.
[0040] 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.
[0041] 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.
[0042] Specifically, the scale satisfies: ; 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.
[0043] 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.
[0044] The mean of multiple dynamic filter responses along the path along the dominant direction is calculated to obtain the path response.
[0045] 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. .
[0046] The path consistency weight is determined based on the dynamic filtering response and the path response.
[0047] Specifically, the path consistency weight satisfies: ; 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.
[0048] 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.
[0049] S04: Filter the boundary saliency weight and the path consistency weight to obtain the final weight.
[0050] 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.
[0051] Specifically, the final weight is obtained as follows: The maximum value between the boundary saliency weight and the path consistency weight is taken as the final weight.
[0052] The final weights are multiplied by the dynamic filtering response to obtain the final feature map.
[0053] 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.
[0054] 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.
[0055] Specifically, the defect identification includes: Morphological post-processing and connected component analysis are performed on the connected regions in the binary image. 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.
[0056] 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.
[0057] 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.
[0058] 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 method for detecting surface defects of a forged product based on machine vision, characterized by, The method comprises: acquiring a gray image of a surface of a forging 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, consistency of gradient directions in a neighborhood, and a mean value of the local structure anisotropy index in the neighborhood; taking the dominant direction as a direction of adaptive Gabor filtering, determining a scale of adaptive Gabor filtering according to a local gray entropy, the first eigenvalue, and the second eigenvalue, performing adaptive Gabor filtering on the gray image, and obtaining a dynamic filtering response; calculating a mean value of a plurality of dynamic filtering responses along a path in the dominant direction, and obtaining 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 and 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 surface of the forging to be detected based on a connected region in the binary image.
2. The machine vision-based forging surface defect detection method according to claim 1, wherein, After the gray image is acquired, the method further comprises: performing Gaussian smoothing on the gray image to suppress noise.
3. The machine vision-based forging surface defect detection method of claim 1, wherein, The structure tensor is calculated by: Using the Sobel operator, the gradient of the gray scale image is calculated in directions and directions. performing Gaussian weighted averaging on the outer product of the gradient in a local window centered on each pixel to obtain the structure tensor.
4. The machine vision-based forging surface defect detection method of claim 1, wherein, The local structure anisotropy index satisfies: ; 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 is the second eigenvalue of the pixel point is the second eigenvalue of the pixel point is the second eigenvalue of the pixel point is a hyperparameter.
5. The machine vision-based forging surface defect detection method of claim 1, wherein, The boundary saliency weight satisfies: ; wherein, is a boundary saliency weight of the pixel point , is a local structure anisotropy index of the pixel point , is a consistency of gradient direction in the neighborhood of the pixel point , is a side length of the neighborhood, is a neighborhood of the pixel point , is a local structure anisotropy index of the pixel point , is a rectified linear unit function.
6. The machine vision-based forging surface defect detection method of claim 1, wherein, The scale satisfies: ; wherein, is the scale of the adaptive Gabor filter of the pixel point , is the scale correction coefficient, is the local gray entropy of the pixel point , is the first eigenvalue of the pixel point , is the second eigenvalue of the pixel point , is the minimum filter wavelength of the Gabor filter, is the hyperparameter, is the maximum function.
7. The machine vision-based forging surface defect detection method of claim 1, wherein, The path consistency weight satisfies: ; 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.
8. The machine vision-based forging surface defect detection method of claim 1, wherein, The final weight is obtained by: taking a maximum value of the boundary saliency weight and the path consistency weight as the final weight.
9. The machine vision-based forging surface defect detection method of claim 1, wherein, The defect recognition comprises: performing morphological post-processing and connected region analysis on the connected region in the binary image; screening a connected region satisfying a preset geometric condition as a final detected defect, and the geometric condition comprises a minimum area, a length-width ratio range, and a circularity range.
10. A machine vision based forging surface defect detection system characterized in that, The method comprises: a processor and a memory, the memory storing 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-9.
Citation Information
Patent Citations
Forging defect detection method based on deep learning
CN113393439A
Neural network-based forging defect rapid target detection method
CN114897817A
Method and system for detecting surface defects of titanium alloy forge piece
CN118379286A
Flaw detection method and system for vacuum isothermal forging raw materials
CN119881084A
Method for Filtering Using Block-Gabor Filters for Determining Descriptors for Images
US20130004028A1
Cited By
Automobile precision component surface defect detection method and system based on machine vision
CN121563991A
Low-illumination color fabric defect rapid detection method and system
CN121582261A
Small-sample defect detection method and system based on visual language large model
CN121724995A
Machine vision-based stock bin material quantity automatic measurement method and system
CN121883572A
An Automatic Measurement Method and System for Material Quantity in Silos Based on Machine Vision
CN121883572B
