1 Introduction

At present, phase information is used as a direct measurement parameter in many metrology technologies. Generally, the height distribution of a measured object is represented by phase information, which is calculated by means of the arc-tangent function and is limited in the range of (− π,π). To get the correct result, the continuous and natural phase must be recovered from the wrapped phase before phase-height mapping. Two-dimensional (2D) phase unwrapping is to recover the real phase from the wrapped phase. Hence, 2D phase unwrapping is a key step in determining whether the measuring results is successful or not.

In the ideal case, if there are no interference signals such as noise, aliased signal and unknown phase discontinuity, phase unwrapping only needs to be carried out by pixel to pixel along the columns or rows of the wrapped phase. The process is to select a point as the start of the phase unwrapping and to compare two neighboring pixels’ phase values along the columns or rows of the wrapped phase. The phase value of the latter should be added 2π or 2 if their phase difference is less than − π, or subtracted 2π or 2 if the phase difference is greater than π. After unwrapping by row (column), the same operation will be carried out by column (row). Error propagation is often caused by incorrect judgment of the wrap count (n) when using this method for phase unwrapping. Itoh condition indicates that the necessary condition of exact tracking is that the neighboring pixels’ phase difference of the true phase satisfies the condition of being greater than − π and less than π. However, in practice, this condition might be violated if the wrapped phase is noise polluted or if the true phase surface is discontinuous, which finally leads to the wrong result in phase unwrapping [1]. In the case of the latter, a solution has been proposed by Bioucasdias and Valadão [2] in 2007. In this paper, a new energy minimization framework for phase unwrapping is introduced. The minimization is carried out by a sequence of max-flow/min-cut calculations. The objective functions are first-order Markov random files. Two algorithms are proposed to solve the two cases that the phase is continuous and discontinuous. Both algorithms solve integer optimization problems by computing a sequence of binary optimizations, each one solved by the graph cut technique. Also, in this case, the temporal phase unwrapping algorithm is also a good choice, as it obtains a series of phase maps on the time axis and unwraps each pixel in the way of point to point [3]. The phase of each pixel has nothing to do with the phase of the pixel around it. In our paper, we only examined the former and completely disregarded the latter.

Many phase unwrapping algorithms have been proposed by scholars to solve the problem mentioned above. Among them, spatial phase unwrapping algorithms can be roughly divided into the path independent algorithm which is to minimize the objective function, and the path-related algorithm which is to follow a certain path [4]. Typical path independent algorithms include least squares algorithm [5,6,7] and minimum discontinuity algorithm [8,9,10,11]. Both of them are derived from the minimum Lp-norm criterion. In this paper, the minimum discontinuity algorithm is selected as a target for analysis and basis to develop a novel algorithm. Most spatial phase unwrapping algorithms are related to paths such as branch-cut phase unwrapping algorithm [12,13,14,15], quality-guided algorithm [16,17,18,19], mask cutting algorithm [20,21,22], fast phase unwrapping algorithm [23, 24] and so on. These kinds of algorithms are mainly used for identifying the residue or according to the quality map, so the two representative algorithms, branch-cut phase unwrapping algorithm and fast phase unwrapping algorithm, were selected for comparison and development.

In this paper, three spatial phase unwrapping algorithms, branch-cut phase unwrapping (BC) algorithm, minimum discontinuity (MD) algorithm and fast phase unwrapping (FPU) algorithm, were briefly reviewed. Three algorithms’ performances were compared in the situations of noise interference. Whereafter, two new algorithms were proposed in this paper. They combine the merits of three basic algorithms, and improve both the speed and the accuracy of phase unwrapping. The results of simulation and actual experiment verify their feasibility. Both of them can be effectively applied to the 2D spatial phase unwrapping.

