
    0-Ph                     F    d dl ZddlmZ ddlmZ ddlmZ ddlm	Z	 d
d	Z
dS )    N   )warn   )	unwrap_1d)	unwrap_2d)	unwrap_3dFc                 &   | j         dvrt          d          t          |t                    r|g| j         z  }nht	          |d          rIt          |t
                    s4t          |          | j         k    rt          d          d |D             }nt          d          | j         dk    rEt          j        	                    |           rt          d          |d	         rt          d
          | j         dv rd| j
        v rt          d           t          j        	                    |           r?t          j        t          j                            |           t          j        dg          }n!t          j        | t          j        d          }t          j        t          j                            |           t          j        d          }t          j        | t          j        dd          }| j         dk    rt)          ||           n=| j         dk    rt+          |||||           n| j         dk    rt-          |||||           t          j        	                    |           r't          j                            ||| j                  S |S )ax
  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`.
    wrap_around : bool 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
        Pseudo-random number generator.
        By default, a PCG64 generator is used (see :func:`numpy.random.default_rng`).
        If `rng` is an int, it is used to seed the generator.

        Unwrapping relies on a random initialization. This sets the
        PRNG to use to achieve deterministic behavior.

    Returns
    -------
    image_unwrapped : array_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``.

    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

    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.
    )r   r      z$Image must be 1, 2, or 3 dimensional__getitem__z>Length of `wrap_around` must equal the dimensionality of imagec                 ,    g | ]}t          |          S  )bool).0was     Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/restoration/unwrap.py
<listcomp>z unwrap_phase.<locals>.<listcomp>P   s    666BtBxx666    z[`wrap_around` must be a bool or a sequence with length equal to the dimensionality of imager   z$1D masked images cannot be unwrappedr   z,`wrap_around` is not supported for 1D images)r   r
   zqImage has a length 1 dimension. Consider using an array of lower dimensionality to use a more efficient algorithmC)dtypeorderF)r   r   subokr   r
   )mask
fill_value)ndim
ValueError
isinstancer   hasattrstrlennpmaisMaskedArrayshaper   requiregetmaskarrayuint8
zeros_likeasarraygetdatafloat64
empty_liker   r   r   arrayr   )imagewrap_aroundrngr   image_not_maskedimage_unwrappeds         r   unwrap_phaser2   
   s}   z z""?@@@+t$$ 
"mej0	m	,	, 

ZS5Q5Q 

{uz))S   76+666:
 
 	
 zQ5u%% 	ECDDDq> 	MKLLLzVU[ 0 0	
 	
 	
 
u5!! ?z"%,,U33RXuEE}U"(#>>>z"%--"6"6bjPSTTTmE3eTTTOzQ"O4444	q"D/;LLLL	q"D/;LLL	u5!! u{{?%BR{SSSr   )FN)numpyr    _shared.utilsr   
_unwrap_1dr   
_unwrap_2dr   
_unwrap_3dr   r2   r   r   r   <module>r8      s}                    ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !j j j j j jr   