Microscope metallographic image recognition and grain size quantitative measurement method and system based on artificial intelligence

By performing boundary prediction, segmentation, feature extraction, and relational reasoning on metallographic images, accurate grain instance masks are generated, solving the segmentation problem of densely adhered grains, realizing automated and precise measurement of grain size, and improving measurement efficiency and accuracy.

CN122156231APending Publication Date: 2026-06-05FUSHUN SPECIAL EQUIP SUPERVISION & INSPECTION INST

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
FUSHUN SPECIAL EQUIP SUPERVISION & INSPECTION INST
Filing Date
2026-03-02
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing technologies suffer from significant under-segmentation and over-segmentation problems when dealing with densely aggregated grains, leading to major deviations in grain size rating results and failing to meet the requirements for accurate quantitative analysis.

Method used

By performing boundary prediction on the original metallographic image to generate a refined boundary map, image segmentation is performed to obtain preliminary regions, regional feature vectors are extracted, a regional relationship graph is constructed and relationship reasoning is performed, merging decision data is generated, and finally instance merging and grain size calculation are performed to achieve accurate segmentation and quantitative measurement of grain instances.

Benefits of technology

It achieves end-to-end automated processing from image to quantitative measurement results, significantly improving the accuracy and robustness of grain size analysis, overcoming the oversegmentation and undersegmentation problems of traditional methods in densely bonded scenarios, and meeting the high-throughput and high-precision requirements of industrial quality inspection and scientific research.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122156231A_ABST
    Figure CN122156231A_ABST
Patent Text Reader

Abstract

The application relates to a microscope metallographic image recognition and grain size quantitative measurement method and system based on artificial intelligence. The method comprises the following steps: performing boundary prediction on an original metallographic image to generate a refined boundary image; performing image segmentation on the refined boundary image to obtain a plurality of preliminary regions; performing feature extraction on each preliminary region to generate a region feature vector; performing graph construction based on the spatial adjacency relationship of the preliminary regions and the region feature vector to generate a region relationship graph; performing relationship reasoning on the region relationship graph to generate merging decision data; performing instance merging on the preliminary regions based on the merging decision data to generate a grain instance mask; and performing grain size calculation on the grain instance mask to generate a grain size measurement result. The method can effectively solve the problem of inaccurate segmentation of traditional methods in the dense and adherent grain field, and realize automatic and high-precision quantitative analysis of grain size.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer vision technology, and in particular relates to a method and system for microscopic metallographic image recognition and quantitative measurement of grain size based on artificial intelligence. Background Technology

[0002] With the deep application of artificial intelligence technology in materials science, image recognition and quantitative analysis based on deep learning has become an important development direction for the automated characterization of metallographic structures. Especially in the core link of grain size measurement, researchers are committed to developing intelligent algorithms that can automatically and accurately identify grain boundaries and segment individual grains to replace traditional manual or semi-automatic measurement methods that rely on human experience, are inefficient, and highly subjective. This will meet the growing demand for high-throughput and highly repeatable analysis in industrial quality inspection and scientific research.

[0003] In current technological practices, mainstream automated grain segmentation methods primarily follow a "semantic segmentation combined with post-processing" approach. First, semantic segmentation networks with encoder-decoder structures, such as U-Net, are used to perform pixel-level classification of metallographic images, predicting each pixel as either a "grain boundary" or "intragranular region," resulting in a preliminary binarized grain boundary network. Subsequently, to resolve the region enclosed by the grain boundary network into independent grain instances (i.e., instance segmentation), additional post-processing steps must be introduced. The most commonly used post-processing technique is the watershed algorithm, which combines distance transform with marker-controlled segmentation. Its principle is to use the segmented grain boundaries as barriers to further divide the intragranular region into independent units representing individual grains. This approach achieves good results in ideal scenarios where grain size is uniform, grain boundaries are clear, and contrast is high.

[0004] However, when dealing with materials that have undergone severe plastic deformation or specific heat treatment processes and are abundant in actual industrial production or research, the inherent defects exposed by the aforementioned existing technical approaches become particularly prominent. The metallographic structure of such materials often features fine, densely distributed grains, and grain boundaries that are blurred and discontinuous due to insufficient corrosion or deformation, resulting in a large number of grains appearing "adhered" in the image. In such densely adhered scenarios, existing methods have significant problems: First, semantic segmentation networks aim to classify pixels, but they cannot distinguish between visually adhered "intragranular" regions belonging to different grain instances. The network tends to predict the entire adhered region as a connected whole, leading to "undersegmentation" at the instance level. Second, subsequent traditional post-processing algorithms such as watersheds heavily rely on clear, continuously closed grain boundaries as input. When the initial grain boundaries provided by semantic segmentation are blurred or broken at the adhesion points, the watershed algorithm will produce severe "oversegmentation" due to the lack of effective barrier markers, or incorrectly merge multiple adhered grains. This contradiction causes a sharp decline in the reliability of segmentation results when existing technologies deal with densely bonded metallographic structures, leading to significant deviations in subsequent grain size statistics and grain size rating results, which cannot meet the requirements of accurate quantitative analysis. Summary of the Invention

[0005] Therefore, it is necessary to provide an artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement method and system that can achieve accurate and robust instance segmentation of densely bonded grains to address the above-mentioned technical problems.

[0006] In a first aspect, this application provides a method for microscopic metallographic image recognition and quantitative measurement of grain size based on artificial intelligence, including:

[0007] S1. Perform boundary prediction on the original metallographic image to generate a refined boundary map;

[0008] S2. Perform image segmentation on the refined boundary map to obtain multiple preliminary regions;

[0009] S3. Extract features from each preliminary region to generate a region feature vector;

[0010] S4. Based on the preliminary spatial adjacency relationships and regional feature vectors, construct a graph to generate a regional relationship graph;

[0011] S5. Perform relational reasoning on the regional relationship diagram to generate merge decision data;

[0012] S6. Based on the merge decision data, perform instance merging on the preliminary region to generate a grain instance mask;

[0013] S7. Calculate the grain size of the grain instance mask and generate the grain size measurement results.

[0014] In one embodiment, S1 includes:

[0015] S11. Perform multi-scale contrast enhancement on the original metallographic image to generate an enhanced image;

[0016] S12. Perform preliminary boundary prediction on the enhanced image to generate an initial boundary probability map;

[0017] S13. Perform boundary optimization on the initial boundary probability map to generate a refined boundary map.

[0018] In one embodiment, S13 includes:

[0019] S131. Concatenate the enhanced image and the initial boundary probability map along the channel dimension to generate the first fusion feature;

[0020] S132. Input the first fused feature into the encoder for feature encoding to generate multi-scale encoded features;

[0021] S133. Combine the initial boundary probability map and multi-scale encoded features to calculate the attention weight map;

[0022] S134. Based on the attention weight map, the decoded features are weighted and fused to generate boundary optimization features;

[0023] S135. Decode and output the boundary optimization features to generate a refined boundary map.

[0024] In one embodiment, S2 includes:

[0025] S21. Perform binarization on the refined boundary map to generate a binarized boundary mask;

[0026] S22. Perform connected component analysis based on binary boundary masks to generate closed contour information;

[0027] S23. Divide the image region according to the closed contour information to generate multiple preliminary regions.

[0028] In one embodiment, S3 includes:

[0029] S31. Perform deep semantic extraction on the original metallographic image to obtain a deep semantic feature map;

[0030] S32. Based on the location information of each preliminary region, extract the corresponding local feature tensor from the deep semantic feature map;

[0031] S33. Perform global average pooling on each local feature tensor to generate pooled feature vectors;

[0032] S34. Concatenate the pooled feature vector with the center coordinates of the corresponding region to generate the region feature vector.

[0033] In one embodiment, S5 includes:

[0034] S51. Update the features of each node in the region relationship graph using a graph convolutional network to generate the updated node feature vector;

[0035] S52. For each edge in the regional relationship graph, concatenate the updated node feature vectors of the two nodes connected by each edge to obtain the concatenated feature vector.

[0036] S53. Input the concatenated feature vector into the fully connected layer for linear transformation to obtain the transformation result. Apply an activation function to the transformation result and calculate the combined confidence score for each edge. The formula for calculating the combined confidence score is:

