A quantitative detection and rating method of metallographic structure based on adaptive region diffusion
Patent Information
- Application Number
- CN202611048651.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-15
- Publication Date
- 2026-08-18
AI Technical Summary
[0004]本发明提供一种基于自适应区域扩散的金相组织定量检测评级方法,用以解决现有技术中存在的复杂金相图像中因晶界模糊或断裂导致的过分割与欠分割、以及自动检测准确率低等问题
[0015] This invention provides a quantitative detection and rating method for metallographic structures based on adaptive region diffusion. It utilizes local structural directional features for directional smoothing and denoising, and organically integrates first-order gradient fields and second-order discontinuity features to construct a grain boundary constraint matrix. This effectively overcomes the shortcomings of traditional methods in identifying blurred or fractured grain boundaries. Simultaneously, by employing a multi-dimensional geometric distance field and a topological seed point denoising and merging mechanism, it eliminates misjudgments caused by texture artifacts within the structure at the source. Furthermore, it introduces an adaptive dynamic control mechanism of geometric contours and boundary hindrance during spatial iterative expansion, achieving precise advancement and perfect convergence of the expansion front. This thoroughly solves the over-segmentation and under-segmentation problems that easily occur in complex metallographic images, significantly improving the accuracy and robustness of irregular topological target area segmentation. Ultimately, it ensures the objectivity, efficiency, and extremely high industrial accuracy of the quantitative detection and rating results for metallographic structures.
Smart Images

