U
    ?h                     @   s8   d Z ddgZddlZddlmZmZ dd Zdd ZdS )z2
:author: Gary Ruben, 2009
:license: modified BSD
frt2ifrt2    N)rollnewaxisc                 C   s   | j dks| jd | jd kr&td|  }|jd }t|d |ftj}|jdd|d< td|D ]8}td|D ]}t	|| | ||< qv|jdd||< qh|jdd||< |S )a  Compute the 2-dimensional finite radon transform (FRT) for an n x n
    integer array.

    Parameters
    ----------
    a : array_like
        A 2-D square n x n integer array.

    Returns
    -------
    FRT : 2-D ndarray
        Finite Radon Transform array of (n+1) x n integer coefficients.

    See Also
    --------
    ifrt2 : The two-dimensional inverse FRT.

    Notes
    -----
    The FRT has a unique inverse if and only if n is prime. [FRT]
    The idea for this algorithm is due to Vlad Negnevitski.

    Examples
    --------

    Generate a test image:
    Use a prime number for the array dimensions

    >>> SIZE = 59
    >>> img = np.tri(SIZE, dtype=np.int32)

    Apply the Finite Radon Transform:

    >>> f = frt2(img)

    References
    ----------
    .. [FRT] A. Kingston and I. Svalbe, "Projective transforms on periodic
             discrete image arrays," in P. Hawkes (Ed), Advances in Imaging
             and Electron Physics, 139 (2006)

       r      z!Input must be a square, 2-D arrayZaxis)
ndimshape
ValueErrorcopynpemptyuint32sumranger   aZainfmrow r   Z/var/www/html/venv/lib/python3.8/site-packages/skimage/transform/finite_radon_transform.pyr      s    +
c                 C   s   | j dks"| jd | jd d kr*td|  dd }|jd }t||ftj}|jdd|d< td|D ]<}td|jd D ]}t	|| |||< q|jdd||< qp|| d t
 j7 }||d   | }|S )aj  Compute the 2-dimensional inverse finite radon transform (iFRT) for
    an (n+1) x n integer array.

    Parameters
    ----------
    a : array_like
        A 2-D (n+1) row x n column integer array.

    Returns
    -------
    iFRT : 2-D n x n ndarray
        Inverse Finite Radon Transform array of n x n integer coefficients.

    See Also
    --------
    frt2 : The two-dimensional FRT

    Notes
    -----
    The FRT has a unique inverse if and only if n is prime.
    See [1]_ for an overview.
    The idea for this algorithm is due to Vlad Negnevitski.

    Examples
    --------

    >>> SIZE = 59
    >>> img = np.tri(SIZE, dtype=np.int32)

    Apply the Finite Radon Transform:

    >>> f = frt2(img)

    Apply the Inverse Finite Radon Transform to recover the input

    >>> fi = ifrt2(f)

    Check that it's identical to the original

    >>> assert len(np.nonzero(img-fi)[0]) == 0

    References
    ----------
    .. [1] A. Kingston and I. Svalbe, "Projective transforms on periodic
             discrete image arrays," in P. Hawkes (Ed), Advances in Imaging
             and Electron Physics, 139 (2006)

    r   r   r   z0Input must be an (n+1) row x n column, 2-D arrayNr   )r	   r
   r   r   r   r   r   r   r   r   r   Tr   r   r   r   r   G   s    1"
)__doc____all__numpyr   r   r   r   r   r   r   r   r   <module>   s
   ;