# An Automatic Detection Method for Cutting Path of Chips in Wafer
## 2 Materials and Methods
### Automatic Detection Algorithm of Chip Cutting Path
#### 2.3.3 Automatic Detection of Chip Region  
At present, the most commonly used method to determine the chip position is the template matching algorithm. Template matching algorithms are based on the gray value [21], correlation [22], and geometric shape [23]. Among them, the gray-scale correlation matching method is more suitable for scenes with stable lighting. Although the correlation matching method can adapt to lighting, large errors will occur when the target area is deformed. Considering the difference in the shapes of different chips, the shape of the chip region in some images changes greatly and is irregular, and sometimes the street will be connected to the chip region and affect the matching accuracy of the geometric shape. The wafer image contains multiple chip regions. In the same batch of wafer products, the chip appearance is roughly the same, but there are also differences. In order to accurately match all chip regions and center-of-gravity positions, we used a template matching algorithm based on frequency domain analysis. The selection of matching templates is described in detail in Section 3.1, and all features of the chip region should be included as much as possible. The template matching algorithm based on the computational frequency domain correlation includes the following steps:  
**Step 1**: Parametric settings for the target image and template image. We assume that the size of target image \(I\) is \(M\times N\). The size of the selected template image \(T\) is \(m\times n\). The target image \(I\) and the template image \(T\) rotated by 180 \({}^{\circ}\) are changed to the frequency domain space by Fourier and are expanded to the size of \((M+m-1\), \(N+n-1)\). The parameterization equation is as follows:  
\[FI=K(\mathcal{F}(I),(M+m-1,N+n-1)) \tag{9}\]  
\[FT=K(\mathcal{F}(rot(T,180)),(M+m-1,N+n-1)) \tag{10}\]  
where \(K(I,(m,n))\) represents the extended function, expanding \(m\) rows and \(n\) columns, respectively, in the row and column directions of \(I\), using trailing 0 to fill. \(rot(I,\theta)\) indicates that \(I\) is rotated counterclockwise \(\theta\). \(F\) represents the Fourier transform. The processing results are shown in Figure 7a,b, and the lower right corner area is locally enlarged. **Step 2**: Calculate the correlation between the parameterized wafer and the template image, and obtain the correlation matrix \(R\). Each value in the correlation matrix \(R\) represents the similarity between the sub-image at the corresponding position in the target image and the template image. The processing result is shown in Figure 7c. The correlation matrix \(R\) is expressed as:  
\[R=0.5+\frac{Icoor-meanIT}{2\times stdT\times P} \tag{11}\]  
_Icoor_ is the real part of the inverse Fourier transform results of the multiplication of the corresponding elements of \(FI\) and \(FT\). \[Icoor=\mathcal{F}^{-1}(FI(x,y)\times FT(x,y))_{R} \tag{12}\]  
where \(\mathcal{F}^{-1}\) represents the inverse Fourier transform and \(meanIT\) is defined as the average compensation:  
\[meanIT=\frac{L(I,(m,n))\times\sum_{i=1}^{m}\sum_{j=1}^{n}T(i,j)}{m\times n} \tag{13}\]\(L(I,\,(m,\,n))\) adds \(I\) to \(m\) rows and \(n\) columns and calculates the row-wise cumulative sum based on the column-wise cumulative sum of \(I\). The \(stdT\) and \(P\) in Equation (11) are defined as:  
\[stdT=\sqrt{(m\times n-1)\times\frac{\sum_{i=1}^{m}\sum_{j=1}^{n}(T(i,j)-\overline {T})}{m\times n}} \tag{14}\]  
\[P=\max\left(\sqrt{\frac{\max\biggl{(}L(I\times I,(m,n))-\frac{L(I,(m,n))^{2}}{ m\times n},0\biggr{)}}{m\times n}},\frac{stdT}{100,000}\right) \tag{15}\]  
where \(\overline{T}\) is the mean of \(T\), and \(\max\) (\(\bullet\)) is defined as the maximum value of the corresponding element selected by comparing a matrix with a matrix or a matrix with a constant.