## 2 Endoscope Imaging and Correction Principle
### Image Correction Principle  
The distortion in the endoscopic image results in serious deformation of the inner surface defect contour, which cannot accurately reflect quantitative information about the defect. To achieve precise measurement of internal surface defects, the image distortion is divided into orthogonal circumferential and axial distortion based on endoscopic imaging principles. The corrected image plane is established as the M-N corrected coordinate system, as shown in Figure 3.  
Where \(A^{\prime\prime}\), \(B^{\prime\prime}\) and \(Q^{\prime\prime}\) represent the corrected positions of \(A^{\prime}\), \(B^{\prime}\) and \(Q^{\prime}\) in Figure 2b, respectively. The blue arrow indicates the axial and circumferential directions of the hole. The core of endoscopic image distortion correction is to establish a mapping relationship between \(Q^{\prime}\) in the phase plane coordinate system U-V and \(Q^{\prime\prime}\) in the corrected coordinate system M-N.  
Figure 3: Coordinate system of corrected image. Figure 2: Endoscopic imaging principle. (a) the spatial coordinate system, (b) the phase plane coordinate system. Let the spatial coordinates of \(Q\) point be (\(x\), \(y\), \(z\)) and its image point be \(Q^{\prime}\) (\(x^{\prime}\), \(y^{\prime}\), \(f\)). According to the pin-hole camera imaging model, the position of image point \(Q^{\prime}\) (\(u\), \(v\)) in the phase plane coordinate can be expressed as Equation (1). \[ \begin{bmatrix}u\\ v\end{bmatrix} = \begin{bmatrix}f_{x}\frac{x}{v}+u_{c}\\ f_{y}\frac{y}{z}+v_{c}\end{bmatrix}  \tag{1}\]  
where \(f_{x}=fdx,f_{y}=fdy\), \(dx\) represents the physical size of each pixel on the U-axis, and \(dy\) represents the physical size on V-axis. The unit of \(dx\) and \(dy\) are mm/pixel, and C (\(u_{c}\), \(v_{c}\)) denotes the center coordinates of the image. According to the triangular relationship, \(z\) in Equation (1) is related to both aperture and the position of the image point in the image, and the relationship can be expressed as Equation (2). \[z=\frac{f\cdot R}{\delta\cdot\sqrt{\left(u-u_{c}\right)^{2}+\left(v-v_{c} \right)^{2}}} \tag{2}\]  
where \(R\) (in mm) represents the radius of the hole part, and \(\delta\) represents the axial distance represented by each pixel on the inner surface of the hole. As a result of imaging, a ring with equal spacing on the inner surface of the hole appears as an uneven diffusion ring in endoscopic images. This can be understood as a nonlinear growth function determined by \(\delta=G(r)\), which is the axial distance growth function based on \(r=\sqrt{\left(u-u_{c}\right)^{2}+\left(v-v_{c}\right)^{2}}\) or the distance between each pixel and center of image. Since points at the same height on the inner surface of the hole should have identical N-axis coordinates after correction, the pixel ring with \(C\) (\(u_{c}\), \(v_{c}\)) as its center in the endoscopic image should be corrected to a horizontal line in the N-M coordinate system. Assuming that the outer radius of the annulus is \(R\) and the inner radius is \(r\), a ray starting from point \(O\) along the positive \(X\)-axis intersects with the inner circle at point \(a\) and with the outer circle at point \(A\) when the center of the known endoscopic image is \(C\) (\(u_{c}\), \(v_{c}\)). The circular ring is bisected along line segment \(OA\), with ray \(OA\) serving as the \(Y\)-axis of the unfolding coordinate system. Counterclockwise unfolding of the circular ring yields the \(X\)-axis of unfolded coordinates. Figure 4 illustrates how circumferential correction for endoscopic images works. Assuming that the coordinate of \(Q^{\prime\prime}\) is (\(m\), \(n\)), according to the position mapping relationship, we can obtain  
\[\left\{ \begin{array}{l}u=\left(m-U_{A^{\prime}}\right)\cdot\cos\varphi+u_{c }\\ v=\left(n-V_{A^{\prime}}\right)\cdot\sin\varphi+v_{c}\end{array} \right.