a
    BCCf                  	   @   s   d dl Z d dlZ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l
mZ g dZed	d
ejdfddZed	ejdfddZdd Zeddd	ddddi fddZed%ddZed&ddZed'ddZed(ddd d!Zed)d#d$ZdS )*    N)normalize_axis_index)special   )_ni_support)	_nd_image)	docfiller)spline_filter1dspline_filtergeometric_transformmap_coordinatesaffine_transformshiftzoomrotate   Zmirrorc                 C   s   |dk s|dkrt dt| } t| }tj|| |d}|rlt| j|||j| t| j|||j| |S |dv rt	| |d< n(t
|}t|| j}t| |||| |S )aG	  
    Calculate a 1-D spline filter along the given axis.

    The lines of the array along the given axis are filtered by a
    spline filter. The order of the spline must be >= 2 and <= 5.

    Parameters
    ----------
    %(input)s
    order : int, optional
        The order of the spline, default is 3.
    axis : int, optional
        The axis along which the spline filter is applied. Default is the last
        axis.
    output : ndarray or dtype, optional
        The array in which to place the output, or the dtype of the returned
        array. Default is ``numpy.float64``.
    %(mode_interp_mirror)s

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

    See Also
    --------
    spline_filter : Multidimensional spline filter.

    Notes
    -----
    All of the interpolation functions in `ndimage` do spline interpolation of
    the input image. If using B-splines of `order > 1`, the input image
    values have to be converted to B-spline coefficients first, which is
    done by applying this 1-D filter sequentially along all
    axes of the input. All functions that require B-spline coefficients
    will automatically filter their inputs, a behavior controllable with
    the `prefilter` keyword argument. For functions that accept a `mode`
    parameter, the result will only be correct if it matches the `mode`
    used when filtering.

    For complex-valued `input`, this function processes the real and imaginary
    components independently.

    .. versionadded:: 1.6.0
        Complex-valued support added.

    Examples
    --------
    We can filter an image using 1-D spline along the given axis:

    >>> from scipy.ndimage import spline_filter1d
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> orig_img = np.eye(20)  # create an image
    >>> orig_img[10, :] = 1.0
    >>> sp_filter_axis_0 = spline_filter1d(orig_img, axis=0)
    >>> sp_filter_axis_1 = spline_filter1d(orig_img, axis=1)
    >>> f, ax = plt.subplots(1, 3, sharex=True)
    >>> for ind, data in enumerate([[orig_img, "original image"],
    ...             [sp_filter_axis_0, "spline filter (axis=0)"],
    ...             [sp_filter_axis_1, "spline filter (axis=1)"]]):
    ...     ax[ind].imshow(data[0], cmap='gray_r')
    ...     ax[ind].set_title(data[1])
    >>> plt.tight_layout()
    >>> plt.show()

    r      spline order not supportedcomplex_outputr   r   .)RuntimeErrornumpyasarrayiscomplexobjr   _get_outputr   realimagarray_extend_mode_to_coder   ndimr   )inputorderaxisoutputmoder    r&   X/var/www/html/django/DPS/env/lib/python3.9/site-packages/scipy/ndimage/_interpolation.pyr   /   s"    F


r   c                 C   s   |dk s|dkrt dt| } t| }tj|| |d}|rht| j||j| t| j||j| |S |dvr| j	dkrt
| j	D ]}t| ||||d |} qn| d |d< |S )	a  
    Multidimensional spline filter.

    Parameters
    ----------
    %(input)s
    order : int, optional
        The order of the spline, default is 3.
    output : ndarray or dtype, optional
        The array in which to place the output, or the dtype of the returned
        array. Default is ``numpy.float64``.
    %(mode_interp_mirror)s

    Returns
    -------
    spline_filter : ndarray
        Filtered array. Has the same shape as `input`.

    See Also
    --------
    spline_filter1d : Calculate a 1-D spline filter along the given axis.

    Notes
    -----
    The multidimensional filter is implemented as a sequence of
    1-D spline filters. The intermediate arrays are stored
    in the same data type as the output. Therefore, for output types
    with a limited precision, the results may be imprecise because
    intermediate results may be stored with insufficient precision.

    For complex-valued `input`, this function processes the real and imaginary
    components independently.

    .. versionadded:: 1.6.0
        Complex-valued support added.

    Examples
    --------
    We can filter an image using multidimentional splines:

    >>> from scipy.ndimage import spline_filter
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> orig_img = np.eye(20)  # create an image
    >>> orig_img[10, :] = 1.0
    >>> sp_filter = spline_filter(orig_img, order=3)
    >>> f, ax = plt.subplots(1, 2, sharex=True)
    >>> for ind, data in enumerate([[orig_img, "original image"],
    ...                             [sp_filter, "spline filter"]]):
    ...     ax[ind].imshow(data[0], cmap='gray_r')
    ...     ax[ind].set_title(data[1])
    >>> plt.tight_layout()
    >>> plt.show()

       r   r   r   r   r   r$   r%   .)r   r   r   r   r   r   r	   r   r   r    ranger   )r!   r"   r$   r%   r   r#   r&   r&   r'   r	      s"    9

