o
    jk                     @   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 ]}td|D ]}t	|| | ||< q;|jdd||< q4|jdd||< |S )a  Compute the 2-dimensional finite Radon transform (FRT) for the input array.

    Parameters
    ----------
    a : ndarray of int, shape (M, M)
        Input array.

    Returns
    -------
    FRT : ndarray of int, shape (M+1, M)
        Finite Radon Transform array of coefficients.

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

    Notes
    -----
    The FRT has a unique inverse if and only if M 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   i/var/www/html/Deteccion_Ine/venv/lib/python3.10/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	|| |||< qB|jdd||< q8|| d t
 j7 }||d   | }|S )aF  Compute the 2-dimensional inverse finite Radon transform (iFRT) for the input array.

    Parameters
    ----------
    a : ndarray of int, shape (M+1, M)
        Input array.

    Returns
    -------
    iFRT : ndarray of int, shape (M, M)
        Inverse Finite Radon Transform coefficients.

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

    Notes
    -----
    The FRT has a unique inverse if and only if M 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   F   s   "0
)__doc____all__numpyr   r   r   r   r   r   r   r   r   <module>   s    :