o
    eC                    @   s:  d Z ddlmZmZmZ ddlmZ ddlZ	ddl
Z
ddlZddlZ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 dd
lmZ ddlmZ ddlmZ dZ dd Z!dyddZ"dyddZ#dd Z$dd Z%dzddZ&dzddZ'dzddZ(dzd d!Z)d{d"d#Z*d$d% Z+d&d' Z,d(d) Z-d*d+ Z.d,d- Z/d.d/ Z0d0d1 Z1d2d3 Z2d4d5 Z3d6d7 Z4d8d9 Z5d:d; Z6d<d= Z7d>d? Z8d@dA Z9dBdC Z:dDdE Z;dFdG Z<	H				Id|dJdKZ=	H					Ld}dMdNZ>G dOdP dPej?Z@G dQdR dRejAZAG dSdT dTejBZCG dUdV dVejDZEG dWdX dXejBZFG dYdZ dZeFZGG d[d\ d\eFZHG d]d^ d^eFZIG d_d` d`eFZJG dadb dbejBZKG dcdd ddeKZLG dedf dfeKZMG dgdh dheKZNG didj djeKZOG dkdl dleKZPG dmdn dneKZQG dodp dpeKZRG dqdr dreKZSG dsdt dteKZTG dudv dveKZUG dwdx dxejVZVdS )~a  
Augmenters that have identical outputs to well-known PIL functions.

The ``like`` in ``pillike`` indicates that the augmenters in this module
have identical outputs and mostly identical inputs to corresponding PIL
functions, but do not *have to* wrap these functions internally. They may
use internally different (e.g. faster) techniques to produce these outputs.

Some of the augmenters in this module may also exist in other modules
under similar name. These other augmenters may currently have the same
outputs as the corresponding PIL functions, but that is not guaranteed
for the future. Use the augmenters in this module if identical outputs
to PIL are required.

List of augmenters:

    * :class:`Solarize`
    * :class:`Posterize`
    * :class:`Equalize`
    * :class:`Autocontrast`
    * :class:`EnhanceColor`
    * :class:`EnhanceContrast`
    * :class:`EnhanceBrightness`
    * :class:`EnhanceSharpness`
    * :class:`FilterBlur`
    * :class:`FilterSmooth`
    * :class:`FilterSmoothMore`
    * :class:`FilterEdgeEnhance`
    * :class:`FilterEdgeEnhanceMore`
    * :class:`FilterFindEdges`
    * :class:`FilterContour`
    * :class:`FilterEmboss`
    * :class:`FilterSharpen`
    * :class:`FilterDetail`
    * :class:`Affine`

Standard usage of these augmenters follows roughly the schema::

    import numpy as np
    import imgaug.augmenters as iaa

    aug = iaa.pillike.Affine(translate_px={"x": (-5, 5)})
    image = np.full((32, 32, 3), 255, dtype=np.uint8)

    images_aug = aug(images=[image, image, image])

Added in 0.4.0.

    )print_functiondivisionabsolute_importN)_normalize_cv2_input_arr_   )meta)