r	   c                 C   sR   |dv rBd}|dkr(t j| |d|d}qJ|dkrJt j| |dd}nd	}| }||fS )
N)nearestgrid-constant   r,   constant)r%   Zconstant_valuesr+   edge)r%   r   )r   pad)r!   r%   cvalnpadpaddedr&   r&   r'   _prepad_for_spline_filter   s    
r4   r.           Tr&   c
                 C   s0  |dk s|dkrt dt| } |du r0| j}| jdk sFt|dk rNt dt| }
tj|| ||
d}|
rt	||||||	d}t
| j|f|jt|d	| t
| j|f|jt|d	| |S |r|dkrt| ||\}}t||tj|d
}nd}| }t|}t
||ddd|||||||	 |S )a  
    Apply an arbitrary geometric transform.

    The given mapping function is used to find, for each point in the
    output, the corresponding coordinates in the input. The value of the
    input at those coordinates is determined by spline interpolation of
    the requested order.

    Parameters
    ----------
    %(input)s
    mapping : {callable, scipy.LowLevelCallable}
        A callable object that accepts a tuple of length equal to the output
        array rank, and returns the corresponding input coordinates as a tuple
        of length equal to the input array rank.
    output_shape : tuple of ints, optional
        Shape tuple.
    %(output)s
    order : int, optional
        The order of the spline interpolation, default is 3.
        The order has to be in the range 0-5.
    %(mode_interp_constant)s
    %(cval)s
    %(prefilter)s
    extra_arguments : tuple, optional
        Extra arguments passed to `mapping`.
    extra_keywords : dict, optional
        Extra keywords passed to `mapping`.

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

    See Also
    --------
    map_coordinates, affine_transform, spline_filter1d


    Notes
    -----
    This function also accepts low-level callback functions with one
    the following signatures and wrapped in `scipy.LowLevelCallable`:

    .. code:: c

       int mapping(npy_intp *output_coordinates, double *input_coordinates,
                   int output_rank, int input_rank, void *user_data)
       int mapping(intptr_t *output_coordinates, double *input_coordinates,
                   int output_rank, int input_rank, void *user_data)

    The calling function iterates over the elements of the output array,
    calling the callback function at each element. The coordinates of the
    current output element are passed through ``output_coordinates``. The
    callback function must return the coordinates at which the input must
    be interpolated in ``input_coordinates``. The rank of the input and
    output arrays are given by ``input_rank`` and ``output_rank``
    respectively. ``user_data`` is the data pointer provided
    to `scipy.LowLevelCallable` as-is.

    The callback function must return an integer error status that is zero
    if something went wrong and one otherwise. If an error occurs, you should
    normally set the Python error status with an informative message
    before returning, otherwise a default error message is set by the
    calling function.

    In addition, some other low-level function pointer specifications
    are accepted, but these are for backward compatibility only and should
    not be used in new code.

    For complex-valued `input`, this function transforms the real and imaginary
    components independently.

    .. versionadded:: 1.6.0
        Complex-valued support added.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.ndimage import geometric_transform
    >>> a = np.arange(12.).reshape((4, 3))
    >>> def shift_func(output_coords):
    ...     return (output_coords[0] - 0.5, output_coords[1] - 0.5)
    ...
    >>> geometric_transform(a, shift_func)
    array([[ 0.   ,  0.   ,  0.   ],
           [ 0.   ,  1.362,  2.738],
           [ 0.   ,  4.812,  6.187],
           [ 0.   ,  8.263,  9.637]])

    >>> b = [1, 2, 3, 4, 5]
    >>> def shift_func(output_coords):
    ...     return (output_coords[0] - 3,)
    ...
    >>> geometric_transform(b, shift_func, mode='constant')
    array([0, 0, 0, 1, 2])
    >>> geometric_transform(b, shift_func, mode='nearest')
    array([1, 1, 1, 1, 2])
    >>> geometric_transform(b, shift_func, mode='reflect')
    array([3, 2, 1, 1, 2])
    >>> geometric_transform(b, shift_func, mode='wrap')
    array([2, 3, 4, 1, 2])

    r   r   r   Nr   !input and output rank must be > 0shaper   )r"   r%   	prefilteroutput_shapeextra_argumentsextra_keywordsr$   r1   r)   )r   r   r   r8   r    lenr   r   r   dictr
   r   r   r4   r	   float64r   r   )r!   mappingr:   r$   r"   r%   r1   r9   r;   r<   r   kwargsr3   r2   filteredr&   r&   r'   r
      sR    m





