A method and system for detecting the grain size of a die-forged gear metal
By constructing a boundary confidence map and adaptively adjusting the energy function of the Chan-Vese model, the problems of oversegmentation and undersegmentation of metallographic images of forged gears were solved, and high precision was achieved in detecting the grain size of forged gear metals.
Patent Information
- Application Number
- CN202511657022.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-13
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2045-11-13
AI Technical Summary
The existing Chan-Vese model cannot accurately distinguish between internal texture and grain boundaries when processing metallographic images of forged gears, resulting in oversegmentation or undersegmentation, which reduces the accuracy of metal grain size detection.
By acquiring local gradient structure information from metallographic images, a boundary confidence map is constructed. The energy function of the Chan-Vese model is adaptively adjusted, and spatially adaptive weights for region separation force and boundary adsorption force are introduced to optimize the energy function and achieve accurate grain size detection.
It improves the accuracy of grain size detection in forged gear metals, accurately captures weak boundaries and ignores internal texture interference, ensuring the precision of grain boundary segmentation.
Smart Images

Figure CN121095259B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology. Specifically, it relates to a method and system for detecting the grain size of forged gear metal. Background Technology
[0002] Forged gears are key load-bearing components in heavy equipment. Their mechanical properties are closely related to the size and morphology of the internal metal grains. Refined grains can significantly improve the strength and toughness of the material. Therefore, after forged gears undergo key manufacturing processes such as heat treatment, rapid and accurate quantitative testing of the metal grain size is an indispensable core technology for ensuring product quality and the safe operation of equipment.
[0003] To achieve automated detection, related technologies typically employ level set algorithms based on regional grayscale statistics, particularly the classic Chan-Vese model. The basic principle of this model is to evolve a closed curve to find the optimal boundary that can divide the image into several regions (such as grain regions and grain boundary regions). The criterion is to minimize the sum of the variances of the pixel grayscale values within each region, thereby enabling the detection of metal grains.
[0004] However, real metallographic images of forged gears often exhibit two challenging characteristics: First, due to the inhomogeneity of industrial rapid corrosion processes or the substructure inherent in the material itself, the interior of a single grain is not an ideal uniform grayscale region, but rather filled with subtle internal textures; second, due to factors such as differences in grain orientation and varying corrosion depths, the boundaries between grains exhibit characteristics of significant strength differences, including both clear strong boundaries and numerous blurred weak boundaries.
[0005] Since the energy function of the Chan-Vese model depends on a globally fixed regional gray-level consistency criterion, when using a globally unified criterion (minimizing the gray-level variance within the region) to handle such complex situations with distinct local features, if the weight of the criterion is increased in an attempt to capture weak boundaries, it will inevitably misjudge normal textures inside the grain as boundaries, leading to oversegmentation of the interior. Conversely, if the weight of the criterion is reduced to ignore the internal texture, it will inevitably lack sufficient power to identify and remain at the true weak boundaries, leading to undersegmentation of the exterior.
[0006] Therefore, since the energy function of this model lacks the ability to perceive the local structural characteristics of the image and the adaptive adjustment mechanism, it cannot accurately distinguish between internal textures that should be ignored and cross-grain level jumps that should be emphasized. A new detection method is urgently needed to solve the oversegmentation and undersegmentation problems of traditional CV models when processing complex metallographic images and improve the accuracy of grain size detection. Summary of the Invention
[0007] To address the problem that the lack of an adaptive adjustment mechanism in the energy function of the Chan-Vese model leads to oversegmentation of the interior and undersegmentation of the exterior when processing metallographic images with internal textures and weak boundaries, thereby reducing the accuracy of metal grain size detection, this invention proposes a method and system for detecting the metal grain size of forged gears.
[0008] In a first aspect, the present invention provides a method for detecting the grain size of forged gear metal, comprising:
[0009] The metallographic image of the forged gear to be inspected is acquired, and edge-preserving denoising is performed on the metallographic image to obtain a denoised image. Based on the local gradient structure information of the pixels in the denoised image, the boundary confidence of the pixels is determined to form a boundary confidence map.
[0010] An adaptive threshold segmentation is performed on the boundary confidence map to divide pixels into boundary pixels and non-boundary pixels. The average radius of the grain is determined based on the distance between the non-boundary pixels and their nearest boundary pixels. An adaptively sized structuring element is determined based on the average radius. The structuring element is used to process the denoised image through morphological reconstruction to generate a binary mask map representing the approximate grain region. This binary mask map is transformed into a signed distance function, which is used as the initial level set function to guide the evolution of the energy function of the Chan-Vese model.
[0011] Based on the global information entropy and pixel confidence values of the boundary confidence map, spatially adaptive region separation force weights and boundary adsorption force weights are generated. The generated region separation force weights and boundary adsorption force weights are applied to reconstruct the energy function of the Chan-Vese model. The initial level set function is iteratively updated to minimize the reconstructed energy function. The zero level plane of the level set function corresponding to the convergence of the energy function is taken as the grain boundary profile. The grain size level is calculated based on the grain boundary profile to complete the grain size detection.
[0012] This technical solution first purifies the original metallographic image through image preprocessing, filtering out random noise interference while fully preserving key structural information characterizing grain boundaries. Then, it deeply analyzes the local gradient structure information within the neighborhood of each pixel, calculating boundary confidence to reflect the probability that a pixel is located at a true crystal boundary, resulting in a structured confidence map. By analyzing its topological features, the average grain size is determined, and this scale information guides subsequent morphological reconstruction operations, generating a high-quality initial contour. Next, using the global statistical properties of the confidence map and the boundary confidence of each pixel, an energy function is reconstructed. This automatically enhances boundary attraction and suppresses region separation when each pixel is near a reliable boundary, and conversely, when it is far from a reliable boundary. By minimizing this energy function, which is sensitive to local image structure and has an adaptive adjustment mechanism, the evolution of the initial crystal contour is driven, accurately capturing true grain boundaries, including weak boundaries, effectively ignoring internal texture interference, and improving the accuracy of grain boundary segmentation and grain size detection.
[0013] Preferably, the method for performing edge-preserving denoising on metallographic images to obtain denoised images is as follows:
[0014] The Perona-Malik anisotropic diffusion algorithm is used to adaptively adjust the intensity of grayscale diffusion based on the gradient magnitude of pixels, so as to remove noise while preserving edges and obtain a denoised image.
[0015] Preferably, the boundary confidence of a pixel is determined based on the following method:
[0016] For each pixel, the gradient direction and gradient magnitude of all neighboring pixels are obtained to form the local gradient structure information of the pixel. The structure tensor of the pixel is determined based on the local gradient structure information. The first and second eigenvalues of the structure tensor are extracted. Based on the first and second eigenvalues, a response term representing the linear gradient strength of the pixel and a suppression term representing the noise probability of the pixel are constructed and multiplied together to determine the boundary confidence of the pixel.
[0017] This technical solution determines the boundary confidence level by using the structural tensor of pixels, transforming the gradient information of pixels from simple magnitudes into feature indicators that can reflect the local geometric structure. This enables a more accurate distinction between real grain boundaries with linear characteristics and internal textures and noise points with anisotropic or point-like characteristics, providing reliable structured prior information for the subsequent energy function.
[0018] Preferably, the average grain radius is determined based on the following method:
[0019] A distance map is constructed by comparing the distances between all non-boundary pixels and their nearest boundary pixels. Local maxima detection is performed on the distance map, and each non-boundary pixel corresponding to a local maximum is identified as a potential grain center. This local maximum is used as the radius estimate of the potential grain center. The boundary confidence of the potential grain center is queried from the boundary confidence map, and the center confidence of the potential grain center is determined by the negative correlation function of the boundary confidence. The radius estimate is used as the mean of the Gaussian kernel function, and the center confidence is used as the weight to construct a weighted kernel density estimation function with the radius variable as the independent variable. The radius variable corresponding to the maximum global probability density of the weighted kernel density estimation function is determined as the average radius of the grain.
[0020] This technical solution estimates the average grain radius from a macroscopic perspective by constructing a statistical model to find the peak value of the weighted kernel density estimation. Instead of simply averaging the estimates of all potential grain radii, it introduces weights based on boundary confidence to estimate the average radius that best represents the main grain size from the topology of the boundary confidence map, effectively avoiding the interference of outlier data on the statistical results.
[0021] Preferably, the method for determining an adaptive size structuring element based on the average radius is as follows: obtain the radius estimates of all potential grain center points, calculate the normalized standard deviation of the radius estimates, determine an adaptive size based on the normalized standard deviation and the average radius of the grain, the adaptive size is negatively correlated with the magnitude of the normalized standard deviation, and define a structuring element with a preset shape and the adaptive size as a template for morphological image processing.
[0022] Preferably, the region separation force weight and the boundary adhesion force weight are generated as follows: using an sigmoid activation function, with the boundary confidence of the pixel and the adaptive threshold of the boundary confidence map as input, the output of the activation function is used as the boundary adhesion force weight of the pixel; 1 minus the boundary adhesion force weight is used as the complementary term of the boundary adhesion force weight, and this complementary term is multiplied by the local texture suppression factor of the pixel to obtain the region separation force weight of the pixel; wherein, the local texture suppression factor of the pixel is determined based on the ratio of the variance of the gray values of all neighboring pixels to the mean of the variance.
[0023] This technical solution determines the spatially adaptive weights of the boundary adsorption term and the region separation term in the energy function. This allows the influence of the boundary adsorption term to be preferentially enhanced in regions identified as boundaries, ensuring that the update of the level set function can guide its zero-level plane (contour) to accurately converge to the high-confidence boundary position. Simultaneously, the weight of the region separation term introduces a local texture suppression factor, ensuring that its contribution is significant only under the strict conditions that pixels are both likely to be located inside the grain and that the local region is relatively smooth. This allows the iterative update process of the level set function to effectively drive contour movement in smooth regions (dominated by the region separation term) and accurately stabilize the contour at boundaries (dominated by the boundary adsorption term), while also actively suppressing the amount of update caused by incorrect contour deformation due to internal texture, thereby improving the accuracy of grain segmentation.
[0024] Preferably, the S-shaped activation function further includes an adaptive sensitivity coefficient for adjusting the switching sensitivity. The adaptive sensitivity coefficient is determined based on the following method: calculating the global information entropy of the boundary confidence map by statistically analyzing the probability distribution of all boundary confidence scores; and determining the adaptive sensitivity coefficient based on the global information entropy and the theoretical maximum entropy determined when calculating the global information entropy, wherein the value of the adaptive sensitivity coefficient is negatively correlated with the global information entropy and positively correlated with the theoretical maximum entropy.
[0025] Preferably, the energy function of the Chan-Vese model is reconstructed by applying the generated region separation force weights and boundary adsorption force weights as follows: the global weights of the data items used to distinguish whether a pixel belongs to an internal region or a boundary region in the energy function of the Chan-Vese model are replaced with region separation force weights. At the same time, a boundary adsorption energy term composed of boundary confidence and boundary adsorption force weights is added to the energy function of the Chan-Vese model.
[0026] This technical solution reconstructs the energy function of the Chan-Vese model. Through the synergistic effect of weight replacement and the addition of boundary adsorption energy terms, the reconstructed energy function can accurately distinguish whether a pixel is located at a real grain boundary or inside a crystal in different image regions based on the structural features of the image, thus achieving precise segmentation of complex metallographic images.
[0027] Preferably, the calculation of grain size grade based on grain boundary profile includes:
[0028] Connectivity analysis is performed on the grain boundary profile to identify and count each individual grain region; the average number of grains per unit area is calculated using the area method, and the average number of grains is substituted into the standard grain size grade calculation formula to determine the final grain size grade.
[0029] Secondly, the present invention also provides a grain size detection system for forged gear metal, the system comprising a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of any method for detecting the grain size of forged gear metal.
[0030] The present invention has the following effects:
[0031] This invention reconstructs the classic Chan-Vese energy function by optimizing the global weights of the data terms used to distinguish whether a pixel belongs to an internal or boundary region. This reconstructs the energy function into a spatially adaptive region separation force weight. Furthermore, it introduces a boundary energy adsorption term constructed from the global information entropy of the image and the boundary confidence of the pixel. This allows the model to dynamically balance region separation and boundary adsorption at the pixel level when segmenting crystal contours. It can accurately capture weak boundaries while ignoring internal texture interference, thereby improving the accuracy of metal grain size detection for forged gears. Attached Figure Description
[0032] Figure 1 This is a flowchart of the present invention;
[0033] Figure 2 These are metallographic images of the forged gear of the present invention;
[0034] Figure 3 This invention performs edge-preserving denoising on metallographic images to obtain a denoised image;
[0035] Figure 4 It is an approximate contour formed by the zero level plane of the initial level set function;
[0036] Figure 5 This is the final segmented grain boundary contour image of the present invention;
[0037] Figure 6 It is the grain boundary contour image that is finally segmented by the traditional model. Detailed Implementation
[0038] Reference Figure 1 A method for detecting the grain size of forged gear metal, specifically including the following steps:
[0039] S1: Obtain the metallographic image of the forged gear to be inspected, and perform edge-preserving denoising on the metallographic image to obtain a denoised image.
[0040] Metallographic images of forged gears are acquired. Since random noise is inevitably introduced during the acquisition process, the Perona-Malik anisotropic diffusion algorithm is used to perform edge-preserving denoising on the metallographic images. Noise and real grain boundaries (especially weak boundaries) in metallographic images may both appear as high-gradient regions. Traditional Gaussian filtering will indiscriminately blur all high-frequency information, making weak boundaries even more difficult to identify while filtering out noise. The Perona-Malik algorithm has a larger diffusion coefficient in flat regions of the image (small gradient magnitude) to perform strong diffusion to smooth noise; while in the boundary regions of the image (large gradient magnitude), the diffusion coefficient is smaller to suppress diffusion and protect the clarity of the edges.
[0041] In this way, this step can effectively filter out random noise while maintaining the clarity and contrast of grain boundaries, providing a high-quality noise-reduced image source.
[0042] Reference Figure 2 The image shows a metallographic image of the forged gear to be inspected, obtained in this embodiment. There are blurred weak boundaries between the grains, and black spots caused by corrosion or material substructure. Figure 3 The image shows the denoised image obtained after edge-preserving denoising of the metallographic image.
[0043] S2: Based on the local gradient structure information of each pixel in the denoised image, determine the boundary confidence of each pixel to form a boundary confidence map.
[0044] In one embodiment, the boundary confidence of each pixel is determined based on the structure tensor: for each pixel in the denoised image, the gradient direction and gradient magnitude of all neighboring pixels (eight-neighborhood) of that pixel are obtained to form the local gradient structure information of that pixel.
[0045] Determine the structure tensor of the pixel based on the local gradient structure information. ,For example:
[0046]
[0047] in, It is a Gaussian smoothing kernel. This is the convolution operator, which means using... This Gaussian smoothing kernel is used for smoothing. Each element in the matrix, The grayscale function represents the image and is used to output the grayscale value of each pixel. It is the gradient operator. Represents the gradient of the image, used to output the gradient vector for each pixel. , The gradient vector of a pixel in directional components, The gradient vector of a pixel in directional components, It is the operator for tensor product / cross product. The gradient vector of a pixel and its tensor product / outer product form a... The matrix, The gradient vector of all neighboring pixels of a pixel. The sum of squares of the directional components, The gradient vector of all neighboring pixels of a pixel. The sum of squares of the directional components,
[0048] The gradient vector of all neighboring pixels of a pixel. Components of direction The sum of the products of the directional components.
[0049] Using matrix eigenvalue decomposition techniques to analyze the structure tensor Perform eigenvalue decomposition to obtain two eigenvalues. and They quantitatively describe the gradient distribution within the neighborhood: This represents the gradient intensity along the direction of the fastest gradient change within the neighborhood of a pixel. Represents the neighborhood of a pixel and The gradient intensity in the vertical direction. By comparing... and The magnitude of the gradient can initially distinguish whether the neighborhood of a pixel is a flat region, an edge line, or corner noise. Flat regions have very small gradients. and They are all very small, approaching 0, and in the edge / grain boundary regions, the gradient is strong only in one direction. It's very big. Approaching 0, corner / noise region, gradient is strong in all directions. and Both are very large, and the two are similar in size.
[0050] Next, based on the first and second eigenvalues of the structure tensor of the pixel, a response term representing the gradient linear feature strength of the pixel and a suppression term representing the noise probability of the pixel are multiplied together to jointly determine the boundary confidence of the pixel.
[0051] Specifically, the following relationship is satisfied:
[0052]
[0053] in, This represents the boundary confidence score for a pixel. The boundary confidence score reflects the probability that a pixel belongs to a true grain boundary, effectively distinguishing grain boundaries from texture or noise points within the grain, and providing reliable structured prior information. The value range is [0,1]. and Let these be the first and second eigenvalues of the structure tensor of the pixel. It is a response term that characterizes the intensity of the gradient linear feature of that pixel. This is a suppression term characterizing the noise probability of that pixel. and These are the built-in adjustment coefficients for the response and inhibition terms, respectively. It is a natural constant.
[0054] in, and It was determined based on the following method:
[0055] Obtain the structure tensor of each pixel and Calculate each pixel and , The linear feature strength used to reflect the local gradient distribution of this pixel. This reflects the isotropic nature of the local gradient distribution of a pixel, i.e., the feature intensity of noise, corner points, or internal texture, and applies to all pixels. The reciprocal of the mean, as All pixels The reciprocal of the mean, as If the edges of the denoised image are blurry, The mean will be very small, leading to This is very large, thus amplifying the response to weak edges. In subsequent calculations of boundary confidence, a large [value]... This amplifies the response to these subtle edge features, ensuring that even blurred grain boundaries can be effectively identified. If the denoised image still retains a significant amount of random noise, or if the grains contain rich substructures (internal texture), these factors will cause... The mean is very large. The corresponding size becomes very small, a small It will reduce the formula's effectiveness This improves the algorithm's sensitivity to noise and internal textures, preventing them from being misidentified as boundaries.
[0056] In the boundary confidence relation, the eigenvalues of the structure tensor contain rich local geometric information. This formula is composed of the product of the response term and the suppression term. middle,
[0057] The magnitude of the gradient reflects the degree of linear concentration of the gradient distribution in the neighborhood of a pixel. For an ideal linear grain boundary, the gradient is concentrated in one direction. , The value is very large, causing the response term to approach 1. For flat regions, For corner points / noise, Whether it's a flat area or a corner / noise, it will cause... Approaching 0, the response term approaches 0. In the suppression term... In the middle, due to the flat area , A value close to 0 will cause the suppression term to approach 1. Ideally, a line boundary has a very small gradient response in the vertical direction. It is very small, close to 0, causing the suppression term to approach 1. For corner points or isolated noise points, and They are all relatively large. A larger value causes the inhibitory term to approach 0, thus exerting an inhibitory effect.
[0058] Thus, through the linkage analysis of this formula, it can be seen that a pixel is considered valid only when it simultaneously satisfies both the conditions of "the gradient has a strong linear characteristic" and "it is not a corner point or noise". and At that time, its boundary confidence level The higher the probability that a pixel belongs to a real grain boundary, the closer the boundary confidence will be to 1. Conversely, the lower the probability that a pixel belongs to a real grain boundary, the more likely it is to be a texture or noise point inside the grain.
[0059] Finally, after obtaining the boundary confidence scores of all pixels, the boundary confidence scores of all pixels together constitute a boundary confidence map.
[0060] S3: Perform adaptive threshold segmentation on the boundary confidence map to divide boundary pixels into non-boundary pixels and determine the average radius of the grains.
[0061] In one embodiment, the Otsu threshold segmentation method is used to perform adaptive threshold segmentation on the boundary confidence map, dividing the pixels into boundary pixels and non-boundary pixels. That is, pixels with a boundary confidence less than the adaptive threshold are considered non-boundary pixels, and pixels with a boundary confidence not less than the adaptive threshold are considered boundary pixels.
[0062] In one embodiment, the average grain radius is determined based on the following:
[0063] For each non-boundary pixel, find the nearest boundary pixel and calculate the distance between them. In this way, each non-boundary pixel will have a distance. The distances between all non-boundary pixels and their nearest boundary pixels form a distance map.
[0064] Local maximum detection is performed on the distance map to obtain all local maxima in the distance map. The non-boundary pixel corresponding to each identified local maximum is taken as a potential grain center, and each local maximum is taken as a radius estimate corresponding to a potential grain center.
[0065] The boundary confidence of each potential grain center is queried based on the boundary confidence map. The center confidence of the potential grain center is determined by the negative correlation function of the boundary confidence. Specifically, the boundary confidence is subtracted from 1 to obtain the center confidence of the potential grain center. This is because the boundary confidence reflects the probability that the potential grain center is located on the boundary. Subtracting this probability from 1 is just enough to reflect the probability that the potential grain center is located at the grain center.
[0066] The radius estimate is used as the mean of the Gaussian kernel function, and the center confidence is used as the weight to construct a weighted kernel density estimation function with the radius variable as the independent variable. The radius variable corresponding to the maximum global probability density obtained by the weighted kernel density estimation function is determined as the average radius of the grain.
[0067] Specifically, the following relationship is satisfied:
[0068]
[0069] in, The average radius of the grain. For the first A potential grain center The number of all potential grain centers. for The radius estimate, which acts as the mean (center point) of the Gaussian kernel function in the formula. For Gaussian kernel function, The bandwidth parameter of the Gaussian kernel function is usually calculated automatically using statistical rules, based on Silverman's rule of thumb. ,in, It is the standard deviation of the radius estimates of all potential grain center points. It is the total number of potential grain centers. For the radius variable, It is a by and The Gaussian kernel function, which is the parameter, is a bell-shaped curve function. Controlling the width of the bell curve will give it a single, discrete radius estimate. Mapped to a Centered on, with a width of The continuous probability distribution allows similar radius estimates to be superimposed. yes The center confidence score is crucial; a higher center confidence score indicates a more likely true grain center. It determines the height of the Gaussian kernel function. The higher the value, the higher the bell curve, and the greater its contribution to the total. The value is very low; the bell curve is very short and has almost no effect. By performing a summation operation, the value is reduced to a minimum. A process The weighted bell curves, when superimposed, generate a single, continuous global radius probability density map. On this map, those with high confidence levels and similar values... They will gather together and form a very high mountain peak. It is about finding the radius value that most reliable radius estimates point to. ,make The largest part of the value The operation involves searching the global radius probability density map to find the peak value of the highest peak and returning the value corresponding to that peak. The value is determined as the average radius of the grain.
[0070] This relationship uses a statistical voting method to find the most representative radius estimate among all potential grain radius estimates and defines it as the grain's average radius. The reason for using this weighted kernel density estimation method to determine the average radius is that a simple arithmetic mean is susceptible to outliers. In metallographic images, texture or noise points within the grain may be incorrectly identified as potential grain centers, but the boundary confidence of these pixels is usually relatively high (because they are texture or noise). By introducing center confidence for weighting, the weight of these pixels can be adjusted. To reduce their size, thus decrease their impact on statistics.
[0071] Thus, the estimated average radius It can represent the size of the main grains in the image, is robust to pseudo grain centers caused by internal textures or noise, and the estimation results are more reliable.
[0072] S4: Determine an adaptively sized structuring element based on the average radius of the grains. Using the structuring element, process the denoised image through morphological reconstruction to generate a binary mask map representing the approximate grain region.
[0073] In one embodiment, the method for determining the adaptive-sized structural element is as follows:
[0074] Obtain a set of radius estimates for all potential grain center points, and calculate the normalized standard deviation of this set. Based on the normalized standard deviation and average grain radius Together determine an adaptive size Adaptive sizing with normalized standard deviation The numerical values are negatively correlated.
[0075] Specifically, , This reflects the uniformity of grain size in the image. When the grain size is very uniform, The smaller the value, the closer it is to 0, indicating that the grain sizes in the image are similar. Approaching R allows for the use of a larger, adaptive size close to R to construct structural elements, enabling efficient removal of noise and small artifacts in subsequent morphological processing. When grain size differences are significant, Large grains indicate the presence of both large and small grains in the image. Automatically shrinking the size and using more conservative structural element dimensions to avoid mistakenly removing small but real grains during processing.
[0076] In this way, by defining a disk-shaped structuring element with the adaptive size as a template for morphological image processing, subsequent processing can better adapt to the grain distribution characteristics of different metallographic images. Using the structuring element, the denoised image is processed through morphological reconstruction to generate a binary mask map to represent the approximate grain region.
[0077] Specifically, morphological reconstruction in the field of image processing is usually referred to as morphological opening operation in a reconstruction manner. This operation can remove noise while preserving the original outline of grains that have not been completely removed. The process is divided into two stages: the first is the erosion stage, in which a standard erosion is performed on the denoised image using disk-shaped structuring elements of adaptive size to eliminate all noise points smaller than the size and break weak bridging. The output of this step is called the labeled image.
[0078] The reconstruction stage then begins. In this stage, the labeled image is used as a seed and the original denoised image is used as a constraint to perform iterative morphological dilation, continuously dilating the labeled image. However, the grayscale value of the expanded pixels is restricted from exceeding the grayscale value of the corresponding position in the denoised image. After the reconstruction stage converges, a grayscale image that retains all surviving grain regions is obtained.
[0079] Next, the grayscale image is converted into a binary mask image through a thresholding process (e.g., Otsu thresholding). Here, "binary" means that the image consists only of foreground and background values, and "mask" indicates that the image will be used as a template for subsequent processing. The binary mask image provides an initial outline of a high-quality, noise-free grain region.
[0080] In this step, the purpose of morphological operations is not to perfectly match the irregular polygonal contours of the grain itself, but to use the adaptive size of the structural element to achieve three functions: removing all noise points smaller than the size, smoothing the tiny burrs at the grain boundaries, and breaking the subtle bridging (weak boundaries) that may exist between two grains. Therefore, the core reason for choosing a disk shape as a template is that it is isotropic. A disk is symmetrical in all directions. When morphological operations are performed using this template, it can shrink or smooth the boundaries to the same extent in all directions, avoiding the directional deviations introduced by square structural elements, thus matching the characteristic of grains growing randomly in all directions on a macroscopic scale.
[0081] S5: Transform the binary mask image into a symbolic distance function, which serves as the initial level set function to guide the evolution of the energy function in the Chan-Vese model.
[0082] The transformation of the generated binary mask image into a symbolic distance function is crucial, as it provides an ideal initial level set function for the subsequent evolution of the Chan-Vese model. This is because the Chan-Vese model is an evolutionary algorithm based on partial differential equations, which requires a continuous and differentiable function (i.e., the level set function). Operations are performed on the binary mask, but the binary mask is discrete and its edges are stepped, so it cannot be directly used for the evolution of partial differential equations.
[0083] This step involves constructing a smooth, continuous function whose zero level precisely corresponds to the outline of the binary mask image. According to its strict definition, the symbolic distance function... The function value must be negative inside the foreground region (i.e., the approximate grain region) represented by the binary mask, positive outside the region, and zero at the boundary. Simultaneously, the absolute value of the function must be equal to the Euclidean distance from the pixel to the nearest boundary.
[0084] Specifically, this is achieved through distance transformation. First, all boundary pixels in the binary mask are identified. If a pixel is itself a foreground pixel and has at least one background pixel in its eight-neighborhood, it is treated as a boundary pixel in the binary mask, thus obtaining a set of boundary pixels. Then, each foreground pixel is traversed, and the nearest boundary pixel is found and its distance is calculated. The distances between all foreground pixels and their nearest boundary pixels form a distance map, called the internal distance map D1. Simultaneously, each background pixel is traversed, and the nearest boundary pixel is found and its distance is calculated. The distances between all background pixels and their nearest boundary pixels form a distance map, called the external distance map D2. By assigning the correct signs to these two distance maps, they are combined into the final signed distance function. That is, for foreground pixels For background pixels, , yes exist The function value of the pixel at that location. yes The pixel at that location The distance value in the middle, yes The pixel at that location The distance values in the initial level set function, the zero level surface, constitute the approximate profile of the grain boundary. The zero level surface is a mathematical term that refers to... The set of all pixels with a value of 0. The function is negative inside the region (approximately grain region) and positive outside the region. Therefore, the only place where the function value is 0 must be the boundary where the inside and outside intersect. Thus, the zero level plane is the mathematical synonym of the profile.
[0085] This completes a crucial data transformation, converting the reliable and noise-free discrete contour from step S4 into a smooth and differentiable function. This high-quality initial function provides an extremely stable and accurate starting point for the subsequent energy function minimization evolution, thereby ensuring the accuracy of grain boundary segmentation and accelerating the convergence of the algorithm.
[0086] Reference Figure 4 The shape of the signed distance function is visualized. Figure 4 The dark areas in the graph represent regions with larger signed distance function values, approximating the central region of the grain. The light-colored boundary contours between the dark areas represent the zero level of the signed distance function, and the pixels at the intersections form the approximate contours of the grain boundaries.
[0087] S6: Based on the global information entropy of the boundary confidence map and the confidence value of each pixel, generate spatially adaptive region separation force weights and boundary adsorption force weights.
[0088] In one embodiment, the spatially adaptive region separation force weight and boundary adhesion force weight for each pixel are generated based on the following method:
[0089] Using a sigmoid activation function, with the pixel boundary confidence score and the adaptive threshold of the boundary confidence map as input, the output of the activation function is used as the boundary adhesion weight of the pixel. The specific relationship is as follows:
[0090]
[0091] in, It is the boundary adhesion weight of that pixel. It is the hyperbolic tangent function, i.e., the sigmoid activation function. It is the boundary confidence of a pixel. An adaptive threshold for the boundary confidence map. It is the hyperbolic tangent function. It is a sensitivity coefficient used to adjust the tendency of a pixel to adhere to the boundary.
[0092] When the boundary confidence Greater than the adaptive threshold When the confidence level is higher, it indicates that the pixel is more likely to be located in the boundary region of high confidence. The input is a positive number, and the output approaches 1. The larger the value, the closer it is to 1, indicating that the boundary adhesion force is activated; when the boundary confidence is not greater than the adaptive threshold, it means that the pixel is more likely to be located in the internal region of the grain. When the input is a negative number, the output value tends to be -1. The smaller the value, the closer it is to 0, and the boundary adsorption force is closed.
[0093] Subtracting the boundary adhesion force weight from 1 yields a complementary term to the boundary adhesion force weight. This complementary term is then multiplied by the local texture suppression factor of the pixel to obtain the region separation force weight of the pixel. The local texture suppression factor of the pixel is determined based on the ratio of the variance of the grayscale values of all neighboring pixels to the mean of that variance, as shown in the following formula:
[0094]
[0095] in, This represents the region separation force weight for that pixel. This is the local texture suppression factor for that pixel. , The variance of the grayscale values of all neighboring pixels of a given pixel is denoted as the local grayscale variance of that pixel. This represents the mean of the local grayscale variances of all pixels. It is a natural constant. This represents the boundary adhesion force weight of the pixel. Controlled by two parts: They are complementary, ensuring that with The complementarity of pixels, when the pixel is located in the boundary region Approaching , Approaching Disable regional separation force; when the pixel is located in the internal region of the grain, Approaching 0, When the value approaches 1, the regional separation force is activated. Yes The key modulation, when the pixel is located in the internal region of the grain. If the local grayscale variance of the pixel approaches 0, then... The larger the pixel, the more likely it is to be located in the texture of the crystal's interior region. It will become smaller, thereby suppressing the regional separation force. Error response to internal texture.
[0096] Among them, the sensitivity coefficient It was determined based on the following method:
[0097] The probability distribution of all boundary confidence scores in the boundary confidence map is statistically analyzed to calculate the global information entropy of the boundary confidence map. Based on this global information entropy and the quantization level used when calculating information entropy. Determined theoretical maximum entropy Together, they determine the adaptive sensitivity coefficient. Specifically, by adjusting this adaptive sensitivity coefficient... The numerical value and global information entropy The negative correlation between the theoretical maximum entropy and the theoretical maximum entropy The positive correlation, calculate an adaptive :
[0098]
[0099] in, To prevent the denominator from being zero, the parameter is usually set to a very small positive number. .
[0100] The reason for using this method to obtain the sensitivity coefficient is that the global information entropy reflects the complexity of the boundary confidence map. If the global information entropy is high, it means that the distinction between boundaries and non-boundaries in the image is very low, the image quality is poor, and the boundaries are blurred. In this case, a smoother transition is needed. The smaller the value, the better. If the global information entropy is very low, it indicates good image contrast and clear boundaries, so a steeper toggle should be used. The larger it is, the more it achieves The adaptive value allows it to automatically adjust the sensitivity of the switching function based on the overall quality of the metallographic image.
[0101] S7: Reconstruct the energy function of the Chan-Vese model by applying the regional separation force weights and the boundary adsorption force weights.
[0102] First, the energy function of the traditional Chan-Vese model will be explained. The aim is to find a level set function To minimize the following overall energy function:
[0103]
[0104] in, This represents the total energy of the CV model that needs to be minimized. It consists of two parts:
[0105] The first part is the regularization term, that is... This function is to maintain the smoothness of the evolution curve. The second part is the data item, namely... This term, also known as the region separation force, is used to find a boundary that minimizes the sum of the gray-level variances of the regions inside and outside the contour. It is a level set function, with its zero level surface. This refers to the evolving grain boundary profile. and They are the interior of the outline. and external areas The average grayscale value of the pixels. It is a fixed weighting coefficient used to adjust the strength of the regularization term. Represents the entire image domain, and integration is performed over the entire image domain. It is the Heaviside function, a step function, when hour, ,when hour, , It is the gradient operator, used to calculate the rate of change. It represents the length of the outline. It is the grayscale function of an image, outputting the grayscale value of each pixel. It is a global, fixed weight used to adjust data items. In most traditional models, It is usually set to 1. The value is relative to It is determined, since It is usually 1. It must be a value less than 1.0 to prevent over-smoothing, and is usually set between 0.1 and 0.5. = 0.2 is a common setting.
[0106] The drawback of traditional models is that they are globally fixed. It cannot perceive the local structural characteristics of an image, resulting in the processing of images with internal textures (requiring low latency). ) and weak boundaries (requiring high When dealing with complex metallographic images, it can result in either oversegmentation of the inner surface or undersegmentation of the outer surface.
[0107] In one embodiment, the method for reconstructing the energy function of the model is as follows:
[0108] Will Global weights used to adjust data items Replace with spatially adaptive region separation force weights ,exist In the middle, add a weighted factor composed of boundary confidence and boundary attraction force. The boundary adsorption energy term formed by the two.
[0109] Therefore, the reconstructed energy function Example as follows:
[0110]
[0111] Reconstructed energy function The functions of each part are described below:
[0112] Regular terms, The functionality remains unchanged, and is retained to ensure a smooth outline.
[0113] Data item, It uses the region separation force weight. Replaced the fixed , It includes local texture suppression factors When a pixel is located in a textured region inside a grain, Reduced, leading to By reducing the size of the model, the regional separation force in the internal texture area is actively suppressed, thereby ignoring the internal texture and solving the problem of oversegmentation of the interior.
[0114] The newly added boundary adsorption energy term, This term is a result of the increase in the energy term, and its driving force does not depend on the regional grayscale statistics. Instead, it is determined by geometric features (boundary confidence). and boundary adsorption force weight This is driven by both factors. When a pixel is located at a true weak boundary, although the grayscale difference is small, its boundary confidence is high. High boundary confidence will activate high... It generates a strong suction force at the real boundary, pulling the contour together. By locking onto the weak boundary, the problem of under-segmentation was solved.
[0115] In this way, the energy function can dynamically balance the two forces of region separation (dominated by the second term) and boundary adsorption (dominated by the third term) at the pixel level, thus achieving accurate segmentation of complex metallographic images.
[0116] S8: Minimize the energy function after step reconstruction by iteratively updating the initial level set function. Use the zero level surface of the level set function corresponding to the convergence of the energy function as the grain boundary profile, and perform grain size detection based on the grain boundary profile.
[0117] In one embodiment, minimizing the reconstructed energy function The process is achieved by solving a partial differential equation representing its gradient descent flow, which is standard in the field for evolving the level set function through numerical optimization. The process, the evolution equation is:
[0118]
[0119] in, represent The goal is to derive the update direction and rate at each pixel, and to determine the values on the right. It is determined by the three parts of the reconstructed energy function. Substituting the three energy terms of the reconstructed energy function into the equation yields the complete evolution process. It is the Dirac function, used to locate the zero horizontal plane. The smoothing force is a regularization term derived from the reconstructed energy function, used to maintain contour smoothness. It is the adaptive region separation force, derived from the data terms of the reconstructed energy function, and is subject to... Modulation to actively ignore internal texture. The newly added boundary adsorption force comes from the boundary adsorption energy term of the reconstructed energy function, and is subject to... The drive is used to precisely lock weak boundaries.
[0120] The specific numerical implementation of iterative minimization is performed by repeatedly executing the following steps:
[0121] Initialization: The initial level set function generated in step S5 is used. As the first Level set function of degree .
[0122] Iteration begins: based on the current Calculate the interior of the contour and external gray mean and For each pixel in the image, using , and , Substituting the parameters into the complete evolution equation, the following calculations are performed. And sum them up to get the total update rate. ;
[0123] Convergence determination: Choose a small step size , This represents how short a time it takes for the allowed function to evolve at this rate, because It is an instantaneous rate, if If the step size is too large, a single update can easily cross the correct minimum energy value, causing the algorithm to fail to converge accurately and in a timely manner, oscillating around the minimum value. Therefore, to ensure numerical stability, a small step size is set. This ensures that each iteration progresses smoothly and incrementally towards the correct convergence direction. Specifically, updates are performed using first-order differences based on the step length:
[0124]
[0125] Check for convergence: If and The change is less than a very small threshold of 0.01, or the number of iterations. After reaching the preset maximum value of 500 times, the energy function converges, the iteration stops, and the final level set function is obtained. If it does not converge, , to proceed with the first This is the second iteration; if it converges, it will eventually converge. All of the above satisfy The set of pixels ( The corresponding zero level plane is defined as the final grain boundary profile.
[0126] Through the detailed process described above, an iterative process based on the numerical solution of partial differential equations is employed. This iterative process, through the dynamic balance and synergistic effect of three forces (smoothing force, adaptive region separation force, and boundary adhesion force) at the pixel level, drives the initial contour to evolve precisely and lock onto the actual grain boundaries, thereby minimizing the reconstructed energy function. This yielded high-precision segmentation results.
[0127] Reference Figure 5 and Figure 6 The effects of this invention and traditional CV models are compared. Figure 6 The final grain boundary contour image is shown when the denoised image is segmented using the traditional Chan-Vese model. While capturing the true boundaries, it also misclassifies all black spots with similar energy as boundaries. The segmentation result is full of pseudo-contours and noise points caused by internal textures. This noise destroys the grain region and affects the accuracy of subsequent connected component analysis and grain size calculation. Figure 5 The final grain boundary contour image using the present invention is shown. By reconstructing the energy function, interference from internal texture regions is actively suppressed. At the same time, by using boundary confidence and boundary adsorption force weights, the contour can be accurately locked on weak boundaries. The final segmentation result ignores internal texture noise points while preserving continuous grain boundary contours.
[0128] In one embodiment, calculating the grain size grade based on grain boundary profiles includes: performing connected component analysis on the grain boundary profiles to identify and count each independent, closed grain region, and calculating the average number of grains per unit area using an area method. The area method is one of the standard grain size rating methods specified in the national standard. This method calculates the average number of grains obtained through statistical analysis. Substitute into the standard grain size grade calculation formula In order to determine the final grain size grade. This enables automated and standardized testing of grain size.
[0129] The present invention also provides a grain size detection system for forged gear metal, comprising: a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions, when executed by the processor, implement the steps of the grain size detection method for forged gear metal.
[0130] The processor may be a central processing unit, a graphics processing unit, an application-specific integrated circuit (ASIC), or a field-programmable gate array (FPGA). The memory may be volatile memory (such as random access memory, RAM) or non-volatile memory (such as read-only memory, hard disk, or solid-state drive).
[0131] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for detecting the grain size of forged gear metal, characterized in that, include: The metallographic image of the forged gear to be inspected is acquired, and edge-preserving denoising is performed on the metallographic image to obtain a denoised image. Based on the local gradient structure information of the pixels in the denoised image, the boundary confidence of the pixels is determined to form a boundary confidence map. An adaptive threshold segmentation is performed on the boundary confidence map to divide pixels into boundary pixels and non-boundary pixels. The average radius of the grain is determined based on the distance between the non-boundary pixel and its nearest boundary pixel. The radius estimates of all potential grain center points are obtained, and the normalized standard deviation of the radius estimates is calculated. An adaptive size is determined based on the normalized standard deviation and the average grain radius. The adaptive size is negatively correlated with the magnitude of the normalized standard deviation. A structuring element with a preset shape and the adaptive size is defined as a template for morphological image processing. The structuring element is used to process the denoised image through morphological reconstruction to generate a binary mask map representing the approximate grain region. The binary mask map is transformed into a signed distance function, which is used as the initial level set function to guide the energy function evolution process of the Chan-Vese model. Based on the global information entropy of the boundary confidence map and the confidence value of the pixel, an sigmoid activation function is used. The boundary confidence of the pixel and the adaptive threshold of the boundary confidence map are used as inputs, and the output of the activation function is used as the boundary adsorption force weight of the pixel. The boundary adsorption force weight is subtracted from 1 to obtain the complementary term of the boundary adsorption force weight. This complementary term is multiplied by the local texture suppression factor of the pixel to obtain the region separation force weight of the pixel. The local texture suppression factor of the pixel is determined based on the ratio of the variance of the gray values of all neighboring pixels to the mean of that variance. The global weight of the data term used in the energy function of the Chan-Vese model to distinguish whether a pixel belongs to an internal or boundary region is replaced with the region separation force weight. Simultaneously, a boundary adsorption energy term composed of the boundary confidence and the boundary adsorption force weight is added to the energy function of the Chan-Vese model. The initial level set function is iteratively updated to minimize the reconstructed energy function. The zero level plane of the level set function corresponding to the convergence of the energy function is used as the grain boundary profile. The grain size level is calculated based on the grain boundary profile to complete the grain size detection.
2. The method for detecting the grain size of forged gear metal according to claim 1, characterized in that, The method for edge-preserving denoising of metallographic images to obtain denoised images is as follows: The Perona-Malik anisotropic diffusion algorithm is used to adaptively adjust the intensity of grayscale diffusion based on the gradient magnitude of pixels, so as to remove noise while preserving edges and obtain a denoised image.
3. The method for detecting the grain size of forged gear metal according to claim 1, characterized in that, The boundary confidence of a pixel is determined based on the following method: For each pixel, the gradient direction and gradient magnitude of all neighboring pixels are obtained to form the local gradient structure information of the pixel. The structure tensor of the pixel is determined based on the local gradient structure information. The first and second eigenvalues of the structure tensor are extracted. Based on the first and second eigenvalues, a response term representing the linear gradient strength of the pixel and a suppression term representing the noise probability of the pixel are constructed and multiplied together to determine the boundary confidence of the pixel.
4. The method for detecting the grain size of forged gear metal according to claim 1, characterized in that, The average grain radius is determined based on the following method: A distance map is constructed by comparing the distances between all non-boundary pixels and their nearest boundary pixels. Local maxima detection is performed on the distance map, and each non-boundary pixel corresponding to a local maximum is identified as a potential grain center. This local maximum is used as the radius estimate of the potential grain center. The boundary confidence of the potential grain center is queried from the boundary confidence map, and the center confidence of the potential grain center is determined by the negative correlation function of the boundary confidence. The radius estimate is used as the mean of the Gaussian kernel function, and the center confidence is used as the weight to construct a weighted kernel density estimation function with the radius variable as the independent variable. The radius variable corresponding to the maximum global probability density of the weighted kernel density estimation function is determined as the average radius of the grain.
5. The method for detecting the grain size of forged gear metal according to claim 1, characterized in that, The S-type activation function also includes an adaptive sensitivity coefficient for adjusting the switching sensitivity, which is determined based on the following method: The probability distribution of all boundary confidence scores in the statistical boundary confidence map is used to calculate the global information entropy of the boundary confidence map. Based on this global information entropy and the theoretical maximum entropy determined when calculating the global information entropy, an adaptive sensitivity coefficient is jointly determined. The value of this adaptive sensitivity coefficient is negatively correlated with the global information entropy and positively correlated with the theoretical maximum entropy.
6. The method for detecting the grain size of forged gear metal according to claim 1, characterized in that, Grain size classification is calculated based on grain boundary profiles, including: Connectivity analysis is performed on the grain boundary profile to identify and count each individual grain region; the average number of grains per unit area is calculated using the area method, and the average number of grains is substituted into the standard grain size grade calculation formula to determine the final grain size grade.
7. A grain size detection system for forged gear metal, characterized in that, The method includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method for detecting the grain size of forged gear metal as described in any one of claims 1-6.
Citation Information
Patent Citations
A fast image segmentation method and device based on Bayesian estimation and a level set
CN109559328A