arithmetic)color)contrast)	geometric)size   )
parametersi   c                 C   sn   | j dko| jd dk}|r| d d d d df } | j dks3| j dkr*| jd dv s3J d|| jf | |fS )N   r   r   r   )r      zaCan apply %s only to images of shape (H, W) or (H, W, 1) or (H, W, 3) or (H, W, 4). Got shape %s.)ndimshape)image	func_nameis_hw1 r   ID:\Projects\ConvertPro\env\Lib\site-packages\imgaug/augmenters/pillike.py_ensure_valid_shapeO   s   
r      c                 C      t j| |dS )a  Invert all array components above a threshold in-place.

    This function has identical outputs to ``PIL.ImageOps.solarize``.
    It does however work in-place.

    Added in 0.4.0.

    **Supported dtypes**:

    See ``~imgaug.augmenters.arithmetic.invert_(min_value=None and max_value=None)``.

    Parameters
    ----------
    image : ndarray
        Image array of shape ``(H,W,[C])``.
        The array *might* be modified in-place.

    threshold : int, optional
        A threshold to use in order to invert only numbers above or below
        the threshold.

    Returns
    -------
    ndarray
        Inverted image.
        This *can* be the same array as input in `image`, modified in-place.

    	threshold)r   Zinvert_r   r   r   r   r   	solarize_]   s   r   c                 C   r   )a  Invert all array components above a threshold.

    This function has identical outputs to ``PIL.ImageOps.solarize``.

    Added in 0.4.0.

    **Supported dtypes**:

    See ``~imgaug.augmenters.arithmetic.invert_(min_value=None and max_value=None)``.

    Parameters
    ----------
    image : ndarray
        Image array of shape ``(H,W,[C])``.

    threshold : int, optional
        A threshold to use in order to invert only numbers above or below
        the threshold.

    Returns
    -------
    ndarray
        Inverted image.

    r   )r   invertr   r   r   r   solarize}   s   r!   c                 C      t | |S )a  Reduce the number of bits for each color channel in-place.

    This function has identical outputs to ``PIL.ImageOps.posterize``.
    It does however work in-place.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.color.quantize_uniform_to_n_bits_`.

    Parameters
    ----------
    image : ndarray
        Image array of shape ``(H,W,[C])``.

    bits : int
        The number of bits to keep per component.
        Values in the interval ``[1, 8]`` are valid.

    Returns
    -------
    ndarray
        Posterized image.
        This *can* be the same array as input in `image`, modified in-place.

    colorlib	posterizer   bitsr   r   r   
posterize_   s   r(   c                 C   r"   )a
  Reduce the number of bits for each color channel.

    This function has identical outputs to ``PIL.ImageOps.posterize``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.color.quantize_uniform_to_n_bits`.

    Parameters
    ----------
    image : ndarray
        Image array of shape ``(H,W,[C])``.

    bits : int
        The number of bits to keep per component.
        Values in the interval ``[1, 8]`` are valid.

    Returns
    -------
    ndarray
        Posterized image.

    r#   r&   r   r   r   r%      s   r%   c                 C   s4   | j }|dkrt| S |tkrt| } t| |S )a^  Equalize the image histogram.

    See :func:`~imgaug.augmenters.pillike.equalize_` for details.

    This function is identical in inputs and outputs to
    ``PIL.ImageOps.equalize``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.equalize_`.

    Parameters
    ----------
    image : ndarray
        ``uint8`` ``(H,W,[C])`` image to equalize.

    mask : None or ndarray, optional
        An optional mask. If given, only the pixels selected by the mask are
        included in the analysis.

    Returns
    -------
    ndarray
        Equalized image.

    r   )r   npcopy_EQUALIZE_USE_PIL_BELOW	equalize_)r   maskr   r   r   r   equalize   s   


r.   c                    s    j dkrdn jd }|dvr# fddt|D }tj|ddS  jjdks2J d	 jjf |d
urR|j dksCJ d|jf |jjdksRJ d|jjf  j}|dkr[ S |dkrh|tk rht	 |S t
 |S )a  Equalize the image histogram in-place.

    This function applies a non-linear mapping to the input image, in order
    to create a uniform distribution of grayscale values in the output image.

    This function has identical outputs to ``PIL.ImageOps.equalize``.
    It does however work in-place.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        ``uint8`` ``(H,W,[C])`` image to equalize.

    mask : None or ndarray, optional
        An optional mask. If given, only the pixels selected by the mask are
        included in the analysis.

    Returns
    -------
    ndarray
        Equalized image. *Might* have been modified in-place.

    r   r   r   )r   r   c                    s&   g | ]}t  d d d d |f qS N)r,   ).0cr   r   r   
<listcomp>(  s    zequalize_.<locals>.<listcomp>)Zaxisuint8z,Expected image of dtype uint8, got dtype %s.Nz*Expected 2-dimensional mask, got shape %s.z+Expected mask of dtype uint8, got dtype %s.r   r   )r   r   r)   arangestackdtypenamer   r+   _equalize_pil__equalize_no_pil_)r   r-   nb_channelsresultr   r   r2   r   r,      s,   *



r,   c           
   	   C   s  | j dkrdn| jd }tjdd|ftjd}t|D ]}| j dkr/| d d d d tjf }n| d d d d ||d f }tt	|gdg|dgddg}t
| d dkritdtj|dd d |f< qt|d d d }|stdtj|dd d |f< q|d }t|}	||dd|f< ||	dd  |ddd |f< |dd d |f  t|  < qtj|d d|dtj}t| |} | S )	Nr   r   r      r7   r      )out)r   r   r)   emptyint32rangenewaxiscv2calcHistr   lennonzeror5   astypesumcumsumintclipr4   iaZ
apply_lut_)
r   r-   r;   lutc_idximage_cZhistostepnrK   r   r   r   r:   ?  s0   
  
 r:   c                 C   s@   |d urt j|d}tt jjt j| |d| d< | S )NL)r-   .)PILImage	fromarrayconvertr)   ZasarrayImageOpsr.   )r   r-   r   r   r   r9   _  s   
r9   c                 C   sj   | j jdksJ d| j jf d| jv rt| S | jdkp$| jd dk}|r/|r/t| ||S t| ||S )a  Maximize (normalize) image contrast.

    This function calculates a histogram of the input image, removes
    **cutoff** percent of the lightest and darkest pixels from the histogram,
    and remaps the image so that the darkest pixel becomes black (``0``), and
    the lightest becomes white (``255``).

    This function has identical outputs to ``PIL.ImageOps.autocontrast``.
    The speed is almost identical.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image for which to enhance the contrast.

    cutoff : number
        How many percent to cut off at the low and high end of the
        histogram. E.g. ``20`` will cut off the lowest and highest ``20%``
        of values. Expected value range is ``[0, 100]``.

    ignore : None or int or iterable of int
        Intensity values to ignore, i.e. to treat as background. If ``None``,
        no pixels will be ignored. Otherwise exactly the given intensity
        value(s) will be ignored.

    Returns
    -------
    ndarray
        Contrast-enhanced image.

    r4   z:Can apply autocontrast only to uint8 images, got dtype %s.r   r   r   )r7   r8   r   r)   r*   r   _autocontrast_pil_autocontrast_no_pil)r   cutoffignoreZstandard_channelsr   r   r   autocontrastm  s   2

r^   c                 C   s    t tjjtj| ||dS )N)r\   r]   )r)   arrayrU   rY   r^   rV   rW   )r   r\   r]   r   r   r   rZ     s   
rZ   c              	   C   s  |d urt |s|g}t| }|jdkr|dtjf }| jdkr'| jd nd}t|D ]}| jdkrC| d d d d tjf }n| d d d d ||d f }t	
t|gdgd dgddg}|d urjd||< |rt|}|d }	|	| d }
|
| }t|d	kd }t|dkrd
}n|d }|dkrd|d |< || ||< t|d d d }||
 }t|d	kd }t|dkrd}nd
|d  }d||d d < |dkr|d
|  ||< t|D ]\}}|r nqtd
ddD ]}|| r nq||krtd}n%d||  }| | }tdtj| | }t|dd
tj}|}tj|tjd}t ||}||d d d d ||d f< q.| jdkrS|d S |S )Nr   .r   r   r   r=   r   d           r?   g     o@r>   ).r   )rN   is_iterabler)   Z
empty_liker   rD   r   smxrangerE   rF   r   rK   rH   rG   	enumeraterC   r5   rI   float64rM   r4   r_   Z	apply_lut)r   r\   r]   r<   r;   rP   rQ   hcsrS   cutZlo_cutZ	lo_cut_nzloZcs_revZhi_cutZ	hi_cut_nzhiZlo_valrO   scaleoffsetZixZimage_c_augr   r   r   r[     sr   





 r[   c                 C   s|   | j jdksJ d| j jf d| jv rt| S t| d\} }t|tj	| 
|}|r<|d d d d tjf }|S )Nr4   zCCan apply PIL image enhancement only to uint8 images, got dtype %s.r   z%imgaug.augmenters.pillike.enhance_*())r7   r8   r   r)   r*   r   r_   rU   rV   rW   ZenhancerD   )r   clsfactorr   r<   r   r   r   _apply_enhance_func  s&   


rp   c                 C      t | tjj|S )as  Change the strength of colors in an image.

    This function has identical outputs to
    ``PIL.ImageEnhance.Color``.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    factor : number
        Colorfulness of the output image. Values close to ``0.0`` lead
        to grayscale images, values above ``1.0`` increase the strength of
        colors. Sane values are roughly in ``[0.0, 3.0]``.

    Returns
    -------
    ndarray
        Color-modified image.

    )rp   rU   ImageEnhanceColorr   ro   r   r   r   enhance_color-     (ru   c                 C   rq   )a  Change the contrast of an image.

    This function has identical outputs to
    ``PIL.ImageEnhance.Contrast``.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    factor : number
        Strength of contrast in the image. Values below ``1.0`` decrease the
        contrast, leading to a gray image around ``0.0``. Values
        above ``1.0`` increase the contrast. Sane values are roughly in
        ``[0.5, 1.5]``.

    Returns
    -------
    ndarray
        Contrast-modified image.

    )rp   rU   rr   ZContrastrt   r   r   r   enhance_contrastX  s   )rw   c                 C   rq   )a  Change the brightness of images.

    This function has identical outputs to
    ``PIL.ImageEnhance.Brightness``.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    factor : number
        Brightness of the image. Values below ``1.0`` decrease the brightness,
        leading to a black image around ``0.0``. Values above ``1.0`` increase
        the brightness. Sane values are roughly in ``[0.5, 1.5]``.

    Returns
    -------
    ndarray
        Brightness-modified image.

    )rp   rU   rr   Z
Brightnessrt   r   r   r   enhance_brightness  rv   rx   c                 C   rq   )aO  Change the sharpness of an image.

    This function has identical outputs to
    ``PIL.ImageEnhance.Sharpness``.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    factor : number
        Sharpness of the image. Values below ``1.0`` decrease the sharpness,
        values above ``1.0`` increase it. Sane values are roughly in
        ``[0.0, 2.0]``.

    Returns
    -------
    ndarray
        Sharpness-modified image.

    )rp   rU   rr   Z	Sharpnessrt   r   r   r   enhance_sharpness  rv   ry   c                 C   s   | j jdksJ d| j jf d| jv rt| S t| d\} }tj| }|	|}t
|}|r>|d d d d tjf }|S )Nr4   z9Can apply PIL filters only to uint8 images, got dtype %s.r   z$imgaug.augmenters.pillike.filter_*())r7   r8   r   r)   r*   r   rU   rV   rW   filterr_   rD   )r   Zkernelr   	image_pilZimage_filteredr<   r   r   r   _filter_by_kernel  s    



r|   c                 C      t | tjjS )a  Apply a blur filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.BLUR`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Blurred image.

    )r|   rU   ImageFilterZBLURr2   r   r   r   filter_blur     "r   c                 C   r}   )a  Apply a smoothness filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.SMOOTH`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Smoothened image.

    )r|   rU   r~   ZSMOOTHr2   r   r   r   filter_smooth  r   r   c                 C   r}   )a  Apply a strong smoothness filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.SMOOTH_MORE`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Smoothened image.

    )r|   rU   r~   ZSMOOTH_MOREr2   r   r   r   filter_smooth_more;  r   r   c                 C   r}   )a  Apply an edge enhancement filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.EDGE_ENHANCE`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Image with enhanced edges.

    )r|   rU   r~   ZEDGE_ENHANCEr2   r   r   r   filter_edge_enhance`  r   r   c                 C   r}   )a  Apply a stronger edge enhancement filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.EDGE_ENHANCE_MORE``
    kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Smoothened image.

    )r|   rU   r~   ZEDGE_ENHANCE_MOREr2   r   r   r   filter_edge_enhance_more  s   #r   c                 C   r}   )a  Apply an edge detection filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.FIND_EDGES`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Image with detected edges.

    )r|   rU   r~   Z
