# The Application of Deep Learning and Image Processing Technology in Laser Positioning
## 2 Template Matching and Invariant Moments  
Template matching is used to look for the part of an image that matches the template image. First, the sizes of the read-in template image and the matched image are calculated and stored. If the template image cannot divide the matched image exactly, the right and bottom of the image are supplemented by 0. The image is then substituted into an algorithm to determine the weight of the template image for each point in the matched image, and the maximum weight is found out in order to know the position of the upper left corner of the template image in the matched image. The length and width of the template image are inputted, and the region of the template image can be indicated in the matched image [8; 9; 10; 11]. The template matching method has numerous algorithms. This study used the Sum of Squared Differences (SSD), expressed as Equation (1) [12; 11]:  
\[D(i,j)=\sum_{s=1}^{M}\sum_{t=1}^{N}\bigl{[}S(i+s-1,j+t-1)-T(s,t)\bigr{]}^{2} \tag{1}\]  
where \(D\) is the resulting region after matching is completed, \(S\) is the \(m\times n\) matched image base, and \(T\) is the \(M\times N\) image template, where \(1\leq i\leq m-M+1,\ 1\leq j\leq n-N+1\). As the weight must be calculated again for the matched image each time the template is changed, template matching takes considerable time; however, the accuracy is much higher than the starting point search method, therefore, this method was used for study [13] (Figure 1). Figure 1: Template matching result example. In continuous conditions, the image function is \(f(x,y)\). The \(p+q\) geometric moment of the image (standard moment) is defined as:  
\[m_{pq}=\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}x^{p}y^{q}f(x,y)dxdy\quad p,q=0,1,2\cdots \tag{2}\]  
According to the 0 th origin moment and the first origin moment, the barycentric coordinates \(\overline{x}\), \(\overline{y}\) of the target area can be obtained:  
\[ \begin{array}{c}\overline{x}=\frac{m_{10}}{m_{00}}\\ \overline{y}=m_{01}/m_{00}\end{array}  \tag{3}\]  
The \(p+q\) central moment is defined as:  
\[\mu_{pq}=\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}(x-\overline{x})^{p}(y -\overline{y})^{q}f(x,y)dxdy\quad p,q=0,1,2\cdots \tag{4}\]  
As the central moment is constructed by selecting the centroid of the target area as the center, the moment calculation will always be the point of the target area in relation to the centroid of the target area. It is unrelated to the position of the target area, and it has translation invariance. For discrete digital images, the integral is substituted by the summation sign:  
\[m_{pq}=\sum_{y=1}^{N}\sum_{x=1}^{M}x^{p}y^{q}f(x,y)\quad p,q=0,1,2\cdots \tag{5}\]  
\[\mu_{pq}=\sum_{y=1}^{N}\sum_{x=1}^{M}(x-\overline{x})^{p}(y-\overline{y})^{q} f(x,y)\quad p,q=0,1,2\cdots \tag{6}\]  
where \(N\) and \(M\) are the height and width of the image, respectively. In order to cancel the effect of scale change on the central moment, each central moment is normalized using 0 th central moment \(\mu_{00}\) to obtain the normalized central moment:  
\[\eta_{pq}=\frac{\mu_{pq}}{\mu_{pq}^{\rho}};\;\textit{where}\;\rho=\frac{p+q}{ 2}+1 \tag{7}\]  
Therefore, the 0 th moment represents the quality of the target area (area). If the scale of the target area changes, the 0 th central moment will decrease and the moment will have scale invariance. Physical significance of various moments:  
0 th moment (\(m_{00}\)): quality of the target area. First moment (\(m_{01},m_{10}\)): centroid of the target area. Second moment (\(m_{02},m_{11},m_{20}\)): turning radius of the target area. Third moment (\(m_{03},m_{12},m_{21},m_{30}\)): orientation and slope of the target area, which reflects the distortion of the target. Central moment: construct invariance of translation. Normalized central moment: construct invariance of scale. Hu moment: construct invariance of rotation. Seven invariant moments \(M1\)-\(M7\) are constructed using the second and third normalized central moments:  
\[