# A Deep Learning Approach to Semantic Segmentation of Steel Microstructures
## 2 Materials and Methods
### Image Preprocessing  
In the preprocessing stage of the segmentation deep learning experiment carried out in this work, a comprehensive approach was implemented to enhance the quality and diversity of the dataset. This involved the initial creation of masks using specialized software, followed by a thorough data augmentation process. Image), with its trainable Weka segmentation plugin, was utilized for the creation of masks [22; 23]. This allowed for the creation of masks, outlining specific regions of interest within the steel microstructure images. Manual annotations made by the authors guided the algorithm in learning the features necessary for accurate segmentation. The annotations of the pearlite areas have been manually performed on two of the original images for each sample. Subsequently, the trainable Weka segmentation option has been applied to the rest of the images to automate the generation of masks since manual mask generation is a time-consuming process and prone to errors. Thus, by using the ImageJ segmentation assistant, the quality of the masks was improved, and the processing time was reduced. Nevertheless, the authors reviewed each generated mask, making adjustments to images containing any errors. Figure 1: Samples of C45E steel in an annealing state, (**a,b**) and normalizing; (**c**) reagent, Nital-1. Figure 2: Microconstituents corresponding to the C45E Steel (reagent Nital-1). The red contours correspond to ferrite (**a**) and pearlite (**b**) areas. The trainable classifier employed for mask creation was based on the Random Forest algorithm. Configured with 200 decision trees, this algorithm demonstrated robustness in handling the complexity of steel micrography images. The training process involved feeding the algorithm with the manually annotated masks, allowing it to learn and generalize patterns within the dataset. Following the initial mask creation and classifier training, a data augmentation step was introduced to enhance the dataset's diversity. This involved applying various transformations such as rotation, scaling, and flipping to the original 34 steel micrography images. The augmented dataset served to increase the model's ability to generalize across a broader range of microstructural variations. Each original image captured by the optical microscope has a resolution of 2080 \(\times\) 1542 pixels. For the execution of the experiments, we have chosen to use images of 224 \(\times\) 224 pixels. This choice is based on various practical and efficiency considerations. Smaller images demand fewer computational resources for both training and inference. The utilization of 224 \(\times\) 224 images enables the model to execute more rapidly. Furthermore, for the transfer learning from pretrained models utilized in the experiments, such as ResNet50, ResNet18, or MobileNetV2, these models are often trained on massive datasets with specific image sizes. Employing the same image size during both training and inference eases the transfer of knowledge from pretrained models, as the initial layers are tailored to that size. It is important to note that although 224 \(\times\) 224 pixels is a commonly used size, it is not a strict constraint. The image size can be adjusted to conduct experiments with a different set of images, but it might be necessary to adjust other model parameters and, in some cases, retrain the model to accommodate the new input size. For data augmentation, each original image and mask were cropped into 54 images of size 224 \(\times\) 224 pixels. Subsequently, rotations of 90\({}^{\circ}\), 180\({}^{\circ}\), and 270\({}^{\circ}\) were applied to the cropped images, resulting in 216 images for each original image. This process yielded a final dataset of 7344 images. These images were distributed randomly, with 70% allocated for training data, 20% for validation data, and 10% for the test data.