Unit 5 / 12

Microstructure Image Analysis and Quantitative Metallography

Gains:

  • Ability to measure quantities such as grain size, phase ratio and porosity from microstructure images with image processing and AI
  • Ability to correctly configure segmentation, thresholding and calibration steps and prevent scale errors
  • Ability to cross-validate AI's microstructure interpretation with standard metallography method and expert observation

The hardness, toughness and fatigue life of a steel are hidden in its microstructure, which is invisible to the naked eye: grain size, phase ratios, porosity (void), inclusions (oxide/sulfur residues in the metal) and distribution of precipitates. Metallography is the science of examining material under a microscope by cutting, polishing and etching (chemically etching the surface and making phases visible). Quantitative metallography is measuring numerical quantities (grain size number, phase percentage, porosity ratio) from these images. Artificial intelligence and image processing can reduce hours of manual counting to minutes; but a miscalibrated scale or poor segmentation makes all the numbers silently wrong. In this unit you will learn how to measure microstructure images with AI and image processing and verify each measurement.

Basic steps of image-based measurement

In quantitative metallography, every measurement passes through the same chain; If a ring were to break, the result would be unreliable:

  • Image quality: Focus, illumination and etching quality. In a poorly etched sample, the boundaries are blurred.
  • Calibration: Converting the scale bar to pixels. How many micrometers is each pixel? If this step is skipped, the entire dimensional measurement will come out at the wrong scale.
  • Segmentation: Dividing the image into regions of interest — which pixel is grain, which pixel is boundary, which pixel is porosity.
  • Thresholding: Separating phases/spaces with a gray tone or color threshold. If two phases are of different brightness, the threshold separates them.
  • Measurement and statistics: Grain counting, area ratio, size distribution calculation.

AI-powered tools (deep learning-trained segmentation models) perform better than simple thresholding, especially on complex, multiphase structures. But AI's segmentation is also a prediction; scale calibration and cross-checking of results with a standard method (e.g., ASTM E112 grain size, ASTM E562 spot count) is mandatory.

Attention: The most common and most insidious mistake is forgetting to calibrate the scale. The image may look "nice" in quantitative terms, but if the pixel-to-micrometer conversion is wrong, the grain size will be 25 µm instead of 8 µm and you won't notice it. Begin each measurement session by verifying the calibration.

Step by step: an AI-powered microstructure measurement

  1. Define purpose: What are you measuring? Grain size, phase ratio or porosity? By what standard?
  2. Calibrate: Measure the pixel length of the scale bar, calculate the µm/pixel ratio and enter it into the tool.
  3. Pre-process: Contrast correction, noise reduction. Ask the AI ​​which filter is suitable.
  4. Segment/threshold: Separate phases or gaps; Visually check that the boundaries are captured correctly.
  5. Measure: Area ratio, number of grains, mean and distribution.
  6. Verify: Manually compare the result with the standard method (e.g. linear intercept vs grain size); Repeat on several images.

Grain size, phase ratio and porosity

Grain size is the average size of the crystal grains of the material; Small grain generally gives higher strength and toughness (Hall-Petch relationship). It is denoted by the ASTM E112 grain size number G; As G increases, the grain becomes smaller. Phase ratio is the volume/area percentage of each phase in a two- or multiphase structure (e.g., ferrite-austenite balance is targeted for ~50/50% in duplex stainless). Porosity is the ratio of voids caused by gas or shrinkage in castings and seriously reduces fatigue life.

measurement

standard method

AI/image processing contribution

critical verification

Grain size (G)

ASTM E112 intersection/comparison

Automatic border detection and counting

Calibration + manual intersection control

Phase ratio (%)

ASTM E562 dot count

Area ratio with thresholding

Etching uniformity, threshold selection

Porosity (%)

ASTM E1245 image analysis

Space segmentation

Polishing artifact discrimination

inclusion

ASTM E45

Shape/distribution classification

Reference template comparison

three mini cases

Case 1 — Grain size without calibration. A technician loads a microstructure image into an AI-powered tool and has the grain size measured; The result is 6 µm. However, the image was taken at 200x magnification instead of 500x, and the previous session's calibration (500x) remained in the tool. The actual grain size is ~15 µm. An incorrect value also misleads the strength estimation via Hall-Petch. The technician gets into the habit of recalibrating the scale bar at each session. Lesson: calibration is sample and magnification specific and cannot be carried over.

Case 2 — Etching artifact was mistaken for phase. The ferrite/austenite ratio is measured in a duplex stainless. Thresholding mistakes dark spots in heavily etched areas for ferrite, giving a ratio of 62% ferrite; whereas the actual balance is ~48%. Excess ferrite creates a false alarm regarding corrosion and toughness. The metallurgist finds the error after standardizing the etching time and checking several areas with manual spot counting. Lesson: poor sample preparation fools even the best algorithm — garbage in, garbage out.

