# Interferometric Wavefront Sensing System Based on Deep Learning
## 2 Method
### Wavefront Analysis Neural Network
#### 2.2.1 Models  
The whole system includes two neural network modules, as shown in Figure 2 The role of net1 is to unwrap the phase calculated by the phase-shifting method. In the previous chapter, we mentioned that the wrapped phase value is limited to \((-\pi,+\pi]\); however, there is such a relationship between the wrapped phase and the true phase, as formulated in Equation (7):  
\[\varphi_{true\text{ phase}}(x,y)=\ \varphi_{wrapped\text{ phase}}(x,y)+2\pi*k(x,y). \tag{7}\]  
Here, \(k(x,y)\) represents the wrap count of each pixel, \(k(x,y)\in Z\). In the wrapped phase, it can be seen that there are obvious dividing lines between regions with different wrap count. Therefore, we can use image segmentation to separate these regions. Inspired by Segnet [20], net1 adopts the encoder-decoder structure, which can segment these regions well and give their classification results. The last layer of net1 is the softmax layer, and the output is a feature map with 11 channels, which represents 11 classification probability value of each pixel. We extract the category index \(n(x,y)\) with the largest probability value to represent the final classification result of the pixel. There is a one-to-one correspondence between the classification result \(n(x,y)\) and the wrap count \(k(x,y)\), as formulated in Equation (8):  
\[k(x,y)=\ n(x,y)-5 \tag{8}\]where \(n(x,y)\in\{0,1,\ldots,9,10\}\), \(k(x,y)\in\{-5,-4,\ldots,4,5\}\). In general conditions, the measuring beam phase change caused by the deformable mirror is small, and the wrap count \(k(x,y)\) corresponding to its wrapped phase is usually in the range of \([-1,1]\). However, to make this method applicable to scenarios with large phase changes, we generated some wavefront maps with larger phase values in the training dataset, and the wrap counts calculated from these maps can reach the range up to \([-5,5]\). Since the unwrapped phase of net1 is not completely correct, it may wrongly estimate the wrap count at individual points, causing these points to have a large deviation from the true value, as shown in Figure 3b,c. To solve this problem, we propose a smooth method to further process the output result, as formulated in Equations (9) and (10). Through a global search, we get the value \(V(x,y)\) of each pixel and subtract it by the average value \(V^{\prime}(x,y)\) of its \(3\times 3\) neighborhood:  
\[\gamma=\ V(x,y)-V^{\prime}(x,y). \tag{9}\]  
Figure 2: The wavefront analysis neural networks. (**a**) The overall structure and process of the deep learning wavefront analysis system, including two neural network modules net1 and net2, and the relationship between the two modules. (**b**) The structure of net1. (**c**) The structure of net2. If the difference \(\gamma\) is greater than the threshold T or less than \(-\)T, then subtract or add \(2\pi\) to the value of the pixel:  
\[\mathrm{V(x,y)}=\left\{ \begin{array}{ll}\mathrm{V(x,y)}+2\pi,&\gamma<-\mathrm{ T}\\ \mathrm{V(x,y)},&-\mathrm{T}<\gamma<\mathrm{T}\\ \mathrm{V(x,y)}-2\pi,&\gamma>\mathrm{T}\end{array} \right.. \tag{10}\]  
T is an empirical value, and it works better when equal to 4. After 10 iterations, most of the bad points will be corrected except for some areas with dense bad points, as shown in Figure 3d. Comparing Figure 3c,d, we find that the bad points are clustered into regions, and the values of all points in a region have the same difference of \(2\pi\)k with the true values. To further correct these regions, we use the Sobel operator to detect the edges and then extract the whole regions. We calculate the average value of an area and subtract it by the average value of adjacent edge pixels outside the area. According to the difference value and Equation (10), the correct value can be obtained. Eventually, we can get a well-restored wavefront, as shown in Figure 3e,f. Due to the long-distance transmission, the wavefront captured by the detector will have some noise. When the wavefront is noisy, it will severely affect the aberration analysis.