## 2 Materials and Methods
### Enhanced Feature Extraction from Chemically Etched Metallographic Specimens
#### 2.3.1. Carbide Detection and Segmentation  
Carbides are key secondary phases in many metallic alloys [66], so they must be detected and measured consistently in metallographic images. Carbide segmentation refers to the isolation of carbide regions from the surrounding matrix (i.e., ferrite, austenite, or other phases). Quantifying the size, shape, distribution, and volume fraction of carbides is essential for understanding their impact on material performance. However, the automated identification of carbides in metallographic images remains a challenging task due to the following factors [67]:  
* Low contrast with matrix phases: In optical microscopy (OM) or SEM (scanning electron microscopy), carbides often share gray levels or backscatter intensity with martensite or bainite. * Irregular shapes and sizes: Carbides can appear as globular, lamellar, or network-like structures depending on heat treatment and alloy composition. * Overlapping or agglomerated structures: In some cases, carbides cluster together or overlap, leading to under-segmentation when using traditional image processing techniques. * Variability among alloys and imaging conditions: Differences in alloy chemistry and imaging parameters (resolution, magnification, illumination) introduce variability that hinders the generalization of rule-based systems. With the aim of solving this challenge, a reliable identification approach must leverage the distinct visual properties of carbides in etched metallographic images. Carbides typically appear as the darkest regions due to their high resistance to chemical etching, which causes them to reflect minimal light under optical microscopy. Their morphology varies depending on the alloy composition and thermal history, but they consistently stand out against the brighter ferritic matrix. This contrast serves as the basis for their initial segmentation through thresholding methods. In our work, we designed a hybrid pipeline for an accurate and efficient carbide detection task in metallographic images. Specifically, we combined object detection using YOLO (You Only Look Once) [68] with a high-precision segmentation model like SAM (Segment Anything Model) [69]). This pipeline is similar to the one that is presented in [70]. This approach combines the speed of YOLO for object detection with the segmentation  
Figure 7. Visualization of the carbide detection process: (**a**) original etched image, (**b**) thresholded version showing ferrite and carbides in white, and (**c**) segmented carbides. accuracy of SAM, providing a robust solution for automated carbide identification and characterization in metallurgical quality control workflows. SAM is a powerful foundational model for image segmentation based on a Vision Transformer (ViT) architecture. SAM uses self-attention mechanisms to analyze spatial relationships and boundaries in the image, generating precise segmentation masks for the prompted regions. These masks often align very well with the actual boundaries of carbides, even in noisy or complex images. Our identification and segmentation pipeline is described below:  
1. _Detection:_ YOLOv11 is used to rapidly localize potential carbide regions by generating bounding boxes around high-probability areas. Then, we apply a region extraction (RE). In other words, each detected bounding box is used to crop a region of interest (ROI) from the original image, isolating a carbide candidate. 2. _Segmentation:_ The ROI and its bounding box are passed as prompts to the SAM model, which performs precise instance segmentation and returns a binary mask or polygonal contour outlining the carbide. 3. _Post-processing:_ Finally, the resulting segmentation masks are converted into contours, which are then used to compute the black-and-white areas of each carbide. These areas correspond to the carbide core and surrounding matrix, respectively, as derived from the thresholded (binarized) image. In this work, we used the YOLOv11n (nano variant) due to its efficiency and low computational footprint.