1 Introduction

Over recent decades, measuring the 3D morphology of objects in the real world has attracted significant research interest, with a particular focus on higher accuracy and speed [1,2,3,4,5]. As an important technique to obtain an object’s topography, the structured light [6, 7]-based optical 3D topography measurement method is widely used in numerous industries, such as manufacturing, detection, biomedicine, and virtual reality. Thus far, many optical 3D measurement techniques have been proposed; among them, fringe projection profilometry (FPP) [8,9,10] is a method for actively projecting and capturing fringes to obtain the 3D shape of an object. This is accomplished primarily by restoring a phase map from a deformed fringe pattern using the phase shift method [8] and Fourier transforms [11, 12]. The important issue that must be mitigated when using this method is the 2π discontinuity jump from − π to π in the wrapped phase; thus, the phase unwrapping is required to obtain the absolute phase. FPP is widely used in practical measurement techniques because of its advantages—it is non-contact, has a simple configuration, operates at a high speed, and provides high-precision results. For the development of FPP, an important research direction is to establish a technique that can accurately and quickly restore the actual shape of a measured object from multiple fringe patterns.

The Fourier method, which requires only a single fringe pattern to achieve 3D measurement, has obvious advantages in terms of speed; however, it is limited to relatively smooth surfaces and those with uniform reflectivity. To improve the robustness of this method, Li [13] developed a technique using two Ronchi grating modes to obtain the phase distribution by Fourier analysis and a coding pattern to ascertain the fringe order, which could obtain high-quality grayscale images in a high-speed measurement environment. Theoretically, relative to the phase-shifting method, the phase accuracy acquired by the Fourier method is much lower. Therefore, the phase-shifting method is a better choice to achieve high-precision measurement and is widely used in 3D optical measurement. Researchers usually use temporal phase unwrapping methods to avoid error transmission during phase unwrapping and facilitate the absolute phase recovery of more complex objects. Based on this, Wang and Zhang [14] first proposed a new method of embedding code words into phases rather than intensities, which is more robust than other methods for 3D measurement. However, abnormal phase errors occur when more code words are used in the aforementioned traditional phase-coding method, limiting the high-frequency applicability. To resolve this issue, Zheng [15] proposed a method that encoded two-stage information; however, this method required at least nine pictures and was time-consuming. In general, a higher frequency means a higher accuracy; further, the fewer the patterns, the higher the speed. Therefore, reducing the number of projections required for measurement is a common way to achieve fast measurement. In recent years, many new methods have been proposed to reduce the number of patterns. Wang [16] proposed an improved two-step phase-coding method of four plus five frames to reduce the number of projection patterns, improving the measurement speed to a certain extent. Hyun [17] proposed new phase-coding methods that use five binary fringe patterns to recover high-quality 3D shapes point-by-point. Deng [18] proposed a 3D phase unwrapping method based on a five-step composite fringe pattern, combining it with a minimum phase pattern to provide more code words. Ma [19] proposed a morphological phase unwrapping method based on a quantized phase-coding structure to ensure high-speed measurement and robustness. Wu [20] proposed new phase-shifting methods that directly encode the phase; they also classified code words into four patterns for projection. The wrapped phase and fringe order were then retrieved to obtain the 3D shape information of the measured object. Wu [21] proposed a dual-wavelength phase-shift method using four patterns to obtain the wrapped phase and fringe order, mitigating the stair-dislocation issue in Wu’s method [20]. Yang [22] proposed a new high-precision and high-speed unconstrained method for projecting four fringe patterns to obtain 3D shapes; the special relationship among the four patterns was used to obtain the fringe order. In conclusion, the field of high-speed and high-quality 3D measurement is still faced with significant challenges.

