## 2 The Proposed Method
### Automatic Template Extraction
#### 2.1.1 Template Size Estimation  
Because the sizes of the die patterns are almost identical, an accurate template size helps find a reliable template. The main procedures for estimating the template size are briefly addressed as follows. 1. Initialize parameters: The original SAT image has a pixel resolution of \(w_{\text{Orig}}\times h_{\text{Orig}}\), patch image has a pixel resolution of \(w_{\text{P}}\times h_{\text{P}}\), and template has an initial pixel resolution of \(w_{\text{Tpl}}\times h_{\text{Tpl}}\), with a similarity threshold of \(T_{\text{SIM}}\). These will be determined and discussed in Section 3.1. 2. The original image is converted into a grayscale image. 3. An image patch \(I_{\text{P}}\) with a pixel resolution of \(w_{\text{P}}\times h_{\text{P}}\) is randomly cropped near the central area from the grayscale SAT image. If the original image is not too large, it can be considered an image patch; thus, this step can be skipped. 4. Histogram equalization is applied to enhance the contrast on this cropped patch. Hence, for different imaging settings of the SAT, consistent performance is maintained when conducting the following steps. Figure 2 shows the results of the cropped patch before and after histogram equalization. 5. An initial template \(I_{\text{Tpl}}\) with a size of \(w_{\text{Tpl}}\times h_{\text{Tpl}}\) is randomly cropped from the patch \(I_{\text{P}}\), as shown in Figure 3. If step 3 is skipped, we crop this initial template from the grayscale SAT image. Figure 2: Cropped patch from Figure 1: (**a**) before and (**b**) after histogram equalization. An ordinary template matching process is conducted to find the parts of image \(I_{\text{P}}\) that are similar to template \(I_{\text{Tpl}}\). This step simply slides the initial template image over the patch as in a two-dimensional convolution and calculates the following metric for comparing the template \(I_{\text{Tpl}}\) against the local region of the patch \(I_{\text{Loc}}\). \[R(x,y)=\frac{\sum_{x^{\prime},y^{\prime}}\left(I_{\text{Tpl}}(x^{\prime},y^{ \prime})\cdot I_{\text{Loc}}(x+x^{\prime},y+y^{\prime})\right)}{\sqrt{\sum_{x^ {\prime},y^{\prime}}I_{\text{Tpl}}(x^{\prime},y^{\prime})^{2}\cdot\sum_{x^{ \prime},y^{\prime}}I_{\text{Loc}}(x+x^{\prime},y+y^{\prime})^{2}}} \tag{1}\]  
where \((x^{\prime},y^{\prime})\) indicates one of the pixels covered by the template for \(0\leq x^{\prime}<w_{\text{Tpl}}\) and \(0\leq y^{\prime}<h_{\text{Tpl}}\), \(I_{\text{Loc}}\) is the local region \(\left[x,x+w_{\text{Tpl}}\right]\times\left[y,y+h_{\text{Tpl}}\right]\) of patch \(I_{\text{P}}\), and \(R(x,y)\) is the normalized cross-correlation between two evaluated images \(I_{\text{Tpl}}\) and \(I_{\text{Loc}}\). Hence, the pixel \(R(x,y)\) forms a correlation map \(R\) for \(0\leq x\leq w_{\text{P}}-w_{\text{Tpl}}\) and \(0\leq y\leq h_{\text{P}}-h_{\text{Tpl}}\). Figure 4 shows the results of map \(R\) obtained from the patches shown in Figures 2b and 3. Notably, the bright pixels indicate that a high similarity occurs at these locations. Figure 4: Correlation map from the patches in Figures 2b and 3. Figure 3: Initial template. A binary thresholding process is applied on this map to obtain a binary map \(R_{\text{B}}\) as follows: \[R_{\text{B}}(x,y)=\left\{ \begin{array}{c}1,\text{ if }R(x,y)\geq T_{\text{SIM}};\\ 0,\text{ otherwise}\end{array} \right.\] (2) This step sets the pixels that correspond with the relatively high correlation values to one and sets others to zero. 8. A morphological opening operation is conducted to reduce small noise in map \(R_{\text{B}}\). Figure 5 shows the results of this step. As observed from the enlarged region depicted on the right, each presented bright dot is an object that is formed with connected bright pixels. The connected component method is applied to label all bright objects in map \(R_{\text{B}}\), and then calculate the centroid of every object.