The structure of this paper is arranged as follows. Section 2 briefly introduces the principles of BC algorithm, MD algorithm, and FPU algorithm. Section 3 simulates the phase unwrapping for a noise-polluted continuous phase by three algorithms, compares and analyzes their performance on phase unwrapping. Section 4 introduces the concepts of two new hybrid algorithms, and presents the corresponding simulation and actual experiments to verify the practicable of these proposed algorithms. Section 5 summarizes this paper.

2 Principles of three basic phase unwrapping algorithms

The spatial phase unwrapping algorithm is in view of the Itoh condition. The point called residue does not satisfy the Itoh condition and consequently causes the unwrapping error. Since the spatial phase unwrapping is an integral process, the error at any point will propagate to the subsequent unwrapping process. Therefore, if the phase unwrapping path passes through the residue, the error will propagate and then result in the failure of phase unwrapping. To reduce the impact of such residues in the process of phase unwrapping, the path-related algorithm bypasses the unreliable area by looking for a proper integral path for phase unwrapping, thus the error of the unwrapped phase would be reduced or restricted in a limited area. The path independent algorithm obtains the correct unwrapped phase by establishing an objective function, and then minimizes its value by iteration until the entire phase has been unwrapped.

In the process of phase unwrapping, due to the existence of residue, the error will be caused and propagated when the path passes through the residues. BC algorithm searches for the residues in a wrapped phase according to the condition that the phase unwrapping result is path independent [12] and generates some branch cuttings by balancing the positive and negative residues. The main idea of BC algorithm is using the branch cutting to guide the phase unwrapping so as to bypass the unreliable area. This algorithm was first proposed by Goldstein [13] in 1988. Then, in 1989, Huntley [14] proposed reducing the complexity of the branch cuttings by eliminating the pairs of positive and negative residues. In recently, an improved algorithm was proposed by Yan Zhang [15] in 2013. In their works, the positive and the negative residues in the interference image are connected, and then re-combined and replaced using the length of the branch cut as criteria, so that the overall length of the branch cut can be reduced gradually and the isolated area in the unwrapping process can be overcome effectively.

The jump is defined as a pair of neighboring pixels whose difference is greater than π in magnitude. The jump can be removed by adding a multiple of 2π to the phase difference. This multiple is called the jump count. In the ideal situation, the sum of the jump counts (i.e., the objective function) of the whole continuous phase is 0. However, in the actual measurement, there is a certain number of jump counts in the phase due to noise and phase discontinuity. According to the minimum Lp-norm criterion [8], the MD algorithm achieves the minimum L1-norm when the objective function reaches the minimum. It completes the phase unwrapping process through a series of iterations. Finally, a phase distribution with the minimum sum of whole jump counts will be found to be the closest to the true phase. Node, edge and loop are used as the auxiliary to complete the iterative process. The node is defined as four corners around a pixel. The edge is defined as directed collections between neighboring pixels. A loop is composed by edges. A growth loop can contain some negative-value edges, provided that its total value is positive. This algorithm uses a series of iterations like adding edges, generating rings, eliminating rings, and updating jump arrays to unwrap the entire wrapped phase map. It was first proposed by Flynn [9] in 1997. Some improved algorithms have also been presented, such as 2D minimum discontinuity phase unwrapping based on edge detection by Ting Zhang [10] in 2009. The pretreatment operation was carried out on the wrapped phase image to identify the isolated noisy pixels and exclude them from the search areas. In the same years, they also proposed to improve the minimum discontinuity algorithm using the tabu search [11]. In this algorithm, the low-quality areas are searched for phase discontinuity in priority. This tabu search strategy ensures that the search starts from the areas whose probability of discontinuity is the highest and thus avoid a useless search as much as possible.