In this paper, a novel fast phase-coding method for high-frequency small patterns is proposed. This method requires only four fringe patterns to detect the 3D information of an object; no other patterns or additional altered patterns are required. In this method, a specific coded sequence modulation quantization coding phase is designed on (0, π). Further, in this study, an encoding phase embedded with a specific sequence is combined with a three-step phase-shifting method to solve the wrapped phase and coding phase; a specific algorithm is used to connect them into a continuous phase, following which the absolute phase is recovered. Median filtering and a correction algorithm are used to make the method more robust to system noise and external interference. This method increases the number of code words, effectively improves decoding accuracy, and can be used for rapid measurement. The high-speed and high-quality measurement performance of the proposed method is described in detail in this paper. Further, simulations with noise and practical experiments verify the effectiveness of the proposed method.

The rest of this paper is structured as follows: Sect. 2 introduces the principles of the conventional phase-coding method, and more importantly the underlying algorithms for encoding and decoding the proposed method. Section 3 reports simulations with noise to validate the feasibility of the proposed method. Section 4 describes experiments that compare the proposed method with the traditional phase-coding and Liu’s method, demonstrating the effectiveness and robustness of the proposed method. Finally, Sect. 5 summarizes the entire paper systematically.

2 Principles

The overall structure of the rapid 3D measurement system designed in this paper is shown in Fig. 1. The framework of the proposed method comprises three parts: components of the system, the data generator, and result, which explain the measurement process of the proposed method. The basic components of the system include a projector, a camera, and a computer, which are used for projection, capture, and processing, respectively. The data generator uses light-intensity formulae to solve for the required data. Four groups of modulated deformed fringe patterns are captured; namely, three sinusoidal phase-shifting fringe patterns are used to calculate the wrapping phase, and one specially coded fringe pattern is used to calculate the fringe order. A specific algorithm connects the segmented fringe order. The result of this process is an error-free reconstructed 3D morphology of the target object.

Fig. 1
figure 1

Principle framework and phase unwrapping process of the proposed method

2.1 Traditional phase-coding method

In the traditional phase-coding method, the setup includes a camera, a projector, and a measured object. To obtain the 3D shape of the object, the camera collects a series of fringe images projected by the projector, which are the necessary N + M deformed fringes for detecting objects. The first groups of N fringe patterns are used to calculate the wrapped phase \(\varphi (x,y)\) with \({2}\pi\) discontinuities; the next groups of M fringe patterns embracing the coding phase \(\phi^{s} (x,y)\) are used to determine the fringe order.

A multistep phase-shifting method is adopted to generate N fringe patterns. The strength distribution of the fringe can be expressed as

$$I_{i} (x,y) = A(x,y) + B(x,y)\cos (\varphi + \delta_{i} ),\,(i = 1,2,3,....,m),$$
(1)

where \((x,y)\) is an arbitrary pixel in the image plane of a camera, \(A(x,y)\) is the average intensity, \(B(x,y)\) is the modulation signal amplitude, \(\delta_{i} = 2\pi n/N,(n = 1,2,...,N)\) is the number of the phase shift, and \(\varphi (x,y)\) is the wrapped phase to be solved. The wrapped phase can be solved as follows:

$$\varphi (x,y) = \tan^{ - 1} \left[ {\frac{{\sum\nolimits_{i = 1}^{k} {I_{i} (x,y)\sin \delta_{i} } }}{{\sum\nolimits_{i = 1}^{k} {I_{i} (x,y)\cos \delta_{i} } }}} \right].$$
(2)

The arctangent function causes the range of the wrapped phase \(\varphi (x,y)\) to be a discontinuous \({2}\pi\), from \({ - }\pi\) to \(\pi\). To obtain the continuous absolute phase \(\Phi (x,y)\), the fringe order must be determined to eliminate the discontinuity of the wrapped phase. Therefore, another group of M fringe patterns phase encoding patterns is used

$$I_{i}^{^{\prime}} (x,y) = A(x,y) + B(x,y)\cos (\phi^{s} + \delta_{i} ),(i = 1,2,3,....,m),$$
(3)

Further, the designed stair code words are embedded in the coding phase pattern, as follows:

$$\phi^{s} (x,y) = - \pi + k \times 2\pi /N.$$
(4)

where N is the total number of fringe orders.

According to the two aforementioned sets of phase shift and coded fringe patterns, the absolute phase can be easily determined by

$$\Phi (x,y) = \varphi (x,y) + 2\pi \times k(x,y).$$
(5)