FIND_EDGESr2   r   r   r   filter_find_edges  r   r   c                 C   r}   )a  Apply a contour filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.CONTOUR`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Image with pronounced contours.

    )r|   rU   r~   ZCONTOURr2   r   r   r   filter_contour  r   r   c                 C   r}   )a  Apply an emboss filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.EMBOSS`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Embossed image.

    )r|   rU   r~   ZEMBOSSr2   r   r   r   filter_emboss  r   r   c                 C   r}   )a  Apply a sharpening filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.SHARPEN`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Sharpened image.

    )r|   rU   r~   ZSHARPENr2   r   r   r   filter_sharpen  r   r   c                 C   r}   )a  Apply a detail enhancement filter kernel to the image.

    This is the same as using PIL's ``PIL.ImageFilter.DETAIL`` kernel.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify.

    Returns
    -------
    ndarray
        Image with enhanced details.

    )r|   rU   r~   ZDETAILr2   r   r   r   filter_detail?  r   r         ?r   r   c                 C   s  t | d} t |d}t|||g\}}	}
d| }tjddd|d  gddd|d  gg dgtjd}tj| ddgd|dgg dgtjd}tjdd|gdd|gg dgtjd}tjdt|	dgt|
ddgg dgtjd}tjt|t|dgt| t|dgg dgtjd}tjdd|d gdd|d gg dgtjd}tjg dg dg dgtjd}||||||fD ]}t||}qtj	
|}|S )	Ng-C6?r   r   r   )r   r   r   r>   )r   r   r   )r   r   r   )maxr)   Zdeg2radr_   float32tanhcossinmatmulZlinalginv)scale_xscale_ytranslate_x_pxtranslate_y_px
rotate_degshear_x_degshear_y_deg	center_pxZ
rotate_radZshear_x_radZshear_y_radZmatrix_centerizeZmatrix_scaleZmatrix_translateZmatrix_shearZmatrix_rotateZmatrix_decenterizematrixZother_matrixr   r   r   _create_affine_matrixg  s   

r         ?r   c
              
   C   s
  | j jdksJ d| j jf d| jv rt| S |dur|nd}t|r-ttt	|}t
| d\} }
tj| }| jdd \}}||	d  ||	d  f}t||||||||d}|ddddf j}t|j|jtjj||d	}|
r|ddddtjf }|S )
a  Apply an affine transformation to an image.

    This function has identical outputs to
    ``PIL.Image.transform`` with ``method=PIL.Image.AFFINE``.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        The image to modify. Expected to be ``uint8`` with shape ``(H,W)``
        or ``(H,W,C)`` with ``C`` being ``3`` or ``4``.

    scale_x : number, optional
        Affine scale factor along the x-axis, where ``1.0`` denotes an
        identity transform and ``2.0`` is a strong zoom-in effect.

    scale_y : number, optional
        Affine scale factor along the y-axis, where ``1.0`` denotes an
        identity transform and ``2.0`` is a strong zoom-in effect.

    translate_x_px : number, optional
        Affine translation along the x-axis in pixels.
        Positive values translate the image towards the right.

    translate_y_px : number, optional
        Affine translation along the y-axis in pixels.
        Positive values translate the image towards the bottom.

    rotate_deg : number, optional
        Affine rotation in degrees *around the top left* of the image.

    shear_x_deg : number, optional
        Affine shearing in degrees along the x-axis with center point
        being the top-left of the image.

    shear_y_deg : number, optional
        Affine shearing in degrees along the y-axis with center point
        being the top-left of the image.

    fillcolor : None or int or tuple of int, optional
        Color tuple or intensity value to use when filling up newly
        created pixels. ``None`` fills with zeros. ``int`` will only fill
        the ``0`` th channel with that intensity value and all other channels
        with ``0`` (this is the default behaviour of PIL, use a tuple to
        fill all channels).

    center : tuple of number, optional
        Center xy-coordinate of the affine transformation, given as *relative*
        values, i.e. ``(0.0, 0.0)`` sets the transformation center to the
        top-left image corner, ``(1.0, 0.0)`` sets it to the the top-right
        image corner and ``(0.5, 0.5)`` sets it to the image center.
        The transformation center is relevant e.g. for rotations ("rotate
        around this center point"). PIL uses the image top-left corner
        as the transformation center if no centerization is included in the
        affine transformation matrix.

    Returns
    -------
    ndarray
        Image after affine transformation.

    r4   zGCan apply PIL affine transformation only to uint8 images, got dtype %s.r   Nz'imgaug.augmenters.pillike.warp_affine()r   r   )r   r   r   r   r   r   r   r   )	fillcolor)r7   r8   r   r)   r*   rN   rb   tuplemaprL   r   rU   rV   rW   r   Zflatr_   Z	transformr   ZAFFINErD   )r   r   r   r   r   r   r   r   r   centerr   r{   heightwidthr   r   r<   r   r   r   warp_affine  sD   V


r   c                       (   e Zd ZdZ			d fdd	Z  ZS )	Solarizea]  Augmenter with identical outputs to PIL's ``solarize()`` function.

    This augmenter inverts all pixel values above a threshold.

    The outputs are identical to PIL's ``solarize()``.

    Added in 0.4.0.

    **Supported dtypes**:

    See ``~imgaug.augmenters.arithmetic.invert_(min_value=None and max_value=None)``.

    Parameters
    ----------
    p : float or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.arithmetic.Invert`.

    threshold : None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.arithmetic.Invert`.

    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.Solarize(0.5, threshold=(32, 128))

    Invert the colors in ``50`` percent of all images for pixels with a
    value between ``32`` and ``128`` or more. The threshold is sampled once
    per image. The thresholding operation happens per channel.

    r   r   N
deprecatedc                    s(   t t| j|dd d |d||||d
 d S )NFT)
pper_channelZ	min_valueZ	max_valuer   Zinvert_above_thresholdseedr8   random_statedeterministic)superr   __init__)selfr   r   r   r8   r   r   	__class__r   r   r   Z  s   

zSolarize.__init__)r   r   NNr   r   __name__
__module____qualname____doc__r   __classcell__r   r   r   r   r   )  s    0r   c                   @   s   e Zd ZdZdS )	Posterizea  Augmenter with identical outputs to PIL's ``posterize()`` function.

    This augmenter quantizes each array component to ``N`` bits.

    This class is currently an alias for
    :class:`~imgaug.augmenters.color.Posterize`, which again is an alias
    for :class:`~imgaug.augmenters.color.UniformColorQuantizationToNBits`,
    i.e. all three classes are right now guarantueed to have the same
    outputs as PIL's function.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.color.Posterize`.

    N)r   r   r   r   r   r   r   r   r   e  s    r   c                       s6   e Zd ZdZ		d
 fdd	Zdd Zdd	 Z  ZS )Equalizea  Equalize the image histogram.

    This augmenter has identical outputs to ``PIL.ImageOps.equalize``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.equalize_`.

    Parameters
    ----------
    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.pillike.Equalize()

    Equalize the histograms of all input images.

    Nr   c                    s   t t| j||||d d S Nr   r8   r   r   )r   r   r   r   r   r8   r   r   r   r   r   r     s   

zEqualize.__init__c                 C   s&   |j d ur|j D ]}t||d< q|S N.)imagesr,   r   batchr   parentshooksr   r   r   r   _augment_batch_  s   

zEqualize._augment_batch_c                 C      g S z=See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`.r   r   r   r   r   get_parameters     zEqualize.get_parametersNNr   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   y  s    (r   c                       r   )	Autocontrasta
  Adjust contrast by cutting off ``p%`` of lowest/highest histogram values.

    This augmenter has identical outputs to ``PIL.ImageOps.autocontrast``.

    See :func:`~imgaug.augmenters.pillike.autocontrast` for more details.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.autocontrast`.

    Parameters
    ----------
    cutoff : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Percentage of values to cut off from the low and high end of each
        image's histogram, before stretching it to ``[0, 255]``.

            * If ``int``: The value will be used for all images.
            * If ``tuple`` ``(a, b)``: A value will be uniformly sampled from
              the discrete interval ``[a..b]`` per image.
            * If ``list``: A random value will be sampled from the list
              per image.
            * If ``StochasticParameter``: A value will be sampled from that
              parameter per image.

    per_channel :  bool or float, optional
        Whether to use the same value for all channels (``False``) or to
        sample a new value for each channel (``True``). If this value is a
        float ``p``, then for ``p`` percent of all images `per_channel` will
        be treated as ``True``, otherwise as ``False``.

    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.pillike.Autocontrast()

    Modify the contrast of images by cutting off the ``0`` to ``20%`` lowest
    and highest values from the histogram, then stretching it to full length.

    >>> aug = iaa.pillike.Autocontrast((10, 20), per_channel=True)

    Modify the contrast of images by cutting off the ``10`` to ``20%`` lowest
    and highest values from the histogram, then stretching it to full length.
    The cutoff value is sampled per *channel* instead of per *image*.

    r      FNr   c           	         sF   t j|dddddg}t}tt| j|||dgg d||||d	 d S )Nr\   )r   1   TZvalue_rangeZtuple_to_uniformZlist_to_choicer4   )Zuint16Zuint32Zuint64Zint8Zint16rB   Zint64float16r   rf   r   r   rf   Zfloat96Zfloat128Zfloat256bool)Zdtypes_allowedZdtypes_disallowedr   r8   r   r   )iapZhandle_discrete_paramr^   r   r   r   )	r   r\   r   r   r8   r   r   Zparams1dfuncr   r   r   r     s   

zAutocontrast.__init__)r   FNNr   r   r   r   r   r   r   r     s    Cr   c                       s:   e Zd Z		d fdd	Zdd Zdd Zd	d
 Z  ZS )_EnhanceBaseNr   c                    s8   t t| j||||d || _tj|d|ddd| _d S )Nr   ro   Tr   )r   r   r   r   r   Zhandle_continuous_paramro   )r   r   ro   factor_value_ranger   r8   r   r   r   r   r   r     s   
z_EnhanceBase.__init__c                 C   sJ   |j d u r|S | t|j |}t|j |D ]\}}| |||d< q|S r   )r   _draw_samplesrG   zipr   )r   r   r   r   r   Zfactorsr   ro   r   r   r   r     s   
z_EnhanceBase._augment_batch_c                 C   s   | j j|f|dS )Nr   )ro   draw_samples)r   Znb_rowsr   r   r   r   r   )  s   z_EnhanceBase._draw_samplesc                 C   s   | j gS r   )ro   r   r   r   r   r   -  s   z_EnhanceBase.get_parametersr   )r   r   r   r   r   r   r   r   r   r   r   r   r     s    
r   c                       (   e Zd ZdZ			d fdd	Z  ZS )EnhanceColora  Convert images to grayscale.

    This augmenter has identical outputs to ``PIL.ImageEnhance.Color``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.enhance_color`.

    Parameters
    ----------
    factor : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Colorfulness of the output image. Values close to ``0.0`` lead
        to grayscale images, values above ``1.0`` increase the strength of
        colors. Sane values are roughly in ``[0.0, 3.0]``.

            * If ``number``: The value will be used for all images.
            * If ``tuple`` ``(a, b)``: A value will be uniformly sampled per
              image from the interval ``[a, b)``.
            * If ``list``: A random value will be picked from the list per
              image.
            * If ``StochasticParameter``: Per batch of size ``N``, the
              parameter will be queried once to return ``(N,)`` samples.

    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.pillike.EnhanceColor()

    Create an augmenter to remove a random fraction of color from
    input images.

    ra   g      @Nr   c              	      "   t t| jt|d||||d d S N)ra   N)r   ro   r   r   r8   r   r   )r   r   r   ru   r   ro   r   r8   r   r   r   r   r   r   h     