The quality of a pixel can be measured using its reliability. Typical quality maps include second difference map [16], modulation map [17], phase derivative variance map [4], maximum phase gradient map [4] and pseudo correlation coefficient map [4]. During the phase unwrapping process, the unwrapping path can be effectively guided using the pixel’s reliability. In the FPU algorithm, two neighboring pixels horizontally or vertically constitute an edge. The reliability of the edge is defined as the sum of two pixels’ reliability along this edge. The main idea of this algorithm is that the unwrapping path is determined by looking at the value of the edges’ reliability. The gather of pixels unwrapped from the same pixel is defined as a group. The reliability of a group is the sum of the reliability of each pixel within one group. Each pixel on the wrapped phase is initialized as an individual group. Finally, all the pixels have been unwrapped from one pixel. This algorithm was proposed by Harráez [23] in 2002. And then Abdul-Rahman [24] extended it to 3D phase unwrapping in 2007.

In this paper, we compared the performance of three basic phase unwrapping algorithms when the continuous phase is polluted by noise. After that, two hybrid algorithms by combining the merits of these three algorithms are proposed and verified.

3 Computer simulation and analysis

For comparing the former mentioned three phase unwrapping algorithms, a continuous phase distribution was simulated to satisfy the function in Eq. (1).

$$f(x,y) = 20\exp \left( { - \frac{{x^{2} + y^{2} }}{4}} \right) + 2x + y( - 3 \le x \le 3, - 3 \le y \le 3)$$
(1)

512 sampling points were taken in both X and Y directions. The continuous phase and its corresponding wrapped phase are shown in Fig. 1.

Fig. 1
figure 1

Simulation of a a continuous phase and b its corresponding wrapped phase

Three algorithms (BC, MD, FPU) were used to unwrap this simulated wrapped phase when it has been interfered by noise. The error of the unwrapping result was obtained by subtracting the continuous phase-added noise from the unwrapped phase. The results presented were obtained with MATLAB coding (three algorithms are implemented in C language of VS2012 platform), and using a personal computer equipped with a 2.7 GHz Core i5 CPU and a 16 GB RAM.

The added noise A is random noise, its mean value is 0.0002 and its variance is 0.16. Its maximum and minimum values are 1.857 rad (the amplitude is equal to 6.1% of the phase information shown in Fig. 1a) and − 1.773 rad (the amplitude is equal to 6.4% of the phase information shown in Fig. 1a), respectively. Five kinds of gradually increasing noise were simulated, and the amplitudes are 1, 1.5, 2, 2.5, and 3 times of noise A, respectively, i.e., the amplitudes of the added random noise changed from ± 6 to ± 18%.

Five noise-polluted phases have been unwrapped by three algorithms, respectively. The results are shown in Fig. 2. From this, it can be seen that the gradually increasing noise has the least influence on MD algorithm, so MD algorithm has the best performance in the situation of noise interference.

Fig. 2
figure 2

Unwrapped results using three algorithms (BC, MD and FPU) to unwrap the phase-added five kinds of noise

After subtracting the continuous phase-added noise from the unwrapped phase results, the errors caused by each algorithm itself are shown in Fig. 3. When the random noise with larger amplitude is added to the wrapped phase, some pixels’ phase values change which might result in these pixels becoming residues and finally fail in the phase unwrapping process and the error of these pixels is ± 2π. These scattered defects can be eliminated with other operations, such as smoothing filtering.

Fig. 3
figure 3

Error of unwrapped result shown in three columns on the right of Fig. 2

The total number of pixels unwrapped incorrectly was counted and is listed in Table 1. When the number of pixels unwrapped wrong is more than 20% of the total pixels of the whole map (52,429 pixels of 512 × 512 pixels), the result of phase unwrapping is considered to be obviously wrong. This number is not recorded and marked out with a dashed line in Table 1. The time required to unwrap the phase with five kinds of noise using three algorithms is shown in Table 2.

Table 1 Total number of pixels unwrapped incorrectly
Table 2 Time consumed to unwrap the phase (s)