[0037]

[0038] in, To combine confidence scores, It is the Sigmoid activation function. and For learnable parameters, This represents a vector concatenation operation. and These are the updated node feature vectors of the two nodes connected by the edge;

[0039] S54. Collect the merge confidence scores of all edges in the regional relationship graph to generate merge decision data.

[0040] In one embodiment, S7 includes:

[0041] S71. Calculate the pixel area for each grain instance mask and generate pixel area data;

[0042] S72. Convert the pixel area data according to the image scale to generate physical area data;

[0043] S73. Calculate the equivalent circle diameter of each grain based on the physical area data, and generate equivalent diameter data;

[0044] S74. Perform statistical analysis on the equivalent diameter data to generate grain size distribution data;

[0045] S75. Calculate the grain size level index based on the equivalent diameter data and generate level index data;

[0046] S76. Integrate grain size distribution data and grade index data to generate grain size measurement results.

[0047] Secondly, this application also provides an artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement system, including:

[0048] The boundary prediction module is used to predict the boundaries of the original metallographic image and generate a refined boundary map.

[0049] The image segmentation module is used to segment the refined boundary map to obtain multiple preliminary regions.

[0050] The region feature extraction module is used to extract features from each preliminary region and generate a region feature vector.

[0051] The graph construction module is used to construct a graph based on the spatial adjacency relationships and feature vectors of the preliminary regions, and generate a regional relationship graph.

[0052] The relation reasoning module is used to perform relation reasoning on the regional relation graph and generate merge decision data.

[0053] The instance merging module is used to merge instances in the preliminary region based on merging decision data to generate a grain instance mask;

[0054] The grain size calculation module is used to calculate the grain size of a grain instance mask and generate grain size measurement results.

[0055] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement method of the first aspect.

[0056] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement method of the first aspect.

[0057] The aforementioned AI-based microscopic metallographic image recognition and grain size quantitative measurement method and system directly generates a refined boundary map that clearly distinguishes adhered regions by intelligently predicting the boundary of the original metallographic image. Subsequently, image segmentation is performed based on this map to obtain multiple independent preliminary regions. Deep features of each region are then extracted to form feature vectors, and these vectors are constructed into a region relationship map based on the spatial adjacency relationships between regions. Next, deep reasoning is performed on this relationship map to generate merging decision data that determines which regions belong to the same grain. Based on the merging decision data, the correct preliminary regions are merged, directly outputting an accurate grain instance mask. Finally, grain size calculation is automatically completed based on the grain instance mask, generating the grain size measurement result. This method effectively overcomes the drawbacks of traditional methods that are prone to oversegmentation or undersegmentation in densely adhered grain scenarios, achieving end-to-end automated processing from image to quantitative measurement results, significantly improving the accuracy, robustness, and efficiency of grain size analysis. Attached Figure Description

[0058] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0059] Figure 1 A flowchart illustrating an artificial intelligence-based method for microscopic metallographic image recognition and quantitative measurement of grain size provided by this invention.

[0060] Figure 2 This is a flowchart illustrating a method for generating merged decision data in an optional embodiment of the present invention.

[0061] Figure 3 This is a schematic diagram of the structure of a microscope metallographic image recognition and grain size quantitative measurement system based on artificial intelligence provided by the present invention. Detailed Implementation

[0062] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0063] In one embodiment, such as Figure 1As shown, an artificial intelligence-based method for microscopic metallographic image recognition and quantitative measurement of grain size is provided. This embodiment illustrates the application of this method to a terminal. It is understood that this method can also be applied to a server, and to a system including both a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps:

[0064] S1. Perform boundary prediction on the original metallographic image to generate a refined boundary map.

[0065] Optionally, a mature encoder-decoder semantic segmentation network is used for boundary prediction, preferably the U-Net++ network. This network progressively extracts deep features from the original metallographic image through the encoder, capturing the abstract representation of grain boundaries in the image. Simultaneously, the decoder progressively upsamples the deep features. Combined with skip connections between the encoder and decoder, it achieves the fusion of shallow detail features and deep abstract features, ensuring the accuracy of boundary prediction. After the original metallographic image is input into the network, the network performs classification prediction for each pixel, outputting a pixel-level boundary probability map, where the probability value of each pixel represents the likelihood that the pixel belongs to a grain boundary. To generate a refined boundary map, the boundary probability map is binarized. An adaptive threshold is used to determine the segmentation threshold. Pixels with probability values ​​higher than the threshold are identified as grain boundary pixels, and pixels with probability values ​​lower than the threshold are identified as non-grain boundary pixels, resulting in a preliminary boundary map. Further, the preliminary boundary map undergoes morphological refinement processing. First, an erosion operation is used to remove small noise points on the boundary, and then a dilation operation is used to restore the integrity of the boundary, avoiding boundary breaks caused by the erosion operation. Finally, a refined boundary map with clear, continuous boundaries and no obvious noise is obtained.

[0066] S2. Perform image segmentation on the refined boundary map to obtain multiple preliminary regions.

[0067] Optionally, the refined boundary map is reverse-processed, setting grain boundary pixels as background pixels and non-grain boundary pixels as foreground pixels to obtain a foreground-background binary map, where foreground pixels correspond to potential grain regions. Subsequently, a connected component analysis algorithm is used to process the foreground-background binary map. This algorithm is based on pixel adjacency principles, selecting the 8-neighborhood adjacency criterion, that is, determining whether pixels above, below, to the left, right, and along the four diagonals of a foreground pixel are foreground pixels. If they are foreground pixels, these pixels are determined to belong to the same connected region. The entire foreground-background binary map is traversed, dividing all mutually adjacent foreground pixels into a connected region, with each connected region corresponding to a preliminary region. Preferably, after connected component analysis, small-area noise region filtering is performed. By counting the number of pixels in each connected region, connected regions with too few pixels are filtered out. These connected regions are mostly noise interference regions generated during the segmentation process and are not actual grain regions. The multiple connected regions obtained after filtering are multiple preliminary regions, each of which is a potential single grain or a set of adhered grains.

[0068] S3. Extract features from each preliminary region to generate a region feature vector.

[0069] Optionally, the extracted features include three categories: shape features, texture features, and grayscale features. Shape features are characterized by parameters such as rectangularity, circularity, and compactness. Rectangularity reflects the degree of fit between the initial region and its circumscribed rectangle; circularity reflects the similarity between the initial region and a circle; and compactness reflects the regularity of the initial region's outline. These shape feature parameters can be obtained by calculating the boundary coordinates of the initial region. Texture features are extracted using Local Binary Pattern (LBP). This LBP algorithm compares the grayscale values ​​of a pixel with those of its neighboring pixels, classifying the neighboring pixels into black and white categories, and then generating the LBP code for that pixel. By statistically analyzing the LBP code histogram of the entire initial region, texture features reflecting the differences in grain surface texture can be obtained. Grayscale features are characterized by grayscale mean, grayscale variance, and grayscale entropy. The grayscale mean reflects the overall brightness level of the initial region; the grayscale variance reflects the dispersion of grayscale values ​​within the initial region; and the grayscale entropy reflects the richness of grayscale information within the initial region. These grayscale feature parameters can be calculated by statistically analyzing the grayscale values ​​of all pixels within the initial region. The extracted shape features, texture features, and grayscale features are normalized to eliminate the dimensional differences between different features. Then, all the normalized features are concatenated in a preset order to obtain a fixed-dimensional region feature vector. Each preliminary region corresponds to a unique region feature vector.

[0070] S4. Based on the initial spatial adjacency relationships and regional feature vectors, construct a graph to generate a regional relationship graph.