r
   c                 C   sb  |dk s|dkrt dt| } t|}t|r>td|jdd }| jdk sbt|dk rjt d|jd | jkrt dt| }tj	|| ||d	}|rt
|||d
}	t| j|f|jt|d|	 t| j|f|jt|d|	 |S |r,|dkr,t| ||\}
}t|
|tj|d}nd}| }t|}t|d|dd|||||dd |S )aZ  
    Map the input array to new coordinates by interpolation.

    The array of coordinates is used to find, for each point in the output,
    the corresponding coordinates in the input. The value of the input at
    those coordinates is determined by spline interpolation of the
    requested order.

    The shape of the output is derived from that of the coordinate
    array by dropping the first axis. The values of the array along
    the first axis are the coordinates in the input array at which the
    output value is found.

    Parameters
    ----------
    %(input)s
    coordinates : array_like
        The coordinates at which `input` is evaluated.
    %(output)s
    order : int, optional
        The order of the spline interpolation, default is 3.
        The order has to be in the range 0-5.
    %(mode_interp_constant)s
    %(cval)s
    %(prefilter)s

    Returns
    -------
    map_coordinates : ndarray
        The result of transforming the input. The shape of the output is
        derived from that of `coordinates` by dropping the first axis.

    See Also
    --------
    spline_filter, geometric_transform, scipy.interpolate

    Notes
    -----
    For complex-valued `input`, this function maps the real and imaginary
    components independently.

    .. versionadded:: 1.6.0
        Complex-valued support added.

    Examples
    --------
    >>> from scipy import ndimage
    >>> import numpy as np
    >>> a = np.arange(12.).reshape((4, 3))
    >>> a
    array([[  0.,   1.,   2.],
           [  3.,   4.,   5.],
           [  6.,   7.,   8.],
           [  9.,  10.,  11.]])
    >>> ndimage.map_coordinates(a, [[0.5, 2], [0.5, 1]], order=1)
    array([ 2.,  7.])

    Above, the interpolated value of a[0.5, 0.5] gives output[0], while
    a[2, 1] is output[1].

    >>> inds = np.array([[0.5, 2], [0.5, 4]])
    >>> ndimage.map_coordinates(a, inds, order=1, cval=-33.3)
    array([  2. , -33.3])
    >>> ndimage.map_coordinates(a, inds, order=1, mode='nearest')
    array([ 2.,  8.])
    >>> ndimage.map_coordinates(a, inds, order=1, cval=0, output=bool)
    array([ True, False], dtype=bool)

    r   r   r   zComplex type not supportedr   Nr6   z"invalid shape for coordinate arrayr7   r"   r%   r9   r=   r)   )r   r   r   r   	TypeErrorr8   r    r>   r   r   r?   r   r   r   r4   r	   r@   r   r   r
   )r!   coordinatesr$   r"   r%   r1   r9   r:   r   rB   r3   r2   rC   r&   r&   r'   r   s  sP    H






