## 4 Methods
### Mosaic of borehole Video
#### 4.3.2 Proposed PTSAD Algorithm
It can detect the gray-scale changes of the image and significantly simplifies calculation. Then, by computing the correlation coefficients of 1D vectors and comparing the correlation between the template and different candidate images, the sub-image matching with the template can be recognized from candidate images. The GPT is a process in which the pixel gray value is superimposed in rows or columns by Equations (3) and (4) respectively, as follows [35]:  
\[R(i)=\frac{1}{n}\sum_{j=1}^{n}T(i,j), \tag{3}\]  
\[C(j)=\frac{1}{m}\sum_{i=1}^{m}T(i,j), \tag{4}\]  
where, \(T\) (\(i,j\)) is the gray value of point (\(i,j\)), \(R\) (\(i\)) is the sum of gray values in row \(i\) and \(C\) (\(j\)) is the sum of gray values in column \(j\). The gray scale projection curve in the x- or y-direction reflects the gray distribution features of image. Thus, this property can be used to identify different candidate images. Suppose \(T\) (\(x\), \(y\)) is the template and \(C_{i}\) (\(x\), \(y\)) are the candidate images, where \(i\) = 1, 2 and 3. We projected \(T\) (\(x\), \(y\)) and \(C_{i}\) (\(x\), \(y\)) to the \(X\)-axis and obtained 1D vectors \(T\) and \(C_{i}\), respectively. The correlation coefficient of the \(T\) and \(C_{i}\) was calculated by Equation (5):  
\[R_{i}(x,y)=\frac{E(T\cdot C_{i})-E(T)\times E(C_{i})}{\sqrt{D(T)\times D(C_{i} )}},i=1,2,3, \tag{5}\]  
Figure 10: The architecture of the proposed projection transformation sum of the absolute difference (PTSAD) algorithm. where, \(E\left(T\right)\) and \(E\left(C_{i}\right)\) are the mean values of vectors \(T\) and \(C_{i}\), respectively. \(D\left(T\right)\) and \(D\left(C_{i}\right)\) are the variance of vectors \(T\) and \(C_{i}\), respectively. The correlation coefficient of vectors in the \(Y\)-axis can be obtained in a similar way. The max of \(R_{i}\)\(\left(x,y\right)\) was used to find the candidate image matching with the template from three candidate images. Subsequently, the matching position was acquired accurately and then the matching parameters between two images were obtained. In summary, the flow of the proposed PTSAD algorithm was as follows:  
Step 1: Load two continuous borehole-wall unfolded images as the source image and examined image respectively, and select the template in the source image. Step 2: Move the template over the preset search area in the examined image and simultaneously calculate the SAD value of the template and the candidate images under the template, and store them in an array. Step 3: Extract the candidate images of three minimum SAD values in the array (the SAD value from small to large in sequence of colors: Red, yellow and blue). Step 4: Calculate the 1D projection vectors of the template and the three candidate images in both the X-axis and Y-axis by GPT, then compute the correlation coefficients of these vectors and find the candidate image, which has the maximum correlation coefficient, that is the candidate image matching with the template. To sum up, the pseudo-code of image matching based on PTSAD is summarized in the Algorithm 1, as following. ```
0: Source image \(P_{m\times n}\), examined image \(Q_{m\times n}\), where \(m\times n\) is the size of image. 0: Horizontal offset \(d_{h}\), vertical offset \(d_{v}\).