## 2 Reconstruction of Polycrystalline Model
### Identifying Individual Grains  
An algorithm utilizing color-based boundary detection was developed to identify individual grains in 2D image slices of synthesized polycrystalline microstructures, as shown in Figure 2. The algorithm starts by applying a color-based mask to the image in order to separate grains of similar color. A pixel erosion algorithm is then implemented to identify grain boundaries. This process involves recursively visiting each grain, eroding it by a few pixels in all directions, and then taking its dot product with the white background after binarization. This process is illustrated in Figure 2 for one of the grains belonging to the polycrystalline microstructure depicted in Figure 1. Next, a skeletonization algorithm [33] is employed to extract a pixel-wide skeleton representation of the grain boundaries, as shown in Figure 3. After successfully identifying each grain, the algorithm proceeds to determine its neighboring grains, which is crucial in order for later stages of the preprocessing phase to identify shared grain boundaries. This is achieved by creating an enlarged bounding box (BBox) around each grain and using it to quickly identify neighboring grains that overlap with it, meaning that at least one of their pixels falls inside the BBox.  
Figure 1: Two-dimensional image slice of a 200 μm \(\times\) 200 μm polycrystal model synthesized using DREAM.3D and further processed using ParaView, showing the pixelated representation of the grain boundaries.  
Figure 2: Identifying individual grains in the pixelated microstructure shown in Figure 1.  
The presence of extremely small features (grains) composed of a limited number of pixels in 2D image slices can lead to difficulties during mesh generation, including the need for excessive mesh refinement and the formation of degenerate elements. Therefore, prior to identifying grain boundaries, it is crucial to identify and eliminate any small, unrealistic features composed of only a few pixels in order to avoid such challenges. To address this issue, the first step is to use an area threshold criterion to identify small grains. Principal Component Analysis (PCA) [34] is then applied to detect any small grains that exhibit a skewed orientation. As seen in Figure 4, such elongated small grains can negatively impact the meshing process by causing unacceptably high element aspect ratios if not treated properly beforehand. Unlike non-elongated small grains, a higher threshold must be used for the area calculation to eliminate elongated small grains. It is important to note that in PCA, the point cloud of a small grain serves as input to determine its principal components. A large difference between principal components indicates asymmetry or possible elongation of a grain. Excessively small and small, elongated grains are eliminated by merging them with one of their neighboring grains, chosen in a way that results in higher convexity after the collapse, as shown in Figure 4. It is important to note that the convexity is evaluated as the ratio of the region's area to its convex hull [35]. This measure ranges from 0 to 1, where 1 refers to a perfectly convex polygon.