Figure CN122591484A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of metallographic testing technology, and more specifically to a quantitative detection and rating method for metallographic structures based on adaptive region diffusion. Background Technology
[0002] Metallographic analysis is a crucial method for evaluating the mechanical properties and processing quality of metallic materials in materials science research and industrial manufacturing. Accurate segmentation and quantitative detection and rating of grain boundaries in metallographic structures are essential for predicting material fatigue life, controlling grain size, and optimizing heat treatment processes. With the rapid development of computer vision and digital image processing technologies, the use of computer algorithms for automated edge extraction and region segmentation of microscopic metallographic images has gradually replaced traditional manual microscopic visual comparison methods, becoming the mainstream technological trend for improving the efficiency and objectivity of materials testing results.
[0003] However, in actual working conditions, due to the limitations of metal sample preparation processes, the degree of chemical etching, and the quality of microscopic imaging, the acquired metallographic images are usually accompanied by complex non-uniform noise and artifacts. Existing automatic image segmentation methods rely heavily on the absolute values of pixel gradients, exhibiting significant limitations when dealing with complex metallographic images. On the one hand, when there are grain boundary blurring or grain boundary fractures caused by insufficient etching in the image, traditional algorithms lack morphology adaptive constraints during the front evolution process, easily leading to boundary penetration and region overflow, resulting in severe undersegmentation problems. On the other hand, texture noise and impurity spots within the metallographic structure are easily misjudged as real edges by the algorithm, leading to oversegmentation. Because existing technologies lack effective multi-dimensional geometric features and dynamic hindrance control mechanisms during region diffusion, they cannot simultaneously ensure the continuity of grain boundaries and the robustness of noise reduction, ultimately resulting in low accuracy in the automatic quantitative detection of metallographic structures. Summary of the Invention
[0004] This invention provides a quantitative detection and rating method for metallographic structures based on adaptive region diffusion, which solves the problems of over-segmentation and under-segmentation caused by grain boundary blurring or fracture in complex metallographic images and low accuracy of automatic detection in the prior art.
[0005] To achieve the above objectives, this invention provides a method for quantitative detection and rating of metallographic structures based on adaptive region diffusion, comprising the following steps: Step S1: Acquire a metallographic image to be tested, calculate its local structural orientation features, and smooth the metallographic image to be tested according to the local structural orientation features to obtain an enhanced metallographic image; Step S2: Perform a difference operation on the enhanced metallographic image to extract the gray-level gradient field and second-order discontinuity features to characterize the structure boundary; map and fuse the gray-level gradient field and the second-order discontinuity features to construct a grain boundary constraint matrix; Step S3: Calculate the spatial Euclidean distance from each non-grain boundary pixel in the enhanced metallographic image to the nearest grain boundary according to the grain boundary constraint matrix to form a multidimensional geometric distance field; from the multidimensional geometric distance field... Candidate seed points are selected from the geometric distance field, and the candidate seed points are denoised and merged to determine the topological center seed point; Step S4: An initial connected region is constructed with the topological center seed point as the starting pixel, and spatial iterative expansion processing is performed on it; In each iteration cycle of the spatial iterative expansion processing, the outward expansion state is controlled according to the geometric contour features of the expansion front of the current connected region and the matrix value of the expansion front in the grain boundary constraint matrix; When the expansion boundary meets the preset convergence condition, the expansion is terminated, and the connected region at the time of termination of expansion is used as the segmentation target area of each independent metallographic structure; Step S5: The morphological feature parameters of each segmentation target area are calculated and matched with the preset structure level mapping rule to obtain the quantitative rating result of the metallographic structure.
[0006] Optionally, the calculation process of the local structural orientation features includes: calculating the first-order partial derivative of the metallographic image to be tested in the orthogonal direction, and constructing a local structural tensor corresponding to each pixel based on the first-order partial derivative; performing spatial neighborhood smoothing on the local structural tensor to obtain a smoothed structural tensor; performing feature decomposition on the smoothed structural tensor to extract feature vectors to characterize tissue orientation, and using the feature vectors as the local structural orientation features.
[0007] Optionally, the process of performing differential operation on the enhanced metallographic image in step S2 specifically includes: calculating the first-order partial derivative of the enhanced metallographic image in the orthogonal direction, and calculating the vector magnitude of the first-order partial derivative to generate the gray-level gradient field; calculating the second-order partial derivative of the enhanced metallographic image in the orthogonal direction to construct a second-order derivative matrix, performing eigenvalue decomposition on the second-order derivative matrix to obtain eigenvalues, and using the eigenvalues as the second-order discontinuity features.
[0008] Optionally, the process of constructing the grain boundary constraint matrix includes: performing numerical interval mapping processing on the gray-level gradient field and the second-order discontinuity feature respectively to obtain a first edge response matrix and a second edge response matrix; and performing a weighted composite superposition operation on the first edge response matrix and the second edge response matrix to construct the grain boundary constraint matrix.
[0009] Optionally, the process of forming a multidimensional geometric distance field specifically includes: extracting boundary features based on the grain boundary constraint matrix to determine the set of grain boundary pixels in the enhanced metallographic image; for each non-grain boundary pixel in the enhanced metallographic image, searching for the pixel with the closest geometric distance in the set of grain boundary pixels, and calculating the spatial Euclidean distance between each non-grain boundary pixel and its corresponding nearest pixel; and reconstructing the calculated spatial Euclidean distances into a matrix according to the spatial coordinates of the corresponding non-grain boundary pixel to form the multidimensional geometric distance field.
[0010] Optionally, the process of selecting candidate seed points includes: based on preset spatial scale parameters, constructing a neighborhood window in a multidimensional geometric distance field with each non-grain boundary pixel as the center, and taking the set of pixels covered by the neighborhood window as the local spatial neighborhood of the corresponding non-grain boundary pixel; in the multidimensional geometric distance field, comparing the distance value of each non-grain boundary pixel with the distance values of other pixels in its corresponding local spatial neighborhood; determining non-grain boundary pixels with distance values greater than the distance values of all other pixels in their corresponding local spatial neighborhood as local maxima, and taking each of the obtained local maxima as the candidate seed points.
[0011] Optionally, the process of determining the topology center seed point includes: calculating the spatial geometric distance between each pair of candidate seed points based on a preset distance threshold; dividing candidate seed points whose spatial geometric distance is less than the distance threshold into the same collaborative set; comparing the distance values of each candidate seed point in the multidimensional geometric distance field within each collaborative set, retaining the candidate seed point with the largest distance value and removing the remaining candidate seed points, and using the retained candidate seed point as the topology center seed point.
[0012] Optionally, the spatial iterative expansion process includes: Step S41: retrieving and determining a set of neighboring candidate pixels that are immediately adjacent to the outer edge of the current connected region expansion; Step S42: calculating the expansion propulsion speed value corresponding to each candidate pixel in the neighboring candidate pixel set based on the geometric contour features and the matrix values in the grain boundary constraint matrix; Step S43: incorporating candidate pixels with expansion propulsion speed values greater than a preset propulsion threshold into the connected region to update the connected region, completing the spatial expansion in the current iteration cycle, and returning to step S41 to execute the next iteration cycle.
[0013] Optionally, the control of the outward expansion propulsion state includes: calculating the local curvature value of each pixel on the current connected region expansion front, and using the local curvature value as the geometric contour feature; substituting the matrix value into the boundary stagnation mapping function for mapping operation to obtain the stagnation coefficient corresponding to each pixel; performing a composite mapping operation on the local curvature value and the stagnation coefficient to calculate the dynamic propulsion step size of each pixel in the normal direction, and determining the propulsion displacement of the expansion boundary within the current iteration period based on the dynamic propulsion step size.
[0014] Optionally, the calculation of morphological feature parameters includes: calculating the zero-order geometric moment and the second-order central moment of each segmented target region; determining the pixel area of each segmented target region based on the zero-order geometric moment; calculating the principal axis length and secondary axis length of each segmented target region based on the second-order central moment; calculating the ratio of the principal axis length to the secondary axis length to obtain the region aspect ratio; calculating the principal axis tilt angle feature based on the second-order central moment; and constructing the morphological feature parameters by vector composite of the pixel area, region aspect ratio, and principal axis tilt angle feature.
[0015] This invention provides a quantitative detection and rating method for metallographic structures based on adaptive region diffusion. It utilizes local structural directional features for directional smoothing and denoising, and organically integrates first-order gradient fields and second-order discontinuity features to construct a grain boundary constraint matrix. This effectively overcomes the shortcomings of traditional methods in identifying blurred or fractured grain boundaries. Simultaneously, by employing a multi-dimensional geometric distance field and a topological seed point denoising and merging mechanism, it eliminates misjudgments caused by texture artifacts within the structure at the source. Furthermore, it introduces an adaptive dynamic control mechanism of geometric contours and boundary hindrance during spatial iterative expansion, achieving precise advancement and perfect convergence of the expansion front. This thoroughly solves the over-segmentation and under-segmentation problems that easily occur in complex metallographic images, significantly improving the accuracy and robustness of irregular topological target area segmentation. Ultimately, it ensures the objectivity, efficiency, and extremely high industrial accuracy of the quantitative detection and rating results for metallographic structures. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 This is a flowchart of the metallographic structure quantitative detection and rating method provided in the embodiments of the present invention; Figure 2 This is a flowchart of constructing a grain boundary constraint matrix provided in an embodiment of the present invention; Figure 3This is a flowchart of spatial iterative expansion and rating provided in an embodiment of the present invention; Figure 4 These are schematic diagrams of different grades of martensite metallographic structures provided in embodiments of the present invention. Detailed Implementation
[0017] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.
[0018] It should be noted that the acquisition, transmission, storage, use, and processing of data in the technical solution of this application all comply with the relevant provisions of national laws and regulations. In the embodiments of this application, certain existing industry solutions such as software, components, and models may be mentioned. These should be considered exemplary, intended only to illustrate the feasibility of implementing the technical solution of this application, and do not imply that the applicant has already used or necessarily used such solutions.
[0019] The following is combined Figures 1 to 4 This invention is described in detail.
[0020] like Figure 1 As shown, this embodiment of the invention provides a method for quantitative detection and rating of metallographic structures based on adaptive region diffusion, including the following steps: Step S1: Acquire the metallographic image to be tested, calculate its local structural orientation features, and smooth the metallographic image to be tested according to the local structural orientation features to obtain an enhanced metallographic image; Step S2: Perform a difference operation on the enhanced metallographic image to extract the gray-level gradient field and second-order discontinuity features to characterize the structure boundary; map and fuse the gray-level gradient field and second-order discontinuity features to construct a grain boundary constraint matrix; Step S3: Calculate the spatial Euclidean distance from each non-grain boundary pixel in the enhanced metallographic image to the nearest grain boundary according to the grain boundary constraint matrix to form a multidimensional geometric distance field; from the multidimensional geometric distance... Candidate seed points are selected from the distance field, and the candidate seed points are denoised and merged to determine the topological center seed point; Step S4: An initial connected region is constructed with the topological center seed point as the starting pixel, and spatial iterative expansion processing is performed on it; In each iteration cycle of the spatial iterative expansion processing, the outward expansion state is controlled according to the geometric contour features of the expansion front of the current connected region and the matrix value of the expansion front in the grain boundary constraint matrix; When the expansion boundary meets the preset convergence condition, the expansion is terminated, and the connected region at the time of termination of expansion is used as the segmentation target area of each independent metallographic structure; Step S5: The morphological feature parameters of each segmentation target area are calculated and matched with the preset structure level mapping rule to obtain the quantitative rating result of the metallographic structure.
[0021] The metallographic image to be tested refers to a digital image of the microstructure of a metal sample surface acquired by a microscopic imaging device, preferably in a single-channel grayscale matrix format. Local structural orientation features refer to the lateral and longitudinal vector attributes characterizing the dominant direction of grayscale geometric distribution within the neighborhood of image pixels, preferably in a floating-point multi-channel array format. The grain boundary constraint matrix is a numerical grid generated by integrating first-order grayscale variation intensity and second-order topological discontinuity features to characterize the probability of grain boundary existence and evolution resistance; its numerical range is preferably normalized to a floating-point number between 0 and 1. The multidimensional geometric distance field refers to the spatial geometric distance matrix between each non-grain boundary pixel and its nearest grain boundary pixel, preferably in a signed integer two-dimensional array format. The topological center seed point refers to the unique coordinate point located at the topological core of a single complete grain, determined after spatial extremum screening and distance aggregation optimization; its storage format is preferably an integer two-dimensional coordinate array. The expansion front refers to the set of dynamically active boundary pixels that are encroaching outwards from the outermost layer of the connected region within the current spatial iteration cycle; its data structure is preferably a dynamic one-dimensional linked list. The segmented target region refers to the independent and non-overlapping finally connected region mesh formed after the complete convergence of the region adaptive diffusion. Its data format is preferably an integer label mapping matrix. The tissue level mapping rule refers to the judgment logic of searching and matching the geometric morphology representation vector of the segmented target region with the standard tissue rating database. The rating result is finally output in the form of an integer level value.
[0022] Specifically, in step S1, to avoid blurring of grain boundary edges due to conventional non-directional Gaussian filtering, a directional filtering logic based on coordinate axis rotation is introduced during the acquisition of the enhanced metallographic image. The specific implementation steps are as follows: First, the first-order differential partial derivatives of the metallographic image under test in the horizontal and vertical directions are calculated, assembling the local structure tensor matrix for each pixel location, and spatial smoothing is performed using a Gaussian kernel with a fixed standard deviation. Next, the eigenvectors of this matrix are solved, and the angle of the principal eigenvector representing the local extension direction of the grain boundary is taken as the local structure direction feature. Subsequently, a local rotation coordinate system is established with the currently processed pixel as the origin, and the two orthogonal axes of this coordinate system are adjusted so that one axis is completely parallel to the grain boundary tangent direction indicated by the local structure direction feature, and the other axis is completely parallel to the normal direction perpendicular to the grain boundary. Building upon this, a larger Gaussian smoothing standard deviation is configured along the tangential direction to perform strong filtering in that direction, removing surface scratches and noise. Simultaneously, a very small Gaussian smoothing standard deviation is configured along the normal direction to strictly limit the smoothing range and prevent isotropic blurring at grain boundary steps. Finally, the constructed heterogeneous directional Gaussian filter kernel is used to perform pixel-by-pixel convolution matrix operations with the original image, outputting an enhanced metallographic image with a clean background and complete boundaries.
[0023] Specifically, in the process of constructing the grain boundary constraint matrix in step S2, in order to simultaneously consider both strong grain boundaries and weak grain boundaries caused by uneven etching, a multi-dimensional composite logic of first-order and second-order edge features is adopted. The specific implementation steps are as follows: First, a first-order difference operation is performed on the input enhanced metallographic image to calculate the vector magnitudes of its horizontal and vertical first-order partial derivatives, generating a gray-level gradient field characterizing the first-order edge intensity. Simultaneously, the second-order horizontal, second-order vertical, and cross partial derivatives of the enhanced metallographic image are calculated, assembling them to form the second-order derivative matrix at each pixel position, and solving for the maxima eigenvalue of this second-order derivative matrix. This maxima eigenvalue is used as the second-order discontinuity feature characterizing the topological curvature of the tissue boundary ridge. Next, in order to eliminate the data magnitude difference between the first-order intensity and the second-order curvature, the gray-level gradient field and the second-order discontinuity feature are independently scaled proportionally to a normalized interval between 0 and 1 using the maximum-minimum normalization method, thereby obtaining the corresponding first edge response matrix and second edge response matrix. Finally, a first-order gradient weight coefficient is set, and the first and second edge response matrices are weighted and superimposed pixel by pixel using this weight coefficient to construct the final grain boundary constraint matrix.
[0024] Specifically, in step S3, to prevent over-segmentation of subsequent regions caused by residual texture noise within the grains, strict threshold filtering and neighborhood suppression logic are introduced. The specific implementation steps are as follows: First, an initial background energy threshold is set, specifically 0.2. The grain boundary constraint matrix is traversed, and pixels with values less than the initial background energy threshold are identified as non-grain boundary pixels, while pixels with values greater than or equal to the initial background energy threshold are marked as potential grain boundaries. Next, a spatial distance transformation algorithm is used to calculate the spatial Euclidean distance between each non-grain boundary pixel and the nearest potential grain boundary, and a multidimensional geometric distance field is reconstructed according to coordinates. Subsequently, to extract local distance peak points as candidate seed points, a preset spatial scale parameter is set. The preset spatial scale parameter refers to a square neighborhood window constructed in the multidimensional geometric distance field centered on each non-grain boundary pixel. The spatial resolution size of this neighborhood window is specifically set to [value missing]. Pixel-wise, local maximum suppression is performed within each neighborhood window, retaining only the pixel with the largest distance value within the current window as a candidate seed point. Finally, to merge redundant seed points that are too close, a preset distance threshold is set, specifically 15 pixels. The spatial geometric distance between each pair of candidate seed points is calculated, and candidate seed points with a geometric distance less than the threshold are grouped into the same collaborative set. Within each set, only the pixel with the largest geometric distance value is retained, thus locking in the final topological center seed point.
[0025] Specifically, during the spatial iterative expansion process in step S4, a multimodal composite speed control logic is introduced to achieve rapid adaptive spreading of the connected region within the grain and precise braking and locking at the grain boundary. The specific implementation steps are as follows: An initial connected region is constructed using each topological center seed point as the starting pixel. Within each spatial iterative evolution cycle, the adjacent expansion front outside the current connected region is retrieved to form an expansion front pixel set. For each front pixel in this set, the curvature value of its local boundary geometry is calculated, and the corresponding matrix value in the grain boundary constraint matrix is retrieved. The advancing step size of each front pixel in the normal direction is dynamically adjusted through the following composite control logic: the advancing step size is inversely proportional to the curvature value and inversely proportional to the matrix value by a negative exponential factor. When the expansion front approaches a flat region inside a low-energy grain, due to its extremely small curvature and matrix value close to 0, the dynamic advancement step size is automatically increased to a set basic constant step size of 1.0 pixel, corresponding to a advancement displacement of 1 pixel, to achieve rapid expansion. When the expansion front approaches a real grain boundary at high energy, the advancement step size adaptively decays as the matrix value increases sharply or the local curvature increases. Simultaneously, a dual, strict quantization convergence condition is introduced: First, when the dynamic advancement step size calculated at the current edge pixel decays to less than 0.05 pixels due to obstruction, its corresponding advancement displacement is quantized to 0, indicating that the point has touched a real grain boundary barrier. The dynamic advancement step size at this point is forcibly cleared to zero and permanently locked, stopping expansion. Second, when the expansion fronts of two different connected regions independently developed from different topological center seed points meet at a certain pixel spatial coordinate and a tag collision occurs, the advancement step size at the collision boundary is forcibly cleared to zero, terminating outward expansion. When all expansion front points in the entire map trigger the above two types of zeroing and locking conditions, causing the global evolution speed to drop to 0, it is determined that the overall preset convergence condition is met, the spatial iterative expansion is completely terminated, and the final segmentation target region is output.
[0026] Specifically, during the quantitative detection and rating process in step S5, the geometric morphology of each generated segmented target region is calculated. First, the total number of pixels contained within each segmented target region is counted, and combined with the actual physical size corresponding to a single pixel, the true geometric area of each target region is accurately determined. Next, the geometric contour distribution of each segmented target region in multidimensional space is further extracted to construct a multivariate morphological feature vector. Finally, the morphological feature vector is input into the tissue-level mapping process, which searches and performs weighted probability matching with a pre-stored standard rating database. Ultimately, the MS1 to MS4 level or unqualified corresponding to the best match is output and displayed as the final rating result.
[0027] like Figure 4As shown, specifically, the implementation process of the preset organization-level mapping rules and weighted probability matching in this embodiment is as follows: The first step is to construct a standard rating database: This database pre-stores standard geometric morphology features corresponding to different martensitic microstructure levels, from MS1 to MS4, based on the martensitic microstructure grading standards. For each standard level, the database pre-stores a three-dimensional standard morphology feature center vector composed of the expected values of the standard grain pixel area, the standard aspect ratio, and the standard principal axis tilt angle. It also pre-stores a three-dimensional inverse covariance matrix characterizing the spatial variation range and correlation of each standard feature. The conversion logic for the standard geometric morphology features is as follows: after calibrating the pixel equivalent k using microscopic images of standard samples from MS1 to MS4 levels, the average pixel area of the standard grains is calculated. , The number of grains per square millimeter corresponding to this level is determined statistically based on actual standard samples; the standard values of aspect ratio and principal axis tilt angle are obtained by averaging the morphological characteristics of typical grains corresponding to the standard level. The inverse covariance matrix is obtained by inverting the covariance matrix of the sample feature vectors corresponding to each standard level, and is used to quantify the range of feature fluctuations.
[0028] The second step involves constructing the multidimensional morphological feature vector of the current metallographic structure: This involves retrieving the segmented target regions output from the upstream step, statistically analyzing the true pixel area, aspect ratio, and principal axis tilt angle of all segmented target regions in the current image, and calculating their arithmetic mean across the entire image to obtain the average pixel area, average aspect ratio, and average principal axis tilt angle. Next, these three average feature values are linearly combined in a fixed order to reconstruct a three-dimensional feature vector representing the morphological characteristics of the entire metallographic structure.
[0029] The third step involves performing a weighted probability matching operation in the multidimensional feature space. To eliminate calculation biases caused by dimensional differences between different morphological parameters, a spatial distance weighted mapping logic is introduced. Specifically, for each standard level from MS1 to MS4, the algebraic difference vector between the three-dimensional feature vector to be measured and the corresponding three-dimensional standard morphological feature center vector is first calculated. Then, using the corresponding three-dimensional inverse covariance matrix, a quadratic matrix product is performed on the difference vector to calculate the generalized multidimensional spatial distance (Mahavior distance) of the current metallographic structure relative to the standard level, thus accurately characterizing the morphological proximity between the current structure and the standard level. After obtaining the generalized multidimensional spatial distances corresponding to each of MS1 to MS4 levels, a negative exponential Gaussian radial basis function is used to probabilistically map the distances, calculate the original matching energy for each level, and then normalize to obtain the relative matching probability for each level.
[0030] Step 4, Level Locking and Result Output: The rating matching process iterates through and compares the relative normalized matching probabilities corresponding to MS1 to MS4 levels, and retrieves and locks the level with the highest relative matching probability: if the highest matching probability is greater than or equal to the preset qualified threshold, such as 0.6, then the corresponding MS1 / MS2 / MS3 / MS4 level is output; if the relative matching probability of all MS1 to MS4 levels is less than the preset qualified threshold, then it is judged as unqualified, and the unqualified result is output.
[0031] The metallographic structure quantitative detection and rating method provided in this invention effectively solves the problems of over-segmentation caused by internal noise interference and under-segmentation caused by weak grain boundary fractures in traditional metallographic segmentation by constructing a grain boundary constraint matrix that integrates first-order gray-level gradient and second-order morphology features, and combining it with a spatial adaptive region diffusion mechanism based on topological center seed points. This method can accurately locate the geometric core of grains while filtering out scratch noise, and achieves adaptive convergence at grain boundary fractures through leading-edge evolution control, thereby completely separating each independent grain entity, significantly improving the accuracy, objectivity, and stability of metallographic structure quantitative detection and automatic rating.
[0032] Preferably, the calculation process of the local structural orientation feature includes: calculating the first-order partial derivative of the metallographic image to be tested in the orthogonal direction, and constructing the local structural tensor corresponding to each pixel based on the first-order partial derivative; performing spatial neighborhood smoothing on the local structural tensor to obtain a smoothed structural tensor; performing feature decomposition on the smoothed structural tensor to extract feature vectors to characterize tissue orientation, and using the feature vectors as the local structural orientation feature.
[0033] The first-order partial derivative in the orthogonal direction refers to the gray-level change rate obtained by approximating the discrete derivatives of the digital image matrix along the horizontal and vertical axes using the finite difference method. Its data format is preferably a 32-bit floating-point dual-channel matrix. The local structure tensor is a symmetric positive semi-definite matrix that comprehensively reflects the multi-directional gray-level change characteristics of the pixel neighborhood, constructed by performing matrix outer product operations on the first-order partial derivatives. Its data format is preferably a floating-point array containing three independent matrix components. Spatial neighborhood smoothing refers to the process of performing weighted low-pass filtering on each matrix component of the structure tensor within a specified spatial range to eliminate impurity texture interference. In this embodiment, the spatial smoothing radius is preferably set to 2 pixels. The smoothed structure tensor is a spatially continuous positive semi-definite matrix reconstructed after spatial neighborhood low-pass filtering, with a data format of a 32-bit floating-point multi-channel array. Eigenvalue decomposition refers to the algebraic operation process of solving the smoothed structure tensor by matrix diagonalization to separate non-negative eigenvalues and corresponding orthogonal eigenvectors. Eigenvectors are unit vectors indicating spatial geometric orientation obtained by decomposing a smoothed structural tensor; the preferred data format is a two-dimensional floating-point vector. Microstructural orientation refers to the potential geometric extension trend of grain boundaries and the macroscopic arrangement direction of phase boundaries in the microstructure of a metallic sample.
[0034] Specifically, in calculating the directional features of the local structure, the grayscale matrix of the original metallographic image to be tested, digitally stored in memory, is first read. Next, in the discrete pixel grid, the algebraic difference of grayscale at each pixel location is calculated along the horizontal and vertical directions using the central difference operator, thereby obtaining the first-order partial derivative of each pixel in the orthogonal directions. Then, the first-order partial derivatives in the horizontal and vertical directions of the current pixel are used to construct a two-dimensional gradient vector, and the outer product of this gradient vector with its transpose is calculated, thus obtaining the original local structure tensor corresponding to each pixel location. Following this, a Gaussian low-pass filter function is introduced as a technique for spatial neighborhood smoothing. The preferred spatial standard deviation of the Gaussian function is set to 1.2. The components in the original local structure tensor are independently calculated using a spatial neighborhood weighted average to eliminate pseudo-structure interference caused by scratches on the sample surface, thereby outputting a smoothed structure tensor. Subsequently, eigenvalue decomposition is performed on the smoothed structure tensor corresponding to each pixel, solving for two non-negative eigenvalues arranged in descending order of value and their corresponding eigenvectors. Finally, since the eigenvectors corresponding to smaller eigenvalues physically indicate the tangent direction of the weakest grayscale change, this specific eigenvector is extracted to accurately characterize the tissue orientation, and this eigenvector is used as the final local structural orientation feature output to provide directional guidance for subsequent adaptive smoothing along grain boundary tangents.
[0035] Specifically, the smoothing process for the metallographic image to be tested is as follows: An anisotropic spatial evolution operator is constructed, and a new operator of size [missing information] is constructed centered on the current pixel. An adaptive neighborhood window is used. The local structural orientation features of the pixel, represented by its feature vector, are read. ,in This indicates the tangential extension direction of the grain boundary. Within the adaptive neighborhood window, it follows the tangential direction. The direction configuration has a large Gaussian smoothing standard deviation And along the normal direction perpendicular to the tangent direction Configure a very small smoothing standard deviation An anisotropic spatial filter is constructed and convolved with the original grayscale matrix. This enables strong smoothing along the grain boundary extension direction to remove noise and sample scratches, while maintaining the original gradient step edges unblurred in the normal direction crossing the grain boundary, ultimately outputting a high-quality enhanced metallographic image.
[0036] In a preferred embodiment of the present invention, by calculating the first-order partial derivatives in orthogonal directions and constructing a local structure tensor, the local distribution of an image can be transformed into matrix features. Then, spatial neighborhood smoothing is used to eliminate noise interference on the tensor components. Finally, feature decomposition accurately extracts the feature vector representing the true grain boundary extension trend. This effectively avoids the misleading influence of isolated scratches and noise in the metal structure on orientation determination, laying an extremely accurate topological orientation foundation for subsequent anisotropic boundary enhancement.
[0037] Preferably, the process of performing differential operation on the enhanced metallographic image in step S2 specifically includes: calculating the first-order partial derivative of the enhanced metallographic image in the orthogonal direction, and calculating the vector magnitude of the first-order partial derivative to generate the gray-level gradient field; calculating the second-order partial derivative of the enhanced metallographic image in the orthogonal direction to construct a second-order derivative matrix, performing eigenvalue decomposition on the second-order derivative matrix to obtain eigenvalues, and using the eigenvalues as the second-order discontinuity features.
[0038] The vector magnitude calculation refers to treating the first-order partial derivatives of a pixel in the horizontal and vertical directions as components of a two-dimensional vector. The absolute magnitude of the vector is determined algebraically by calculating the sum of the squares of these two components and then taking the square root. The calculation result is preferably stored in a 32-bit floating-point single-channel format. The gray-level gradient field is a numerical matrix reflecting the intensity of gray-level spatial changes and boundary strength at each pixel location in the enhanced metallographic image. Its numerical range is preferably normalized to the full range of gray-level values between 0 and 255. The second-order partial derivatives in orthogonal directions refer to the rate of change of gray-level variation obtained by performing finite-difference approximation calculations along the horizontal, vertical, and diagonal axes on the first-order partial derivatives. This rate of change characterizes the curvature of the image's gray-level surface. The data format is preferably 32-bit floating-point numbers. The second-order derivative matrix is a 2x2 symmetric square matrix constructed by arranging the horizontal, vertical, and cross second-order partial derivatives at each pixel coordinate. Its data format is preferably a floating-point array containing three independent matrix components. Eigenvalues are scalar values representing the magnitude of principal curvature obtained by algebraically diagonalizing the second derivative matrix. In this embodiment, two eigenvalues are extracted for each pixel, preferably in 32-bit floating-point format. Second-order discontinuity features utilize the eigenvalue with the largest absolute value to quantitatively characterize the geometric properties of the valley bottom or ridge midline of the image's grayscale topological surface, precisely indicating the grain boundaries of fine grooves in the microstructure.
[0039] Specifically, in step S2, the differential operation on the enhanced metallographic image is performed as follows: First, the grayscale matrix of the digitally stored enhanced metallographic image is read from memory. Next, using a direction-selective discrete difference operator, discrete difference convolution is performed on the enhanced metallographic image along two mutually orthogonal directions, horizontal and vertical, outputting the first-order partial derivative of each pixel in the orthogonal directions. Then, the vector magnitude of the obtained first-order partial derivatives is calculated. The horizontal and vertical first-order partial derivatives of the current pixel are squared respectively, then the two squared results are summed. Finally, the square root operation is performed on the sum to obtain the geometric magnitude of the spatial grayscale gradient vector of that pixel. This process is repeated for all pixels in the entire image to generate a grayscale gradient field that clearly displays the global boundary intensity. Simultaneously, deep differential calculations are performed again on the enhanced metallographic image using the differential operator. Second-order partial derivatives along the horizontal, vertical, and diagonal directions are calculated at each pixel location. These three second-order partial derivatives are then arranged according to a specific spatial topological relationship, constructing a 2x2 symmetric second-order derivative matrix at each pixel location. Next, a matrix eigenvalue solving algorithm is invoked to independently perform eigenvalue decomposition on the second-order derivative matrix corresponding to each pixel coordinate in the entire image, solving for two non-negative eigenvalues representing the local principal curvature. Finally, the two eigenvalues corresponding to each pixel are compared numerically, and the eigenvalue with the largest absolute value is selected. Since this eigenvalue can physically capture the extreme and extremely thin central axis of the image's gray-scale topological surface with exceptional sensitivity, it is directly used as the second-order discontinuity feature for output and storage, completing the multi-dimensional stereoscopic representation of the tissue boundary.
[0040] A preferred embodiment of this invention deeply integrates the calculation of the vector magnitude of the first-order partial derivative with the eigenvalue decomposition of the second-order derivative matrix. This not only enables the accurate capture of large-scale, high-contrast conventional grain boundaries using gray-scale gradient fields, but also allows for the precise identification of the central axis of fine grooves and shallow, weak grain boundaries that cannot be effectively identified by the first-order gradient using second-order discontinuity features. This parallel extraction of dual-layer difference features provides extremely rich boundary topological information for the subsequent construction of high-precision, multi-scale grain boundary constraint matrices, fundamentally overcoming the defect of single-gradient features that easily miss weak edges when dealing with complex metallographic structures.
[0041] Preferably, the process of constructing the grain boundary constraint matrix includes: performing numerical interval mapping processing on the gray-level gradient field and the second-order discontinuity feature respectively to obtain a first edge response matrix and a second edge response matrix; and performing a weighted composite superposition operation on the first edge response matrix and the second edge response matrix to construct the grain boundary constraint matrix.
[0042] The numerical interval mapping process refers to the normalization process of scaling the input matrix feature values to a preset standard interval through linear or nonlinear transformations, thereby eliminating the influence of different dimensions on the subsequent feature fusion results. The first edge response matrix is a normalized matrix generated from the gray-level gradient field after numerical interval mapping, used to characterize the strength of large-scale tissue boundaries. Its data format is preferably a single-channel two-dimensional array of floating-point numbers between zero and one. The second edge response matrix is a normalized matrix generated from second-order discontinuity features after numerical interval mapping, used to characterize the probability of the existence of fine topological discontinuities. Its data format is preferably a single-channel two-dimensional array of floating-point numbers between zero and one. The weighted composite superposition operation is an algebraic operation process in which the first and second edge response matrices are multiplied by their respective weight coefficients and then summed at corresponding positions.
[0043] Specifically, the calculation formula for the weighted composite superposition operation is as follows:
[0044] in, For pixel coordinates, The value of the first edge response matrix after the first-order gray-level gradient field is mapped by linear maximum extremum normalization; The value of the second edge response matrix is obtained by mapping the second-order discontinuous feature matrix; and These represent the corresponding first-order gradient weighting coefficient and second-order feature fusion weighting coefficient, respectively. To balance the extraction of coarse grain boundaries with significant erosion and the fracture repair at weak grain boundaries in fine grooves, this embodiment preferably sets... =0.6 and =0.4. The numerical value of the composite matrix obtained by superposition. This constitutes the grain boundary constraint matrix.
[0045] Specifically, the internal process of constructing the grain boundary constraint matrix is as follows: First, the gray-level gradient field and second-order discontinuity features output from the upstream process are obtained. Next, numerical interval mapping processing is performed on the gray-level gradient field and the second-order discontinuity features respectively. When mapping the gray-level gradient field, the maximum and minimum values of the gradient across the entire image are calculated. The maximum-minimum normalization mapping logic is used to proportionally map the gradient value of each pixel to a normalized interval of zero to one, thereby obtaining the first edge response matrix. Similarly, when mapping the second-order discontinuity features, the maximum-minimum normalization mapping logic is used to map its feature values to a normalized interval of zero to one, obtaining the second edge response matrix. This achieves the dimensionless and normalized transformation of boundary features at different levels. Subsequently, preset weighting coefficients are introduced. Finally, a weighted composite superposition operation is performed on the first edge response matrix and the second edge response matrix. The pixel values in the first edge response matrix are multiplied by 0.6, and the pixel values at the same coordinate positions in the second edge response matrix are multiplied by 0.4. The product results are then added according to their positions to reconstruct composite boundary data. This data is then normalized and shifted again in the zero-to-one interval to finally construct a grain boundary constraint matrix that is completely consistent with the resolution of the original image and highly integrates the two-layer features.
[0046] In a preferred embodiment of the present invention, numerical interval mapping processing is performed on the gray-level gradient field and the second-order discontinuity features respectively, effectively eliminating the problems of dimensional differences and inconsistent numerical spans among multi-source image features, and ensuring the balance of subsequent fusion. A weighted composite superposition operation is used to perform deep positional fusion of the first-order normalized features and the second-order normalized features, which can dynamically balance the expression weights of significant grain boundaries and micro-grooves. This results in a grain boundary constraint matrix that possesses both high robustness against internal scratch noise and high sensitivity to extremely weak grain boundary fractures, providing a high-quality constraint boundary that balances macroscopic strength and microscopic topology for subsequent adaptive region expansion.
[0047] Preferably, the process of forming a multidimensional geometric distance field specifically includes: extracting boundary features based on the grain boundary constraint matrix to determine the set of grain boundary pixels in the enhanced metallographic image; for each non-grain boundary pixel in the enhanced metallographic image, searching for the pixel with the closest geometric distance in the set of grain boundary pixels, and calculating the spatial Euclidean distance between each non-grain boundary pixel and its corresponding nearest pixel; and reconstructing the calculated spatial Euclidean distances into a matrix according to the spatial coordinates of the corresponding non-grain boundary pixel to form the multidimensional geometric distance field.
[0048] Boundary feature extraction refers to the discrete geometric analysis process of binarizing the grain boundary constraint matrix using a set threshold and extracting the grain boundary central axis skeleton. In this embodiment, the energy determination threshold is preferably set to 0.35. The grain boundary pixel set refers to the discrete set of all pixel coordinates that are connected in the image space and represent the grain boundary lines, as determined after boundary feature extraction. Its storage format is preferably a 1D dynamic linked list composed of integer 2D spatial coordinates. Non-grain boundary pixels refer to the remaining pixels in the metallographic image located in the internal regions of each grain, excluding the grain boundary pixel set. Spatial Euclidean distance refers to the linear geometric step size between the coordinates of two pixels in the 2D image space. Specifically, it is the actual geometric distance obtained by summing the squares of the differences between the horizontal and vertical coordinates of the two pixels and then taking the square root. Its data format is preferably a 32-bit floating-point number. Matrix reconstruction refers to the process of rearranging and filling all the discretely calculated distance scalar values according to their corresponding pixel grid coordinates and assembling a 2D matrix with the same spatial resolution as the original enhanced metallographic image.
[0049] Specifically, the internal process of forming a multidimensional geometric distance field is as follows: First, the grain boundary constraint matrix constructed in the upstream step is retrieved. Next, boundary feature extraction is performed based on the grain boundary constraint matrix. This is done by comparing the hindrance energy value of each pixel in the grain boundary constraint matrix with a preset energy threshold of 0.35. Pixels greater than or equal to this threshold are marked as boundary points, and a refined skeleton extraction is performed on them to accurately locate the set of grain boundary pixels in the enhanced metallographic image. Then, for each non-grain boundary pixel in the enhanced metallographic image, a spatial nearest neighbor search is performed across the entire image to retrieve the specific boundary pixel in the grain boundary pixel set that has the closest spatial geometric distance to the current non-grain boundary pixel. Following this, the distance calculation logic is invoked to calculate the spatial Euclidean distance between each current non-grain boundary pixel and its corresponding nearest pixel, obtaining the minimum absolute geometric step size from each internal pixel to the nearest boundary. Finally, matrix reconstruction is performed. The calculated spatial Euclidean distances are rewritten into a pre-initialized empty matrix according to the real spatial coordinates of the corresponding non-grain boundary pixels in the image grid. For coordinates of pixels belonging to the grain boundary set, their distance values are directly assigned to 0. This reconstructs the discrete distance data into a multidimensional geometric distance field that is completely consistent with the size of the input image. The data is stored in a 32-bit floating-point 2D matrix to quantitatively characterize the spatial centripetal evolution trend of each point inside the grain towards the grain boundary.
[0050] In a preferred embodiment of the present invention, a set of grain boundary pixels is extracted based on the grain boundary constraint matrix, and the spatial Euclidean distance from each non-grain boundary pixel to the nearest grain boundary pixel is calculated. Finally, a multi-dimensional geometric distance field is formed through matrix reconstruction, successfully transforming complex fracture and ambiguous grain boundary morphology into a continuously distributed spatial distance potential field. This effectively transforms complex boundary identification into the problem of finding topological cores in continuous space, laying a solid geometric metric foundation for subsequent accurate selection of candidate seed points at grain centers.
[0051] Preferably, the process of selecting candidate seed points includes: based on preset spatial scale parameters, constructing a neighborhood window in a multidimensional geometric distance field with each non-grain boundary pixel as the center, and taking the set of pixels covered by the neighborhood window as the local spatial neighborhood of the corresponding non-grain boundary pixel; in the multidimensional geometric distance field, comparing the distance value of each non-grain boundary pixel with the distance values of other pixels in its corresponding local spatial neighborhood; determining non-grain boundary pixels with distance values greater than the distance values of all other pixels in their corresponding local spatial neighborhood as local maxima, and taking each of the obtained local maxima as the candidate seed points.
[0052] Further preferably, the process of determining the topology center seed point includes: calculating the spatial geometric distance between each pair of candidate seed points based on a preset distance threshold; classifying candidate seed points whose spatial geometric distance is less than the distance threshold into the same collaborative set; comparing the distance values of each candidate seed point in the multidimensional geometric distance field within each collaborative set, retaining the candidate seed point with the largest distance value and removing the remaining candidate seed points, and using the retained candidate seed point as the topology center seed point.
[0053] The spatial scale parameter refers to the geometric size feature used to limit the comparison range of the local neighborhood. Its value is positively correlated with the expected average size of the grains in the metallographic structure to be tested. In this embodiment, its value is preferably set to 7, and the data format is integer. The neighborhood window refers to the local discrete sampling area opened in the digital image matrix with the current pixel to be processed as the geometric center. The local spatial neighborhood refers to the set of specific pixel coordinates and their values mapped and covered by the neighborhood window in the multidimensional geometric distance field. The local maximum point refers to the center pixel point whose distance value reaches the highest peak in its corresponding local spatial neighborhood. Its data storage format is preferably a 2-dimensional Boolean matrix. The candidate seed point refers to the set of pixel coordinates with local multidimensional geometric distance peak characteristics retained after screening by local maxima. The distance threshold refers to the spatial geometric distance boundary used to determine whether two candidate seed points belong to the same grain core region. In this embodiment, its value is preferably set to 15 pixels, and the data format is 32-bit floating point. The collaborative aggregation set refers to the clustered coordinate set formed by candidate seed points that are spatially adjacent and whose distance is less than the distance threshold. Its storage format is preferably a dynamic integer coordinate linked list. The topological center seed point refers to the core pixel point with the global maximum distance potential that is uniquely retained after distance value comparison in each collaborative set, and is used to characterize the true geometry and topological center of each independent grain.
[0054] Specifically, in the candidate seed point selection process, the first stage works as follows: First, the planar multidimensional geometric distance field generated in the upstream step is retrieved, and each non-grain boundary pixel within it is traversed. Then, based on the preset spatial scale parameter 7, with each current non-grain boundary pixel as the geometric center, a multidimensional geometric distance field containing 7 is dynamically constructed. A neighborhood window of 7 pixels is defined, and the set of 49 pixels covered by this window is extracted as the local spatial neighborhood of the corresponding non-grain boundary pixel. Then, non-maximum suppression comparison is performed at the matrix numerical level of the multidimensional geometric distance field. The distance values of each non-grain boundary pixel at the current center position are compared one by one with the distance values of the other 48 pixels in its corresponding local spatial neighborhood. Next, a logical judgment is performed: if and only if the distance value of the current center non-grain boundary pixel is strictly greater than the distance values of all other 48 pixels in its local spatial neighborhood, it indicates that the point is at the geometric peak of the spatial distance distribution, and thus the specific non-grain boundary pixel is determined as a local maximum point. Finally, the entire image is traversed to complete the above comparison and filtering, and each obtained local maximum point is output as a candidate seed point, and its spatial row and column coordinates are sequentially written into a pre-initialized dynamic coordinate linked list.
[0055] In the process of determining the topological center seed point, the second stage continues with the following steps: First, the dynamic coordinate linked list corresponding to the candidate seed points output in the previous steps is retrieved. Next, based on a preset distance threshold of 15 pixels, a spatial geometric metric algorithm is invoked to calculate the spatial geometric distance between any two candidate seed points. This spatial geometric distance is obtained using Euclidean distance calculation logic. Subsequently, connectivity clustering is performed based on the calculated spatial geometric distances, grouping candidate seed points with a spatial geometric distance of less than 15 pixels into the same collaborative set, thereby constructing multiple independent collaborative set sets across the entire map. Then, within each collaborative set set, the multidimensional geometric distance field is retrieved again, and the distance values of all candidate seed points included in the current collaborative set are compared one by one in the multidimensional geometric distance field. Finally, a filtering and elimination logic is executed within each collaborative aggregation set, retaining only the candidate seed point with the largest distance value, and deleting and eliminating all other candidate seed points in the set. Ultimately, the unique candidate seed point retained in each collaborative aggregation set is determined and stored as the topology center seed point, thus completing the adaptive denoising and accurate merging of the grain center point.
[0056] In the preferred embodiment of this invention, by combining local maximum initial screening with spatial distance-based collaborative depth aggregation, not only can the core region of the grain be efficiently located, but also the interference of pseudo-peaks caused by intracrystalline impurities or uneven corrosion can be adaptively eliminated, ensuring that each independent grain has one and only one high-confidence seed point, fundamentally eliminating the over-segmentation phenomenon during subsequent regional diffusion.
[0057] like Figure 3 As shown, preferably, the spatial iterative expansion process includes: Step S41: retrieving and determining a set of neighboring candidate pixels that are immediately adjacent to the outer edge of the current connected region expansion; Step S42: calculating the expansion propulsion speed value corresponding to each candidate pixel in the neighboring candidate pixel set based on the geometric contour features and the matrix values in the grain boundary constraint matrix; Step S43: incorporating candidate pixels with expansion propulsion speed values greater than a preset propulsion threshold into the connected region to update the connected region, completing the spatial expansion in the current iteration cycle, and returning to step S41 to execute the next iteration cycle.
[0058] A further preferred embodiment of the control of the outward expansion propulsion state includes: calculating the local curvature value of each pixel on the current connected region expansion front edge, and using the local curvature value as the geometric contour feature; substituting the matrix value into the boundary stagnation mapping function for mapping operation to obtain the stagnation coefficient corresponding to each pixel; performing a composite mapping operation on the local curvature value and the stagnation coefficient to calculate the dynamic propulsion step size of each pixel in the normal direction, and determining the propulsion displacement of the expansion boundary within the current iteration cycle based on the dynamic propulsion step size.
[0059] In this context, the current connected region refers to a 2D connected image region that grows outward from the topological center seed point and is composed of merged pixels within the current iteration cycle. Its data format is preferably a 2D integer label matrix. The expansion front refers to the boundary line with a single pixel width formed at the outermost edge of the current connected region. Its data format is preferably a 1D dynamic array composed of boundary pixel coordinates. The neighborhood candidate pixel set refers to the set of neighboring pixels in the digital image matrix that are in direct contact with the outer edge of the expansion front and have not been absorbed by any connected region. In this embodiment, an 8-neighborhood definition method is preferably used for retrieval, and the data format is stored as an integer 2D coordinate linked list. The local curvature value refers to the geometric feature used to characterize the curvature of the boundary line, calculated using the geometric position and orientation of the current pixel and its spatially adjacent boundary pixels on the expansion front boundary. Its data format is preferably a 32-bit floating-point number. The stagnation coefficient is a dimensionless scalar coefficient used to quantitatively delay or block the outward expansion of the boundary. Its value range is preferably a floating-point number between 0 and 1. Boundary stagnation mapping function refers to a logic that nonlinearly maps the stagnation energy values in the grain boundary constraint matrix to an exponentially decaying function logic with a high stagnation response. Composite mapping operation refers to the algebraic operation process of multiplying the local curvature value representing the curvature driving force and the stagnation coefficient representing the boundary resistance, each with its corresponding weight. Dynamic advance step size refers to the continuous spatial theoretical displacement length of each pixel along its boundary geometric normal direction, obtained after the composite mapping operation. The preferred data format is a 32-bit floating-point number, with the unit being pixels. Advance displacement refers to the actual executable grid step distance obtained after quantizing the dynamic advance step size according to the discrete pixel grid rules. The data format is a non-negative integer, with the unit being pixels. The quantization rule is: the value of the dynamic advance step size is rounded to the nearest integer; when the step size is less than 0.5 pixels, the advance displacement is 0; when the step size is greater than or equal to 0.5 pixels and less than 1.5 pixels, the advance displacement is 1, and so on. The expansion propulsion speed value is numerically equal to the dynamic propulsion step size, with units of pixels per iteration period. It is used to comprehensively evaluate the merging tendency of candidate pixels, and the data format is preferably a 32-bit floating-point number. The preset propulsion threshold is a critical speed control parameter for determining whether a neighboring candidate pixel meets the conditions for merging into the current connected region. In this embodiment, its value is preferably set to 0.45, and the data format is a 32-bit floating-point number.
[0060] Specifically, in this embodiment, the specific calculation formulas for the boundary retardation mapping function and the dynamic propulsion step size in step S4 are as follows: The boundary retardation mapping function is preferably a negative exponential decay function, and its expression is as follows: ,in, Representing coordinates The corresponding resistance coefficient value; This represents the normalized matrix value corresponding to the coordinate in the grain boundary constraint matrix, with a value range from 0 to 1. This represents the preset retardation sensitivity coefficient, in this embodiment... The preferred value is 3.5. The normal direction is dynamically advanced by adjusting the step size based on geometric contour features. The specific formula for calculating the composite weighted product is as follows:
[0061] The spatial displacement is determined by the dynamic propulsion step size. Decide; This represents a preset basic advance step size scalar, which is preferably 1.0 pixel width in this embodiment; This represents the local curvature value at the current leading edge pixel. The curvature constraint weighting coefficient is preferably 0.5. Therefore, when the expanded boundary is close to the true grain boundary (… The resistance coefficient approaches 1. When there is a sudden drop or abrupt change in the curvature of the leading edge, the step size adaptively decays and converges.
[0062] In this embodiment, the preset convergence condition specifically includes the following collaborative judgment criteria: Criterion 1: During the spatial iterative expansion process, if the current expansion front pixel coordinates The numerical values in the grain boundary constraint matrix satisfy If the expansion front point has completely touched the real grain boundary barrier, then it is determined that the edge energy threshold in this embodiment is... The preferred value is 0.80. The boundary pixel that triggers this criterion is locked and stops expanding outward in subsequent iteration cycles. Criterion 2: When the expansion fronts of two or more connected regions that have independently developed and expanded from different topological center seed points meet at a certain spatial pixel, a conflict in the region attribution label of the pixel is detected. Then, the outward expansion at the meeting boundary is immediately forcibly terminated to prevent over-segmentation and penetration between regions. The overall evolution termination condition is defined as follows: When all expansion front pixels in the entire map stop expanding outward due to triggering criterion 1 or criterion 2, or when the total number of pixels merged into the connected region for updating in the current iteration cycle drops to 0, it is determined that the overall preset convergence condition is met, and the spatial iterative expansion process is completely converged and terminated.
[0063] Specifically, during the spatial iterative expansion process, the first stage proceeds as follows: First, the seed points of each topological center determined in the upstream steps are retrieved and used as the starting pixels of the initial connected region. Next, at the start of the current iteration cycle, a boundary tracking algorithm is used to retrieve the outermost edge of the current connected region, determining the expansion front edge of a single pixel width. Subsequently, using this expansion front edge as a reference, an 8-neighborhood of unoccupied pixels immediately adjacent to it is searched outwards. The coordinates of all these searched outer pixels are summarized to retrieve and determine the set of candidate neighboring pixels immediately adjacent to the expansion front edge of the current connected region. Following this, for each pixel on the expansion front edge of the current connected region, the spatial coordinates of multiple boundary points adjacent to the current pixel are extracted. Finite difference is used to approximate the direction of the boundary tangent and normal, thereby calculating the local curvature value of each pixel on the expansion front edge of the current connected region. This local curvature value is then directly output and stored as the geometric contour feature.
[0064] In the process of regulating the outward expansion and calculating the propulsion speed, the second stage continues with the following steps: First, the pre-constructed grain boundary constraint matrix is retrieved, and the specific matrix values corresponding to the expansion front and the neighborhood candidate pixel set in the grain boundary constraint matrix are obtained. Next, the matrix values are substituted into a preset boundary hindrance mapping function for nonlinear mapping operations. The higher the grain boundary energy represented by the matrix values, the closer the mapping output value is to 0, thereby calculating the hindrance coefficient corresponding to each pixel. Subsequently, the local curvature value is substituted into the dynamic propulsion step size formula, and a composite mapping operation is performed in combination with the corresponding hindrance coefficient to calculate the dynamic propulsion step size of each pixel in the normal direction. Immediately afterwards, based on the dynamic propulsion step size, the propulsion displacement of the expansion boundary within the current iteration cycle is determined in the current digital grid space, and the propulsion displacement and dynamic propulsion step size are comprehensively reconstructed in combination with the spatial physical time step to calculate the expansion propulsion speed value corresponding to each candidate pixel in the neighborhood candidate pixel set. The data format is stored as a 32-bit floating-point number. In this calculation, the local curvature value is calculated using the curvature constraint factor in the formula, and the stagnation coefficient is directly used as a product term without additional weighting.
[0065] During the process of updating the connected regions and determining the termination of the iteration, the final execution of the third stage is as follows: First, the calculated expansion propagation speed values of each candidate pixel are compared one by one with the preset propagation threshold of 0.45. Next, a logical determination is performed, and candidate pixels with expansion propagation speed values greater than the preset propagation threshold of 0.45 are determined as valid expansion points. These valid expansion points are directly incorporated into the current connected region, and the connected region is updated by rewriting the corresponding values of the 2D label matrix. Subsequently, the spatial expansion within the current iteration cycle is completed. Immediately after the expansion of the current cycle is completed, the cached data of the previous cycle is automatically cleared, and the process returns to step S41 to retrieve the updated expansion front again, thereby executing the cyclic expansion of the next iteration cycle. Finally, when the expansion propagation speed values of all candidate pixels within a certain iteration cycle are less than or equal to the preset propagation threshold, or when the expansion front coincides with the connected region boundary of the adjacent grain and satisfies the preset convergence condition, the current cyclic expansion is terminated, and the connected region at the time of termination is output and stored as the segmentation target area of each independent metallographic structure.
[0066] In a preferred embodiment of the present invention, by controlling the composite weighted product of the local curvature of space and the grain boundary retardation coefficient, the adaptive adjustment of the boundary expansion state can be achieved, enabling the connected region to advance rapidly inside the grain and converge precisely at the grain boundary edge, effectively ensuring the accuracy of segmentation of complex metallographic structures.
[0067] Preferably, the calculation of morphological feature parameters includes: calculating the zero-order geometric moment and the second-order central moment of each segmented target region; determining the pixel area of each segmented target region based on the zero-order geometric moment; calculating the principal axis length and secondary axis length of each segmented target region based on the second-order central moment; calculating the ratio of the principal axis length to the secondary axis length to obtain the region aspect ratio; calculating the principal axis tilt angle feature based on the second-order central moment; and constructing the morphological feature parameters by vector composite of the pixel area, region aspect ratio, and principal axis tilt angle feature.
[0068] The segmented target area refers to the closed 2D connected pixel region representing each independent metallographic structure, output from the aforementioned steps. Its data format is preferably a 2D binary label matrix. The zeroth-order geometric moment is the scalar integral value obtained by unweighted summation of the connected states of all pixels within the segmented target area. Its data format is preferably a 64-bit integer. The second-order central moment is the geometric moment value used to characterize the dispersion of the spatial mass distribution of the region, obtained by subtracting the region's centroid coordinates from the pixel coordinates and then performing a second-order power translation and weighted summation in orthogonal directions. It contains three independent components: horizontal, vertical, and intersecting directions. Its data format is preferably a 32-bit floating-point number. The pixel area is the absolute physical quantity representing the total number of pixels contained in the segmented target area, directly mapped from the zeroth-order geometric moment. The principal axis length is the maximum geometrically equivalent span in the direction of spatial distribution extension within the metallographic structure region. The secondary axis length is the minimum geometrically equivalent span in an orthogonal direction perpendicular to the principal axis extension direction. The aspect ratio of a region refers to the ratio of the length of the principal axis to the length of the secondary axis, used to characterize the degree of flattening or elongation of the metallographic grains. The data format is a 32-bit floating-point number. The principal axis tilt angle feature refers to the geometric angle between the direction of the principal axis extension and the positive horizontal direction of the image. Its value range is preferably between -90 degrees and +90 degrees. The data format is a 32-bit floating-point number. Vector composite construction refers to the algebraic operation process of recombining and assembling multiple scalar morphological features obtained from discrete calculations according to a preset dimensional order and packaging them into a multidimensional feature vector. Morphological feature parameters refer to the composite feature vectors generated after vector composite construction, used to comprehensively and quantitatively characterize the morphological features of a single metallographic structure. Their format is preferably a 1-dimensional floating-point array composed of 3-dimensional scalars.
[0069] Specifically, in the process of calculating geometric moments and areas, the internal structure of the first stage is as follows: First, the 2D binary matrix corresponding to each segmentation target region output from the upstream step is retrieved. Next, all pixels within each segmentation target region are traversed. Based on the spatial row and column coordinates of the pixels, a discrete integration operation is performed across the entire image, directly accumulating the state values of each pixel within the region to calculate the zero-order geometric moment of each segmentation target region. Subsequently, the pixel area of each segmentation target region is determined based on the zero-order geometric moment, and the value of the zero-order geometric moment is directly converted into the pixel area, achieving scalar extraction of the absolute size of the grain. Following this, the abscissa and ordinate of the geometric centroid of the current segmentation target region are calculated using the zero-order and first-order geometric moments. Finally, all pixels within the segmentation target region are traversed again, and the abscissa and ordinate of the geometric centroid are subtracted from the row and column coordinates of each pixel to perform a centering translation, eliminating the influence of spatial displacement. Weighted summation of the squared terms and cross-product terms is then performed to calculate the second-order central moment containing three components for each segmentation target region.
[0070] In the process of calculating morphological features and constructing vectors, the second stage continues with the following steps: First, the second-order central moments components calculated in the previous steps are retrieved. Next, based on the algebraic transformation relationship of the equivalent ellipse, the sum and difference of the horizontal and vertical components are calculated, and the square root operation is performed using the square of the cross component. Based on the second-order central moments, the principal axis length and secondary axis length of each segmented target region are calculated. Subsequently, the divider logic is invoked to calculate the ratio of the principal axis length to the secondary axis length, thereby calculating the region aspect ratio to quantitatively characterize the grain stretching state. Immediately afterward, the second-order central moments are retrieved again. By calculating the ratio of twice the cross component to the difference between the horizontal and vertical components, and further performing arctangent trigonometric function operations and coefficient scaling, the principal axis tilt angle feature is calculated based on the second-order central moments to characterize the spatial extension orientation of the grain. Finally, the pixel area, region aspect ratio, and principal axis tilt angle features are combined into a vector to construct a vector. By creating a 1D dynamic array with a preset length of 3, the previously calculated pixel area, region aspect ratio, and principal axis tilt angle features are sequentially filled into each dimension of the array according to a set fixed position order. The morphological feature parameters are then constructed and stored in memory for matching and retrieval in downstream rating steps.
[0071] In a preferred embodiment of the present invention, multidimensional features are calculated based on geometric moments and central moments and vector composite construction is performed to achieve high-precision quantitative characterization of the multidimensional morphology of a single grain, providing comprehensive and objective data support for subsequent accurate automated metallographic structure grading.
[0072] In summary, the metallographic structure quantitative detection and rating method based on adaptive region diffusion provided by this invention smooths and enhances the original image by calculating local structural orientation features, and fuses gray-level gradient fields and second-order discontinuity features to construct a high-precision grain boundary constraint matrix, significantly improving the characterization ability of complex and ambiguous boundaries. Then, by using a multidimensional geometric distance field reconstructed by computational space Euclidean distance, the method combines local maximum screening with collaborative aggregation depth based on distance thresholds to adaptively eliminate pseudo-peak interference caused by impurities or scratches inside the grains, achieving accurate positioning of the topological center seed point of each independent grain. Subsequently, in the spatial iterative expansion process, the local curvature value characterizing the geometric contour features of the boundary and the hindrance coefficient characterizing the boundary resistance are combined and weighted to control the expansion boundary, enabling it to rapidly advance within the grain and adaptively and accurately converge at the grain boundary, fundamentally eliminating over-segmentation and under-segmentation phenomena. Finally, based on the zero-order geometric moment and the second-order central moment, multi-dimensional morphological feature parameters are precisely constructed and level-matched, realizing fully automated and high-precision closed-loop detection of metallographic structures from morphology enhancement, centroid positioning, topological segmentation to quantitative grading, greatly improving the intelligence level of metallographic structure detection and the objectivity and accuracy of grading results.
[0073] The above description is merely a preferred embodiment of the technical solution of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for quantitative detection and rating of metallographic structure based on adaptive area diffusion, characterized in that, Includes the following steps: Step S1: Obtain the metallographic image to be tested, calculate its local structural orientation features, and smooth the metallographic image to be tested according to the local structural orientation features to obtain an enhanced metallographic image; Step S2: Perform differential operation on the enhanced metallographic image to extract the gray-level gradient field and second-order discontinuity features to characterize the tissue boundary; map and fuse the gray-level gradient field and second-order discontinuity features to construct a grain boundary constraint matrix; Step S3: Based on the grain boundary constraint matrix, calculate the spatial Euclidean distance from each non-grain boundary pixel in the enhanced metallographic image to the nearest grain boundary, forming a multidimensional geometric distance field; Candidate seed points are selected from the multidimensional geometric distance field, and the candidate seed points are denoised and merged to determine the topological center seed point; Step S4: Construct an initial connected region starting with the topological center seed point as the starting pixel, and perform spatial iterative expansion processing on it; In each iteration of the spatial iterative expansion process, the outward expansion state is controlled according to the geometric contour characteristics of the current connected region expansion front and the matrix value of the expansion front in the grain boundary constraint matrix. Expansion terminates when the expansion boundary meets the preset convergence condition, and the connected region at the time of termination of expansion is used as the segmentation target area for each independent metallographic structure. Step S5: Calculate the morphological feature parameters of each segmented target area and match them with the preset tissue level mapping rules to obtain the quantitative rating results of metallographic tissue.
2. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The calculation process for the local structural orientation features includes: Calculate the first-order partial derivative of the metallographic image under test in the orthogonal direction, and construct the local structure tensor corresponding to each pixel based on the first-order partial derivative; The local structure tensor is subjected to spatial neighborhood smoothing to obtain a smooth structure tensor; The smooth structure tensor is subjected to feature decomposition, and feature vectors are extracted to characterize the tissue orientation. The feature vectors are used as the local structural orientation features.
3. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The process of performing differential operation on the enhanced metallographic image in step S2 specifically includes: calculating the first-order partial derivative of the enhanced metallographic image in the orthogonal direction, and calculating the vector magnitude of the first-order partial derivative to generate the gray-level gradient field; calculating the second-order partial derivative of the enhanced metallographic image in the orthogonal direction to construct the second-order derivative matrix, performing eigenvalue decomposition on the second-order derivative matrix to obtain eigenvalues, and using the eigenvalues as the second-order discontinuity features.
4. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The process of constructing the grain boundary constraint matrix includes: performing numerical interval mapping processing on the gray-level gradient field and the second-order discontinuity feature respectively to obtain a first edge response matrix and a second edge response matrix; and performing a weighted composite superposition operation on the first edge response matrix and the second edge response matrix to construct the grain boundary constraint matrix.
5. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The process of forming the multidimensional geometric distance field specifically includes: Boundary feature extraction is performed based on the grain boundary constraint matrix to determine the set of grain boundary pixels in the enhanced metallographic image; For each non-grain boundary pixel in the enhanced metallographic image, the pixel with the closest geometric distance to it in the set of grain boundary pixels is retrieved, and the spatial Euclidean distance between each non-grain boundary pixel and its corresponding nearest pixel is calculated. The calculated spatial Euclidean distances are reconstructed into a matrix based on the spatial coordinates of the corresponding non-grain boundary pixels to form the multidimensional geometric distance field.
6. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The process of screening candidate seed points includes: Based on the preset spatial scale parameters, a neighborhood window is constructed in the multidimensional geometric distance field with each non-grain boundary pixel as the center, and the set of pixels covered by the neighborhood window is used as the local spatial neighborhood of the corresponding non-grain boundary pixel. In the multidimensional geometric distance field, the distance value of each non-grain boundary pixel is compared with the distance value of other pixels in its corresponding local spatial neighborhood; Non-grain boundary pixels whose distance values are greater than the distance values of all other pixels in the corresponding local spatial neighborhood are identified as local maxima, and each of the obtained local maxima is used as a candidate seed point.
7. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The process of determining the topological center seed point includes: Based on a preset distance threshold, the spatial geometric distance between each pair of candidate seed points is calculated; Candidate seed points whose spatial geometric distance is less than the distance threshold are grouped into the same collaborative set; Within each collaborative aggregation set, the distance values of each candidate seed point in the multidimensional geometric distance field are compared. The candidate seed point with the largest distance value is retained and the remaining candidate seed points are removed. The retained candidate seed point is used as the topological center seed point.
8. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The spatial iterative expansion process includes: Step S41: Retrieve and determine the set of neighboring candidate pixels that are immediately adjacent to the outside of the current connected region expansion front; Step S42: Based on the geometric contour features and the matrix values in the grain boundary constraint matrix, calculate the expansion propulsion speed value corresponding to each candidate pixel in the neighborhood candidate pixel set; Step S43: Incorporate candidate pixels whose expansion propulsion speed value is greater than the preset propulsion threshold into the connected region to update the connected region, complete the spatial expansion in the current iteration cycle, and return to step S41 to execute the next iteration cycle.
9. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The regulation of the outward expansion propulsion state includes: Calculate the local curvature value of each pixel on the front edge of the current connected region expansion, and use the local curvature value as the geometric contour feature; Substitute the matrix values into the boundary stagnation mapping function to perform mapping operations and obtain the stagnation coefficients corresponding to each pixel. The local curvature value and the stagnation coefficient are combined and mapped to calculate the dynamic advance step size of each pixel in the normal direction. The advance displacement of the expansion boundary in the current iteration period is determined based on the dynamic advance step size.
10. The method for quantitative detection and rating of metallographic structures according to claim 1, characterized in that, The calculation of morphological characteristic parameters includes: Calculate the zero-order geometric moment and the second-order central moment of each segmented target region; determine the pixel area of each segmented target region based on the zero-order geometric moment; calculate the principal axis length and secondary axis length of each segmented target region based on the second-order central moment. The ratio of the principal axis length to the secondary axis length is calculated to obtain the region aspect ratio. The principal axis tilt angle feature is calculated based on the second-order central moment. The pixel area, region aspect ratio, and principal axis tilt angle feature are combined into a vector to construct the morphological feature parameters.