Ë
    \;j‹•  ã                   óà   — 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
„ Zd„ Zd„ Zd„ Zd„ Zd„ Z G d„ dej0                  «      Z G d„ dej0                  «      Zy)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>   Úint8Úint16Úuint8Úuint16c                 óf   — | 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.

    )ÚdtypeÚnameÚ_FLIPLR_DTYPES_CV2Ú_fliplr_cv2Ú_fliplr_sliced©Úarrs    ú_G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\imgaug/augmenters/flip.pyÚfliplrr   §  s,   € ðV ‡y�y‡~�~Ô+Ñ+Ü˜3ÓÐÜ˜#ÓÐó    c                 ó   — | d d …d d d…df   S )Néÿÿÿÿ.© r   s    r   r   r   ×  s   € ØŠq‘$�B�$˜ˆ|ÑÐr   c           
      ó¨  — | j                   dk(  rt        j                  | «      S | j                  dk(  r{| j                  d   dkD  rit        j                  | j                  d   «      D �cg c]&  }t        j                  t        | d|f   «      d«      ‘Œ( }}t        j                  |d¬«      }nk| j                  }|d   s!t        j                  | «      } | j                  }|d	   st        j                  | «      } t        j                  t        | «      d«      }|j                  d
k(  r$| j                  dk(  r|dt        j                  f   S |S c c}w )Nr   é   r   i   .r   )ÚaxisÚOWNDATAÚC_CONTIGUOUSr	   )ÚsizeÚnpÚcopyÚndimÚshapeÚsmÚxrangeÚcv2Úflipr   ÚstackÚflagsÚascontiguousarrayÚnewaxis)r   ÚcÚchannelsÚresultr,   s        r   r   r   Û  s&  € ð ‡x�x�1‚}Ü�w‰w�s‹|Ðð ‡x�x�1‚}˜Ÿ™ 2™¨Ò,ô
 �y‰y˜Ÿ™ 2™Ô'ó
ñ (ð ô �H‰HÔ.¨s°3¸°6©{Ó;¸QÕ?à'ð 	ð 
ô
 —‘˜(¨Ô,‰ð
 —	‘	ˆØ�YÒÜ—'‘'˜#“,ˆCØ—I‘IˆEØ�^Ò$Ü×&Ñ& sÓ+ˆCä—‘Ô3°CÓ8¸!Ó<ˆà‡{�{�aÒ˜CŸH™H¨šMØ�cœ2Ÿ:™:�oÑ&Ð&Ø€Mùò+
s   Á*+Ec                 ó   — | 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   s    r   Úflipudr3   ü  s   € ðR ‰t�ˆt�Sˆy‰>Ðr   c                  ó   — t        | i |¤ŽS )zAlias for Fliplr.)ÚFliplr©ÚargsÚkwargss     r   ÚHorizontalFlipr9   (  ó   € ô �4Ð"˜6Ñ"Ð"r   c                  ó   — t        | i |¤ŽS )zAlias for Flipud.)ÚFlipudr6   s     r   ÚVerticalFlipr=   .  r:   r   c                   ó6   ‡ — e Zd ZdZ	 	 	 dˆ fd„	Zd„ Zd„ Zˆ xZS )r5   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.

    c                 ój   •— t         t        | �  ||||¬«       t        j                  |d«      | _        y ©N)Úseedr   Úrandom_stateÚdeterministicÚp)Úsuperr5   Ú__init__ÚiapÚhandle_probability_paramrD   ©ÚselfrD   rA   r   rB   rC   Ú	__class__s         €r   rF   zFliplr.__init__e  ó:   ø€ ô 	Œf�dÑ$Ø˜DØ%°]ð 	%ô 	Dô ×-Ñ-¨a°Ó5ˆ�r   c                 óø  — | j                   j                  |j                  f|¬«      }t        |«      D �]B  \  }}|dk\  sŒ|j                  �%t        |j                  |   «      |j                  |<   |j                  �4t        |j                  |   j                  «      |j                  |   _        |j                  �4t        |j                  |   j                  «      |j                  |   _	        |j                  �L|j                  |   }|j                  d   }	|j                  D ]  }