r   c	                 C   s  |dk s|dkrt dt| } |du rDt|tjr>|j}n| j}| jdk sZt|dk rbt dt| }	t	j
|| ||	d}|	rt|||||d}
t| j|f|jt|d	|
 t| j|f|jt|d	|
 |S |r|dkrt| ||\}}t||tj|d
}nd}| }t	|}tj|tjd}|jdvsN|jd dk rVt d|jdkr|jd | jd kr|jd | j| jd fv r|jd | jd krdg| j dg }t|| j |ksd|j| j|}t||d| j| jf }|d| jd| jf }|jd | jkr2t d|jdkrX|jd |jkrXt d|jjsj| }t	|| j}tj|tjd}|jdks|jd dk rt d|jjs| }|jdkrtjddd t|||| |||||d	 n t|dd|||||||dd |S )a  
    Apply an affine transformation.

    Given an output image pixel index vector ``o``, the pixel value
    is determined from the input image at position
    ``np.dot(matrix, o) + offset``.

    This does 'pull' (or 'backward') resampling, transforming the output space
    to the input to locate data. Affine transformations are often described in
    the 'push' (or 'forward') direction, transforming input to output. If you
    have a matrix for the 'push' transformation, use its inverse
    (:func:`numpy.linalg.inv`) in this function.

    Parameters
    ----------
    %(input)s
    matrix : ndarray
        The inverse coordinate transformation matrix, mapping output
        coordinates to input coordinates. If ``ndim`` is the number of
        dimensions of ``input``, the given matrix must have one of the
        following shapes:

            - ``(ndim, ndim)``: the linear transformation matrix for each
              output coordinate.
            - ``(ndim,)``: assume that the 2-D transformation matrix is
              diagonal, with the diagonal specified by the given value. A more
              efficient algorithm is then used that exploits the separability
              of the problem.
            - ``(ndim + 1, ndim + 1)``: assume that the transformation is
              specified using homogeneous coordinates [1]_. In this case, any
              value passed to ``offset`` is ignored.
            - ``(ndim, ndim + 1)``: as above, but the bottom row of a
              homogeneous transformation matrix is always ``[0, 0, ..., 1]``,
              and may be omitted.

    offset : float or sequence, optional
        The offset into the array where the transform is applied. If a float,
        `offset` is the same for each axis. If a sequence, `offset` should
        contain one value for each axis.
    output_shape : tuple of ints, optional
        Shape tuple.
    %(output)s
    order : int, optional
        The order of the spline interpolation, default is 3.
        The order has to be in the range 0-5.
    %(mode_interp_constant)s
    %(cval)s
    %(prefilter)s

    Returns
    -------
    affine_transform : ndarray
        The transformed input.

    Notes
    -----
    The given matrix and offset are used to find for each point in the
    output the corresponding coordinates in the input by an affine
    transformation. The value of the input at those coordinates is
    determined by spline interpolation of the requested order. Points
    outside the boundaries of the input are filled according to the given
    mode.

    .. versionchanged:: 0.18.0
        Previously, the exact interpretation of the affine transformation
        depended on whether the matrix was supplied as a 1-D or a
        2-D array. If a 1-D array was supplied
        to the matrix parameter, the output pixel value at index ``o``
        was determined from the input image at position
        ``matrix * (o + offset)``.

    For complex-valued `input`, this function transforms the real and imaginary
    components independently.

    .. versionadded:: 1.6.0
        Complex-valued support added.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Homogeneous_coordinates
    r   r   r   Nr   r6   r7   )offsetr:   r"   r%   r9   r=   r)   Zdtype)r   r(   z no proper affine matrix providedr(   zoExpected homogeneous transformation matrix with shape {} for image shape {}, but bottom row was not equal to {}z&affine matrix has wrong number of rowsz)affine matrix has wrong number of columnszno proper offset providedzpThe behavior of affine_transform with a 1-D array supplied for the matrix parameter has changed in SciPy 0.18.0.
stacklevelF)r   r   r   
isinstanceZndarrayr8   r    r>   r   r   r   r?   r   r   r   r4   r	   r@   r   allformat
ValueErrorflags
contiguouscopy_normalize_sequencewarningswarnr   
zoom_shiftr
   )r!   matrixrG   r:   r$   r"   r%   r1   r9   r   rB   r3   r2   rC   Zexptdmsgr&   r&   r'   r     s    U




"


