o
    &j                     @   s   d Z ddlmZmZm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 	 	 h d	Zd
d Zdd Zdd Zdd Zdd Zdd ZG dd dejZG dd dejZdS )z
Augmenters that apply mirroring/flipping operations to images.

List of augmenters:

    * :class:`Fliplr`
    * :class:`Flipud`

    )print_functiondivisionabsolute_importN)_normalize_cv2_input_arr_   )meta   )
parameters>   Zint8Zint16Zuint8Zuint16c                 C   s   | j jtv r
t| S t| S )a  Flip an image-like array horizontally.

    **Supported dtypes**:

        * ``uint8``: yes; fully tested
        * ``uint16``: yes; fully tested
        * ``uint32``: yes; fully tested
        * ``uint64``: yes; fully tested
        * ``int8``: yes; fully tested
        * ``int16``: yes; fully tested
        * ``int32``: yes; fully tested
        * ``int64``: yes; fully tested
        * ``float16``: yes; fully tested
        * ``float32``: yes; fully tested
        * ``float64``: yes; fully tested
        * ``float128``: yes; fully tested
        * ``bool``: yes; fully tested

    Parameters
    ----------
    arr : ndarray
        A 2D/3D `(H, W, [C])` image array.

    Returns
    -------
    ndarray
        Horizontally flipped array.

    Examples
    --------
    >>> import numpy as np
    >>> import imgaug.augmenters.flip as flip
    >>> arr = np.arange(16).reshape((4, 4))
    >>> arr_flipped = flip.fliplr(arr)

    Create a ``4x4`` array and flip it horizontally.

    )Zdtypename_FLIPLR_DTYPES_CV2_fliplr_cv2_fliplr_slicedarr r   W/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/imgaug/augmenters/flip.pyfliplr  s   +r   c                 C   s   | d d d d ddf S )N.r   r   r   r   r   r     s   r   c                    s    j dkr
t S  jdkr- jd dkr- fddt jd D }tj|dd}n  j}|d s<t   j}|d	 sEt	  t
t d
}|jdkr^ jdkr^|dtjf S |S )Nr      r   i   c                    s$   g | ]}t t d |f dqS ).r   )cv2flipr   ).0cr   r   r   
<listcomp>  s    z_fliplr_cv2.<locals>.<listcomp>)ZaxisZOWNDATAZC_CONTIGUOUSr   r   .)sizenpcopyndimshapesmxrangestackflagsZascontiguousarrayr   r   r   Znewaxis)r   Zchannelsresultr"   r   r   r   r     s"   