[0071] Optionally, the construction of the regional relationship graph is centered on the initial regions, with each node representing a preliminary region and edges representing pairs of preliminary regions that are spatially adjacent and have similar features. The graph structure is constructed through spatial adjacency determination and feature similarity calculation. The determination of spatial adjacency is based on the boundary coordinates and circumscribed rectangle coordinates of the preliminary regions. First, the coordinates of the circumscribed rectangle of each preliminary region are calculated, including the x-coordinate of the top-left corner, the y-coordinate of the top-left corner, the x-coordinate of the bottom-right corner, and the y-coordinate of the bottom-right corner. Then, it is determined whether the circumscribed rectangles of any two preliminary regions overlap or are adjacent. If they do, it is further determined whether the boundary pixels of the two preliminary regions are adjacent. If they are, the two preliminary regions are determined to have a spatial adjacency relationship. The similarity calculation of the regional feature vectors uses a cosine similarity algorithm. This algorithm measures feature similarity by calculating the cosine of the angle between the feature vectors of two regions. The closer the cosine value is to 1, the more similar the features of the two preliminary regions are; the closer the cosine value is to 0, the greater the difference in features between the two preliminary regions. The process iterates through all initial pairs of regions with spatial adjacency, calculates the cosine similarity of the feature vectors for each pair, and sets a preset similarity threshold. When the feature similarity between two pairs of initial regions is higher than the preset threshold, an edge is established between the nodes corresponding to the two initial regions, and the weight of the edge is the feature similarity of the pair of regions. If the feature similarity is lower than the preset threshold, no edge is established. After traversing all pairs of initial regions and establishing edge connections, a complete region relationship graph is generated, which clearly reflects the spatial associations and feature similarities between the initial regions.

[0072] S5. Perform relational reasoning on the regional relationship diagram to generate merge decision data.

[0073] Optionally, a Graph Convolutional Network (GCN) is used to perform relational reasoning on the region relation graph. This GCN network can transmit feature information through edge connections between nodes, capture deep relationships between preliminary regions, and then determine whether adjacent preliminary regions belong to the same grain, generating merging decision data. First, the node features (i.e., the region feature vector of each preliminary region) and edge weights (i.e., feature similarity) of the region relation graph are input into the GCN network. Each layer of the GCN network updates the node features by aggregating the feature information of each node's neighboring nodes, combining its own node features and edge weights, and gradually mining the dependencies between nodes. Specifically, the feature update process of the graph convolutional layer is implemented through linear transformation and activation functions. First, a linear transformation is performed on the node features and neighboring node features, then the neighboring node features are weighted and summed according to the edge weights, and finally, the merged features are non-linearly mapped through an activation function to obtain the updated node features. After multiple layers of graph convolution operations, the feature vector of each node can fully integrate the feature information of all its neighboring nodes, reflecting the deep relationship between the preliminary region and its neighboring regions. Subsequently, a classifier is set in the output layer of the graph convolutional network. Each node corresponds to an output value, which represents the probability of merging the initial region with the adjacent initial regions. The merging probabilities of all nodes and the corresponding adjacent region pairs are organized into merging decision data. Region pairs with merging probabilities higher than a preset decision threshold are determined to be region pairs that need to be merged, and region pairs with merging probabilities lower than the preset decision threshold are determined to be region pairs that do not need to be merged.

[0074] S6. Based on the merge decision data, perform instance merging on the preliminary region to generate a grain instance mask.

[0075] Optionally, all pairs of regions to be merged in the merging decision data are traversed, and the pairs are sorted in descending order of merging probability. Pairs with higher merging probabilities are merged first to avoid erroneous merging due to improper merging order. For each pair of initial regions to be merged, the pixel sets of the two regions are merged, and the boundary coordinates, bounding rectangle coordinates, and region feature vector of the merged region are updated. The boundary coordinates of the merged region are the union of the boundary coordinates of the two original regions, the bounding rectangle coordinates are the coordinates of the smallest rectangle that can contain the two original regions, and the region feature vector is the weighted average of the feature vectors of the two original regions, with the weights being the percentage of pixels in each region. After the merging operation is completed, the merged region is used as the new initial region. The region relationship graph is updated, the nodes and related edge connections corresponding to the two merged original regions are deleted, and new region nodes and corresponding edge connections are added. Then, the remaining pairs of regions to be merged are traversed, and the above merging process is repeated. When all pairs of regions to be merged have been merged and no new pairs of regions to be merged exist, the merging process is stopped. At this point, each remaining region is an independent grain instance. Finally, a grain instance mask is generated. The grain instance mask is a pixel-level annotation map with the same size as the original metallographic image. Each grain instance corresponds to a unique pixel identifier value. The background area and grain boundary area correspond to fixed pixel identifier values. By filling the pixel identifier value of each grain instance into the corresponding pixel position, a grain instance mask that clearly distinguishes each independent grain can be obtained.

[0076] S7. Calculate the grain size of the grain instance mask and generate the grain size measurement results.

[0077] Optionally, the grain size calculation strictly follows the relevant standards for measuring the grain size of metallic materials. Based on the pixel information of each grain instance in the grain instance mask and the calibration parameters of the original metallographic image, quantitative calculation of the grain size is achieved. First, the calibration scale of the original metallographic image is obtained. This calibration scale represents the correspondence between image pixels and actual physical dimensions, determined by the microscope's magnification. This parameter can be obtained through the microscope's calibration function and is used to convert the pixel dimensions in the image into actual physical dimensions. Then, each grain instance in the grain instance mask is traversed, and the number of pixels in each grain instance is counted. Combined with the calibration scale, the number of pixels is converted into the actual area of ​​each grain instance. Further, the equivalent circle diameter of each grain instance is calculated. The equivalent circle diameter is the diameter of a circle with the same actual area as the grain instance, which can be derived from the actual area of ​​the grain instance. The equivalent circle diameter directly reflects the grain size. Subsequently, the grain size distribution is statistically analyzed based on the equivalent circle diameter, and statistical parameters such as the average and standard deviation of the grain size are calculated to characterize the uniformity of the grain size. Finally, based on the grain size classification standard and the average equivalent circle diameter of the grains, the grain size grade corresponding to the metallographic image is determined. The actual area, equivalent circle diameter, grain size distribution statistical parameters, and overall grain size grade of each grain instance are compiled and summarized to generate complete grain size measurement results. The grain size measurement results can be directly used for quantitative analysis of grain size in industrial quality inspection or scientific research.

[0078] The aforementioned AI-based microscopic metallographic image recognition and grain size quantitative measurement method provides reliable support for segmentation by performing refined boundary prediction on the original metallographic image; preliminary regions are obtained through connected region analysis, and essential grain features are captured by multi-dimensional feature extraction; a region relationship graph is constructed based on spatial adjacency and feature similarity, and accurate relationship reasoning is achieved using graph convolutional networks, thereby completing the reasonable merging of adhered regions and generating accurate grain instance masks; finally, grain size quantitative calculation is completed based on standard methods. This method automates and improves the accuracy of grain recognition and grain size measurement, effectively solving the undersegmentation and oversegmentation problems of existing technologies in densely adhered grain scenarios, eliminating reliance on human experience, improving measurement efficiency and repeatability, and meeting the needs of industrial quality inspection and scientific research for high-throughput and high-precision grain size quantitative analysis.

[0079] In one embodiment, S1 includes:

[0080] S11. Perform multi-scale contrast enhancement on the original metallographic image to generate an enhanced image.

[0081] Optionally, a multi-scale Retinex algorithm is used to enhance the contrast of the original metallographic image. The multi-scale Retinex algorithm decomposes the original metallographic image into a reflection component and an illumination component. The reflection component contains the image's detailed features and contrast information, while the illumination component mainly affects the overall brightness uniformity of the image. By separating and enhancing the reflection component, the image's detail contrast can be effectively improved, while suppressing interference caused by uneven illumination. Specifically, the original metallographic image is first converted to a grayscale image to avoid interference from the color channel on the enhancement effect. Then, multiple Gaussian filters of different scales are selected to perform Gaussian blurring on the grayscale original metallographic image, resulting in multiple sets of blurred images at different scales. Each scale of blurred image corresponds to a different degree of illumination component estimation. Further, multiple sets of reflection component estimates at different scales are obtained by taking the logarithmic difference between the original grayscale image and each set of blurred images. These multiple reflection component estimates are then weighted and averaged to obtain the final reflection component image. Finally, the final reflection component image is subjected to grayscale stretching to map its grayscale values ​​to a preset reasonable range, eliminating the problem of grayscale value overflow in the enhanced image. The result is an enhanced image with clear details, moderate contrast, and uniform illumination, effectively highlighting the blurred grain boundary details in the original metallographic image.