2.2 Improved four frame phase-coding method

The phase-coding method is widely used in the field of 3D measurement. The traditional phase-coding method uses one group of phase-shifting patterns to solve the wrapped phase, and another group of coded phase patterns to expand the wrapped phase. Therefore, at least six fringe patterns are required to restore the absolute phase. In contrast, the proposed method uses only one specially designed coded phase pattern, in combination with three-step phase-shift patterns, to recover the absolute phase. Figure 2 shows the proposed specific encoded pattern for this approach.

Fig. 2
figure 2

Coded pattern of a particular encoding sequence

To implement the four patterns based on the proposed method, one technique is to adopt sinusoidal fringe patterns with phase shifts of \(- 2\pi /3, \, 0\) and \({2}\pi /{3}\) for wrapped phases, as shown in Fig. 1a. Another technique is one additional phase-coded fringe pattern embedded within the specific coding sequence \(CS[x_{i} ]\), as shown in Fig. 1b. Then, the mathematical expressions that generate the four fringe patterns can be expressed as

$$I_{1} (x,y) = A(x,y) + B(x,y)\cos (\varphi (x,y) - 2\pi /3),$$
(6)
$$I_{2} (x,y) = A(x,y) + B(x,y)\cos (\varphi (x,y)),$$
(7)
$$I_{3} (x,y) = A(x,y) + B(x,y)\cos (\varphi (x,y) + 2\pi /3),$$
(8)
$$I_{4} (x,y) = A(x,y) + B(x,y)\cos (\varphi^{s} (x,y)),$$
(9)

From Eqs. (6, 7, 8, 9), it can be seen that there are only four unknowns to be solved:\(A(x,y)\), \(B(x,y)\),\(\varphi (x,y)\), and \(\phi^{s} (x,y)\). In theory, four light-intensity equations can solve for the four unknowns in the phase-coding method. Therefore, according to \(I_{1} ,I_{2} ,I_{3} ,I_{4}\), the average intensity \(A(x,y)\), intensity modulation \(B(x,y)\), wrapped phase \(\varphi (x,y)\), and coding phase \(\phi^{s} (x,y)\) can be solved using Eqs. (10) to (13), respectively

$$A(x,y) = (I_{1} + I_{2} + I_{3} )/3,$$
(10)
$$B(x,y) = \left[ {\frac{{(I_{1} - I_{3} )^{2} }}{3} + \frac{{(2I_{2} - I_{1} - I_{3} )^{2} }}{9}} \right]^{1/2} ,$$
(11)
$$\varphi (x,y) = \tan^{ - 1} \left[ {\sqrt 3 (I_{1} - I_{3} )/(2I_{2} - I_{1} - I_{3} )} \right],$$
(12)
$$\phi^{s} (x,y) = \cos^{ - 1} \left[ {\frac{{I_{4} (x,y) - A(x,y)}}{B(x,y)}} \right],$$
(13)

The aforementioned formulae show that the coding phase is solved by the \(\cos^{ - 1}\) function, which means that the range of the coding phase \(\phi^{s} (x,y)\) solved using Eq. (13) is only half that of the wrapped phase \(\varphi (x,y)\), i.e., \(\left[ {0,\pi } \right]\). Further, only one pattern \(I_{{4}}\) obtains less phase information, and one pattern is more sensitive to noise, resulting in unknown errors. Thus, this method limits the total number of fringe orders. To improve the number and robustness of the embedded code words, a special coding sequence \(CS[x_{i} ]\) is proposed for modulating the quantization phase, as shown in Fig. 2.

$$CS = 024130241302413......$$

This coding sequence guarantees that the difference between adjacent code words is greater than or equal to 2; therefore, the coding phase embedded in a particular sequence can be expressed as

$$\phi^{s} (x,y) = CS\left[ {{\text{floor}}[x/p]} \right] \times \frac{\pi }{L}$$
(14)

where L is the quantization level (L = 5), \(x\) is the horizontal resolution of the projector, and \(p\) is the number of pixels in a fringe period.

