# A Method for Borehole Image Reverse Positioning and Restoration Based on Grayscale Characteristics
## 4 Borehole Image Error Analysis and Restoration
### Grayscale Error Analysis and Restoration Methods  
The eccentricity of the panoramic imaging probe in the borehole results in uneven illumination of the borehole wall, leading to grayscale errors in borehole images, manifested  
Figure 11: Result of color space transferring. as longitudinal bands of light and dark on the image. As shown in Figure 12, when the probe is centered in the borehole, a uniformly illuminated image can be obtained within a uniform borehole wall; when the probe is eccentric in the borehole, the image near the probe side of the borehole wall is too bright, and the image away from the probe side of the borehole wall is too dark. In order to perform grayscale restoration of borehole images, it is necessary to quantitatively analyze the grayscale errors in the images. According to the grayscale feature model of borehole images established in this paper, there is a quantitative relationship between the probe position and the grayscale of borehole images. For a given borehole probe position, the grayscale error matrix caused by probe eccentricity can be quantitatively calculated. For any pixel in the borehole image \((\theta,h)\), according to (10), when the panoramic imaging probe is centered in the borehole, we have:  
\[\left\{ \begin{aligned} k(h)&=0\\ \theta_{0}(h)&=0\end{aligned} \right.. \tag{15}\]  
Then, the grayscale value of that point is:  
\[D_{0}(\theta,h)=\lg\lambda \tag{16}\]  
where \(D_{0}\) is the grayscale value of a point on the borehole wall when the probe is centered. According to the working principle of the borehole imaging system, when the panoramic imaging probe is eccentric and its position coordinates are \((kr_{B},\theta_{0},h)\), the grayscale error matrix caused by this can be represented as:  
\[B(\theta,h)=D(\theta,h)-D_{0}(\theta,h). \tag{17}\]  
From Equations (10), (16) and (17), we obtain:  
\[B(\theta,h)=\lg\frac{1}{\left(\frac{S}{r_{B}}\right)^{2}} \tag{18}\]  
Figure 12: Grayscale 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. Through (18), the grayscale error matrix of the borehole image can be calculated. According to Equation (17), subtracting the original borehole image \(D(\theta,h)\) from the calculated error image \(B(\theta,h)\) yields the borehole image after grayscale restoration. For the borehole image shown in Figure 7, the probe trajectory coordinates are obtained through row-wise regression analysis, as described at the end of Section 3.2. By substituting the coordinates into Equation (18), the grayscale offset matrix \(B(\theta,h)\) is calculated, as shown in Figure 13.  
Figure 13 shows the grayscale error matrix calculated under the three-dimensional position of the probe, caused by probe eccentricity. This matrix exhibits typical longitudinal band characteristics, consistent with the characteristics of the original borehole image. By subtracting the grayscale values of the borehole image \(D(\theta,h)\) from the grayscale error image \(B(\theta,h)\), the borehole image after grayscale restoration can be obtained, as shown in Figure 14. It can be noted that the restored image no longer exhibits longitudinal light and dark band features caused by probe eccentricity. For further analysis, histograms of the borehole image before and after grayscale restoration were plotted, as shown in Figure 15.  
Analyzing Figure 15b, it can be observed that there is only one peak in the image, with most pixel grayscale values distributed around the peak. Compared to Figure 15a, where two peaks of light and dark are present on the image histogram, it indicates that the borehole image after restoration no longer exhibits uneven brightness. Figure 14: Borehole image after grayscale restoration. Figure 13: Calculation result of grayscale offset matrix.