## 3 Implementation of Reconstruction Method
### The Ambiguous Gray Scale  
According to [PERSON]'s reflection theory, the surfaces with an equivalent gradient have the same reflection characteristics. The surface with two peaks and valleys is shown in Figure 5a. The synthetic image of a light source located at (0, 0, 1) is shown in Figure 5b. It can be seen that the gray scales of the peaks are consistent with that of valleys and the peaks. However, the valleys in the surface cannot be distinguished in the synthetic image. Therefore, the image of a surface with multiple peaks and valleys is prone to producing ambiguous gray scale information, resulting in an inability to identify the convexity and concavity of the surface.  
The relationship between the topography, gradient, and gray scale of the above-mentioned surface in the \(x\)-direction is shown in Figure 6. We can see that the ambiguous gray scale information will mutate the calculated surface gradient, and the mutational points are mainly concentrated in the valleys. Hence, for solving the ambiguous problem of the gray scale, it is important to identify the valley from the image and correct the corresponding calculated surface gradient.  
Figure 4: Gray gradient curve in the \(x\)-direction.  
Figure 5: (**a**) Multiple peaks and surface valleys; and (**b**) Synthetic image.  
Based on the principle of optical imaging, the points on the focal plane can form a clear image on the imaging sensor, while the image formed by the points outside the focal plane is not clear. Due to the focal plane usually being close to the peaks of surface topography, the images of the peaks are relatively clear. Hence, the clarity of image can be used to identify the peaks and valleys from the image. The image definition represents the clarity of image details and textures [36]. If the image contains richer details, there will be a sharper change in the gray scale that will ultimately produce a clearer image, as shown in Figure 7.  
The entropy function evaluation algorithm is an effective evaluation method for image definitions, which calculates the information entropy of an image to evaluate the clarity. The entropy function \(H(E)\) can be defined as:  
\[H(E)=-\sum_{x=1}^{m}\sum_{y=1}^{n}E(x,y)In[E(x,y)] \tag{11}\]  
where \(m\times n\) represents the image size. A larger \(H(E)\) will result in a clearer image.  
Moreover, the machined surface topography has the statistical self-similarity and self-affinity, as the gray distribution of different rows in the image is similar [37; 38]. Therefore, during the process of correcting the surface gradient, each peak value of a gray scale row is first extracted and the sub-images with the same size are collected by taking each peak value as the center. After this, the information entropy of each sub-image is calculated by the entropy function \(H(E)\), and the average entropy of all the sub-images is obtained. After this, the sub-image with an information entropy that is lower than the average entropy is defined as the surface valley. Finally, we recognized the column position of the above peak values of the valleys in the image. The gray scales between the minimums on both sides of the column are extracted, and the corresponding calculated surface gradient values are corrected.  
Figure 6: The relationship between surface topography, surface gradient, and gray scale.  
Figure 7: The change in gray scale: (**a**) Clear image; and (**b**) Blurred image.