From Table 1, it can be obviously seen that the wrapped phase with slight noise can be correctly unwrapped by all the three algorithms. With the increase in noise, the number of pixels unwrapped incorrectly using the FPU algorithm was the first to exceed 20%. Among them, MD algorithm is stable and robust, and the number of pixels unwrapped incorrectly is not more than 20% until the end, so it was only slightly affected by the increasing noise. The BC algorithm is easy to form in some isolated areas where the residue is dense and the phase cannot be unwrapped. The FPU algorithm develops the wrong result, because it can not choose the correct phase unwrapping path in an area of heavy noise. The MD algorithm causes the error occurring in an area of heavy noise by to its smooth effect on the unwrapped phase. Moreover, from Table 2, it is seen that this algorithm consumes much more time than the other two algorithms because of the large number of iterations.

In summary, the MD algorithm is the last to fail when the noise is gradually enhanced, so it has the strongest anti-noise performance among these three algorithms. Of course, compared to the other two algorithms, it takes longer time to unwrap the phase.

4 Principles and performances of two hybrid algorithms

4.1 Principles of two new hybrid algorithms

In BC algorithm, the branch cuttings generated by the algorithm tend to close on themselves, which might lead to isolated regions in the unwrapped result where the residues are dense, but it has the advantage of fast speed. The MD algorithm shows the best anti-noise performance, but it is time consuming, and the consumed memory is also larger than the other two algorithms. So, combining the BC algorithm with the MD algorithm is a good choose for speed and accuracy. First, the pixels are unwrapped in one large isolated area using the BC algorithm, then the MD algorithm is used to unwrap the remaining pixels and finally to optimize the unwrapped phase. In this hybrid algorithm (named BC–MD algorithm), most of the wrapped phase was unwrapped using the BC algorithm, only a few iterations of the MD algorithm were used to unwrap the other wrapped phase. Therefore, the phase unwrapping process using this hybrid algorithm will be quicker compared to doing the whole process using the conventional MD algorithm, and its result will be more accurate than that of the BC algorithm.

The phase unwrapping process of BC–MD algorithm is as shown in the following steps.

  1. 1.

    Determining the unreliable region in the 2 × 2 closed loop area. The pixel at the upper left corner in an unreliable region will be marked as a residue, which is further identified and divided into positive and negative ones.

  2. 2.

    Forming the branch cutting by balancing the positive and negative residues, or connecting the residues with the boundary.

  3. 3.

    Choosing one pixel outside the branch cuttings as the starting point of the phase unwrapping to unwrap the pixels that are not on the branch cuttings.

  4. 4.

    Calculating the horizontal jump array and the vertical jump array according the current phase distribution, and initializing the node array.

  5. 5.

    Determining whether the edges can be successfully added with these three arrays. Once a loop is generated by the increasing edges, all the edges constituting a loop will be removed, and three arrays will also be updated. At that time, the phase value of the pixels enclosed in the removed loop will be changed 2π which will decrease the discontinuity of the wrapped phase.

  6. 6.

    Repeating step (5) until no new edge is extended and finally computing the whole unwrapped phase with the accumulation of jump counts.

The FPU algorithm can lead to the wrong result, because it did not choose the correct phase unwrapping path in the area of heavy noise, and the error will propagate on the regions with dense noise. Combining it with the MD algorithm can overcome the shortcomings of both the algorithms. An appropriate threshold is set according to the percent which is the number of the wrong pixels divided by all the pixels. First of all, to estimate the percentage of the number of pixels unwrapped correctly to the total number of pixels, a number slightly less than that should be set as the percentage of the pixels that will be unwrapped by FPU algorithm. Then all the pixels should be sorted according to their reliability. The number of pixels that will be unwrapped by the FPU algorithm is equal to the proportional threshold multiplied by the value of the pixels of the whole image. With this percentage, the wrapped phase is divided into two parts. The pixels belonging to this percentage are considered to be of high quality or reliability, and will be unwrapped using the FPU algorithm. The others will be regarded as low quality or reliability and unwrapped with MD algorithm. After these two procedures, a global phase distribution should be optimized as the final result of the phase unwrapping. This hybrid algorithm (named FPU–MD algorithm) not only avoids the phase unwrapping error caused by the FPU algorithm, but also solves the problem of the slow speed of the MD algorithm.