r   c                 C   sR  |dk s|dkrt dt| } | jdk r4t dt| }tj|| |d}|rddlm} t	|||d}	|| j
|f|j
t
|d	|	 || j|f|jt|d	|	 |S |r|dkrt| ||\}
}t|
|tj|d
}nd}| }t|}t|| j}dd |D }tj|tjd}|jjs4| }t|d||||||d	 |S )a  
    Shift an array.

    The array is shifted using spline interpolation of the requested order.
    Points outside the boundaries of the input are filled according to the
    given mode.

    Parameters
    ----------
    %(input)s
    shift : float or sequence
        The shift along the axes. If a float, `shift` is the same for each
        axis. If a sequence, `shift` should contain one value for each axis.
    %(output)s
    order : int, optional
        The order of the spline interpolation, default is 3.
        The order has to be in the range 0-5.
    %(mode_interp_constant)s
    %(cval)s
    %(prefilter)s

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

    See Also
    --------
    affine_transform : Affine transformations

    Notes
    -----
    For complex-valued `input`, this function shifts the real and imaginary
    components independently.

    .. versionadded:: 1.6.0
        Complex-valued support added.

    Examples
    --------
    Import the necessary modules and an exemplary image.

    >>> from scipy.ndimage import shift
    >>> import matplotlib.pyplot as plt
    >>> from scipy import datasets
    >>> image = datasets.ascent()

    Shift the image vertically by 20 pixels.

    >>> image_shifted_vertically = shift(image, (20, 0))

    Shift the image vertically by -200 pixels and horizontally by 100 pixels.

    >>> image_shifted_both_directions = shift(image, (-200, 100))

    Plot the original and the shifted images.

    >>> fig, axes = plt.subplots(3, 1, figsize=(4, 12))
    >>> plt.gray()  # show the filtered result in grayscale
    >>> top, middle, bottom = axes
    >>> for ax in axes:
    ...     ax.set_axis_off()  # remove coordinate system
    >>> top.imshow(image)
    >>> top.set_title("Original image")
    >>> middle.imshow(image_shifted_vertically)
    >>> middle.set_title("Vertically shifted image")
    >>> bottom.imshow(image_shifted_both_directions)
    >>> bottom.set_title("Image shifted in both directions")
    >>> fig.tight_layout()
    r   r   r   r   r6   r   )r   rD   r=   r)   c                 S   s   g | ]
}| qS r&   r&   ).0iir&   r&   r'   
<listcomp>      zshift.<locals>.<listcomp>rH   NF)r   r   r   r    r   r   r   scipy.ndimage._interpolationr   r?   r   r   r4   r	   r@   r   rR   rO   rP   rQ   r   rU   )r!   r   r$   r"   r%   r1   r9   r   Z_shiftrB   r3   r2   rC   r&   r&   r'   r   z  sH    I





r   F)	grid_modec                C   s  |dk s|dkrt dt| } | jdk r4t dt|| j}tdd t| j|D }t	| }	tj
|| ||	d}|	rdd	lm}
 t|||d
}|
| j|f|jt|d| |
| j|f|jt|d| |S |r|dkrt| ||\}}t||tj|d}nd}| }|rbd}|dkr4d}n|dkrBd}|durbtjd||dd t|}t|}t| j}|s|d8 }|d8 }tj||tj| jtjd|dkd}t|}t||d||||||	 |S )a  
    Zoom an array.

    The array is zoomed using spline interpolation of the requested order.

    Parameters
    ----------
    %(input)s
    zoom : float or sequence
        The zoom factor along the axes. If a float, `zoom` is the same for each
        axis. If a sequence, `zoom` should contain one value for each axis.
    %(output)s
    order : int, optional
        The order of the spline interpolation, default is 3.
        The order has to be in the range 0-5.
    %(mode_interp_constant)s
    %(cval)s
    %(prefilter)s
    grid_mode : bool, optional
        If False, the distance from the pixel centers is zoomed. Otherwise, the
        distance including the full pixel extent is used. For example, a 1d
        signal of length 5 is considered to have length 4 when `grid_mode` is
        False, but length 5 when `grid_mode` is True. See the following
        visual illustration:

        .. code-block:: text

                | pixel 1 | pixel 2 | pixel 3 | pixel 4 | pixel 5 |
                     |<-------------------------------------->|
                                        vs.
                |<----------------------------------------------->|

        The starting point of the arrow in the diagram above corresponds to
        coordinate location 0 in each mode.

    Returns
    -------
    zoom : ndarray
        The zoomed input.

    Notes
    -----
    For complex-valued `input`, this function zooms the real and imaginary
    components independently.

    .. versionadded:: 1.6.0
        Complex-valued support added.

    Examples
    --------
    >>> from scipy import ndimage, datasets
    >>> import matplotlib.pyplot as plt

    >>> fig = plt.figure()
    >>> ax1 = fig.add_subplot(121)  # left side
    >>> ax2 = fig.add_subplot(122)  # right side
    >>> ascent = datasets.ascent()
    >>> result = ndimage.zoom(ascent, 3.0)
    >>> ax1.imshow(ascent, vmin=0, vmax=255)
    >>> ax2.imshow(result, vmin=0, vmax=255)
    >>> plt.show()

    >>> print(ascent.shape)
    (512, 512)

    >>> print(result.shape)
    (1536, 1536)
    r   r   r   r   r6   c                 S   s    g | ]\}}t t|| qS r&   )intround)rX   rY   Zjjr&   r&   r'   rZ   5  r[   zzoom.<locals>.<listcomp>r7   )r   rD   r=   r)   Nr.   r,   wrapz	grid-wrapzHIt is recommended to use mode = {} instead of {} when grid_mode is True.r(   rI   rH   )outwhere)r   r   r   r    r   rR   tuplezipr8   r   r   r\   r   r?   r   r   r4   r	   r@   rS   rT   rM   r   r   divideZ	ones_likeZascontiguousarrayr   rU   )r!   r   r$   r"   r%   r1   r9   r]   r:   r   Z_zoomrB   r3   r2   rC   Zsuggest_modeZzoom_divZzoom_nominatorr&   r&   r'   r     st    G










