## 2 Materials and Methods
### Analysis of the XCT Images Implementing a Machine Learning (ML) Segmentation  
The separation of the metal, bone, pores, osteoid tissue, and metallic grains from each other on the 3D images was carried out with the Ilastik program [15] and two custom in-house 2D UNets [16], forming a three-stage sequential ML process. Ilastik was used to annotate/generate efficiently the training data, which were subsequently employed to train the UNets. This approach reduced considerably the time required to annotate the training labels compared to purely manual annotation. In other words, we accelerated the annotation of the required (by the UNets) training labels with the ML capabilities of Ilastik. Ilastik has been developed by the Ilastik team in [PERSON]'s laboratory at the European Molecular Biology Laboratory (EMBL) in Heidelberg (Germany), and uses iterative ML algorithms to segment, classify, track, and count the different image areas in 2D images and 3D stacks. The pixel classification workflow in Ilastik assigns pixels to a group based on pixel/voxel features. These features can be selected by the user from a wide range of operations, for example, smoothed pixel/voxel intensity, edge filters, and texture descriptors. The user then selects some representative areas in the 3D image stack by color-coding the different areas to be segmented. Based on the image areas assigned to the classes by the user, the system interactively trains a random forest classifier. The predictions in the image data can be previewed so that the training can be improved interactively. The result is a unique classification of each pixel/voxel into a previously defined class. These classifications can then be extracted. The main challenge with these XCT datasets is that it is very difficult to distinguish the bone and osteoid phases from each other based solely on gray values, as they appear very similar. The osteoid phase appears typically slightly darker compared to the bone phase due to its lower density. However, the variation of contrast arising from beam hardening within the XCT datasets can result in certain regions where the bone phase appears darker compared to the osteoid phase located at a different region (i.e., regions in different images within the 3D stack or different locations within the same image). An example of this is shown in Figure 6. The complete segmentation of the datasets with Ilastik could have been possible, but with a lot more (manual) effort to account for all deviations across all regions. Our three-stage ML segmentation method accelerated the whole process by overcoming the above limitations. Our training strategy was the following:  
Firstly, we conditioned the five XCT datasets (labeled: 1382, 1384, 1385, 1386, and 1387) with a non-local-means (NLM) filter [17] (parameters: sigma = 2, smoothing_factor = 1) to reduce noise. Secondly, we extracted from the dataset 1385 eleven random images (4 + 1 along xy plane, 2 along xz plane, and 2 along yz plane, (xy, xz, and yz planes, as shown in Figure 7). Ilastik was employed to annotate the various phases/labels only within these eleven images (metal, bone, pores, osteoid tissue, and metallic grains), which then served as the training/validation/testing data for the UNets. The extra (+1) image from the xy plane was reserved only for testing the final segmentation accuracy (i.e., training/validation: ten image pairs, testing: one image pair). Thirdly, to increase the number of training/validation data, we randomly mirrored/rotated the 10 images to a total of 2000 image pairs (input images and ground truth labels), of which 1800 image pairs (90%) were used as training data, and 200 image pairs (10%) were used as validation data. To improve generalization (i.e., to distinguish the similar bone and osteoid phases better during segmentation), we introduced to the training/validation datasets random