# A Method for Borehole Image Reverse Positioning and Restoration Based on Grayscale Characteristics
## 4 Borehole Image Error Analysis and Restoration
### Perspective Error Analysis and Restoration Methods  
When the panoramic imaging probe is eccentric within the borehole, there exists a perspective error in the azimuthal information of the borehole image, manifested as horizontal deformation in the image, as shown in Figure 16. When the probe is centered within the borehole, the image accurately depicts azimuthal information; however, when the probe is eccentric, the images near the probe side of the borehole wall become stretched, while those away from it become compressed.  
Figure 16: Perspective error caused by probe eccentricity. (**a**) Situation of the probe working centered in the borehole; (**b**) borehole image with the probe centered in the borehole; (**c**) situation of the probe working off-center in the borehole; (**d**) borehole image with the probe eccentrically positioned in the borehole.  
Figure 15: Grayscale histogram of borehole image. (**a**) Histogram before restoration; (**b**) histogram after restoration.  
In the spatial coordinate system, the perspective error of the borehole image is demonstrated by the discrepancy between the polar angle in the probe coordinate system \(\theta_{P}\), and the one in the borehole coordinate system \(\theta_{B}\) of a certain point on the borehole wall, as depicted in Figure 17.  
According to geometric principles, for any depth \(h\), the mathematical relationship between the polar angles \(\theta_{P}\) and \(\theta_{B}\) of any point on the borehole wall can be expressed as:  
\[\tan\theta_{P}=\frac{r_{B}\sin\theta_{B}-k(h)\cdot r_{B}\sin\theta_{0}(h)}{r_{ B}\cos\theta_{B}-k(h)\cdot r_{B}\cos\theta_{0}(h)} \tag{19}\]  
Therefore, to perform perspective restoration on the borehole image, (19) enables the construction of the perspective-restored borehole image matrix \(E^{\prime}(\theta_{B},h)\) represented as:  
\[E^{\prime}(\theta_{B},h)=E(\theta_{P},h) \tag{20}\]  
In constructing the perspective-restored image \(E^{\prime}(\theta_{B},h)\), all pixels of the image are processed sequentially. For any point in the image \(E(\theta_{P},h)\), its restored pixel value is calculated using Equation (20). Processing all the pixels in the image yields the perspective-restored borehole image \(E^{\prime}\).  
For the borehole image shown in Figure 7, substituting the probe trajectory coordinates calculated into (19) yields the azimuthal angle of the borehole wall. The error between the borehole image azimuthal angle and the borehole wall azimuthal angle yields the azimuthal error matrix, as shown in Figure 18. The azimuthal error matrix has a maximum value of +0.1803 rad and a minimum value of \(-0.1803\) rad, corresponding to a total error range of approximately \(20.665^{\circ}\).  
Based on the calculation results of the azimuthal error matrix on the grayscale-error-repaired image, the perspective-restored borehole image is constructed according to Equation (20), as depicted in Figure 19.  
In the original borehole image, the dark bands signify areas where the imaging probe is distanced from the borehole wall, resulting in image compression, whereas the bright bands denote areas where the imaging probe is in proximity to the borehole wall, leading to image stretching. In the perspective-restored image, the dark band parts are stretched, and the bright band parts are compressed, effectively correcting the perspective errors caused by probe eccentricity. The total azimuthal error of \(20.665^{\circ}\) observed in the original borehole image has been fully corrected through the perspective restoration process.  
Figure 17: Probe coordinate system and borehole coordinate system.