r   r   r   c	                    s2  t | }	|	j}
|
dk r tdt  t dkr<tdtdd  D sVtd d dk rr d  |
7  <  d dk r d  |
7  <  d dk s d dk s d |
ks d |
krtd	   t	|t
| }}t ||g| |gg}t |	j  }|rT|\}}|dd||gd|d|gg }t j|dd
d t}n  }||d d  }|d d }|| }}|| < t|}t |	}tj||	||d}|
dkrt|	||||||||	 nZtj fddt|
D  }t|}|D ].}|	| }|| }t|||||||||	 q|S )a  
    Rotate an array.

    The array is rotated in the plane defined by the two axes given by the
    `axes` parameter using spline interpolation of the requested order.

    Parameters
    ----------
    %(input)s
    angle : float
        The rotation angle in degrees.
    axes : tuple of 2 ints, optional
        The two axes that define the plane of rotation. Default is the first
        two axes.
    reshape : bool, optional
        If `reshape` is true, the output shape is adapted so that the input
        array is contained completely in the output. Default is True.
    %(output)s
    order : int, optional
        The order of the spline interpolation, default is 3.
        The order has to be in the range 0-5.
    %(mode_interp_constant)s
    %(cval)s
    %(prefilter)s

    Returns
    -------
    rotate : ndarray
        The rotated input.

    Notes
    -----
    For complex-valued `input`, this function rotates the real and imaginary
    components independently.

    .. versionadded:: 1.6.0
        Complex-valued support added.

    Examples
    --------
    >>> from scipy import ndimage, datasets
    >>> import matplotlib.pyplot as plt
    >>> fig = plt.figure(figsize=(10, 3))
    >>> ax1, ax2, ax3 = fig.subplots(1, 3)
    >>> img = datasets.ascent()
    >>> img_45 = ndimage.rotate(img, 45, reshape=False)
    >>> full_img_45 = ndimage.rotate(img, 45, reshape=True)
    >>> ax1.imshow(img, cmap='gray')
    >>> ax1.set_axis_off()
    >>> ax2.imshow(img_45, cmap='gray')
    >>> ax2.set_axis_off()
    >>> ax3.imshow(full_img_45, cmap='gray')
    >>> ax3.set_axis_off()
    >>> fig.set_layout_engine('tight')
    >>> plt.show()
    >>> print(img.shape)
    (512, 512)
    >>> print(img_45.shape)
    (512, 512)
    >>> print(full_img_45.shape)
    (724, 724)

    r(   z!input array should be at least 2Dz&axes should contain exactly two valuesc                 S   s   g | ]}t | qS r&   )float
is_integerrX   axr&   r&   r'   rZ     r[   zrotate.<locals>.<listcomp>z'axes should contain only integer valuesr   r   z invalid rotation plane specified)r#   g      ?r7   c                    s*   g | ]"}| v rt d gn
t| qS )N)slicer*   ri   axesZ	img_shaper&   r'   rZ     s   )r   r   r    rN   listr>   rL   sortr   ZcosdgZsindgr   r8   ZptpZastyper^   rc   r   r   r   r   	itertoolsproductr*   )r!   Zanglerm   Zreshaper$   r"   r%   r1   r9   Z	input_arrr    csZ
rot_matrixZin_plane_shapeZiyZixZ
out_boundsZout_plane_shapeZ
out_centerZ	in_centerrG   r:   r   Zplanes_coordrF   iaZoar&   rl   r'   r   j  sp    B
0






r   )Nr   r.   r5   T)r5   NNr   r.   r5   T)Nr   r.   r5   T)Nr   r.   r5   T)rf   TNr   r.   r5   T)rp   rS   r   Zscipy._lib._utilr   Zscipyr    r   r   Z_ni_docstringsr   __all__r@   r   r	   r4   r
   r   r   r   r   r   r&   r&   r&   r'   <module>   s^   WK   i      l     