Therefore, the code \(C\) can be obtained from the coding phase \(\phi^{s} (x,y)\) of the resolution.

$$C(x,y) = {\text{round}}\,[L \times \phi^{s} (x,y)/\pi ]$$
(15)

where the \({\text{round}}()\) function outputs the nearest integer to the number.

Quantifying the modulation phase can maximize the number of code words. Before retrieving the absolute phase, the correct continuous fringe order \(K\) must be calculated according to the code \(C\). The segmented fringe order \(k_{1} (x,y)\) and \(k_{2} (x,y)\) can be determined as follows:

$$\left\{ \begin{gathered} k_{1} (x,y) = 1,{\text{ if }}C(x,y) = 0 \hfill \\ k_{1} (x,y) = 2,{\text{ if }}C(x,y) = 2 \hfill \\ k_{1} (x,y) = 3,{\text{ if }}C(x,y) = 4 \hfill \\ k_{1} (x,y) = 4,{\text{ if }}C(x,y) = 1 \hfill \\ k_{1} (x,y) = 5,{\text{ if }}C(x,y) = 3 \hfill \\ \end{gathered} \right.$$
(16)
$$k_{2} (i,j) = \left\{ \begin{gathered} k_{2} (i,j - 1),\,{ |}k_{1} (i,j) - k_{1} (i,j - 1){|} \le L - {2 } \hfill \\ k_{2} (i,j - 1) + 1, \, k_{1} (i,j) - k_{1} (i,j - 1) \le - {(}L - 1{)} \hfill \\ k_{2} (i,j - 1) - 1, \, k_{1} (i,j) - k_{1} (i,j - 1) \ge {(}L - 1{)} \hfill \\ \end{gathered} \right.$$
(17)

where \(k_{1}\) represents the sequence number of periodic cycles in each sub-region, which has a one-to-one correspondence with the wrapped phase. \(k_{2}\) is used to identify the serial number of each sub-region, which represents the number of segmented regions; \(L - 2\) is the threshold value to ensure that the sequence number remains unchanged.

Evidently, the continuous fringe order \(K(x,y)\) can be precisely calculated, as follows:

$$K = k_{1} + L \times k_{2}$$
(18)

The absolute phase can be restored by combining the wrapped phase with the fringe order. The calculation method is shown in Eq. (5). The phase unwrapping modes of the j-th row of the proposed method are shown in Fig. 3.

Fig. 3
figure 3

Schematic pattern of j-th row phase unwrapping modes of the proposed method

3 Principle of the simulation with noise

To verify the feasibility of the proposed method, a simulation experiment with noise is carried out. The period in the simulation experiment is set to 57 pixels, and the simulation frequency \(f_{sim}\) could then be calculated as \(f_{sim} = 1140/57 = 20\). Figure 4 shows the phase-coding simulation with noise; Gaussian noise (SNR =  = 22.5) is added to the four fringe patterns. Figure 4a–c shows the ideal sinusoidal patterns, coded pattern, and coding phase, respectively. Figures 4d–f shows the sinusoidal pattern, coded pattern, and coding phases with noise, respectively. Figure 4g shows that the proposed method can correctly solve the coding phase without being affected by noise. Figure 4h shows that the fringe order is perfectly aligned with the wrapped phase, and the absolute phase is shown in Fig. 4i. Therefore, the simulation results clearly demonstrate the feasibility and robustness of the proposed method to Gaussian noise.

Fig. 4
figure 4

Simulation of phase coding with noise: a Ideal sinusoidal fringe patterns; b ideal coded fringe pattern; c ideal coding phase; d sinusoidal fringe patterns with noise; e coded fringe pattern with noise; f coding phase with noise; g coding phase after correction; h correctly solved fringe order and wrapped phase; and i final absolute phase

To further verify the superiority of the proposed method, the phase errors were analyzed through simulations. Figure 5 shows the actual output value, ideal output value, phase error, and its maximum and minimum values. Further, the phase error range can be calculated using Eq. (19).

$$\Delta E = Y_{{{\text{MAX}}}} - Y_{{{\text{MIN}}}}$$
(19)
Fig. 5
figure 5

Phase error analysis patterns

where \(\Delta {\text{E}}\) is the phase error range, \({\text{Y}}_{{{\text{MAX}}}}\) is the maximum error, and \({\text{Y}}_{{{\text{MIN}}}}\) is the minimum error.

The phase error range can be easily calculated using the following Eq. (20).

$$\Delta {\text{E}}_{{{\text{pro}}}} {\text{ = Y}}_{{{\text{MAX}}}} - {\text{Y}}_{{{\text{MIN}}}} = 0.4756 < 0.5$$
(20)

where \(\Delta {\text{E}}_{pro}\) is the phase error range of the proposed method.

The difference between adjacent code words in the proposed method is greater than or equal to 2. Further, we encode in the range of \((0,\pi )\), so the minimum phase difference between adjacent code words is \(\pi /2( \approx 1.57)\). However, the phase error range of the proposed method is lower than 0.5. Therefore, the proposed method has significant advantages in identifying the phase more clearly and obtaining the correct fringe order.

4 Experiments

To further verify the effectiveness of the proposed method, an FPP system is built. The system comprises a 1140 × 912-resolution projector (Light Crafter 4500, Texas Instruments, USA), a 1,280 × 1,024-resolution CCD camera (Model H-HV 135 lm), and a high-speed computer workstation. The system is positioned to ensure that the optical centers of the projector and camera are on the same horizontal axis, and that the distance between them is 40 cm. The projector and camera project and capture downward, respectively, forming a triangular formation with the object to be measured. The object is placed on a reference plane 120 cm away from the FPP system. The experimental device is shown in Fig. 6.

Fig. 6
figure 6

Experimental setup of the FPP system

A phase error analysis is carried out in the practical experiment. The same parameters are used in the experiment as those in the simulation. Figure 7 shows the ideal output value, the actual output value, the phase error, and the maximum and minimum error values.

Fig. 7
figure 7

Phase error analysis diagram of a certain row

The phase error range of practical operation experiments can be calculated using Eq. (19), to be \(\Delta E = 0.5447\). This value is almost the same as that in the simulation, which verifies the advantage of the proposed method.

To evaluate the performance of the proposed method, a fringe with a preset number of periods is projected and captured to measure the 3D morphology of the object. At this stage, three groups of experiments are carried out to verify the performance. The first group measures a plastic dolphin to assess the effectiveness of the proposed method. The second group compares the superiority of the proposed method with traditional phase-coding and Liu’s method. The third group measures two isolated plaster objects to assess the performance of the proposed method.

4.1 Evaluation

The frequency represents the number of fringe periods in the fringe direction. In the experiments, to improve the measurement accuracy of the proposed method, the period in the evaluation experiment is set to 57 pixels; the evaluation frequency \(f_{eva}\) can then be calculated as \(f_{eva} = 1140/19 = 60\). Further, the white plate is selected as the reference plane for fringe projection and measurement. Figure 8a shows one of the three captured modulated sinusoidal fringe patterns. Figure 8b shows the captured modulated coded fringe patterns. Figure 8c shows the wrapped phase pattern of the proposed method. Figure 8d shows the coding phase pattern. Then, the fringe order could be correctly solved using Eq. (10), as shown in Fig. 8e. Figure 9a and b clearly shows that, in the proposed method, the coding phase and fringe order could be precisely aligned with the wrapped phase. Figure 10 shows the 3D measurement results of the proposed method, including the measurement of the reference plane and the object, as shown in Fig. 10a and b. As can be seen from the recovery rate in Fig. 10, the discontinuities of the wrapped phase are eliminated, and there is no significant measurement error. The proposed method reconstructs the measured sculpture correctly, which verifies the performance of the method.

Fig. 8
figure 8

Measurement results of the proposed method: a one of the sinusoidal intensity fringe patterns; b coded intensity fringe pattern; c Wrapped phase pattern; d coding phase pattern; and e fringe order pattern

Fig. 9
figure 9

One cross section of the object: a alignment of the coding phase and wrapped phase in row 300; b alignment of the fringe orders and wrapped phase in row 300

Fig. 10
figure 10

3D reconstruction results of the proposed method: a absolute phase of the experimental board; b absolute phase of the object; and c 3D shape measurement

4.2 Comparison

To better assess the measurement quality of the proposed method, the traditional method and Liu’s method are used to measure the same object at different frequencies, and the 3D measurement quality of the three methods is compared. In the 3D measurement experiments, the periods in the comparison experiments are set to 38 pixels, 28.5 pixels, and 22.8 pixels, respectively; the comparison frequencies \(f_{1} ,f_{2}\), and \(f_{3}\) can then be calculated as \(f_{1} = 1140/38 = 30,f_{2} = 1140/28.5 = 40,f_{3} = 1140/22.8 = 50\). The measurement results are shown in Fig. 11. When solving the fringe order, the traditional phase-coding method is easily affected by the number of code words and phase errors. This results in a misalignment between the fringe order and the wrapped phase; therefore, the correct absolute phase pattern cannot be obtained. It can be seen from these measurement results that, with increases in the frequency, the error increases and the quality of the measurement results decreases. Liu’s method had good measurement results and a rapid execution time. The coding range of Liu’s method is also only \(\pi\), from \(\left( { - \frac{\pi }{{2}},\frac{\pi }{{2}}} \right)\). In this method, with increases in the frequency (for example, from 50 to 60), a small number of errors occur, leading to misalignments in the wrapped phase and fringe order. Figure 11 confirms that the proposed method could obtain better measurement results at different frequencies. In particular, the errors of fringe matching do not occur in this method when the period increases.

Fig. 11
figure 11

Comparison of the 3D measurement results of the three methods

To compare the accuracy of the abovementioned comparison methods, Fig. 12 shows the absolute phase patterns of the three methods at \(f_{3} = 60\). Figure 12a shows the disadvantages of severe phase jump anomalies in the traditional method, which results in the recovery of only part of the target in the measurement results. Figure 12b shows that Liu’s method is affected by increases in the number of code words, resulting in a certain error in the alignment of the fringe order. Figure 12c shows that, relative to the other two methods, the absolute phase recovery of the proposed method is more accurate.

Fig. 12
figure 12

Absolute phase-contrast pattern of the three methods

4.3 Isolated objects (discontinuities)

In the isolated object experiment, as shown in Fig. 13, two isolated objects are measured to assess the reliability of the proposed method for measuring complex objects. It is important to note that the two sculptures do not require special data processing measures, as only the predesigned fringe pattern is projected onto the object surface. Then, the camera captures the distorted fringe modulated by the object and finally processes the image on the computer using the proposed method, as shown in Fig. 13a and b. Figure 13c shows the wrapped phase pattern solved by the phase-shifting method. Figure 13d shows the coding phase pattern resolved from the single coded pattern of the proposed method. The fringe order is identified according to the specific coding sequence, as shown in Fig. 13e. The figure shows that the coding phase and fringe order have good stair properties, even in complex regions. Thus, the absolute phase is recovered, as shown in Fig. 13f. The 3D measurement results of isolated objects are shown in Fig. 14, where the details of the measured objects (such as the protrusions on the surface of the starfish and the lines of the snail shell) are very distinct in the reconstruction.

Fig.13
figure 13

3D measurement process of complex objects: a modulated sinusoidal fringe pattern; b modulated coded fringe pattern; c wrapped phase; d coding phase; e fringe order; and f absolute phase

Fig. 14
figure 14

3D measurement results of complex objects

5 Conclusion

In this paper, a new fast 3D measurement method based on phase coding is proposed to reconstruct the 3D shapes of objects. 3D information can be accurately detected by projecting only four fringe images. A set of special quantization phase-coding schemes is designed to obtain more multilevel fringe orders, which ensures that the difference between adjacent code words is greater than or equal to 2. A reduction in the number of modes effectively improves the measurement speed; more code words significantly increase the measurement accuracy, and the difference between adjacent code words ensures high robustness. Simulation and reconstruction experimental results verify the performance of the proposed method in terms of its high precision and fast 3D measurements; further, the method is also highly robust and stable.