[0082] S12. Perform preliminary boundary prediction on the enhanced image to generate an initial boundary probability map.

[0083] Optionally, the U-Net semantic segmentation network is selected for preliminary boundary prediction of the enhanced image. This network adopts an encoder-decoder symmetrical structure, which can effectively capture deep abstract features and shallow detail features of the image, adapting to the extraction requirements of grain boundary details in the enhanced image. First, the enhanced image is input into the encoder part of the U-Net network. The encoder gradually reduces the resolution of the image through multiple convolution and pooling operations, while extracting deep features of the image to capture the overall contour and abstract representation of the grain boundary. The decoder part gradually restores the resolution of the image through multiple deconvolution operations (upsampling), and fuses the deep features extracted by the encoder with the shallow detail features of the corresponding layer through skip connections to ensure the accuracy of boundary prediction and avoid missed boundary detection due to feature loss. The output layer of the network uses the sigmoid activation function, mapping the prediction result of each pixel to a probability range of 0 to 1. The closer the probability value is to 1, the greater the probability that the pixel belongs to the grain boundary, and the closer the probability value is to 0, the greater the probability that the pixel belongs to the non-grain boundary (intra-grain). By traversing all pixels of the enhanced image, the grain boundary probability value corresponding to each pixel is obtained. Arranging these probability values ​​according to pixel position generates an initial boundary probability map, which can initially reflect the distribution location of grain boundaries in the enhanced image.

[0084] S13. Perform boundary optimization on the initial boundary probability map to generate a refined boundary map.

[0085] Optionally, the initial boundary probability map is first binarized, and an adaptive thresholding algorithm is used to determine the segmentation threshold. This algorithm automatically calculates the optimal segmentation threshold based on the grayscale distribution characteristics of the initial boundary probability map, classifying pixels with probability values ​​higher than the threshold as grain boundary pixels and those lower as non-grain boundary pixels, thus obtaining a preliminary boundary binary map. Subsequently, the preliminary boundary binary map undergoes morphological optimization. First, an erosion operation is used to traverse the preliminary boundary binary map, removing tiny noise points and isolated pixels attached to the grain boundaries to avoid noise interference with boundary integrity. Then, a dilation operation is used to process the eroded boundary binary map, restoring any grain boundary fragments that may have broken during the erosion process, ensuring the continuity of the grain boundaries. Further, the morphologically optimized boundary binary map undergoes boundary smoothing. A Gaussian filtering algorithm is used to smooth the boundary pixels, eliminating jagged distortions on the boundaries and making the grain boundary contours more regular, while avoiding boundary blurring caused by over-smoothing. After these three optimization steps, a refined boundary map with clear, continuous boundaries, no obvious noise, and regular contours is generated.

[0086] In the above embodiments, multi-scale contrast enhancement processing is first used to effectively improve the contrast and clarity of the original metallographic image, highlighting blurred grain boundary details and solving the problems of uneven illumination and indistinct grain boundaries in the original image. Then, a U-Net network is used to perform preliminary boundary prediction of the enhanced image, accurately capturing the distribution location of grain boundaries. Finally, multi-step optimization processing is used to eliminate noise and repair boundaries, resulting in a high-quality, refined boundary map. This embodiment is progressive and tightly integrated, effectively improving the accuracy and completeness of boundary prediction.

[0087] In one embodiment, S13 includes:

[0088] S131. The enhanced image and the initial boundary probability map are concatenated along the channel dimension to generate the first fusion feature.

[0089] Optionally, the enhanced image and the initial boundary probability map are first checked for size consistency to ensure that their height and width are exactly the same, avoiding stitching failure due to size mismatch. Channel-dimensional stitching is then performed only after the check passes. The enhanced image is a single-channel grayscale image, containing only the detailed texture and grayscale features of the metallographic structure; the initial boundary probability map is also a single-channel image, containing the probability information of each pixel belonging to a grain boundary. Channel-dimensional stitching uses a tensor stitching operation, stacking and fusing the single-channel tensor corresponding to the enhanced image and the single-channel tensor corresponding to the initial boundary probability map along the channel axis. The resulting dual-channel feature tensor is the first fused feature, which fully combines the detailed features of the enhanced image with the grain boundary position probability information of the initial boundary probability map.

[0090] S132. Input the first fused feature into the encoder for feature encoding to generate multi-scale encoded features.

[0091] Optionally, the same U-Net network encoder structure used for preliminary boundary prediction is selected. This encoder consists of multiple convolutional blocks and pooling layers connected sequentially. Specifically, after the first fused feature is input into the encoder, it first undergoes two convolution operations through the first convolutional block. After each convolution operation, a Rectified Linear Unit (ReLU) is used as the activation function to extract shallow detail features from the first fused feature. These shallow features mainly correspond to the surface texture and fine contours of the metallographic structure, and also contain preliminary location information of the initial grain boundaries. Subsequently, a max pooling layer is used for downsampling to reduce the resolution of the feature map, retain key features, and reduce computational cost. Afterward, it is processed alternately through multiple convolutional blocks and pooling layers. With each pooling layer, the feature map resolution is halved, and the feature level extracted by the convolutional blocks gradually deepens, transitioning from shallow detail features to deep abstract features. The deep features mainly correspond to the overall structure of the metallographic structure and the macroscopic distribution patterns of grain boundaries. After processing by all convolutional blocks and pooling layers, multiple feature maps of different resolutions and levels are finally output. These feature maps together constitute multi-scale encoded features, which can comprehensively cover the feature information of metallographic structures from details to the whole.

[0092] S133. Combine the initial boundary probability map and multi-scale encoded features to calculate the attention weight map.

[0093] Optionally, the multi-scale encoded features are uniformly sized. A bilinear interpolation algorithm is used to upsample all encoded features at different resolutions to the same resolution as the initial boundary probability map, ensuring that corresponding elements can be calculated. After upsampling, the encoded features at all scales are concatenated along the channel dimension to obtain a comprehensive encoded feature that integrates multi-scale information. This comprehensive encoded feature contains both shallow detail features and deep abstract features, comprehensively reflecting the feature differences of the grain boundary region. Subsequently, the comprehensive encoded feature is concatenated with the initial boundary probability map using the same channel dimension concatenation method as S131, resulting in a fused feature that integrates multi-scale encoded features and initial grain boundary probability information. This fused feature is then input into a convolutional layer. The number of channels in the fused feature is compressed to a single channel through convolution operations. A sigmoid activation function is then used to map the convolution output to a probability range of 0 to 1, resulting in a single-channel attention weight map. The value of each pixel in the attention weight map is the attention weight. The closer the value is to 1, the greater the possibility that the region corresponding to the pixel is a grain boundary and needs to be focused on. The closer the value is to 0, the more likely the region corresponding to the pixel is a non-grain boundary region and can be appropriately suppressed. In this way, precise focusing on grain boundary regions can be achieved.

[0094] S134. Based on the attention weight map, the decoded features are weighted and fused to generate boundary optimization features.

[0095] Optionally, the decoded features are generated by the decoder part of the U-Net network. The decoder and encoder have a symmetrical structure. Multi-scale encoded features are upsampled through deconvolution operations to gradually restore the feature map resolution. Simultaneously, the multi-scale encoded features output by the encoder are initially fused with the corresponding level's decoded features through skip connections to obtain initial decoded features. These initial decoded features contain the location information of grain boundary regions and detailed features of the metallographic structure, but still suffer from some noise interference and boundary blurring. The weighted fusion process uses pixel-wise multiplication, multiplying the attention weight map with the initial decoded features at corresponding pixels. Decoded features corresponding to high-weight pixels in the attention weight map are enhanced, while those corresponding to low-weight pixels are suppressed. Preferably, after pixel-wise multiplication, residual connections are added, element-wise summing the initial decoded features with the weighted features to mitigate potential feature loss during weighted fusion and retain effective information in the decoded features. After the above weighted fusion processing, the resulting feature tensor is the boundary optimization feature. This feature highlights the feature information of grain boundary regions, suppresses background noise and interference from non-grain boundary regions, and retains key details of the metallographic structure.