r   c                 C   s   | ddddf S )a  Flip an image-like array vertically.

    **Supported dtypes**:

        * ``uint8``: yes; fully tested
        * ``uint16``: yes; fully tested
        * ``uint32``: yes; fully tested
        * ``uint64``: yes; fully tested
        * ``int8``: yes; fully tested
        * ``int16``: yes; fully tested
        * ``int32``: yes; fully tested
        * ``int64``: yes; fully tested
        * ``float16``: yes; fully tested
        * ``float32``: yes; fully tested
        * ``float64``: yes; fully tested
        * ``float128``: yes; fully tested
        * ``bool``: yes; fully tested

    Parameters
    ----------
    arr : ndarray
        A 2D/3D `(H, W, [C])` image array.

    Returns
    -------
    ndarray
        Vertically flipped array.

    Examples
    --------
    >>> import numpy as np
    >>> import imgaug.augmenters.flip as flip
    >>> arr = np.arange(16).reshape((4, 4))
    >>> arr_flipped = flip.flipud(arr)

    Create a ``4x4`` array and flip it vertically.

    Nr   .r   r   r   r   r   flipud  s   )r$   c                  O      t | i |S )zAlias for Fliplr.)Fliplrargskwargsr   r   r   HorizontalFlip(     r*   c                  O   r%   )zAlias for Flipud.)Flipudr'   r   r   r   VerticalFlip.  r+   r-   c                       8   e Zd ZdZ			d fdd	Zdd Zd	d
 Z  ZS )r&   a
  Flip/mirror input images horizontally.

    .. note::

        The default value for the probability is ``0.0``.
        So, to flip *all* input images use ``Fliplr(1.0)`` and *not* just
        ``Fliplr()``.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.flip.fliplr`.

    Parameters
    ----------
    p : number or imgaug.parameters.StochasticParameter, optional
        Probability of each image to get flipped.

    seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
        See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.

    name : None or str, optional
        See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.

    random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
        Old name for parameter `seed`.
        Its usage will not yet cause a deprecation warning,
        but it is still recommended to use `seed` now.
        Outdated since 0.4.0.

    deterministic : bool, optional
        Deprecated since 0.4.0.
        See method ``to_deterministic()`` for an alternative and for
        details about what the "deterministic mode" actually does.

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.Fliplr(0.5)

    Flip ``50`` percent of all images horizontally.


    >>> aug = iaa.Fliplr(1.0)

    Flip all images horizontally.

    r   N
deprecatedc                    *   t t| j||||d t|d| _d S N)seedr
   random_statedeterministicp)superr&   __init__iaphandle_probability_paramr5   selfr5   r2   r
   r3   r4   	__class__r   r   r7   e  
   
zFliplr.__init__c                 C   s  | j j|jf|d}t|D ]\}}|dkr|jd ur%t|j| |j|< |jd ur6t|j| j|j| _|jd urGt|j| j	|j| _	|j
d urd|j
| }|jd }	|j
D ]
}
|	t|
j |
_qY|jd ur|j| }|jd }	|jD ]}|j|j}}|	| |_|	| |_qv|jd ur|j| }|jd }	|jD ]}|	|jd d df  |jd d df< q|jd ur|j| }|jd }	|jD ]}|	|jd d df  |jd d df< qq|S )Nr3         ?r   r   )r5   draw_samplesnb_rows	enumerateimagesr   heatmapsarr_0to1segmentation_mapsr   	keypointsr   floatxbounding_boxesx1x2polygonsexteriorline_stringscoords)r;   batchr3   parentshookssamplesisamplekpsoiwidthkpbbsoibbrL   rM   psoipolylsoilsr   r   r   _augment_batch_n  sN   

















&



&zFliplr._augment_batch_c                 C      | j gS z=See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`.r5   r;   r   r   r   get_parameters     zFliplr.get_parametersr   NNr/   r/   __name__
__module____qualname____doc__r7   ra   rf   __classcell__r   r   r<   r   r&   4  s    0	1r&   c                       r.   )r,   a  Flip/mirror input images vertically.

    .. note::

        The default value for the probability is ``0.0``.
        So, to flip *all* input images use ``Flipud(1.0)`` and *not* just
        ``Flipud()``.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.flip.flipud`.

    Parameters
    ----------
    p : number or imgaug.parameters.StochasticParameter, optional
        Probability of each image to get flipped.

    seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
        See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.

    name : None or str, optional
        See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.

    random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
        Old name for parameter `seed`.
        Its usage will not yet cause a deprecation warning,
        but it is still recommended to use `seed` now.
        Outdated since 0.4.0.

    deterministic : bool, optional
        Deprecated since 0.4.0.
        See method ``to_deterministic()`` for an alternative and for
        details about what the "deterministic mode" actually does.

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.Flipud(0.5)

    Flip ``50`` percent of all images vertically.

    >>> aug = iaa.Flipud(1.0)

    Flip all images vertically.

    r   Nr/   c                    r0   r1   )r6   r,   r7   r8   r9   r5   r:   r<   r   r   r7     r>   zFlipud.__init__c                 C   s  | j j|jf|d}t|D ]\}}|dkr|jd ur*|j| d d ddf |j|< |jd ur@|j| jd d ddf |j| _|jd urV|j| jd d ddf |j| _|j	d urs|j	| }|j
d }	|j	D ]
}
|	t|
j |
_qh|jd ur|j| }|j
d }	|jD ]}|j|j}}|	| |_|	| |_q|jd ur|j| }|j
d }	|jD ]}|	|jd d df  |jd d df< q|jd ur|j| }|j
d }	|jD ]}|	|jd d df  |jd d df< qq|S )Nr?   r@   r   .r   r   )r5   rA   rB   rC   rD   rE   rF   rG   r   rH   r   rI   yrK   y1y2rN   rO   rP   rQ   )r;   rR   r3   rS   rT   rU   rV   rW   rX   heightrZ   r[   r\   rp   rq   r]   r^   r_   r`   r   r   r   ra     sJ   

















&



&zFlipud._augment_batch_c                 C   rb   rc   rd   re   r   r   r   rf     rg   zFlipud.get_parametersrh   ri   r   r   r<   r   r,     s    /	3r,   )rm   
__future__r   r   r   numpyr   r   Z	six.movesZmovesr   Zimgaug.imgaugr    r   r	   r8   r   r   r   r   r$   r*   r-   Z	Augmenterr&   r,   r   r   r   r   <module>   s.    	  I  I0!,q