U
    t»|e~,  ã                   @   st   d dl Z d dlmZ ddlmZ ddlmZ dddd	gZd
d„ Zdd„ Zddd„Z	ddd„Z
ddd„Zddd	„ZdS )é    N)Únormalize_axis_indexé   )Ú_ni_support)Ú	_nd_imageÚfourier_gaussianÚfourier_uniformÚfourier_ellipsoidÚfourier_shiftc                 C   sž   | d krH|j jtjtjtjfkr4tj|j|j d�} qštj|jtjd�} nRt| ƒtkr†| tjtjtjtjfkrtt	dƒ‚tj|j| d�} n| j|jkršt	dƒ‚| S ©N©Údtypezoutput type not supportedzoutput shape not correct)
r   ÚtypeÚnumpyÚ	complex64Ú
complex128Úfloat32ÚzerosÚshapeÚfloat64ÚRuntimeError©ÚoutputÚinput© r   úS/var/www/website-v5/atlas_env/lib/python3.8/site-packages/scipy/ndimage/_fourier.pyÚ_get_output_fourier(   s     ÿ
 ÿr   c                 C   s’   | d krD|j jtjtjfkr0tj|j|j d�} qŽtj|jtjd�} nJt| ƒtkrz| tjtjfkrhtdƒ‚tj|j| d�} n| j|jkrŽtdƒ‚| S r
   )r   r   r   r   r   r   r   r   r   r   r   r   Ú_get_output_fourier_complex9   s    r   éÿÿÿÿc                 C   sf   t  | ¡} t|| ƒ}t|| jƒ}t || j¡}t j|t jd�}|jj	sN| 
¡ }t | ||||d¡ |S )a  
    Multidimensional Gaussian fourier filter.

    The array is multiplied with the fourier transform of a Gaussian
    kernel.

    Parameters
    ----------
    input : array_like
        The input array.
    sigma : float or sequence
        The sigma of the Gaussian kernel. If a float, `sigma` is the same for
        all axes. If a sequence, `sigma` has to contain one value for each
        axis.
    n : int, optional
        If `n` is negative (default), then the input is assumed to be the
        result of a complex fft.
        If `n` is larger than or equal to zero, the input is assumed to be the
        result of a real fft, and `n` gives the length of the array before
        transformation along the real transform direction.
    axis : int, optional
        The axis of the real transform.
    output : ndarray, optional
        If given, the result of filtering the input is placed in this array.

    Returns
    -------
    fourier_gaussian : ndarray
        The filtered input.

    Examples
    --------
    >>> from scipy import ndimage, datasets
    >>> import numpy.fft
    >>> import matplotlib.pyplot as plt
    >>> fig, (ax1, ax2) = plt.subplots(1, 2)
    >>> plt.gray()  # show the filtered result in grayscale
    >>> ascent = datasets.ascent()
    >>> input_ = numpy.fft.fft2(ascent)
    >>> result = ndimage.fourier_gaussian(input_, sigma=4)
    >>> result = numpy.fft.ifft2(result)
    >>> ax1.imshow(ascent)
    >>> ax2.imshow(result.real)  # the imaginary part is an artifact
    >>> plt.show()
    r   r   ©r   Úasarrayr   r   Úndimr   Ú_normalize_sequencer   ÚflagsÚ
contiguousÚcopyr   Úfourier_filter)r   ÚsigmaÚnÚaxisr   Úsigmasr   r   r   r   H   s    .

c                 C   sf   t  | ¡} t|| ƒ}t|| jƒ}t || j¡}t j|t jd�}|jj	sN| 
¡ }t | ||||d¡ |S )a  
    Multidimensional uniform fourier filter.

    The array is multiplied with the Fourier transform of a box of given
    size.

    Parameters
    ----------
    input : array_like
        The input array.
    size : float or sequence
        The size of the box used for filtering.
        If a float, `size` is the same for all axes. If a sequence, `size` has
        to contain one value for each axis.
    n : int, optional
        If `n` is negative (default), then the input is assumed to be the
        result of a complex fft.
        If `n` is larger than or equal to zero, the input is assumed to be the
        result of a real fft, and `n` gives the length of the array before
        transformation along the real transform direction.
    axis : int, optional
        The axis of the real transform.
    output : ndarray, optional
        If given, the result of filtering the input is placed in this array.

    Returns
    -------
    fourier_uniform : ndarray
        The filtered input.

    Examples
    --------
    >>> from scipy import ndimage, datasets
    >>> import numpy.fft
    >>> import matplotlib.pyplot as plt
    >>> fig, (ax1, ax2) = plt.subplots(1, 2)
    >>> plt.gray()  # show the filtered result in grayscale
    >>> ascent = datasets.ascent()
    >>> input_ = numpy.fft.fft2(ascent)
    >>> result = ndimage.fourier_uniform(input_, size=20)
    >>> result = numpy.fft.ifft2(result)
    >>> ax1.imshow(ascent)
    >>> ax2.imshow(result.real)  # the imaginary part is an artifact
    >>> plt.show()
    r   r   r   ©r   Úsizer'   r(   r   Úsizesr   r   r   r   ‚   s    .