[0096] S135. Decode and output the boundary optimization features to generate a refined boundary map.

[0097] Optionally, continuing the decoder structure of the U-Net network, the boundary optimization features are progressively decoded. The decoder sequentially processes the features through multiple deconvolution blocks and upsampling layers, gradually improving the resolution until it is restored to the same resolution as the original metallographic image and the enhanced image. Each deconvolution block contains two deconvolution operations to improve the feature map resolution. After each deconvolution operation, the ReLU activation function is used to enhance the non-linear expressive power of the features. Simultaneously, skip connections are used to fuse the corresponding multi-scale encoded features from the encoder output with the current decoded features, supplementing the details lost during decoding and ensuring accurate restoration of boundary details. After the decoding process is complete, the final high-resolution feature map is input into the output layer. The output layer uses the Sigmoid activation function to map the value of each pixel in the feature map to a probability range of 0 to 1, resulting in the optimized boundary probability map. Subsequently, the optimized boundary probability map is binarized, and an adaptive thresholding algorithm consistent with the boundary optimization is used to determine the segmentation threshold. Pixels with probability values ​​higher than the segmentation threshold are identified as grain boundary pixels, and pixels with probability values ​​lower than the segmentation threshold are identified as non-grain boundary pixels. Finally, a refined boundary map with clear, continuous, noise-free, and regular contours is generated.

[0098] In the above embodiments, the effective information of the image and the initial boundary probability map is enhanced by channel-dimensional stitching and fusion. Multi-scale encoded features are extracted by the encoder, and attention weight maps are calculated in combination with the initial boundary probability map to achieve precise focusing of the grain boundary region. Then, the decoding features are optimized by weighted fusion, and finally, a refined boundary map is obtained by decoding. This embodiment is progressive and tightly connected, making full use of image detail features and grain boundary probability information, effectively repairing the blurring and breakage of the initial boundary, suppressing noise interference, and significantly improving the accuracy and completeness of boundary prediction.

[0099] In one embodiment, S2 includes:

[0100] S21. Perform binarization on the refined boundary map to generate a binarized boundary mask.

[0101] Optionally, the consistency of pixel values ​​in the refined boundary map is first checked to ensure that all pixel values ​​are within a uniform numerical distribution range, providing a unified computational basis for binarization processing. Preferably, an adaptive threshold binarization algorithm is used. This algorithm can autonomously calculate an appropriate segmentation threshold based on the local grayscale distribution characteristics of the refined boundary map, avoiding the misjudgment of grain boundary pixels in areas with uneven brightness, which occurs with the global threshold algorithm. Specifically, taking the grain boundary pixels in the refined boundary map as the target objects, all pixels with values ​​higher than the adaptive threshold are uniformly assigned a preset grain boundary identifier value, and all pixels with values ​​lower than the adaptive threshold are uniformly assigned a preset background identifier value. After reassigning the pixel values, the entire image is traversed to check for abnormal pixels, and isolated noise pixels with grain boundary identifier values ​​are removed to avoid interference from single noise pixels in subsequent region analysis. Finally, a binarized boundary mask containing only two types of pixels—grain boundary identifier values ​​and background identifier values—is generated. This mask can clearly and without redundancy distinguish between grain boundary regions and non-grain boundary regions, allowing the grain boundary contour to form a clear pixel boundary in the image.

[0102] S22. Perform connected region analysis based on binary boundary mask to generate closed contour information.

[0103] Optionally, based on the binarized boundary mask, the 8-neighbor adjacency criterion is used to conduct connected region analysis. The 8-neighbor adjacency criterion can comprehensively determine the surrounding adjacency relationship of the target pixel. Compared with the 4-neighbor criterion, it can effectively avoid the problem of fragmented identification of grain boundary contours. In specific operation, the grain boundary marker pixel in the binarized boundary mask is used as the only analysis target. All pixels of the entire mask are traversed row by row and column by column. For each grain boundary marker pixel, it is determined whether its eight adjacent pixels in the top, bottom, left, right and four diagonal directions have the same grain boundary marker value. All adjacent grain boundary marker pixels are classified into the same connected region until the traversal of all pixels and region division are completed. Subsequently, contour extraction is performed on each divided connected region. A contour tracking algorithm is used to track all edge pixels of the region sequentially from the starting edge pixel of each connected region in a fixed direction, while simultaneously recording the two-dimensional coordinate information of each edge pixel. After extraction, the closure of all tracked contours is checked. For non-closed contours with pixel breaks, linear interpolation is used to fill in the missing edge pixels at the breaks, so that the contours corresponding to each connected region form a complete closed state. Finally, the pixel coordinate information of all closed contours is classified and organized according to the connected region to which they belong, generating closed contour information containing the complete pixel coordinate sequence of each closed contour.

[0104] S23. Divide the image region according to the closed contour information to generate multiple preliminary regions.

[0105] Optionally, using the metallographic image enhanced with multi-scale contrast as the base map for region division, the closed contour information is first mapped onto the base map one by one according to pixel coordinates, completing the precise matching between the contour coordinates and the pixel coordinates of the base map, ensuring that the spatial position of the contour completely corresponds to the actual grain boundary position in the metallographic image. Then, using each independent closed contour as the physical boundary, pixel-level region division operation is performed on the base map. Specifically, an algorithm for determining whether a pixel is inside a polygon is used. For each pixel in the base map, by calculating the spatial positional relationship between the pixel and each side of the corresponding closed contour, it is accurately determined whether the pixel is inside the internal region of a certain closed contour. After completing the assignment determination of all base map pixels pixel by pixel, all pixels inside the same closed contour are grouped into an independent image region, so that each closed contour corresponds to an internal region enclosed by it. After the initial segmentation is completed, the validity of all segmented image regions is verified. By counting the number of pixels in each region, tiny regions with too few pixels are filtered out. These tiny regions are invalid regions caused by grain boundary noise and are not real grain-related regions. After verification, the remaining valid independent image regions are uniquely numbered, and basic attribute information such as the pixel coordinate range and total number of pixels of each region is recorded. Finally, all numbered valid independent image regions are organized into multiple preliminary regions. Each preliminary region is a complete region surrounded by a closed grain boundary contour.

[0106] In the above embodiment, the refined boundary map is first subjected to adaptive threshold binarization to obtain a binary boundary mask with clear pixel boundaries. Then, grain boundary contours are extracted through 8-neighbor connected region analysis and closure repair is completed to generate accurate closed contour information. Finally, the metallographic image is divided into pixel-level regions using the closed contours as boundaries, and invalid micro-regions are filtered out to generate multiple preliminary regions. This embodiment achieves ordered region division of the metallographic image based on closed and accurate grain boundary contours, effectively avoiding the problem of chaotic region division caused by non-closed contours, eliminating invalid regions caused by noise, and improving the realism and effectiveness of the preliminary regions.

[0107] In one embodiment, S3 includes:

[0108] S31. Perform deep semantic extraction on the original metallographic image to obtain a deep semantic feature map.

[0109] Optionally, a mature Residual Network (ResNet) is selected as the deep semantic extraction network. This ResNet network, by introducing residual connection structures, effectively alleviates the gradient vanishing problem during deep network training and can stably extract deep semantic features from the original metallographic image. Specifically, the original metallographic image is first converted into a standardized image that meets the input requirements of the ResNet network. The image pixel values ​​are normalized to eliminate differences in grayscale dimensions. Then, the standardized original metallographic image is input into the ResNet network. The ResNet network performs convolution operations and batch normalization through multiple residual blocks. Each residual block contains two convolutional layers and one residual connection. The convolutional layers are used to extract image features, batch normalization is used to stabilize the training process and accelerate convergence, and the residual connection skips some convolutional layers, directly transferring shallow features to deeper layers, thus achieving the fusion of shallow detailed features and deep abstract features. After all residual blocks are processed, the output feature map is the deep semantic feature map. The deep semantic feature map contains deep semantic information such as the intrinsic structure of grains and grain boundary correlation in the original metallographic image, rather than simple surface grayscale or texture features.