zEnhanceColor.__init__)r   NNr   r   r   r   r   r   r   r   2  s    5r   c                       r   )EnhanceContrastaM  Change the contrast of images.

    This augmenter has identical outputs to ``PIL.ImageEnhance.Contrast``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.enhance_contrast`.

    Parameters
    ----------
    factor : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Strength of contrast in the image. Values below ``1.0`` decrease the
        contrast, leading to a gray image around ``0.0``. Values
        above ``1.0`` increase the contrast. Sane values are roughly in
        ``[0.5, 1.5]``.

            * If ``number``: The value will be used for all images.
            * If ``tuple`` ``(a, b)``: A value will be uniformly sampled per
              image from the interval ``[a, b)``.
            * If ``list``: A random value will be picked from the list per
              image.
            * If ``StochasticParameter``: Per batch of size ``N``, the
              parameter will be queried once to return ``(N,)`` samples.

    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.pillike.EnhanceContrast()

    Create an augmenter that worsens the contrast of an image by a random
    factor.

    r   g      ?Nr   c              	      r   r   )r   r   r   rw   r   r   r   r   r     r   zEnhanceContrast.__init__r   NNr   r   r   r   r   r   r   r   s      6r   c                       r   )EnhanceBrightnessaN  Change the brightness of images.

    This augmenter has identical outputs to
    ``PIL.ImageEnhance.Brightness``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.enhance_brightness`.

    Parameters
    ----------
    factor : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Brightness of the image. Values below ``1.0`` decrease the brightness,
        leading to a black image around ``0.0``. Values above ``1.0`` increase
        the brightness. Sane values are roughly in ``[0.5, 1.5]``.

            * If ``number``: The value will be used for all images.
            * If ``tuple`` ``(a, b)``: A value will be uniformly sampled per
              image from the interval ``[a, b)``.
            * If ``list``: A random value will be picked from the list per
              image.
            * If ``StochasticParameter``: Per batch of size ``N``, the
              parameter will be queried once to return ``(N,)`` samples.

    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.pillike.EnhanceBrightness()

    Create an augmenter that worsens the brightness of an image by a random
    factor.

    r   Nr   c              	      r   r   )r   r   r   rx   r   r   r   r   r     r   zEnhanceBrightness.__init__r   r   r   r   r   r   r     r   r   c                       r   )EnhanceSharpnessa  Change the sharpness of images.

    This augmenter has identical outputs to
    ``PIL.ImageEnhance.Sharpness``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.enhance_sharpness`.

    Parameters
    ----------
    factor : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Sharpness of the image. Values below ``1.0`` decrease the sharpness,
        values above ``1.0`` increase it. Sane values are roughly in
        ``[0.0, 2.0]``.

            * If ``number``: The value will be used for all images.
            * If ``tuple`` ``(a, b)``: A value will be uniformly sampled per
              image from the interval ``[a, b)``.
            * If ``list``: A random value will be picked from the list per
              image.
            * If ``StochasticParameter``: Per batch of size ``N``, the
              parameter will be queried once to return ``(N,)`` samples.

    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.pillike.EnhanceSharpness()

    Create an augmenter that randomly decreases or increases the sharpness
    of an image.

    ra   g       @Nr   c              	      r   r   )r   r   r   ry   r   r   r   r   r   .  r   zEnhanceSharpness.__init__)r   NNr   r   r   r   r   r   r   r     r   r   c                       s2   e Zd Z		d	 fdd	Zdd Zdd Z  ZS )
_FilterBaseNr   c                    s"   t t| j||||d || _d S r   )r   r   r   r   )r   r   r   r8   r   r   r   r   r   r   <  s
   

z_FilterBase.__init__c                 C   s(   |j d ur|j D ]	}| ||d< q|S r   )r   r   r   r   r   r   r   E  s   

z_FilterBase._augment_batch_c                 C   r   r   r   r   r   r   r   r   L  r   z_FilterBase.get_parametersr   )r   r   r   r   r   r   r   r   r   r   r   r   :  s    	r   c                       &   e Zd ZdZ		d fdd	Z  ZS )
FilterBluraR  Apply a blur filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel ``PIL.ImageFilter.BLUR``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_blur`.

    Parameters
    ----------
    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.pillike.FilterBlur()

    Create an augmenter that applies a blur filter kernel to images.

    Nr   c                       t t| jt||||d d S N)r   r   r8   r   r   )r   r   r   r   r   r   r   r   r   z  
   