The phase unwrapping process of FPU–MD algorithm is as shown in the following steps.

  1. 1.

    Calculating the reliability of each edge and sorting them by the magnitudes of the reliability.

  2. 2.

    Taking out the edge with the maximum reliability and judging whether two pixels on a side belong to the same group or not. The edge is valid if two pixels do not belong to the same group. For two groups, the group with less reliability is unwrapped with respect to the group with greater reliability. This operation involves two sub-steps: unwrapping the pixel belonging to the group with less reliability using the other pixel, calculating the value added to the pixel and adding the same constant to the rest of the group with less reliability. Finally, both unwrapped groups are joined together into a single new group.

  3. 3.

    Choosing the next edge with greater reliability and to repeat step (2) until all edges in higher quality are dealt with.

  4. 4.

    Repeating steps (4)–(6) in BC–MD algorithm.

4.2 Performance comparison of the five phase unwrapping algorithms in computer simulation

A continuous phase with a size of 512 × 512 pixels was simulated and its phase value is 5.6 times that of the peaks’ function. A random noise was added to the upper half part of it, as shown in Fig. 4a. Its mean value is 0.0008 and its variance is 1.4509. Its maximum and minimum values are 5.2827 rad and − 5.2713 rad (the amplitude is equal to 6.2% of the phase information as shown in Fig. 4a), respectively. Its corresponding wrapped phase is shown in Fig. 4b, c.

Fig. 4
figure 4

Continuous phase (a) and its corresponding wrapped phase (b, c)

The wrapped phase mentioned above was unwrapped using three basic algorithms and two new hybrid algorithms, respectively. The unwrapped result and error are shown in Fig. 5.

Fig. 5
figure 5

Unwrapped results and errors of the simulated phase using five algorithms

The number of pixels unwrapped incorrectly and their consumed time are shown in Table 3. The reason why the MD algorithm takes such a long time to unwrap the phase is that there are a large number of iterative processes, such as adding edges, generating loops, eliminating loops, updating jump arrays and so on. Therefore, in terms of the number of added edges and generated loops, the MD algorithm and the hybrid algorithm are compared. The edges and loops generated in the process of phase unwrapping are also shown in Table 3.

Table 3 The number of pixels unwrapped incorrectly, the number of edges and loops generated in the process of phase unwrapping and the consumed time of five algorithms

The result of this simulated experiment demonstrates that the consumed time of two new hybrid algorithms in phase unwrapping has been reduced compared to the MD algorithm. Meanwhile, the number of edges and loops formed by the two hybrid algorithms are less than that formed by the MD algorithm. The number of pixels that are unwrapped incorrectly is smaller than that of the BC algorithm and the FPU algorithm. However, the results still have some obvious errors. The main reason is that the aim of MD algorithm is to minimize the objective function, so that it will smoothen the phase in the area of heavy noise. Therefore, the error would be produced compared with the original phase. Because the main idea of MD algorithm is to find the situation in which the objective function is the smallest in the whole field. The phase might be distorted when the object itself has discontinuity or abrupt changes. Therefore, the proposed algorithms might be flawed and unable to unwrap correctly when the object itself has abrupt changes.

4.3 The actual experiment

Two actual experiments were used to prove the effectiveness of two new hybrid algorithms. The schematic diagram of the experimental setup is shown in Fig. 6a. A DLP projector with the resolution of 1280 × 800 pixels was used to project a sinusoidal fringe pattern as shown in Fig. 6b onto two measured models, a Buddha sculpture and a facial mask, and a uEye USB CMOS camera (UI-1240SENIR-GL) with the resolution of 1280 × 1024 pixels and a 16-mm lens was used to capture the deformed fringe patterns from another orientation. Two deformed fringes of 1024 × 1280 pixels were recorded which are shown in Fig. 7a, c. Their wrapped phase was calculated by Fourier fringe analysis [25] and is shown in Fig. 7b, d. In FTP, the frequency domain distribution is obtained by Fourier transform of the modulated fringe, and then the fundamental frequency is filtered out by a bandpass filter. And then, the fundamental frequency is transformed by inverse Fourier transform from which the wrapped phase can be obtained.