[0110] S32. Based on the location information of each preliminary region, extract the corresponding local feature tensor from the deep semantic feature map.

[0111] Optionally, the location information of each preliminary region is read. This location information is the pixel coordinate range of each preliminary region recorded during the region division process, including the x-coordinate of the upper left corner, the y-coordinate of the upper left corner, the x-coordinate of the lower right corner, and the y-coordinate of the lower right corner, clarifying the spatial position of each preliminary region in the original metallographic image. Since the resolution of the deep semantic feature map differs from the original metallographic image, a bilinear interpolation algorithm is first used to map the pixel coordinate range of the preliminary region to the coordinate system of the deep semantic feature map, ensuring accurate coordinate matching and avoiding offsets in feature extraction. Then, a region-of-interest (ROI) pooling algorithm is used to crop the corresponding feature region from the deep semantic feature map for each mapped preliminary region coordinate range. The RIO pooling algorithm can uniformly pool feature regions corresponding to preliminary regions of different sizes into fixed-size feature blocks. Regardless of the differences in the size and shape of the preliminary regions, it can output feature blocks of consistent size, with each feature block corresponding to a local feature tensor. During the extraction process, all preliminary regions are traversed one by one, and the local feature tensor corresponding to each preliminary region is extracted according to the above process, ensuring that each preliminary region corresponds to a unique local feature tensor containing deep semantic information.

[0112] S33. Perform global average pooling on each local feature tensor to generate pooled feature vectors.

[0113] Optionally, global average pooling aggregates features along the spatial dimensions of the local feature tensor, eliminating spatial redundancy, preserving effective semantic features along the channel dimensions, and converting the two-dimensional feature tensor into a one-dimensional feature vector, facilitating feature concatenation. For each local feature tensor, its dimensions include the number of channels, height, and width. Global average pooling only operates on the height and width spatial dimensions, calculating the arithmetic mean of all pixel values ​​within each channel, resulting in a unique average value for each channel. Iterating through all channels of the local feature tensor, the average values ​​of each channel are arranged sequentially by channel, forming a one-dimensional vector, which is the pooled feature vector. Through global average pooling, the deep semantic information in the local feature tensor is preserved, the feature dimensions are effectively compressed, and the computational cost is reduced, while avoiding overfitting. This ensures that the generated pooled feature vector accurately represents the deep semantic features of the corresponding initial region, and that the pooled feature vectors for all initial regions have the same dimension.

[0114] S34. Concatenate the pooled feature vector with the center coordinates of the corresponding region to generate the region feature vector.

[0115] Optionally, the center coordinates of each preliminary region are calculated. Based on the pixel coordinate range of each preliminary region, the center x-coordinate and center y-coordinate are obtained through arithmetic operations. The center x-coordinate is the average of the x-coordinates of the upper left and lower right corners of the preliminary region, and the center y-coordinate is the average of the y-coordinates of the upper left and lower right corners of the preliminary region. The obtained center coordinates can accurately represent the spatial center position of each preliminary region in the original metallographic image. Subsequently, the center coordinates are normalized, mapping the center x-coordinate and center y-coordinate to the numerical range of 0 to 1, so that the coordinate values ​​are consistent with the numerical range of the pooling feature vector, eliminating the influence of dimensional differences on the subsequent use of features. The normalization process adopts the linear normalization method. Finally, the channel dimension concatenation method is used to stack and fuse the normalized center coordinates (two-dimensional vector) with the corresponding pooling feature vector (one-dimensional vector). The one-dimensional vector obtained after concatenation is the region feature vector. This region feature vector contains both deep semantic features and spatial location information of the preliminary region, and can more comprehensively represent the attributes of the preliminary region compared with a single semantic feature.

[0116] In the above embodiment, a deep semantic extraction is first performed on the original metallographic image using a residual network to obtain a deep semantic feature map containing deep grain information. Then, combined with preliminary regional location information, a fixed-size local feature tensor is extracted using a region-of-interest pooling algorithm. A pooled feature vector is generated by compressing the dimension through global average pooling, and finally, the center coordinates are concatenated to obtain the regional feature vector. This embodiment fully integrates semantic features and spatial location information, effectively solving the problem of insufficient representation by a single feature and improving the comprehensiveness and accuracy of regional features.

[0117] In an optional embodiment, such as Figure 2 As shown, S5 includes:

[0118] S51. Update the features of each node in the region relationship graph using a graph convolutional network to generate the updated node feature vector.

[0119] Optionally, a conventional graph convolutional network is used to update node features. This graph convolutional network is a mature graph feature learning structure. The initial features of each node in the region relation graph are the region feature vectors generated earlier, and the edge weights are the feature similarity when the graph structure was constructed earlier. Specifically, the network performs feature aggregation and update operations layer by layer. For each node, it first traverses all its neighboring nodes, and the initial feature vectors of the neighboring nodes are weighted and summed according to the weights of the corresponding edges to obtain the neighbor feature aggregation result. Then, the neighbor feature aggregation result is concatenated with the node's own initial region feature vector and input into the convolutional layer to complete the linear transformation. After passing through the modified linear unit activation function, a non-linear mapping is performed to realize the update of the node features. Preferably, after multiple layers of the above operations, the features of each node are fully integrated with the feature information of all its neighboring nodes, eliminating the one-sidedness of single node features. The final output one-dimensional feature vector of each node is the updated node feature vector. Each node corresponds to a unique updated feature vector, and the feature dimension is consistent with the initial region feature vector.

[0120] S52. For each edge in the regional relationship graph, concatenate the updated node feature vectors of the two nodes connected by each edge to obtain the concatenated feature vector.

[0121] Optionally, a full traversal of all edges in the regional relationship graph is performed first, assigning a unique identifier to each edge. Simultaneously, a node association index is established for each edge to accurately match the numbers of the two connected nodes and the corresponding updated node feature vector storage addresses, avoiding mismatches between edge and node features. Then, a standardized vector concatenation operation is performed on each edge. This operation involves sequentially stacking feature dimensions. First, the updated node feature vector of the first node is retained in its original element order. Then, all elements of the updated node feature vector of the second node are sequentially concatenated to form a new one-dimensional feature vector. During the vector concatenation operation, the dimensional consistency of the two vectors to be concatenated must be verified in real time to ensure that the dimension of the concatenated vector is twice that of a single updated node feature vector. After traversing and completing the concatenation operation for all edges, each edge in the regional relationship graph corresponds to a unique concatenated feature vector, which contains all updated semantic and spatial feature information of the nodes at both ends of the edge.

[0122] S53. Input the concatenated feature vector into the fully connected layer for linear transformation to obtain the transformed result. Apply an activation function to the transformed result and calculate the combined confidence score for each edge. The formula for calculating the combined confidence score is:

[0123]

[0124] in, To combine confidence scores, It is the Sigmoid activation function. and For learnable parameters, This represents a vector concatenation operation. and These are the updated node feature vectors of the two nodes connected by the edge.

[0125] Optionally, the fully connected layer used is a conventional single-output fully connected structure, where the learnable parameters in the formula... For the weight matrix, Both the bias vector and the weight vector are obtained through iterative optimization during model training using a conventional gradient descent algorithm, with the training process occurring concurrently with the training of the graph convolutional network. Specifically, the concatenated feature vector corresponding to each edge is input into the fully connected layer in tensor form. Matrix multiplication is then performed, combining the concatenated feature vector with the weight matrix. Multiply, then add the bias vector to each element of the result. The linear transformation process is completed to obtain a one-dimensional linear transformation result. This result is then input into the Sigmoid activation function, a non-linear activation function that maps inputs of any numerical range to the interval between 0 and 1. Its output value is the merge confidence score of the corresponding edge. The entire calculation process strictly follows the given formula to ensure that the score calculation logic and operation steps for all edges are completely consistent. The magnitude of the score value can characterize the degree of merging and matching of the preliminary regions represented by the two corresponding nodes.

[0126] S54. Collect the merge confidence scores of all edges in the regional relationship graph to generate merge decision data.