zFilterBlur.__init__r   r   r   r   r   r   r   Q  
    )r   c                       r   )FilterSmoothaf  Apply a smoothening filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel ``PIL.ImageFilter.SMOOTH``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_smooth`.

    Parameters
    ----------
    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.pillike.FilterSmooth()

    Create an augmenter that applies a smoothening filter kernel to images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r     r   zFilterSmooth.__init__r   r   r   r   r   r   r     r   r   c                       r   )FilterSmoothMorea  Apply a strong smoothening filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel ``PIL.ImageFilter.BLUR``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_smooth_more`.

    Parameters
    ----------
    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.pillike.FilterSmoothMore()

    Create an augmenter that applies a strong smoothening filter kernel to
    images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r     r   zFilterSmoothMore.__init__r   r   r   r   r   r   r     
    *r   c                       r   )FilterEdgeEnhancea  Apply an edge enhance filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel
    ``PIL.ImageFilter.EDGE_ENHANCE``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_edge_enhance`.

    Parameters
    ----------
    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.pillike.FilterEdgeEnhance()

    Create an augmenter that applies a edge enhancement filter kernel to
    images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r     r   zFilterEdgeEnhance.__init__r   r   r   r   r   r   r     
    +r   c                       r   )FilterEdgeEnhanceMorea  Apply a strong edge enhancement filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel
    ``PIL.ImageFilter.EDGE_ENHANCE_MORE``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_edge_enhance_more`.

    Parameters
    ----------
    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.pillike.FilterEdgeEnhanceMore()

    Create an augmenter that applies a strong edge enhancement filter kernel
    to images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r   G  r   zFilterEdgeEnhanceMore.__init__r   r   r   r   r   r   r     r   r   c                       r   )FilterFindEdgesau  Apply a edge detection kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel
    ``PIL.ImageFilter.FIND_EDGES``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_find_edges`.

    Parameters
    ----------
    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.pillike.FilterFindEdges()

    Create an augmenter that applies an edge detection filter kernel to images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r   z  r   zFilterFindEdges.__init__r   r   r   r   r   r   r   P  r   r   c                       r   )FilterContouray  Apply a contour detection filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel ``PIL.ImageFilter.CONTOUR``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_contour`.

    Parameters
    ----------
    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.pillike.FilterContour()

    Create an augmenter that applies a contour detection filter kernel to
    images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r     r   zFilterContour.__init__r   r   r   r   r   r   r     r   r   c                       r   )FilterEmbossa^  Apply an emboss filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel ``PIL.ImageFilter.EMBOSS``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_emboss`.

    Parameters
    ----------
    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.pillike.FilterEmboss()

    Create an augmenter that applies an emboss filter kernel to images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r     r   zFilterEmboss.__init__r   r   r   r   r   r   r     r   r   c                       r   )FilterSharpenag  Apply a sharpening filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel ``PIL.ImageFilter.SHARPEN``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_sharpen`.

    Parameters
    ----------
    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.pillike.FilterSharpen()

    Create an augmenter that applies a sharpening filter kernel to images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r   	  r   zFilterSharpen.__init__r   r   r   r   r   r   r     r   r   c                       r   )FilterDetailax  Apply a detail enhancement filter kernel to images.

    This augmenter has identical outputs to
    calling ``PIL.Image.filter`` with kernel ``PIL.ImageFilter.DETAIL``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.filter_detail`.

    Parameters
    ----------
    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.pillike.FilterDetail()

    Create an augmenter that applies a detail enhancement filter kernel to
    images.

    Nr   c                    r   r   )r   r   r   r   r   r   r   r   r   D	  r   zFilterDetail.__init__r   r   r   r   r   r   r   	  r   r   c                       sX   e Zd ZdZ				d fdd		Z fd
dZ		dddZ fddZdd Z  Z	S )Affinea  Apply PIL-like affine transformations to images.

    This augmenter has identical outputs to
    ``PIL.Image.transform`` with parameter ``method=PIL.Image.AFFINE``.

    .. warning::

        This augmenter can currently only transform image-data.
        Batches containing heatmaps, segmentation maps and
        coordinate-based augmentables will be rejected with an error.
        Use :class:`~imgaug.augmenters.geometric.Affine` if you have to
        transform such inputs.

    .. note::

        This augmenter uses the image center as the transformation center.
        This has to be explicitly enforced in PIL using corresponding
        translation matrices. Without such translation, PIL uses the image
        top left corner as the transformation center. To mirror that
        behaviour, use ``center=(0.0, 0.0)``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.pillike.warp_affine`.

    Parameters
    ----------
    scale : number or tuple of number or list of number or imgaug.parameters.StochasticParameter or dict {"x": number/tuple/list/StochasticParameter, "y": number/tuple/list/StochasticParameter}, optional
        See :class:`~imgaug.augmenters.geometric.Affine`.

    translate_percent : None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter or dict {"x": number/tuple/list/StochasticParameter, "y": number/tuple/list/StochasticParameter}, optional
        See :class:`~imgaug.augmenters.geometric.Affine`.

    translate_px : None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter or dict {"x": int/tuple/list/StochasticParameter, "y": int/tuple/list/StochasticParameter}, optional
        See :class:`~imgaug.augmenters.geometric.Affine`.

    rotate : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.geometric.Affine`.

    shear : number or tuple of number or list of number or imgaug.parameters.StochasticParameter or dict {"x": int/tuple/list/StochasticParameter, "y": int/tuple/list/StochasticParameter}, optional
        See :class:`~imgaug.augmenters.geometric.Affine`.

    fillcolor : number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional
        See parameter ``cval`` in :class:`~imgaug.augmenters.geometric.Affine`.

    center : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        The center point of the affine transformation, given as relative
        xy-coordinates.
        Set this to ``(0.0, 0.0)`` or ``left-top`` to use the top left image
        corner as the transformation center.
        Set this to ``(0.5, 0.5)`` or ``center-center`` to use the image
        center as the transformation center.
        See also paramerer ``position`` in
        :class:`~imgaug.augmenters.size.PadToFixedSize` for details
        about valid datatypes of this parameter.

    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.pillike.Affine(scale={"x": (0.8, 1.2), "y": (0.5, 1.5)})

    Create an augmenter that applies affine scaling (zoom in/out) to images.
    Along the x-axis they are scaled to 80-120% of their size, along
    the y-axis to 50-150% (both values randomly and uniformly chosen per
    image).

    >>> aug = iaa.pillike.Affine(translate_px={"x": 0, "y": [-10, 10]},
    >>>                          fillcolor=128)

    Create an augmenter that translates images along the y-axis by either
    ``-10px`` or ``10px``. Newly created pixels are always filled with
    the value ``128`` (along all channels).

    >>> aug = iaa.pillike.Affine(rotate=(-20, 20), fillcolor=(0, 256))

    Rotate an image by ``-20`` to ``20`` degress and fill up all newly
    created pixels with a random RGB color.

    See the similar augmenter :class:`~imgaug.augmenters.geometric.Affine`
    for more examples.

    r   Nra   r   r   r   c                    s<   t t| j|||||d|ddd||	|
|d t|| _d S )Nr   ZconstantFauto)rl   translate_percenttranslate_pxrotateshearordercvalmodeZ
fit_outputbackendr   r8   r   r   )r   r   r   sizelibZ_handle_position_parameterr   )r   rl   r   r   r   r   r   r   r   r8   r   r   r   r   r   r   	  s   
zAffine.__init__c                    sR   |  }t|dkst|dkrd|v sJ dd|f tt| ||||S )Nr   r   r   zpillike.Affine can currently only process image data. Got a batch containing: %s. Use imgaug.augmenters.geometric.Affine for batches containing non-image data.z, )Zget_column_namesrG   joinr   r   r   )r   r   r   r   r   colsr   r   r   r   	  s   "

zAffine._augment_batch_Fc           	      C   s   |du sJ dt |D ]B\}}|d u r|jn|| }|j|||d}t||d |d |d |d |d |d	 |d
 t|j| |j| |j| fd
|d< q|S )NFzWGot unexpectedly return_matrices=True. pillike.Affine does not yet produce that output.)Z	arr_shapeimage_shaper   r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   .)re   r   Zget_affine_parametersr   r   r  center_xcenter_y)	r   r   samplesZimage_shapesZreturn_matricesir   r  paramsr   r   r   _augment_images_by_samples	  s.   
z!Affine._augment_images_by_samplesc                    s   t t| ||}t| jtr$| jd j||d}| jd j||d}n| jj|df|d}|d d df }|d d df }||_||_|S )Nr   r   r   r   )	r   r   r   
isinstancer   r   r   r  r	  )r   Z
nb_samplesr   r
  xxyyZxyr   r   r   r   	  s$   zAffine._draw_samplesc                 C   s   | j | j| j| j| j| jgS r   )rl   	translater   r   r  r   r   r   r   r   r   

  s   zAffine.get_parameters)r   NNra   ra   r   r   NNr   r   )NF)
r   r   r   r   r   r   r  r   r   r   r   r   r   r   r   M	  s    g
r   )r   r/   )r   N)r   r   r   r   r   r   r   r   )	r   r   r   r   r   r   r   Nr   )Wr   
__future__r   r   r   Z	six.movesmovesrc   numpyr)   rE   Z	PIL.ImagerU   ZPIL.ImageOpsZPIL.ImageEnhanceZPIL.ImageFilterZimgaugrN   Zimgaug.imgaugr    r   r   r	   r$   r
   Zcontrastlibr   r   r  r   r   r+   r   r   r!   r(   r%   r.   r,   r:   r9   r^   rZ   r[   rp   ru   rw   rx   ry   r|   r   r   r   r   r   r   r   r   r   r   r   r   Invertr   r   Z	Augmenterr   Z_ContrastFuncWrapperr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    1

 

&
C
 
A[+,+,%%%%&%%%%(
B
 <=[!ABBC2234433223