|	t        |
j                  «      z
  |
_        Œ! |j                  �[|j                  |   }|j                  d   }	|j                  D ].  }|j                  |j                   }}|	|z
  |_        |	|z
  |_        Œ0 |j"                  �V|j"                  |   }|j                  d   }	|j"                  D ])  }|	|j$                  d d …df   z
  |j$                  d d …df<   Œ+ |j&                  €�Œí|j&                  |   }|j                  d   }	|j&                  D ])  }|	|j(                  d d …df   z
  |j(                  d d …df<   Œ+ �ŒE |S )N©rB   ç      à?r   r   )rD   Údraw_samplesÚnb_rowsÚ	enumerateÚimagesr   ÚheatmapsÚarr_0to1Úsegmentation_mapsr   Ú	keypointsr&   ÚfloatÚxÚbounding_boxesÚx1Úx2ÚpolygonsÚexteriorÚline_stringsÚcoords)rJ   ÚbatchrB   ÚparentsÚhooksÚsamplesÚiÚsampleÚkpsoiÚwidthÚkpÚbbsoiÚbbr[   r\   ÚpsoiÚpolyÚlsoiÚlss                      r   Ú_augment_batch_zFliplr._augment_batch_n  s@  € Ø—&‘&×%Ñ% u§}¡}Ð&6Ø3?ð &ó Aˆä" 7×+‰IˆAˆvØ˜‹}Ø—<‘<Ð+Ü&,¨U¯\©\¸!©_Ó&=�E—L‘L ‘Oà—>‘>Ð-Ü17ØŸ™ qÑ)×2Ñ2ó24�E—N‘N 1Ñ%Ô.ð ×*Ñ*Ð6Ü5;Ø×/Ñ/°Ñ2×6Ñ6ó68�E×+Ñ+¨AÑ.Ô2ð —?‘?Ð.Ø!ŸO™O¨AÑ.�EØ!ŸK™K¨™N�EØ#Ÿoœo˜Ø$¤u¨R¯T©T£{Ñ2˜�ð .ð ×'Ñ'Ð3Ø!×0Ñ0°Ñ3�EØ!ŸK™K¨™N�EØ#×2Ô2˜à!#§¡¨¯©˜B˜Ø %¨¡
˜œØ %¨¡
˜�ð	 3ð —>‘>Ð-Ø Ÿ>™>¨!Ñ,�DØ ŸJ™J q™M�EØ $§¤˜ð /4°d·m±mÂAÀqÀDÑ6IÑ.I˜Ÿ™¢a¨ dÒ+ð !.ð
 ×%Ñ%Ò1Ø ×-Ñ-¨aÑ0�DØ ŸJ™J q™M�EØ"×/Ô/˜ð +0°"·)±)ºA¸q¸D±/Ñ*A˜Ÿ	™	¢! Q $šò 0ðO ,ðX ˆr   c                 ó   — | j                   gS ©z=See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`.©rD   ©rJ   s    r   Úget_parameterszFliplr.get_parametersŸ  ó   € à—‘ˆxˆr   ©r   NNÚ
deprecatedrx   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__rF   rp   ru   Ú__classcell__©rK   s   @r   r5   r5   4  s$   ø„ ñ.ð` Ø!%Ø:Fõ6ò/öbr   r5   c                   ó6   ‡ — e Zd ZdZ	 	 	 dˆ fd„	Zd„ Zd„ Zˆ xZS )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.

    c                 ój   •— t         t        | �  ||||¬«       t        j                  |d«      | _        y r@   )rE   r<   rF   rG   rH   rD   rI   s         €r   rF   zFlipud.__init__Õ  rL   r   c                 óò  — | j                   j                  |j                  f|¬«      }t        |«      D �]?  \  }}|dk\  sŒ|j                  �$|j                  |   d d d…df   |j                  |<   |j
                  �3|j
                  |   j                  d d d…df   |j
                  |   _        |j                  �3|j                  |   j                  d d d…df   |j                  |   _        |j                  �L|j                  |   }|j                  d   }	|j                  D ]  }