[0127] Optionally, a master table of edge information association is first constructed for the regional relationship graph. This table contains a unique identifier for each edge, the numbers of the two initial regions it connects to, the node feature index, and the calculated merge confidence score, ensuring precise binding of all edge attribute information to scores without omissions or misalignments. Then, the merge confidence scores and corresponding dual-region numbers for all edges are extracted in batches from the master table. The relevant information for all edges is then reordered according to the initial region numbering order, allowing edge information from adjacent regions to be centrally arranged for quick retrieval during the merge operation. Further, the sorted information is structured and converted into a tensor format suitable for the instance merge step operations. Dimension identifiers and information descriptions are added to the structured data to ensure direct parsing and retrieval. The resulting structured information set is the merge decision data, which fully preserves the merge confidence scores and regional association information for all edges.

[0128] In the above embodiment, the node features of the regional relationship graph are first updated through a graph convolutional network, allowing each node to fully integrate the association features of its neighboring nodes. Then, the updated node features at both ends of the edge are concatenated to obtain a concatenated feature vector. After linear transformation by a fully connected layer and quantification calculation using a sigmoid activation function, the merging confidence score is calculated. Finally, the scores and regional association information are combined to generate structured merging decision data. This embodiment relies on a mature network structure and standardized mathematical operations to accurately mine the deep association features between preliminary regions in densely connected scenarios, realize the quantitative determination of the necessity of regional merging, and generate complete and standardized merging decision data, effectively improving the accuracy and reliability of merging decisions.

[0129] In one embodiment, S7 includes:

[0130] S71. Calculate the pixel area for each grain instance mask and generate pixel area data.

[0131] Optionally, pixel identifier verification is first performed on the grain instance mask to confirm that each grain instance corresponds to a unique pixel identifier value. Background and grain boundary regions have independent fixed identifier values ​​to avoid identifier confusion that could lead to calculation errors. Specifically, the entire grain instance mask is traversed one by one according to the unique identifier value of each grain instance. The number of pixels corresponding to each identifier value is counted, and the counted number of pixels is the pixel area of ​​the corresponding grain instance. During the count, pixels in the background and grain boundary regions are automatically filtered out, and isolated noise pixels in each grain instance are removed to prevent noise pixels from affecting the accuracy of area calculation. After the count is completed, the unique identifier value of each grain instance is bound to the corresponding pixel area value to form key-value pair structured data, which is the pixel area data.

[0132] S72. Convert the pixel area data according to the image scale to generate physical area data.

[0133] Optionally, the image scale is a calibration conversion relationship between the pixel size of the original metallographic image and the actual physical size, obtained by the microscope's imaging system. It includes the actual physical area conversion parameter corresponding to each pixel. First, the complete conversion parameters of the image scale are read and their validity is verified to ensure that there are no missing or incorrect parameters. Then, the pixel area value of each grain instance in the pixel area data is substituted one by one, and the conversion from pixel area to physical area is completed through multiplication. That is, the pixel area value of the grain instance is multiplied by the actual physical area conversion parameter corresponding to each pixel to obtain the actual physical area of ​​the corresponding grain instance. After the conversion is completed, all physical area values ​​are normalized to unify the unit of measurement of physical area. Then, the unique identifier value of each grain instance is bound to the corresponding actual physical area value to generate structured physical area data.

[0134] S73. Calculate the equivalent circle diameter of each grain based on the physical area data, and generate equivalent diameter data.

[0135] Optionally, the equivalent circle diameter is the diameter of a circle equal to the actual physical area of ​​the grain. Its calculation is derived from the formula for the area of ​​a circle. First, the actual physical area values ​​of all grain instances in the physical area data are retrieved. Then, the equivalent circle diameter is calculated for each grain instance one by one according to the derived formula. Specifically, the inverse operation of the circle area is performed on the actual physical area value to obtain the radius of the corresponding equivalent circle. Then, the equivalent circle diameter is obtained through the conversion relationship between radius and diameter. During the calculation process, the consistency of numerical calculation accuracy is maintained to avoid cumulative errors caused by step-by-step calculations. After the calculation is completed, the rationality of the equivalent circle diameter values ​​of all grain instances is checked, and abnormal values ​​that clearly do not conform to the metallographic structure characteristics are eliminated. Then, the unique identifier value of each grain instance is bound to the corresponding equivalent circle diameter value to form structured equivalent diameter data, ensuring that each grain instance has a unique corresponding equivalent circle diameter value.

[0136] S74. Perform statistical analysis on the equivalent diameter data to generate grain size distribution data.

[0137] Optionally, the equivalent circle diameter values ​​of all grain instances in the equivalent diameter data are first extracted globally to ensure no values ​​are missed or duplicated. Then, multi-dimensional statistical analysis is performed on the extracted values. Specifically, the overall statistical parameters of the equivalent circle diameter are first calculated, including the mean, median, standard deviation, and coefficient of variation. The mean reflects the overall level of grain size, while the standard deviation and coefficient of variation reflect the dispersion of grain size. Then, the equivalent circle diameter values ​​are divided into equidistant intervals, and the number of grain instances in each interval and their proportion to the total number of grain instances are counted. After all statistical operations are completed, the interval division information of the equivalent circle diameter, the number of grains in each interval, and their proportion are integrated with the overall statistical parameters. The integrated information is then arranged in a structured manner according to the ascending order of the equivalent circle diameter values ​​to generate grain size distribution data. This data fully reflects the overall distribution characteristics and individual differences of grain size in the metallographic image.

[0138] S75. Calculate the grain size level index based on the equivalent diameter data and generate the level index data.

[0139] Optionally, the calculation of the grain size index strictly follows the area method (clause 8.2) specified in the national standard for grain size measurement of metallic materials (GB / T6394-2017). The core calculation formula is derived based on the average equivalent circle diameter and fully complies with the national standard requirements. The specific derivation and final formula are as follows: First, calculate the number of grains per unit area using the average equivalent circle diameter d. , That is, the number of grains per unit area, and then... Substitute the formula for calculating the grain size index as specified in the national standard: ,in denoted as the grain size index, d is the average equivalent circle diameter of all grain instances, and lg is a commonly used logarithmic function. The average number of grains per unit area is used. First, the equivalent circle diameter values ​​of all grain instances are extracted from the equivalent diameter data. The average equivalent circle diameter is obtained through arithmetic averaging, and this average value is the core parameter for calculating the grain size index. Then, the average equivalent circle diameter value is substituted into the calculation formula specified in the aforementioned national standard. The average equivalent circle diameter value is first subjected to natural logarithmic calculation, and then the result is substituted back into the formula to complete a linear calculation, yielding the grain size index value. The calculation process strictly follows the formula's operational logic and steps to maintain the accuracy of the numerical calculation and avoid calculation errors. After the calculation is completed, the obtained grain size index value is verified against a standard range to determine whether it conforms to the conventional distribution range of grain size levels in metallic materials. Finally, the average equivalent circle diameter value, the grain size index value, and the range verification results are integrated to generate structured level index data, ensuring the professionalism, compliance, and accuracy of the index calculation results.

[0140] S76. Integrate grain size distribution data and grade index data to generate grain size measurement results.

[0141] Optionally, the grain size distribution data and grade index data are first checked for data consistency to confirm that the statistical base of grain instances in the two types of data is completely consistent, with no missing data, duplication, or statistical bias. Then, the two types of data are normalized to unify the structured storage format. Specifically, the average equivalent circle diameter and core values ​​of the grain size grade index are extracted from the grade index data, while key statistical information such as the mean, median, standard deviation, and the number and proportion of grains in each size interval are extracted from the grain size distribution data. Simultaneously, independent pixel area data, physical area data, and equivalent diameter data for each grain instance are added to form a complete dataset. Next, measurement-related explanatory information is added to this dataset, including image scale parameters, calculation standards, and data statistical range. Finally, all information is integrated and arranged according to a preset standardized structure to generate complete grain size measurement results. These results include both quantitative data for individual grain instances and statistical data on the overall metallographic structure.

