skimage2.restoration.unwrap_phase#

skimage2.restoration.unwrap_phase(image, wrap_around=False, rng=None)[source]#

Recover the original from a wrapped phase image.

From an image wrapped to lie in the interval [-pi, pi), recover the original, unwrapped image.

Parameters:
image(M[, N[, P]]) ndarray or masked array of floats

The values should be in the range [-pi, pi). If a masked array is provided, the masked entries will not be changed, and their values will not be used to guide the unwrapping of neighboring, unmasked values. Masked 1D arrays are not allowed, and will raise a ValueError. NaN values in the image form an implicit mask. We combine this implicit mask with any mask from a masked array, with logical OR. The output values under the resulting mask are set to the minimum of the unwrapped phase.

wrap_aroundbool or sequence of bool, optional

When an element of the sequence is True, the unwrapping process will regard the edges along the corresponding axis of the image to be connected and use this connectivity to guide the phase unwrapping process. If only a single boolean is given, it will apply to all axes. Wrap around is not supported for 1D arrays.

rng{numpy.random.Generator, int}, optional

Unwrapping relies on a random per-pixel initialization. If a numpy random number generator (RNG), then use that to generate the initialization. If None, create a new RNG. If an int, seed a new RNG with this passed integer.

Returns:
image_unwrappedarray_like, double

Unwrapped image of the same shape as the input. If the input image was a masked array, the mask will be preserved.

Raises:
ValueError

If called with a masked 1D array or called with a 1D array and wrap_around=True.

Notes

The algorithm proceeds by calculating an unreliability score for each image location, and unwrapping first through areas with the lowest scores (lowest unreliability). For some locations, such as corner pixels, border pixels where wrap_around is False for the relevant edge, and pixels that are neighbors to masked pixels, we cannot calculate unreliability due to missing data in some neighbors. In this case we set unreliability to a high value plus some random component, where the random component prevents memory location bias in the order of unwrapping. The random component means there can be slight differences from run to run in the corner pixels, border pixels (depending on wrap_around), or pixels next to a masked pixel, unless you constrain the randomness with the rng argument.

References

[1]

Miguel Arevallilo Herraez, David R. Burton, Michael J. Lalor, and Munther A. Gdeisat, “Fast two-dimensional phase-unwrapping algorithm based on sorting by reliability following a noncontinuous path”, Journal Applied Optics, Vol. 41, No. 35 (2002) 7437,

[2]

Abdul-Rahman, H., Gdeisat, M., Burton, D., & Lalor, M., “Fast three-dimensional phase-unwrapping algorithm based on sorting by reliability following a non-continuous path. In W. Osten, C. Gorecki, & E. L. Novak (Eds.), Optical Metrology (2005) 32–40, International Society for Optics and Photonics.

Examples

>>> c0, c1 = np.ogrid[-1:1:128j, -1:1:128j]
>>> image = 12 * np.pi * np.exp(-(c0**2 + c1**2))
>>> image_wrapped = np.angle(np.exp(1j * image))
>>> image_unwrapped = unwrap_phase(image_wrapped)
>>> np.std(image_unwrapped - image) < 1e-6   # A constant offset is normal
True