|	t        |
j                  «      z
  |
_        Œ! |j                  �[|j                  |   }|j                  d   }	|j                  D ].  }|j                  |j                  }}|	|z
  |_        |	|z
  |_        Œ0 |j                   �V|j                   |   }|j                  d   }	|j                   D ])  }|	|j"                  d d …df   z
  |j"                  d d …df<   Œ+ |j$                  €�Œê|j$                  |   }|j                  d   }	|j$                  D ])  }|	|j&                  d d …df   z
  |j&                  d d …df<   Œ+ �ŒB |S )NrN   rO   r   .r   r   )rD   rP   rQ   rR   rS   rT   rU   rV   r   rW   r&   rX   ÚyrZ   Úy1Úy2r]   r^   r_   r`   )rJ   ra   rB   rb   rc   rd   re   rf   rg   Úheightri   rj   rk   r„   r…   rl   rm   rn   ro   s                      r   rp   zFlipud._augment_batch_Þ  sZ  € Ø—&‘&×%Ñ% u§}¡}Ð&6Ø3?ð &ó Aˆä" 7×+‰IˆAˆvØ˜‹}Ø—<‘<Ð+ð ',§l¡l°1¡o±d¸°d¸C°iÑ&@�E—L‘L ‘Oà—>‘>Ð-àŸ™ qÑ)×2Ñ2±4°R°4¸°9Ñ=ð —N‘N 1Ñ%Ô.ð ×*Ñ*Ð6à×/Ñ/°Ñ2×6Ñ6±t¸°t¸S°yÑAð ×+Ñ+¨AÑ.Ô2ð —?‘?Ð.Ø!ŸO™O¨AÑ.�EØ"Ÿ[™[¨™^�FØ#Ÿoœo˜Ø%¬¨b¯d©d«Ñ3˜�ð .ð ×'Ñ'Ð3Ø!×0Ñ0°Ñ3�EØ"Ÿ[™[¨™^�FØ#×2Ô2˜à!#§¡¨¯©˜B˜Ø &¨¡˜œØ &¨¡˜�ð	 3ð —>‘>Ð-Ø Ÿ>™>¨!Ñ,�DØ!ŸZ™Z¨™]�FØ $§¤˜ð /5°t·}±}ÂQÈÀTÑ7JÑ.J˜Ÿ™¢a¨ dÒ+ð !.ð
 ×%Ñ%Ò1Ø ×-Ñ-¨aÑ0�DØ!ŸZ™Z¨™]�FØ"×/Ô/˜ð +1°2·9±9ºQÀ¸T±?Ñ*B˜Ÿ	™	¢! Q $šò 0ðS ,ð\ ˆr   c                 ó   — | j                   gS rr   rs   rt   s    r   ru   zFlipud.get_parameters  rv   r   rw   ry   r   s   @r   r<   r<   ¥  s$   ø„ ñ-ð^ Ø!%Ø:Fõ6ò1öfr   r<   )r}   Ú
__future__r   r   r   Únumpyr#   r)   Ú	six.movesÚmovesr'   Úimgaug.imgaugr   Ú r   r
   rG   r   r   r   r   r3   r9   r=   Ú	Augmenterr5   r<   r   r   r   Ú<module>r�      s�   ðñ÷ AÑ @ã Û 
Ý å 3Ý Ý  ðEðN
DòN
 :Ð ò-ò`òòB)òX#ò#ômˆT�^‰^ô môbnˆT�^‰^õ nr   