[0142] In the above embodiment, the pixel area of ​​the grain instance mask is first statistically analyzed and converted into the actual physical area using an image scale. Then, the equivalent circle diameter of each grain is derived. Grain size distribution data is obtained through multi-dimensional statistical analysis. The grain size level index is calculated using the national standard formula. Finally, various data are integrated to generate standardized grain size measurement results. This embodiment strictly follows the industry standard for grain size measurement of metallic materials, achieving accurate conversion from pixel-level data to actual physical parameters. The statistical analysis dimensions are comprehensive, and the measurement results include both detailed data of individual grains and overall statistical characteristics. It eliminates the subjectivity and randomness of manual measurement, improves the accuracy, standardization, and data integrity of quantitative grain size measurement, and is suitable for the high-precision measurement needs of densely adhered grain scenarios.

[0143] The aforementioned AI-based microscopic metallographic image recognition and grain size quantitative measurement method and system uses the original metallographic image as the processing object. First, it enhances image quality through multi-scale contrast enhancement, and then uses an encoder-decoder structure optimized with channel stitching and attention mechanisms to complete accurate boundary prediction, generating a refined boundary map. Next, it divides multiple preliminary regions from the refined boundary map through binarization and connected component analysis. Through deep semantic extraction combined with the spatial location information of the preliminary regions, it generates a region feature vector with both semantic and spatial characteristics. Based on this feature vector and spatial adjacency relationships, it constructs a region relationship graph. Subsequently, it uses a graph convolutional network to update node features and quantifies the merging confidence of edges, generating merging decision data. It then performs accurate instance merging of the preliminary regions to obtain a grain instance mask. Finally, according to the area method of GB / T 6394-2017, it extracts the pixel area from the grain instance mask and converts it to physical area. After calculating the equivalent circle diameter, it derives the grain size level index using the national standard formula, and integrates statistical data to generate standardized grain size measurement results. This technical solution effectively solves the problems of undersegmentation and oversegmentation in the processing of densely bonded metallographic structures by using attention mechanism-optimized accurate boundary prediction and graph convolutional network-driven intelligent region merging decision-making. Furthermore, the grain size calculation strictly follows the national standard area method, which greatly improves the accuracy, standardization and repeatability of quantitative grain size measurement, meeting the needs of industrial quality inspection and scientific research for high-throughput and high-precision metallographic analysis.

[0144] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0145] Based on the same inventive concept, this application also provides a system for implementing the aforementioned artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement method. The solution provided by this system is similar to the implementation scheme described in the above method. Therefore, the specific limitations of one or more embodiments of the artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement system provided below can be found in the above-described limitations of the artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement method, and will not be repeated here.

[0146] In one exemplary embodiment, such as Figure 3 As shown, an artificial intelligence-based microscope metallographic image recognition and grain size quantitative measurement system 10 is provided, comprising:

[0147] Boundary prediction module 11 is used to predict the boundaries of the original metallographic image and generate a refined boundary map;

[0148] Image segmentation module 12 is used to segment the refined boundary map to obtain multiple preliminary regions;

[0149] The region feature extraction module 13 is used to extract features from each preliminary region and generate a region feature vector;

[0150] Graph construction module 14 is used to construct a graph based on the spatial adjacency relationship and feature vector of the preliminary region, and generate a regional relationship graph;

[0151] Relationship reasoning module 15 is used to perform relationship reasoning on the regional relationship diagram and generate merge decision data;

[0152] The instance merging module 16 is used to merge instances in the preliminary region based on the merging decision data to generate a grain instance mask;

[0153] The grain size calculation module 17 is used to calculate the grain size of the grain instance mask and generate the grain size measurement results.

[0154] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps of the artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement method as described above.

[0155] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the aforementioned artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement method.

[0156] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The components described as separate parts may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this disclosure according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0157] The above-described embodiments are merely illustrative of several implementation methods of the embodiments of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the embodiments of this application, and these modifications and improvements all fall within the protection scope of the embodiments of this application.

Claims

1. An artificial intelligence-based microscopic metallographic image recognition and grain size quantitative measurement method, characterized in that, The method includes: S1. Perform boundary prediction on the original metallographic image to generate a refined boundary map; S2. Perform image segmentation on the refined boundary map to obtain multiple preliminary regions; S3. Extract features from each of the preliminary regions to generate a region feature vector; S4. Based on the spatial adjacency relationship of the preliminary region and the feature vector of the region, a graph is constructed to generate a region relationship graph; S5. Perform relational reasoning on the regional relational graph to generate merge decision data; S6. Based on the merging decision data, perform instance merging on the preliminary region to generate a grain instance mask; S7. Calculate the grain size of the grain instance mask and generate the grain size measurement result.

2. The method according to claim 1, characterized in that, S1 includes: S11. Perform multi-scale contrast enhancement on the original metallographic image to generate an enhanced image; S12. Perform preliminary boundary prediction on the enhanced image to generate an initial boundary probability map; S13. Perform boundary optimization on the initial boundary probability map to generate the refined boundary map.

3. The method according to claim 2, characterized in that, S13 includes: S131. The enhanced image and the initial boundary probability map are concatenated along the channel dimension to generate a first fusion feature; S132. Input the first fused feature into the encoder for feature encoding to generate multi-scale encoded features; S133. Combine the initial boundary probability map and the multi-scale encoded features to calculate the attention weight map; S134. Based on the attention weight map, the decoded features are weighted and fused to generate boundary optimization features; S135. Decode and output the boundary optimization features to generate the refined boundary map.

4. The method according to claim 1, characterized in that, S2 includes: S21. Perform binarization processing on the refined boundary map to generate a binarized boundary mask; S22. Perform connected region analysis based on the binarized boundary mask to generate closed contour information; S23. Divide the image region according to the closed contour information to generate the multiple preliminary regions.

5. The method according to claim 1, characterized in that, S3 includes: S31. Perform deep semantic extraction on the original metallographic image to obtain a deep semantic feature map; S32. Based on the location information of each preliminary region, extract the corresponding local feature tensor from the deep semantic feature map; S33. Perform a global average pooling operation on each of the local feature tensors to generate a pooled feature vector; S34. The pooled feature vector and the center coordinates of the corresponding region are concatenated to generate the region feature vector.

6. The method according to claim 1, characterized in that, S5 includes: S51. Update the features of each node in the region relationship graph using a graph convolutional network to generate an updated node feature vector; S52. For each edge in the region relation graph, the updated node feature vectors corresponding to the two nodes connected by each edge are concatenated to obtain a concatenated feature vector. S53. The concatenated feature vector is input into a fully connected layer for linear transformation to obtain the transformation result. An activation function is applied to the transformation result to calculate the combined confidence score corresponding to each edge. The formula for calculating the combined confidence score is as follows: in, To combine confidence scores, It is the Sigmoid activation function. and For learnable parameters, This represents a vector concatenation operation. and These are the updated node feature vectors of the two nodes connected by the edge; S54. Collect the merging confidence scores of all edges in the regional relationship graph to generate the merging decision data.

7. The method according to claim 1, characterized in that, S7 includes: S71. Calculate the pixel area for each of the said grain instance masks to generate pixel area data; S72. Convert the pixel area data according to the image scale to generate physical area data; S73. Calculate the equivalent circle diameter of each grain based on the physical area data, and generate equivalent diameter data; S74. Perform statistical analysis on the equivalent diameter data to generate grain size distribution data; S75. Calculate the grain size level index based on the equivalent diameter data, and generate level index data; S76. Integrate the grain size distribution data and the level index data to generate the grain size measurement result.

8. A microscopic metallographic image recognition and grain size quantitative measurement system based on artificial intelligence, characterized in that, The system includes: The boundary prediction module is used to predict the boundaries of the original metallographic image and generate a refined boundary map. An image segmentation module is used to segment the refined boundary map to obtain multiple preliminary regions; The region feature extraction module is used to extract features from each of the preliminary regions and generate a region feature vector. The graph construction module is used to construct a graph based on the spatial adjacency relationship of the preliminary region and the feature vector of the region, and generate a region relationship graph; The relationship reasoning module is used to perform relationship reasoning on the regional relationship graph and generate merge decision data; The instance merging module is used to merge instances in the preliminary region based on the merging decision data to generate a grain instance mask; The grain size calculation module is used to calculate the grain size of the grain instance mask and generate grain size measurement results.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 7.