## 2 Principle
### Principle of Fringe Segmentation by Dynamic Threshold and Edge Detection  
To decompose the essential three frames of binary deformed patterns with a duty cycle of 1/3 from the captured deformed pattern, a specific decomposition method should be carried out. The optical proximity effect (OPE) at the edges between each of the adjacent fringes with different grayscales in the projected quaternary grating must be considered. As shown in Figure 5a, there are several pixels of transition at these edges. Threshold segmentation will lead to incorrect segmentation on the boundary. Figure 5b shows that there are several pixels at the edge of the highest gray level and the lowest gray level that are classified as the intermediate gray levels. Therefore, we propose a fringe segmentation method based on fringe edge detection and region dynamic gray threshold detection.  
The region dynamic gray threshold detection is based on the individual period process row by row. It is important to decompose the period into rows. Figure 6a, b shows the distribution of gray value and the differential values of the 513 th row along the horizontal direction, so we can find the zero-crossing point easily, and the coordinates correspond to the fringe edges between the highest gray level and the lowest gray level, which are also the periodic boundaries.  
Figure 4: Quaternary grating encoding and capturing: (**a**) coding matrix; (**b**) the cutaway view of quaternary grating; (**c**) captured fringe pattern; and (**d**) captured deformed pattern.  
Figure 5: The optical proximity effect (OPE) on the boundary of the period of the deformed pattern: (**a**) the gray value distribution on the boundary of the period of the deformed pattern; and (**b**) the inaccurate segmentation of the deformed pattern.  
Therefore, each period in a row can be decomposed by the edge detection at each local minimum differential value, and the whole procedure of fringe segmentation is illustrated in Figure 7. Firstly, calculating the differential of the captured deformed pattern row by row; then, segmenting every period in the current row; and then, clustering the grayscales in every period. Because the cluster elements corresponding to the real grayscales among the different periods may be disparate, e.g., the cluster \(1\) represents the lowest grayscale in one period which is shadow information, but in another period, the amount of shadow pixels may be larger than the second grayscale and if the first cluster represents the second grayscale in this period, it is obviously a mistake. We must thus do a cluster element correspondence adjustment by read the real gray value of each cluster to make the correspondence between cluster elements and the real grayscale in each period appropriately. In this way, the captured deformed pattern is globally clustered to be another deformed pattern with only four grayscales (if the shadow exists) or three grayscales (if there is no shadow). If the cluster elements of this clustered deformed pattern are reassigned to 3, 2, 1 and 0 in the descending order of correspondence, where 0 represents the shadow, a quaternary deformed pattern demodulates successfully. While the three non-zero grayscales are picked out and pasted into the corresponding pixel positions on the three black images, respectively, after normalization, three binary deformed patterns with 1/3 duty cycle and 1/3 period displacement are decomposed. After that, a little bit of sporadic points may be wrong clustered, so an appropriate spatial filter is needed to optimize the three binary deformed patterns. It must be pointed out that this method can prevent incorrect segmentation, caused by the inhomogeneous illumination and the uneven surface reflectivity.  
Figure 6: The gray value and differential value of the fringe patterns of the 513 th row; (**a**) the distribution of the gray value; and (**b**) the distribution of differential value.  
Figure 7: Fringe segment procedure.