Case 3 — Correct use, porosity map. A casting team wants to measure the porosity rate in the cross-section of an aluminum part. The AI ​​segmentation model quickly separates the gaps and gives a distribution map with 2.3% porosity. The team visually checks that the scratches that appear during polishing are not mistaken for voids, confirms the result according to ASTM E1245, and sees that the porosity is concentrated in the feeder area and improves the casting design. AI brought speed, decision was made by standard and observation.

Copiable prompt templates

MEASUREMENT PLAN TEMPLATE"Role: You are a quantitative metallography assistant. Purpose: measure [grain size / phase ratio / porosity]. Material: [...]. Magnification: [...]. Standard: [e.g. ASTM E112]. Give me a step-by-step measurement plan: sample preparation, etching, CALIBRATION step, segmentation/thresholding, measurement and VERIFICATION. Highlight calibration as the first and mandatory step. Result Tell me which standard method to manually cross-check.”

SEGMENTATION ERROR CHECK TEMPLATE "I have segmented [phase/gap] on a microstructure image. List the points that could go wrong: etch artifact, polishing scratch, out-of-field region, overlapping boundaries. Write how to check for each and how to fix it. What visual-checks should I do before accepting the result?"

GRAIN SIZE INTERPRETATION TEMPLATE "I measured ASTM E112 grain size number G = [value], magnification [x]. Explain how this G value corresponds to the approximate average grain diameter and its effect on strength in terms of Hall-Petch. Remind me that the G value depends on calibration; tell me step by step how to verify the result by the linear intersection method."

PYTHON IMAGE PROCESSING SKELETON TEMPLATE"Role: You are the image processing code assistant. Write skeleton code that calculates phase area ratio on a microstructure image with scikit-image: (1) µm/pixel variable EXPRESSLY at the top for scale calibration, (2) conversion to grayscale, (3) thresholding, (4) area ratio, (5) printing the result. Add comments to each step. Threshold Specify in the code that the value and calibration must be verified MANUALLY."

Weak prompt / Strong prompt

WEAK PROMPT: "Tell me the grain size of this microstructure."

STRONG PROMPT:"Role: You are a quantitative metallography assistant. I want to measure grain size according to ASTM E112. Image 500x, scale bar 50 µm = 240pixel (i.e. 0.208 µm/pixel). Give me the steps to calculate grain size by linear intersection method, tell me how many lines/how many intersections to count, convert the result to G number. I need to verify the calibration and at least "Remind me that I have to repeat it in 3 different areas. You cannot 'read' the final result; set up the method."

The weak prompt asks the AI ​​to "read" the image — but the AI ​​doesn't know scale and etching and may come up with a made-up number. The powerful prompt makes the calibration clear, asks for the standard method, requires repetition and verification, and uses AI as a method-setting tool, not measurement.

Common mistakes

  • Forgetting to calibrate the scale or measuring with the previous session's calibration.
  • Relying on segmentation without correcting bad/non-uniform etching.
  • Mistaking a polishing scratch or stain for porosity/phase.
  • Measurement from a single area and generalization to the entire sample; statistics require several fields.
  • Assuming the AI ​​has "seen" the image and using it without verifying the exact number it gives.
  • Accepting the segmentation result without visually checking it.

In summary

In quantitative metallography, AI and image processing accelerate grain size, phase ratio and porosity measurement and enable powerful segmentation of complex structures. However, the validity of the results depends on scale calibration, good sample preparation, and cross-validation with the standard method (ASTM E112/E562/E1245). Make calibration the first step, inspect segmentation by eye, repeat in several areas, and use AI as the tool that establishes the measurement method and writes the code, not the one that "reads" the image.

Application task

Take a microstructure image (your own sample or a lecture sample) and scale bar value. With the template "PYTHON IMAGE PROCESSING SKELETON", ask the AI ​​for a code that calculates the phase area ratio; Make sure µm/pixel calibration is at the top and turned on in the code. Run the code and compare the resulting area ratio with manual point counting (10x10 grid) on the same image. Write the difference between the two results and the possible cause (threshold choice, artifact) in one paragraph.

checklist

  • [ ] I calibrated the scale bar to pixel and verified it in each session.
  • [ ] I checked that the etching/sample preparation was uniform.
  • [ ] I visually inspected the segmentation/thresholding result and removed artifacts.
  • [ ] I repeated the measurement in at least a few different areas.
  • [ ] I manually cross-checked the result with a standard method (E112/E562/E1245).
  • [ ] I used AI as a method and code tool, not as a "reader" of the image.