# Integrated Image Processing Toolset for Tracking Direction of Metal Grain Deformation
## 3 Integrated Image Processing Toolset
### Microscope Image-Stitching Algorithm  
In the stitching process, multiple images were captured using a 50-scope lens and stitched together to create a single image that includes all the areas of the specimen. This allowed us to track the location of one specific grain by tracing the pixel similarity between the 50-scope and 200-scope images. In this study, the microscope image-stitching algorithm was designed based on the image pre-processing, image registration, and image stacking. One of the unique features of the proposed image-stitching algorithm is the use of an FD that utilizes the normal cross-correlation on the edge of the metallographic image based on binary logic matching (BLM), which promises a faster image registration process. This approach improves the conventional feature-point matching methods, which are computationally expensive [47]. Figure 4 shows the detailed steps and an illustration of the image-stitching algorithm. In this study, the image binarization process was conducted to reduce the computation load from 256 intensity values of 8-bit data into logical 1-bit data. However, directly extracting the gray-level image into a binary image can potentially reduce the performance of the binary extraction process, causing an erosion of the features [30; 32]. As discussed in Section 1, a combination of the image pre-processing and image binarization enhances the image's clarity, providing a robust binary image [26]. Therefore, the contrast-limited adaptive histogram equalization (CLAHE) algorithm developed by [PERSON] et al. (2014) was used to increase the image's sharpness and clarity by adjusting the contrast of the image (Figure 4) [49; 50]. In the CLAHE algorithm, histogram equalization is used to measure the intensity level of each pixel. It then increases the contrast level to address excessive shadows (Appendix A). Figure 3: Experimental setup of 4-point bending test: (**a**) geometric view and (**b**) top view. The observation was conducted in compressive, tensile, and a combination of compressive and tensile stress areas. the similarity value, the BLM algorithm is proposed as a quantitative logic approach for correlating the two binary inputs. BLM is mathematically defined as follows:  
\[[A\to B]=\sum_{iy=1}^{nC_{x}}\sum_{ix=1}^{nC_{x}}A_{(ix,iy)}{}^{B(ix,iy)}\times B _{(ix,iy)}{}^{A(ix,iy)} \tag{3}\]  
where \(nC_{x}\) and \(nC_{y}\) are the number of filter steps assessed in the \(x\) and \(y\) directions, respectively. BLM is proposed to provide a continuous calculation during the tracing process that can measure the level of similarity between the two sets of binary features from a binarized metallographic image. Until now, the limitation of BLM is that it is only applicable for measuring the similarity level based on the binary input. However, it does not rule out the possibility of further applications where the BLM algorithm can be used to solve other problems corresponding to the gray-level and sRGB images. Figure 5 shows the heatmap of the operation using BLM on sequence numbers from 0 to 1 with an interval of 0.2 and its visualization in computing the pixel similarity. Finally, to complete the image-stitching process, an image-stacking algorithm was utilized. In this process, the maximum value on the correlation map gathered from the image registration process is found and used as the anchor point (Figure S6). The stacking position \([x\;y]\) is then determined with respect to the size of the image (\(imPx\)) and the overlap point (\(\Delta\)) is indicated by the anchor point. The image-positioning coordinates are computed as follows:  
\[[x\;y]=\sum_{i=1}^{n-Im}imPx_{[x,y(i-1)]}-\left(\Delta_{x[(1:i-1)]}\right)+ \left(\Delta_{y[(1:i-1)]}\right) \tag{4}\]  
The detailed algorithm for microscope image stitching based on the BLM is given in Algorithm 1.