Fig. 6
figure 6

Schematic diagram of the actual experiment. a Experimental setup. b Projected fringe pattern

Fig. 7
figure 7

Deformed fringe and wrapped phase of two models. a, b Buddha sculpture; c, d facial mask

The wrapped phase of Buddha sculpture was unwrapped using BC, MD algorithms and their combination BC–MD, respectively, and the results are shown in Fig. 8. The second row of Fig. 8 corresponds to detailed information about the three algorithms. It can be seen that in the unwrapping result of the BC algorithm, the unwrapping process failed in the area of the nose and the right side of the face. The results of the MD algorithm and the hybrid algorithm are relatively better in these regions.

Fig. 8
figure 8

Unwrapped results of Buddha sculpture’s wrapped phase (row 1) and detailed information (row 2) using a BC; b MD; c BC–MD algorithm

The consumed time of three algorithms is 0.154, 12.390, and 1.781 s, respectively. In the process of implementation, the number of edges formed by the MD algorithm and the hybrid algorithm are 84795704 and 10618675, and the number of loops is 778 and 247, respectively. Because the BC algorithm in the hybrid algorithm unwrapped all the pixels outside the isolated region, the jump number of the whole field was greatly reduced. Therefore, in the process of phase unwrapping, the number of edges formed by the hybrid algorithm is less than that formed by the MD algorithm. Because the unwrapping path of the BC algorithm is continuous, the number of loops formed by the hybrid algorithm is also reduced accordingly.

The wrapped phase of the facial mask was unwrapped using FPU, MD algorithm and their combination FPU–MD algorithm, respectively, and the results are shown in Fig. 9. The second row of Fig. 9 corresponds to detailed information about the three algorithms. It can be seen that in the unwrapping result of the FPU algorithm, the area of the nose and mouth is wrong, but the results of the MD algorithm and the hybrid algorithm are correct in these regions.

Fig. 9
figure 9

Unwrapped results of the facial mask’s wrapped phase (row 1) and detailed information (row 2) using a FPU; b MD; c FPU–MD algorithm

The consumed time of three algorithms is, respectively, 0.641, 45.949 and 23.360 s. The number of edges formed by the MD algorithm and the hybrid algorithm is 284445573 and 149575906, and the number of loops is 2097 and 17865, respectively. The edges formed by the phase unwrapping of the hybrid algorithm are less than that of the MD algorithm. The reason why the number of loops formed by the hybrid algorithm is more than that by the MD algorithm is that after the high-quality region is unwrapped by the FPU algorithm, the phase of the whole image is divided into a number of discrete small regions, so a large loop originally formed in the MD algorithm will be dispersed in the hybrid algorithm to form a number of small loops.

5 Conclusions

In this paper, three spatial phase unwrapping algorithms, branch-cut phase unwrapping (BC) algorithm, fast phase unwrapping (FPU) algorithm and minimum discontinuity (MD) algorithm, have been briefly reviewed. The computer simulation results show that both the BC algorithm and FPU algorithm have high speed in phase unwrapping, and the MD algorithm shows the best anti-noise performance. However, it is time consuming compared to the other two algorithms.

Based on the comparison of the three basic algorithms, two new hybrid algorithms, BC–MD and FPU–MD, were proposed. These new algorithms combine the advantages of the original algorithms and offset the disadvantages of each other. Compared with the BC and FPU, the two new hybrid algorithms have the advantage of accuracy, and compared with the MD, the two new hybrid algorithms have the advantage of speed. The characteristics and availabilities of these two new algorithms have been proved by the results of computer simulation and actual experiments. Both of them can be effectively applied to the 2D spatial phase unwrapping.