# Three-Dimensional Imaging of Metallic Grain by Stacking the Microscopic Images
## 3 Algorithms for 3D Imaging of Grains and Results  
### Local Positioning  
As mentioned above, the main goal of this study is to image MG in 3D. To reach our purpose, micrographs are taken while repeatedly polishing. At this time, the height information measured by the micrometer is taken as the \(z\)-axis. Then the location of the boundary of a specific MG selected in the photo is stored as the \(x\)-\(y\) coordinates. Therefore, it is possible to obtain three-dimensional coordinates for the node representing the boundary of the MG. However, as the experimental methodology seems very simple, a challenge associated with this technique is a positional error within \(\pm\)7 \(\upmu\)m that occurred when the specimen was polished, and the same area was observed, even though we used very accurate equipment to avoid this (backlash play), because of the high special-resolution used (2 \(\upmu\)m). As an example, Figure 2 is a photograph (hereinafter, \(n\)th layer photo) taken after polishing an area of 130 \(\times\) 98 \(\upmu\)m three times, four times, and fifth times, respectively, using a microscope at a magnification of 500. For mutual comparison, a white line with a + mark is indicated in the center. Based on the 3 rd layer, the position of the 4 th layer is shifted to the upper left. Further, based on the 4 th layer, the 5 th layer has moved to the right. Meaning the photos of each layer are not in the same position. To correctly stake the images, improve the accuracy, and achieve high precision of the final desired result, we have developed and used a set of algor  
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline \multirow{2}{*}{**Layer**} & \multicolumn{5}{c}{**Height of Layer (mm)**} \\ \cline{2-6}  & **1 st Point** & **2 nd Point** & **3 rd Point** & **4 th Point** & **Average** \\ \hline  
\[[\Delta X_{2},\Delta Y_{2}]=min(S_{1}(i,j),\{(i,j)\in\pm h\}) \tag{6}\]  
Thereafter, as shown in Equations (7)-(9), the reflecting region in the \(n\)th layer photo becomes the reference, and the local positioning is repeated by comparing it with the target \((n+1)\)th layer photo. Using this process along with \(\Delta X_{n}\) and \(\Delta Y_{n}\) for each layer obtained using Equation (10), the region of interest of the first layer photo, to be the same region as the other target photos, each local positioning of the region having \(X_{1},Y_{1}\) and \(X_{2},Y_{2}\) as the diagonal vertices layer, can be observed, as shown in Equation (11). \[\left[P_{\Delta\Delta\Delta y}^{n}\right]=\left[P_{target}^{n}(x_{1}+\Delta X _{n}:x_{2}+\Delta X_{n},y_{1}+\Delta Y_{n}:y_{2}+\Delta Y_{n})\right] \tag{7}\]  
\[\left[P_{\Delta\Delta y}^{n+1}(i,j)\right]=\left[P_{target}^{n+1}(x_{1}+i:x_{2 }+i,y_{1}+j:y_{2}+j)\right] \tag{8}\]  
\[S_{n}(i,j)=\sum_{(x,y)=(1,1)}^{(\Delta x_{1},\Delta y)}\left[abs(\left[P_{ \Delta\Delta y}^{n}\right]-\left[P_{\Delta\Delta xy}^{n+1}(i,j)\right])\right] \tag{9}\]  
\[[\Delta X_{n+1},\Delta Y_{n+1}]=min(S_{n}(i,j),\{(i,j)\in\pm h\}) \tag{10}\]  
\[\left[P_{align}^{n}\right]=\left[P_{target}^{n}(X_{1}+\Delta X_{n}:X_{2}+ \Delta X_{n},Y_{1}+\Delta Y_{n}:Y_{2}+\Delta Y_{n})\right] \tag{11}\]  
On the other hand, \(X_{1},X_{2},Y_{1},Y_{2}\) of Equation (11) to be selected for observing the change of a specific cross section of the MG are independent of \(x_{1},x_{2},y_{1},y_{2}\) of Equations (1), (2), (7) and (8), which were selected for local positioning. As an example, local positioning was performed at \((x_{1},y_{1})=(250,200)\), \((x_{2},y_{2})=(2000,1000)\), \(\Delta X_{17}=55\) and \(\Delta Y_{17}=167\) in the 3 rd layer photo in Figure 4a,c. Further, values of \(\Delta X_{18}=35\) and \(\Delta Y_{18}=170\) were obtained in the 4 th layer photo of Figure 4b,d. Then, by adjusting \((X_{1},X_{2},Y_{1},Y_{2})\), an area of 1700 \(\times\) 1200 pixels in Figure 4a,b, and also 420 \(\times\) 420 pixels in Figure 4c,d were selected, respectively. Figure 4: Microscopic photographs with local positioning in a certain area.