c                 C   s†   t  | ¡} | jdkrtdƒ‚t|| ƒ}|jdkr4|S t|| jƒ}t || j¡}t j|t j	d�}|j
jsn| ¡ }t | ||||d¡ |S )ah  
    Multidimensional ellipsoid Fourier filter.

    The array is multiplied with the fourier transform of an ellipsoid of
    given sizes.

    Parameters
    ----------
    input : array_like
        The input array.
    size : float or sequence
        The size of the box used for filtering.
        If a float, `size` is the same for all axes. If a sequence, `size` has
        to contain one value for each axis.
    n : int, optional
        If `n` is negative (default), then the input is assumed to be the
        result of a complex fft.
        If `n` is larger than or equal to zero, the input is assumed to be the
        result of a real fft, and `n` gives the length of the array before
        transformation along the real transform direction.
    axis : int, optional
        The axis of the real transform.
    output : ndarray, optional
        If given, the result of filtering the input is placed in this array.

    Returns
    -------
    fourier_ellipsoid : ndarray
        The filtered input.

    Notes
    -----
    This function is implemented for arrays of rank 1, 2, or 3.

    Examples
    --------
    >>> from scipy import ndimage, datasets
    >>> import numpy.fft
    >>> import matplotlib.pyplot as plt
    >>> fig, (ax1, ax2) = plt.subplots(1, 2)
    >>> plt.gray()  # show the filtered result in grayscale
    >>> ascent = datasets.ascent()
    >>> input_ = numpy.fft.fft2(ascent)
    >>> result = ndimage.fourier_ellipsoid(input_, size=20)
    >>> result = numpy.fft.ifft2(result)
    >>> ax1.imshow(ascent)
    >>> ax2.imshow(result.real)  # the imaginary part is an artifact
    >>> plt.show()
    é   z'Only 1d, 2d and 3d inputs are supportedr   r   é   )r   r   r    ÚNotImplementedErrorr   r+   r   r   r!   r   r"   r#   r$   r   r%   r*   r   r   r   r   »   s    2



c                 C   sd   t  | ¡} t|| ƒ}t|| jƒ}t || j¡}t j|t jd�}|jj	sN| 
¡ }t | ||||¡ |S )aü  
    Multidimensional Fourier shift filter.

    The array is multiplied with the Fourier transform of a shift operation.

    Parameters
    ----------
    input : array_like
        The input array.
    shift : float or sequence
        The size of the box used for filtering.
        If a float, `shift` is the same for all axes. If a sequence, `shift`
        has to contain one value for each axis.
    n : int, optional
        If `n` is negative (default), then the input is assumed to be the
        result of a complex fft.
        If `n` is larger than or equal to zero, the input is assumed to be the
        result of a real fft, and `n` gives the length of the array before
        transformation along the real transform direction.
    axis : int, optional
        The axis of the real transform.
    output : ndarray, optional
        If given, the result of shifting the input is placed in this array.

    Returns
    -------
    fourier_shift : ndarray
        The shifted input.

    Examples
    --------
    >>> from scipy import ndimage, datasets
    >>> import matplotlib.pyplot as plt
    >>> import numpy.fft
    >>> fig, (ax1, ax2) = plt.subplots(1, 2)
    >>> plt.gray()  # show the filtered result in grayscale
    >>> ascent = datasets.ascent()
    >>> input_ = numpy.fft.fft2(ascent)
    >>> result = ndimage.fourier_shift(input_, shift=200)
    >>> result = numpy.fft.ifft2(result)
    >>> ax1.imshow(ascent)
    >>> ax2.imshow(result.real)  # the imaginary part is an artifact
    >>> plt.show()
    r   )r   r   r   r   r    r   r!   r   r"   r#   r$   r   r	   )r   Úshiftr'   r(   r   Úshiftsr   r   r   r	   þ   s    -

)r   r   N)r   r   N)r   r   N)r   r   N)r   Únumpy.core.multiarrayr   Ú r   r   Ú__all__r   r   r   r   r   r	   r   r   r   r   Ú<module>   s   ÿ
:
9
C