A method for automatic grain identification and precise quantitative characterization based on metallographic images
Automatically identify and quantify the grains of metal materials through image processing methods, solving the problems of low efficiency and poor accuracy in the prior art, achieving efficient and accurate analysis of grains, and providing a deeper level of material performance analysis.
Patent Information
- Application Number
- CN202211625549.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-16
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2042-12-16
AI Technical Summary
In the prior art, the automatic identification and precise quantification analysis of metal grains are inefficient, manual statistical methods are time-consuming and have large errors, and it is impossible to accurately calculate the grain area and distribution.
Image processing methods are adopted, including grayscale conversion, bottom cap transformation, grain boundary threshold extraction, image closing operation, mark-based watershed segmentation and eight-neighborhood connectivity inspection to achieve automatic identification and precise quantification of grains.
Improves the efficiency and accuracy of grain recognition and quantification, and can quickly and accurately calculate the maximum area, average area and distribution of grains, providing a deeper level of material performance analysis.
Smart Images

Figure CN116188560B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of material microscopic analysis, and in particular to a method for automatic grain recognition and precise quantitative characterization based on metallographic images. Background Art
[0002] Grain count and analysis of metal materials are essential for research related to material microscopic analysis and performance evaluation. Generally speaking, the grain size of a metal material in a steady state conforms to the Hall-Petch relationship with the material's yield strength. That is, the smaller the grain size, the higher the yield strength and the better the plasticity and toughness. Conversely, a smaller grain size indicates poorer mechanical properties and greater susceptibility to quenching deformation and cracking.
[0003] Currently, the quantification and analysis of grain size in metal materials is typically performed through manual counting. This method is not only time-consuming, but also prone to statistical errors due to fatigue when counting is too long. Furthermore, manual counting can only count the number of grains, but cannot calculate their area or conduct in-depth analysis of their size and distribution. Therefore, based on the shortcomings of manual counting methods for analyzing and quantifying grain images, the present invention proposes an image processing method for automatically identifying and accurately quantifying grains in metal material grain images. Summary of the Invention
[0004] The purpose of the present invention is to overcome the above-mentioned deficiencies in the prior art and, by leveraging the advantages of image processing methods in image segmentation and quantitative analysis, provide a method for automatic grain identification and precise quantitative characterization analysis of metal material grain images (i.e., analysis of the maximum area, minimum area, average area, grain area size distribution and grain size of metal material grains).
[0005] The technical solution adopted by the present invention to solve the above problems is: a method for automatic grain recognition and precise quantitative characterization based on metallographic images, which is characterized by comprising the following steps:
[0006] S1, grayscale conversion: the imported metallographic image is recorded as I, and the metallographic image is converted into a grayscale image with pixel values of 0 to 255 by grayscale conversion, which is recorded as I1;
[0007] S2, bottom hat transformation: perform morphological bottom hat transformation on the grayscale converted metallographic image I1, and the image after morphological bottom hat transformation is recorded as I2;
[0008] S3, grain boundary threshold extraction: According to the grayscale distribution in the bottom-hat transformed image I2, manually select an appropriate threshold to extract the grain boundaries in the image I2; that is, the threshold of the grain boundary is 255, and the threshold of the grain is 0. This binary image is recorded as I3;
[0009] S4, image closing operation: Since there are many noise points in image I3, in order to better segment the grains in image I3, it is necessary to perform image closing operation on each grain of the binary image I3 to eliminate the noise points inside the grain as much as possible. The image after the closing operation is recorded as I4;
[0010] S5, watershed segmentation based on markers: first, perform distance transformation on the image I4 after the closing operation, and record the image obtained by the distance transformation as I5; then, perform binarization on the image I5 to obtain image I6, and classify and mark the connected areas in the image I6 using the 8-neighborhood connectivity check method to obtain image mark1; subtract the image I4 after the closing operation from the binarized image I6 to obtain the foreground area I7 of the grain, assign the pixel value of the position of the image mark1 corresponding to the pixel value of 255 in the image I7 to 0, and assign the pixel value of the position of the image mark1 corresponding to the pixel value of 0 in the image I4 to -1, and then perform watershed segmentation on the grain image I combined with the marker image mark1 to obtain image mark2;
[0011] S6. Check and improve the grain segmentation effect: Check the grain image mark2 after watershed segmentation. If the grain segmentation effect is good, proceed to the next step of grain quantization. If the grain segmentation effect is poor, return to step S3, re-extract the grain boundary threshold, and then proceed to steps S4 and S5.
[0012] S7, grain quantification analysis: Use the image traversal method to count the area of each grain in the image mark2, calculate the average area and maximum area of the grain, draw the distribution curve of the grain area, and then calculate the grain size according to the definition of grain size.
[0013] Furthermore, the specific implementation method of step S1 is: the grayscale conversion calculation formula of image I1 is Gray=R×0.299+G×0.587+B×0.114, where Gray is the pixel value of the grayscale image I1, and R, G, and B are the pixel values of image I.
[0014] Furthermore, step S2 includes the following sub-steps:
[0015] S21. Convert the grayscale image I1 into a three-dimensional matrix A(x, y, z), where x and y are the plane positions of the pixels corresponding to the image I1, and z is the grayscale value corresponding to the pixels in the image I1; perform an expansion and then an erosion operation (closing operation) on the three-dimensional matrix A to obtain a matrix B;
[0016] S22. Subtract matrix B from matrix A to obtain matrix C (bottom-hat transformation), and then convert matrix C into a grayscale image I2.
[0017] Furthermore, the specific implementation method of step S3 is: according to the grayscale distribution of image I2, appropriate grayscale values gray_min and gray_max are selected as the threshold interval for grain boundary extraction of image I2, that is, when the grayscale value of the pixel in image I2 is ≥ gray_min and ≤ gray_max, the pixel value of the area is recorded as 255, and the remaining pixel values that do not meet the grayscale interval are recorded as 0, and the resulting binary image is recorded as I3.
[0018] Furthermore, step S4 includes the following sub-steps:
[0019] S41, create an image I4 with the same size as I3 and a pixel value of 0;
[0020] S42, performing an 8-neighborhood connectivity check on the area with pixels 0 in the binary image I3, and marking the pixels in the image I4 corresponding to the non-adjacent areas of I3 as 1, 2, 3, 4, ... respectively;
[0021] S43, performing the image closing operation of step S21 on the regions with pixel values of 1, 2, 3, 4, ... in image I4. To ensure the integrity of the grain structure, when the image closing operation is performed on the grain regions with pixel values of 1, 2, 3, 4, ... in image I4, the pixel values connected to the background region remain unchanged;
[0022] S44 , assigning a value of 1 to the pixel area of the image I4 where the pixel value is 0, assigning a value of 0 to the pixel area of the image I4 where the pixel value is 255, and then assigning a value of 255 to the pixel area of the image I4 where the pixel value is 1.
[0023] Furthermore, step S5 includes the following sub-steps:
[0024] S51, storing the area with a pixel value of 255 in the image I4 into the subset z1 in the form of coordinates, and storing the area with a pixel value of 0 in the image I4 into the subset z2 in the form of coordinates;
[0025] S52. Calculate the minimum distance from each coordinate in subset z1 to the coordinates in subset z2 using the Euclidean distance formula to form a set containing coordinates and distances, denoted as z3. The minimum distance value in set z3 is denoted as z_min, and the maximum distance value in z3 is denoted as z_max.
[0026] S53. Create an image I5 of the same size as image I4 and with a pixel value of 0. Place image I5 at the coordinate position of set z3 and assign its pixel value according to the formula G(x, y) = 255 × |z3(x, y)-z_min| / |z_max-z_min|.
[0027] S54, traverse the image I5 to find the maximum pixel value G_max, traverse the pixels in the image I5 and assign the pixel grayscale value greater than 0.05*G_max to 255, and the pixel grayscale value less than 0.05*G_max to 0, and record the image after this transformation as I6;
[0028] S55, creating an image mark1 of the same size as I6 with a pixel value of 0, performing a connectivity check on the areas of image I6 with a pixel value of 255 using an 8-connected neighborhood check method, and marking the unconnected areas of mark1 corresponding to the areas of image I6 as 1, 2, 3, ...;
[0029] S56, assigning a value of -1 to the borders around the image mark1;
[0030] S57. Traverse the area where the pixel value in the mark1 image is 0. If there is a pixel value that is not 0 in the upper, lower, left, or right neighborhood of the area where the pixel value in the image is 0, calculate the grayscale gradient of the pixel position of the point corresponding to the original image I. The calculation formula of the grayscale gradient is: min(max(abs(R-RL), abs(G-GL), abs(B-BL)); max(abs(R-RR), abs(G-GR), abs(B-BR)); max(abs(R-RT), abs(G-GT), abs(B-BT)); max (abs(R-RB), abs(G-GB), abs(B-BB)); where R, G, B are the RGB values of the target pixel, RL, GL, BL are the RGB values of the pixels in the area to the left of the target pixel, RR, GR, BR are the RGB values of the pixels in the neighborhood to the right of the target pixel, RT, GT, BT are the RGB values of the pixels in the neighborhood above the target pixel, RB, GB, BB are the RGB values of the pixels in the neighborhood below the target pixel, and the pixels for which the grayscale gradient is calculated are placed in the queue of the set q in the form of coordinate positions;
[0031] S58, scan the set q from left to right according to the size of the gradient value. When the coordinate position in the scanned set q corresponds to the four neighborhood coordinates of the pixel point in the mark1 image and there is a marked pixel, assign the pixel at this position in the mark1 image to the marked pixel value of the four neighborhood coordinates, delete its coordinate position in the queue of the set q, and find out whether there is an area with a value of 0 in the four neighborhood pixels of the marked pixel point position in the mark1 image. If so, calculate its gradient according to the grayscale gradient method in step S57, put it into the queue of the set q in the form of coordinate position, and exit this scan; when the coordinate position in the scanned set q corresponds to the four neighborhood pixels of the pixel point in the mark1 image and there are two or more different marked pixels, assign the pixel at this position in the mark1 image to -1, delete its coordinate position in the queue of the set q, search for whether there is an area with a value of 0 in the four neighborhood pixels of the pixel point position in the mark1 image. If so, calculate its gradient according to the grayscale gradient method in step S57, put it into the queue of the set q in the form of coordinate position, and exit this scan;
[0032] S59. Repeat the above step S58 until the area with a pixel value of 0 in the mark1 image disappears, and record the image mark1 after the segmentation as mark2.
[0033] Furthermore, the specific implementation method of step S6 is: if there are two or more independent grains in principle in the image mark2, but their mark pixel values are the same, if such a situation exists for a large number of grains in the mark2 image, steps S4 and S5 must be repeated.
[0034] Furthermore, step S7 includes the following sub-steps:
[0035] S71, traverse the pixels in the image mark2, count the number of pixels with different marks, that is, the areas of different grains, and perform quantitative analysis on the areas of the grains;
[0036] S72, the formula for calculating grain size is G = 3.321928 lgN A -2.954, where N A is the number of grains per square millimeter, G is the grain size, the number of grains in this metallographic image can be known through the above steps, and according to the scale of the metallographic image, the number of grains per square millimeter in the metallographic image N can be known. A , and then the grain size G of the metallographic image can be known through the above grain size calculation formula.
[0037] Compared with existing technologies, this invention offers the following advantages and effects: Using image-based methods to segment metal material grain images saves time, improves efficiency, and maintains high accuracy compared to manual statistical methods for grain differentiation. Quantitative analysis of metal material grain images can deeply mine metallographic image information, revealing a deeper understanding of the relationship between the metal's structure and properties, providing inspectors with more material reference information. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 is a flow chart of the method of the present invention;
[0039] Figure 2 The original grain image I in the embodiment of the present invention;
[0040] Figure 3 is a grain image I1 after grayscale conversion in an embodiment of the present invention;
[0041] Figure 4 is the grain image I2 after bottom-hat transformation in an embodiment of the present invention;
[0042] Figure 5 The binary image I3 is extracted by the grain boundary threshold in the embodiment of the present invention;
[0043] Figure 6 is a grain image I4 after image closing operation in an embodiment of the present invention;
[0044] Figure 7 is a grain image I5 after distance transformation in an embodiment of the present invention;
[0045] Figure 8 is a binary image I6 obtained by performing threshold extraction on the grain image I5 in an embodiment of the present invention;
[0046] Figure 9 This is the grain foreground area image I7 in the embodiment of the present invention;
[0047] Figure 10 is the grain image mark2 after watershed segmentation in the embodiment of the present invention;
[0048] Figure 11 is a schematic diagram of a set q in an embodiment of the present invention;
[0049] Figure 12 Schematic diagram of grain identification quantification in an embodiment of the present invention. DETAILED DESCRIPTION
[0050] The present invention will be further described in detail below with reference to the accompanying drawings and through examples. The following examples are intended to explain the present invention but the present invention is not limited to the following examples.
[0051] Example
[0052] like Figure 1 As shown, a method for automatic grain recognition and precise quantitative characterization based on metallographic images includes the following steps:
[0053] S1. Grayscale conversion: The metallographic images imported this time are as follows Figure 2 As shown, denoted as I, the gray value calculation formula is: Gray = R × 0.299 + G × 0.587 + B × 0.114, where Gray is the value of image I after grayscale conversion, and R, G, and B are the RGB pixel values of image I. According to the above gray value calculation formula, grayscale conversion is performed on image I, and the grayscale image obtained by grayscale conversion is denoted as I1, as shown Figure 3 shown.
[0054] S2, bottom hat transformation: performing morphological bottom hat transformation on the grayscale image I1 after grayscale conversion. The image after morphological bottom hat transformation is recorded as I2. The specific steps include the following:
[0055] S21. Convert the grayscale image I1 into a three-dimensional matrix A(x, y, z), where x and y are the plane positions of the pixels corresponding to image I1, and z is the pixel value in image I1. Perform an expansion and then erosion operation (closing operation) on the three-dimensional matrix A to obtain a matrix B.
[0056] S22, subtract matrix B from matrix A to obtain matrix C (bottom hat transformation), and then convert matrix C into a grayscale image I2, such as Figure 4 shown.
[0057] S3, grain boundary threshold extraction: According to the grayscale distribution in image I2, the grayscale lower limit of image I2 is manually selected as gray_min = 16, and the grayscale upper limit is gray_max = 255. That is, when the grayscale pixel value in image I2 is ≥ gray_min and ≤ gray_max, the pixel grayscale value of the area is recorded as 255, and the remaining pixel values that do not meet the grayscale interval are recorded as 0. The binary image is recorded as I3. The area with pixel value 0 in image I3 is the grain, and the area with pixel value 255 is the grain boundary. Figure 5 shown.
[0058] S4, image closing operation: Since there are many noise points in the grain image I3, in order to better segment the grains in the image, it is necessary to perform image closing operation on each grain of the binary image I3 to eliminate the noise inside the grain as much as possible. The image after the closing operation is recorded as I4, as shown in Figure 6 As shown, it specifically includes the following sub-steps:
[0059] S41, create an image I4 with the same size as I3 and a pixel value of 0;
[0060] S42, performing an 8-neighborhood connectivity check on the area with pixels 0 in the binary image I3, and marking the pixels of I4 corresponding to the non-adjacent areas of I3 as 1, 2, 3, 4, ... respectively;
[0061] S43, performing the image closing operation of step S21 on the regions with pixel values of 1, 2, 3, 4, ... in I4, respectively. To ensure the integrity of the grain structure, when the image closing operation is performed on the grain regions with pixel values of 1, 2, 3, 4, ... in I4, the pixel values connected to the background region remain unchanged;
[0062] S44. Assign a value of 1 to the pixel area of the image I4 where the pixel value is 0 after the closing operation, assign a value of 0 to the pixel area of the image I4 where the pixel value is 255, and then assign a value of 255 to the pixel area of the image I4 where the pixel value is 1.
[0063] S5, watershed segmentation based on markers: First, perform distance transformation on image I4, and the image obtained by distance transformation is I5, as shown in Figure 7 As shown. Then perform binarization on image I5 to obtain image I6, as shown Figure 8 As shown. The connected areas in image I6 are classified and marked using the eight-neighborhood connectivity check method to obtain image mark1. Image I4 is subtracted from the binarized image I6 to obtain the foreground area I7 of the grain, as shown Figure 9 As shown. The pixel value of the image mark1 corresponding to the pixel value of 255 in the image I7 is assigned to 0, and the pixel value of the image mark1 corresponding to the pixel value of 0 in the image I4 is assigned to -1. Then, the grain image I is combined with the marker image mark1 to perform watershed segmentation to obtain the image mark2, as shown. Figure 10 The specific steps include the following:
[0064] S51, storing the area with a pixel value of 255 in the image I4 in the form of coordinates into the subset z1, and storing the area with a pixel value of 0 in the image I4 in the form of coordinates into the subset z2;
[0065] S52. Calculate the minimum distance from each coordinate in subset z1 to each coordinate in subset z2 using the Euclidean distance formula to form a set containing coordinates and distances, denoted as z3. The minimum distance value in set z3 is denoted as z_min, and the maximum distance value in set z3 is denoted as z_max.
[0066] S53. Create an image I5 of the same size as image I4 and with a pixel value of 0, and assign the pixel value corresponding to the coordinate position of set z3 in image I5 according to the formula G(x, y) = 255 × |z3(x, y)-z_min| / |z_max-z_min| to it;
[0067] S54, traverse the image I5 to find the grayscale maximum value G_max, traverse the pixels in the I5 image, assign the pixels with grayscale values greater than 0.15*G_max to 255, and assign the pixels with grayscale values less than 0.15*G_max to 0, and record the image after this transformation as I6;
[0068] S55, creating an image mark1 of the same size as I6 with a pixel value of 0, performing a connectivity check on the regions of image I6 with a pixel value of 255 using an eight-connected neighborhood check method, and marking the unconnected regions of mark1 corresponding to the regions of image I6 as 1, 2, 3, ...;
[0069] S56, assigning a value of -1 to the borders around the image mark1;
[0070] S57. Traverse the area where the pixel value in the mark1 image is 0. If there is a non-zero marked pixel in the upper, lower, left, and right neighborhoods of the area where the pixel value in the mark1 image is 0, calculate the grayscale gradient of the pixel position at that point in the original image I. The grayscale gradient calculation formula is: min(max(abs(R-RL), abs(G-GL), abs(B-BL)); max(abs(R-RR), abs(G-GR), abs(B-BR)); max(abs(R-RT), abs(G-GT), abs(B-BT)). ; max(abs(R-RB), abs(G-GB), abs(B-BB)); where R, G, B are the RGB values of the target pixel, RL, GL, BL are the RGB values of the pixels in the area to the left of the target pixel, RR, GR, BR are the RGB values of the pixels in the neighborhood to the right of the target pixel, RT, GT, BT are the RGB values of the pixels in the neighborhood above the target pixel, RB, GB, BB are the RGB values of the pixels in the neighborhood below the target pixel, and the pixels for grayscale gradient calculation are placed in the queue of set q in the form of coordinate positions, as shown in the following example: Figure 11 As shown;
[0071] S58. Scan the set q from left to right and from top to bottom according to the size of the gradient value. When the coordinate position in the scanned set q corresponds to the four neighborhood coordinates of the pixel point in the mark1 image and there is a marked pixel, assign the pixel at this position in the mark1 image to the marked pixel value with the same four neighborhood coordinates, delete its coordinate position in the queue of the set q, search whether there is an area with a value of 0 in the four neighborhood pixels of the pixel point position in the mark1 image, if so, calculate its gradient according to the grayscale gradient method in step S57, put it into the queue of the set q in the form of coordinate position, and exit this scan; when the coordinate position in the scanned set q corresponds to the four neighborhood pixels of the pixel point in the mark1 image and there are two or more different marked pixels, assign the pixel at this position in the mark1 image to -1, delete its coordinate position in the queue of the set q, search whether there is an area with a value of 0 in the four neighborhood pixels of the pixel point position in the mark1 image, if so, calculate its gradient according to the grayscale gradient method in step S57, put it into the queue of the set q in the form of coordinate position, and exit this scan;
[0072] S59. Repeat the above step S58 until the area with a pixel value of 0 in the mark1 image disappears, and record the image mark1 after the segmentation as mark2.
[0073] S6. Check and improve the grain segmentation effect: Check the grain image mark2 after watershed segmentation. If the grain segmentation effect is good, proceed to the next step of grain quantization. If the grain segmentation effect is poor, that is, there are two or more independent grains in the image mark2 in principle, but their pixel values are the same. If such a situation exists for a large number of grains in the mark2 image, return to step S3, re-extract the grain boundaries, and then proceed to steps S4 and S5.
[0074] S7, grain quantification: Use the image traversal method to count the grain area in the segmented image mark2, calculate the average area and maximum area of the grains, and draw the distribution curve of the grains, such as Figure 12 As shown. Then calculate the grain size according to the definition of grain size. Specifically including the following sub-steps:
[0075] S71, traverse the pixels in the image mark2, count the number of pixels with different marks, that is, the areas of different grains, and perform quantitative analysis on the areas of the grains;
[0076] S72, Grain size calculation formula: G = 3.321928 lgN A -2.954, where N Ais the number of grains per square millimeter, G is the grain size, the number of grains in this grain image can be known through the above steps, and according to the scale of the grain image, the number of grains per square millimeter in the grain image N can be known. A , and then through the above grain size calculation formula, it can be known that the grain size G of the grain image is level 5.5, and the standard rating of the metallographic image is also level 5.5, indicating that this method has high accuracy.
[0077] The present invention first performs noise reduction preprocessing on the grain image with the help of an image method, then uses a marker-based watershed segmentation method to segment the grains in the metallographic image, and uses an eight-neighborhood connectivity check method to mark the segmented single grains.
[0078] The present invention quantitatively analyzes the grains in the metallographic image, which enables the experimenter to quickly and accurately obtain the grain size in the grain image, and can quantitatively analyze the area of each grain and the distribution of the grain area, such as Figure 12 This helps material scientists better compare and analyze the performance of metal component materials and helps track the evolution trend of material organization.
[0079] The contents not described in detail in this specification belong to the prior art known to professional and technical personnel in this field.
[0080] Although the present invention has been disclosed above with reference to the embodiments, it is not intended to limit the scope of protection of the present invention. Any changes and modifications made by any technician familiar with the technology without departing from the concept and scope of the present invention should fall within the scope of protection of the present invention.
Claims
1. A method for automatic grain recognition and precise quantitative characterization based on metallographic images, characterized by: The following steps are involved: S1, grayscale conversion: the imported metallographic image is recorded as I, and the metallographic image is converted into a grayscale image with pixel values of 0 to 255 by grayscale conversion, which is recorded as I1; S2, bottom hat transformation: perform morphological bottom hat transformation on the grayscale converted metallographic image I1, and the image after morphological bottom hat transformation is recorded as I2; S3, grain boundary threshold extraction: According to the grayscale distribution in the bottom-hat transformed image I2, manually select an appropriate threshold to extract the grain boundaries in the image I2; that is, the threshold of the grain boundary is 255, and the threshold of the grain is 0. This binary image is recorded as I3; S4, image closing operation: Since there are many noise points in image I3, in order to better segment the grains in image I3, an image closing operation is performed on each grain in the binary image I3 to eliminate the noise points inside the grain as much as possible. The image after the closing operation is recorded as I4; S5, watershed segmentation based on markers: first, perform distance transformation on the image I4 after the closing operation, and record the image obtained by the distance transformation as I5; then, perform binarization on the image I5 to obtain image I6, and classify and mark the connected areas in the image I6 using the 8-neighborhood connectivity check method to obtain image mark1; subtract the image I4 after the closing operation from the binarized image I6 to obtain the foreground area I7 of the grain, assign the pixel value of the position of the image mark1 corresponding to the pixel value of 255 in the image I7 to 0, and assign the pixel value of the position of the image mark1 corresponding to the pixel value of 0 in the image I4 to -1, and then perform watershed segmentation on the grain image I combined with the marker image mark1 to obtain image mark2; Step S5 includes the following sub-steps: S51, storing the area with a pixel value of 255 in the image I4 into the subset z1 in the form of coordinates, and storing the area with a pixel value of 0 in the image I4 into the subset z2 in the form of coordinates; S52. Calculate the minimum distance from each coordinate in subset z1 to the coordinates in subset z2 using the Euclidean distance formula to form a set containing coordinates and distances, denoted as z3. The minimum distance value in set z3 is denoted as z_min, and the maximum distance value in z3 is denoted as z_max. S53. Create an image I5 of the same size as image I4 and with a pixel value of 0. Place image I5 at the coordinate position of set z3 and assign its pixel value according to the formula G(x,y)=255×|z3(x,y)-z_min| / |z_max-z_min|. S54, traverse the image I5 to find the maximum pixel value G_max, traverse the pixels in the image I5 and assign the pixel grayscale value greater than 0.05*G_max to 255, and the pixel grayscale value less than 0.05*G_max to 0, and record the transformed image as I6; S55, creating an image mark1 of the same size as I6 with a pixel value of 0, performing a connectivity check on the areas of image I6 with a pixel value of 255 using an 8-connected neighborhood check method, and marking the unconnected areas of mark1 corresponding to the areas of image I6 as 1, 2, 3, ...; S56, assigning a value of -1 to the borders around the image mark1; S57. Traverse the area where the pixel value in the mark1 image is 0. If there is a pixel value that is not 0 in the upper, lower, left, or right neighborhood of the area where the pixel value in the image is 0, calculate the grayscale gradient of the pixel position of the point corresponding to the original image I. The calculation formula of the grayscale gradient is: min(max(abs(R-RL), abs(G-GL), abs(B-BL)); max(abs(R-RR), abs(G-GR), abs(B-BR)); max(abs(R-RT), abs(G-GT), abs(B-BT)); max x(abs(R-RB), abs(G-GB), abs(B-BB)); where R, G, and B are the RGB values of the target pixel, RL, GL, and BL are the RGB values of the pixels in the area to the left of the target pixel, RR, GR, and BR are the RGB values of the pixels in the neighborhood to the right of the target pixel, RT, GT, and BT are the RGB values of the pixels in the neighborhood above the target pixel, and RB, GB, and BB are the RGB values of the pixels in the neighborhood below the target pixel. The pixels for grayscale gradient calculation are placed in the queue of set q in the form of coordinate positions. S58, scan the set q from left to right according to the size of the gradient value. When the coordinate position in the scanned set q corresponds to the four neighborhood coordinates of the pixel point in the mark1 image and there is a marked pixel, assign the pixel at this position in the mark1 image to the marked pixel value of the four neighborhood coordinates, delete its coordinate position in the queue of the set q, and find out whether there is an area with a value of 0 in the four neighborhood pixels of the marked pixel point position in the mark1 image. If so, calculate its gradient according to the grayscale gradient method in step S57, put it into the queue of the set q in the form of coordinate position, and exit this scan; when the coordinate position in the scanned set q corresponds to the four neighborhood pixels of the pixel point in the mark1 image and there are two or more different marked pixels, assign the pixel at this position in the mark1 image to -1, delete its coordinate position in the queue of the set q, search for whether there is an area with a value of 0 in the four neighborhood pixels of the pixel point position in the mark1 image. If so, calculate its gradient according to the grayscale gradient method in step S57, put it into the queue of the set q in the form of coordinate position, and exit this scan; S59, repeat the above step S58 until the area with pixel value 0 in the mark1 image disappears, and the image mark1 after the segmentation is completed is recorded as mark2; S6. Check and improve the grain segmentation effect: Check the grain image mark2 after watershed segmentation. If the grain segmentation effect is good, proceed to the next step of grain quantization. If the grain segmentation effect is poor, return to step S3, re-extract the grain boundary threshold, and then proceed to steps S4 and S5. S7, grain quantification analysis: Use the image traversal method to count the area of each grain in the image mark2, calculate the average area and maximum area of the grain, draw the distribution curve of the grain area, and then calculate the grain size according to the definition of grain size; Step S7 includes the following sub-steps: S71, traverse the pixels in the image mark2, count the number of pixels with different marks, that is, the areas of different grains, and perform quantitative analysis on the areas of the grains; S72, the formula for calculating grain size is G = 3.321928 lgN A -2.954, where N A is the number of grains per square millimeter, G is the grain size, the number of grains in this metallographic image can be known, and according to the scale of the metallographic image, the number of grains per square millimeter in the metallographic image N can be known. A , and then the grain size G of the metallographic image can be known through the above grain size calculation formula.
2. The method for automatic grain identification and precise quantitative characterization based on metallographic images according to claim 1 is characterized by: The specific implementation method of step S1 is as follows: the grayscale conversion calculation formula of image I1 is Gray=R×0.299+G×0.587+B×0.114, where Gray is the pixel value of the grayscale image I1, and R, G, and B are the pixel values of image I; Step S2 includes the following sub-steps: S21. Convert the grayscale image I1 into a three-dimensional matrix A(x, y, z), where x and y are the plane positions of the pixels corresponding to the image I1, and z is the grayscale value corresponding to the pixels in the image I1; perform dilation and erosion operations on the three-dimensional matrix A to obtain a matrix B. S22, subtracting matrix B from matrix A to obtain matrix C, and then converting matrix C into a grayscale image I2; The specific implementation method of step S3 is as follows: according to the grayscale distribution of image I2, appropriate grayscale values gray_min and gray_max are selected as the threshold interval for grain boundary extraction in image I2. That is, when the grayscale value of a pixel in image I2 is ≥ gray_min and ≤ gray_max, the pixel value of this area is recorded as 255, and the remaining pixel values that do not meet this grayscale interval are recorded as 0, and the resulting binary image is recorded as I3; Step S4 includes the following sub-steps: S41, create an image I4 with the same size as I3 and a pixel value of 0; S42, performing an 8-neighborhood connectivity check on the area with pixels 0 in the binary image I3, and marking the pixels in the image I4 corresponding to the non-adjacent areas of I3 as 1, 2, 3, 4, ... respectively; S43, performing the image closing operation of step S21 on the regions with pixel values of 1, 2, 3, 4, ... in image I4. To ensure the integrity of the grain structure, when the image closing operation is performed on the grain regions with pixel values of 1, 2, 3, 4, ... in image I4, the pixel values connected to the background region remain unchanged; S44, assigning a value of 1 to the pixel region of image I4 where the pixel value is 0, assigning a value of 0 to the pixel region of image I4 where the pixel value is 255, and then assigning a value of 255 to the pixel region of image I4 where the pixel value is 1; The specific implementation method of step S6 is: if there are two or more independent grains in principle in the image mark2, but their mark pixel values are the same, if there are a large number of grains in the mark2 image, then steps S4 and S5 are repeated.
Citation Information
Patent Citations
Marked watershed segmentation-based steel grain boundary automatic extraction method
CN106599793A
Cited By
Metallographic image grain size determination method based on artificial intelligence
CN121169842A