o
    e                     @   sB  d Z ddlmZmZm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dZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Z	&	dd'd(Z 	&	dd)d*Z!d+d, Z"d-d. Z#d/d0 Z$		1dd2d3Z%		1dd4d5Z&d6d7 Z'd8d9 Z(d:d; Z)d<d= Z*d>d? Z+d@dA Z,dBdC Z-ddEdFZ.ddGdHZ/dIdJ Z0G dKdL dLej1Z2G dMdN dNej1Z3G dOdP dPe3Z4G dQdR dRe3Z5G dSdT dTe3Z6G dUdV dVej1Z7G dWdX dXej1Z8G dYdZ dZe9Z:G d[d\ d\ej1Z;G d]d^ d^e8Z<d_d` Z=G dadb dbe8Z>G dcdd ddej1Z?G dedf dfej1Z@G dgdh dhej1ZAG didj djeAZBG dkdl dleBZCG dmdn dneAZDG dodp dpeAZEG dqdr dreAZFG dsdt dteAZGG dudv dveAZHG dwdx dxej1ZIG dydz dze9ZJG d{d| d|eIZKe
Ld}	&			dddZMG dd dej1ZNdS )a  
Augmenters that perform simple arithmetic changes.

List of augmenters:

    * :class:`Add`
    * :class:`AddElementwise`
    * :class:`AdditiveGaussianNoise`
    * :class:`AdditiveLaplaceNoise`
    * :class:`AdditivePoissonNoise`
    * :class:`Multiply`
    * :class:`MultiplyElementwise`
    * :class:`Cutout`
    * :class:`Dropout`
    * :class:`CoarseDropout`
    * :class:`Dropout2d`
    * :class:`TotalDropout`
    * :class:`ReplaceElementwise`
    * :class:`ImpulseNoise`
    * :class:`SaltAndPepper`
    * :class:`CoarseSaltAndPepper`
    * :class:`Salt`
    * :class:`CoarseSalt`
    * :class:`Pepper`
    * :class:`CoarsePepper`
    * :class:`Invert`
    * :class:`Solarize`
    * :class:`ContrastNormalization`
    * :class:`JpegCompression`

    )print_functiondivisionabsolute_importN   )meta   )
parameters)dtypes)random)imgaug.augmenters.arithmetic_fill_rectangle_constant_)r   _fill_rectangle_gaussian_)constantZgaussianc                 C   N   | j dkr
t| S tj| g dg ddd | jjdkr"t| |S t| |S )a  Add a single scalar value or one scalar value per channel to an image.

    This method ensures that ``uint8`` does not overflow during the addition.

    **Supported dtypes**:

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

        - (1) Non-uint8 dtypes can overflow. For floats, this can result
              in +/-inf.

    Parameters
    ----------
    image : ndarray
        Image array of shape ``(H,W,[C])``.
        If `value` contains more than one value, the shape of the image is
        expected to be ``(H,W,C)``.

    value : number or ndarray
        The value to add to the image. Either a single value or an array
        containing exactly one component per channel, i.e. ``C`` components.

    Returns
    -------
    ndarray
        Image with value added to it.

    r   booluint8uint16int8int16float16float32uint32uint64uint128uint256int32int64int128int256float64float96float128float256NallowedZ
disallowedZ	augmenterr   )	sizenpcopyiadtgate_dtypesdtypename_add_scalar_to_uint8_add_scalar_to_non_uint8)imagevalue r2   LD:\Projects\ConvertPro\env\Lib\site-packages\imgaug/augmenters/arithmetic.py
add_scalar<   s   
)


r4   c                 C   s8  t |pt |pt |o|jdk}| }| jdkrdn| jd }tt	|dd
tj}tjddtjd}|r|jdksKJ d	|j|jf | jd
ksZJ d| j| jf | jd |jksnJ d| jd |jf t|d d tjf d|f|tjd d f  }n|| }t|dd
| j}t | |S )Nr   r      r      r,   zLExpected `value` to be 1-dimensional, got %d-dimensional data with shape %s.   znExpected `image` to be 3-dimensional when adding one value per channel, got %d-dimensional data with shape %s.zjExpected number of channels in `image` and number of components in `value` to be identical. Got %d vs. %d.)iais_single_numberis_np_scalaris_np_arrayr'   ndimshaper(   cliproundastyper   arangetilenewaxisr,   	apply_lut)r0   r1   is_single_valueis_channelwisenb_channelsvalue_rangetablesr2   r2   r3   r.   y   sH   


r.   c           	      C   s   | j }t|pt|pt|o|jdk}| }| jdkr!dn| jd }dd|r,|ndf}t	|
|}| j jd }t d|j j|f }tj||dd}tj| |g| j |gdd\} }tj| || dd	} t| |S )
Nr   r   r5   %s%dTvalidater	   Zincrease_itemsize_factornooutcasting)r,   r;   r<   r=   r>   r'   r?   r@   r(   arrayreshapeitemsizekindr*   clip_to_dtype_value_range_promote_array_dtypes_addrestore_dtypes_)	r0   r1   input_dtyperH   rI   rJ   r@   rW   dtype_targetr2   r2   r3   r/      s,   

r/   c                 C   s:   t j| g dg ddd | jjdkrt| |S t| |S )a.  Add an array of values to an image.

    This method ensures that ``uint8`` does not overflow during the addition.

    **Supported dtypes**:

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

        - (1) Non-uint8 dtypes can overflow. For floats, this can result
              in +/-inf.

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

    values : ndarray
        The values to add to the image. Expected to have the same height
        and width as `image` and either no channels or one channel or
        the same number of channels as `image`.

    Returns
    -------
    ndarray
        Image with values added to it.

    r   r   Nr%   r   )r*   r+   r,   r-   _add_elementwise_to_uint8_add_elementwise_to_non_uint8)r0   valuesr2   r2   r3   add_elementwise   s   (

rb   c                 C   sZ   |j jdkrt|}| tj} t|ddtj}| | }t|ddtj}|S )Nfr6   r7   r   )r,   rX   r(   rB   rC   r   rA   r   )r0   ra   	image_augr2   r2   r3   r_     s   

r_   c                 C   s   | j }| j}| jdkr| dtjf } |jdkr|dtjf }| j d }| jjd }td|jj|f }tj||dd}|j d dkrLt	|dd|f}tj
| |g| j|gdd\} }tj| || d	d
} t| |} t|dkrt| d S | S )Nr   .r5   rM   d   rN   r   rP   rQ   rR   .r   )r@   r,   r?   r(   rF   rW   rX   r*   rY   rE   rZ   r[   r\   len)r0   ra   input_shaper]   rJ   rW   r^   r2   r2   r3   r`     s0   



r`   c                 C   r   )a  Multiply an image by a single scalar or one scalar per channel.

    This method ensures that ``uint8`` does not overflow during the
    multiplication.

    **Supported dtypes**:

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

        - (1) Non-uint8 dtypes can overflow. For floats, this can result in
              +/-inf.

    note::

        Tests were only conducted for rather small multipliers, around
        ``-10.0`` to ``+10.0``.

        In general, the multipliers sampled from `multiplier` must be in a
        value range that corresponds to the input image's dtype. E.g. if the
        input image has dtype ``uint16`` and the samples generated from
        `multiplier` are ``float64``, this function will still force all
        samples to be within the value range of ``float16``, as it has the
        same number of bytes (two) as ``uint16``. This is done to make
        overflows less likely to occur.

    Parameters
    ----------
    image : ndarray
        Image array of shape ``(H,W,[C])``.
        If `value` contains more than one value, the shape of the image is
        expected to be ``(H,W,C)``.

    multiplier : number or ndarray
        The multiplier to use. Either a single value or an array
        containing exactly one component per channel, i.e. ``C`` components.

    Returns
    -------
    ndarray
        Image, multiplied by `multiplier`.

    r   r   r   Nr%   r   )	r'   r(   r)   r*   r+   r,   r-   _multiply_scalar_to_uint8_multiply_scalar_to_non_uint8)r0   
multiplierr2   r2   r3   multiply_scalarH  s   
7


rl   c                 C   s&  t |pt |pt |o|jdk}| }| jdkrdn| jd }t|}tj	ddtjd}|r~|jdksBJ d|j|jf | jdksQJ d	| j| jf | jd |jkseJ d
| jd |jf t
|d d tjf d|f|tjd d f  }n|| }t|dd| j}t | |S )Nr   r   r5   r   r8   r9   zQExpected `multiplier` to be 1-dimensional, got %d-dimensional data with shape %s.r:   zvExpected `image` to be 3-dimensional when multiplying by one value per channel, got %d-dimensional data with shape %s.zoExpected number of channels in `image` and number of components in `multiplier` to be identical. Got %d vs. %d.r7   )r;   r<   r=   r>   r'   r?   r@   r(   r   rD   rE   rF   rA   rC   r,   rG   )r0   rk   rH   rI   rJ   rK   rL   r2   r2   r3   ri     sH   
	

ri   c           	      C   s   | j }t|pt|pt|o|jdk}| }| jdkr!dn| jd }dd|r,|ndf}t	|
|}t| j j|j jdkrCdnd}t d|j j|f }tj||dd}tj| |g| j |gdd\} }tj| || d	d
} t| |S )Nr   r   r5   rc   rM   TrN   rP   rQ   rR   )r,   r;   r<   r=   r>   r'   r?   r@   r(   rU   rV   maxrW   rX   r*   rY   rZ   multiplyr\   )	r0   rk   r]   rH   rI   rJ   r@   rW   r^   r2   r2   r3   rj     s2   

rj   c                 C   sR   t j| g dg ddd |jjdkr| |9 } | S | jjdkr$t| |S t| |S )a  Multiply an image with an array of values.

    This method ensures that ``uint8`` does not overflow during the addition.

    **Supported dtypes**:

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

        - (1) Non-uint8 dtypes can overflow. For floats, this can result
              in +/-inf.

    note::

        Tests were only conducted for rather small multipliers, around
        ``-10.0`` to ``+10.0``.

        In general, the multipliers sampled from `multipliers` must be in a
        value range that corresponds to the input image's dtype. E.g. if the
        input image has dtype ``uint16`` and the samples generated from
        `multipliers` are ``float64``, this function will still force all
        samples to be within the value range of ``float16``, as it has the
        same number of bytes (two) as ``uint16``. This is done to make
        overflows less likely to occur.

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

    multipliers : ndarray
        The multipliers with which to multiply the image. Expected to have
        the same height and width as `image` and either no channels or one
        channel or the same number of channels as `image`.

    Returns
    -------
    ndarray
        Image, multiplied by `multipliers`.

    r   r   Nr%   br   )r*   r+   r,   rX   r-   _multiply_elementwise_to_uint8"_multiply_elementwise_to_non_uint8)r0   multipliersr2   r2   r3   multiply_elementwise  s   5

rs   c                 C   sj   |j jdkr|jtjdd}| tj}n|jtjdd}| tj}tj||d|d}tj|tj	ddS )Nrc   Fr)   rQ   )rT   rS   )rB   )
r,   rX   rC   r(   r   r   rn   r*   r\   r   )r0   rr   rd   r2   r2   r3   rp   8  s   rp   c                 C   s   | j }t|}t|}t| j j|j jdkrdnd}t d|j j|f }tj||d||fd}|jd dkrG| jd }t	|dd|f}tj
| |g| |gdd\} }tj| || d	d
} t| |S )Nrc   r   r   rM   T)rO   Zvalidate_valuesr5   rP   rQ   rR   )r,   r(   minrm   rW   rX   r*   rY   r@   rE   rZ   rn   r\   )r0   rr   r]   Zmul_minZmul_maxrW   r^   rJ   r2   r2   r3   rq   J  s,   



rq   r   Fc	           	   
   C   s   t t| ||||||||	S )a  Fill a single area within an image using a fill mode.

    This cutout method uses the top-left and bottom-right corner coordinates
    of the cutout region given as absolute pixel values.

    .. note::

        Gaussian fill mode will assume that float input images contain values
        in the interval ``[0.0, 1.0]`` and hence sample values from a
        gaussian within that interval, i.e. from ``N(0.5, std=0.5/3)``.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    Added in 0.4.0.

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

    x1 : number
        See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    y1 : number
        See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    x2 : number
        See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    y2 : number
        See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    fill_mode : {'constant', 'gaussian'}, optional
        See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    cval : number or tuple of number, optional
        See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    fill_per_channel : number or bool, optional
        See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    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.arithmetic.cutout_`.

    Returns
    -------
    ndarray
        Image with area filled in.

    )cutout_r(   r)   )	r0   x1y1x2y2	fill_modecvalfill_per_channelseedr2   r2   r3   cutoutw  s   
7r   c	                 C   s   ddl }	| jdd \}
}ttt|d|}ttt|d|
}ttt|d|}ttt|d|
}||krx||krx|tv sOJ dttt |f t| \}}|		|}t
||}|| ||||||dkt|tjstt|n|d} | S )a  Fill a single area within an image using a fill mode (in-place).

    This cutout method uses the top-left and bottom-right corner coordinates
    of the cutout region given as absolute pixel values.

    .. note::

        Gaussian fill mode will assume that float input images contain values
        in the interval ``[0.0, 1.0]`` and hence sample values from a
        gaussian within that interval, i.e. from ``N(0.5, std=0.5/3)``.

    Added in 0.4.0.

    **Supported dtypes**:

    minimum of (
        :func:`~imgaug.augmenters.arithmetic._fill_rectangle_gaussian_`,
        :func:`~imgaug.augmenters.arithmetic._fill_rectangle_constant_`
    )

    Parameters
    ----------
    image : ndarray
        Image to modify. Might be modified in-place.

    x1 : number
        X-coordinate of the top-left corner of the cutout region.

    y1 : number
        Y-coordinate of the top-left corner of the cutout region.

    x2 : number
        X-coordinate of the bottom-right corner of the cutout region.

    y2 : number
        Y-coordinate of the bottom-right corner of the cutout region.

    fill_mode : {'constant', 'gaussian'}, optional
        Fill mode to use.

    cval : number or tuple of number, optional
        The constant value to use when filling with mode ``constant``.
        May be an intensity value or color tuple.

    fill_per_channel : number or bool, optional
        Whether to fill in a channelwise fashion.
        If number then a value ``>=0.5`` will be interpreted as ``True``.

    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
        A random number generator to sample random values from.
        Usually an integer seed value or an ``RNG`` instance.
        See :class:`imgaug.random.RNG` for details.

    Returns
    -------
    ndarray
        Image with area filled in.
        The input image might have been modified in-place.

    r   Nr   z6Expected one of the following fill modes: %s. Got: %s.      ?)rw   rx   ry   rz   r|   per_channelrandom_state)	importlibr@   ru   rm   int_CUTOUT_FILL_MODESstrlistkeysimport_modulegetattr
isinstanceiarandomZRNG)r0   rw   rx   ry   rz   r{   r|   r}   r~   r   heightwidthmodule_namefnamemodulefuncr2   r2   r3   rv     s4   ?




rv   c                 C   s   | j j}|dv rd}	d}
d}n	t| j \}	}
}t|t|	 d d }|| }|| }||f}|r?| jdkr?|| jd f }|j|
||d	}| j jd
krR|dk}nt	||	|
| j }| jdkrtt|| ||||ddf< | S || ||||f< | S )aZ  Fill a rectangular image area with samples from a gaussian.

    Added in 0.4.0.

    **Supported dtypes**:

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

        - (1) Possible loss of resolution due to gaussian values being sampled
              as ``float64`` s.
        - (2) Float input arrays are assumed to be in interval ``[0.0, 1.0]``
              and all gaussian samples are within that interval too.

    )rc   ro           r         ?g       @g      @r:   r   )r'   ro   N)r,   rX   r*   get_value_range_of_dtypefloatr?   r@   normalr(   rA   rC   Z
atleast_3d)r0   rw   rx   ry   rz   r|   r   r   rX   	min_valueZcenter_value	max_valueZstddevr   r   r@   rectZrect_vrr2   r2   r3   r     s.    


 r   c           
      C   s   t |rJ|rF| jdkrdn| jd }|du r|d }n.t||k r9tt|t| }	t||	fd| }nt||krE|d| }n|d }tj	|| j
d| ||||df< | S )a  Fill a rectangular area within an image with constant value(s).

    `cval` may be a single value or one per channel. If the number of items
    in `cval` does not match the number of channels in `image`, it may
    be tiled up to the number of channels.

    Added in 0.4.0.

    **Supported dtypes**:

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

    r   Nr5   r   r9   .)r;   is_iterabler?   r@   rg   r   r(   ceilrE   rU   r,   )
r0   rw   rx   ry   rz   r|   r   r   rJ   mulr2   r2   r3   r   R  s   

"r   c                 C   s   t j| g dg ddd | j}| jdkr| dtjf } |jdkr(|dtjf }|dk}|jd dkrA| jd	 }t|dd|f}| jjd
v rR|jjdkrRt	|}t j
|| jdd}|j| jdd}|| |< t|dkrq| d S | S )a  Replace components in an image array with new values.

    **Supported dtypes**:

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

        - (1) ``uint64`` is currently not supported, because
              :func:`~imgaug.dtypes.clip_to_dtype_value_range_()` does not
              support it, which again is because numpy.clip() seems to not
              support it.
        - (2) `int64` is disallowed due to being converted to `float64`
              by :func:`numpy.clip` since 1.17 (possibly also before?).

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

    mask : ndarray
        Mask of shape ``(H,W,[C])`` denoting which components to replace.
        If ``C`` is provided, it must be ``1`` or match the ``C`` of `image`.
        May contain floats in the interval ``[0.0, 1.0]``.

    replacements : iterable
        Replacements to place in `image` at the locations defined by `mask`.
        This 1-dimensional iterable must contain exactly as many values
        as there are replaced components in `image`.

    Returns
    -------
    ndarray
        Image with replaced components.

    )
r   r   r   r   r   r   r   r   r   r!   )	r   r   r   r   r   r    r"   r#   r$   Nr%   r   .r   r   r5   )iuro   rc   FrN   rt   rf   )r*   r+   r@   r?   r(   rF   rE   r,   rX   rB   rY   rC   rg   )r0   maskZreplacementsrh   Zmask_threshrJ   replacement_samplesr2   r2   r3   replace_elementwise_  s2   /$



r   Tc                 C   s   t t| ||||dS )a  Invert an array.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.invert_`.

    Parameters
    ----------
    image : ndarray
        See :func:`invert_`.

    min_value : None or number, optional
        See :func:`invert_`.

    max_value : None or number, optional
        See :func:`invert_`.

    threshold : None or number, optional
        See :func:`invert_`.

    invert_above_threshold : bool, optional
        See :func:`invert_`.

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

    r   r   	thresholdinvert_above_threshold)invert_r(   r)   )r0   r   r   r   r   r2   r2   r3   invert  s   r   c                 C   s^  h d}t | j\}}}|du r|n|}|du r|n|}||ks0J dt|t|| jjf ||ksCJ dt|t|| jjf ||k sSJ dt|t|f ||ks[||krn| jj|v snJ dd|| jjf | jjdkr|t| ||||S ttt	t
d	}	|	| jj }
|du r|
| ||S |
t| ||}|r| |k}n| |k }|| | |< | S )
a	  Invert an array in-place.

    Added in 0.4.0.

    **Supported dtypes**:

    if (min_value=None and max_value=None):

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

    if (min_value!=None or max_value!=None):

        * ``uint8``: yes; fully tested
        * ``uint16``: yes; tested
        * ``uint32``: yes; tested
        * ``uint64``: no (1)
        * ``int8``: yes; tested
        * ``int16``: yes; tested
        * ``int32``: yes; tested
        * ``int64``: no (2)
        * ``float16``: yes; tested
        * ``float32``: yes; tested
        * ``float64``: no (2)
        * ``float128``: no (3)
        * ``bool``: no (4)

        - (1) Not allowed due to numpy's clip converting from ``uint64`` to
              ``float64``.
        - (2) Not allowed as int/float have to be increased in resolution
              when using min/max values.
        - (3) Not tested.
        - (4) Makes no sense when using min/max values.

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

    min_value : None or number, optional
        Minimum of the value range of input images, e.g. ``0`` for ``uint8``
        images. If set to ``None``, the value will be automatically derived
        from the image's dtype.

    max_value : None or number, optional
        Maximum of the value range of input images, e.g. ``255`` for ``uint8``
        images. If set to ``None``, the value will be automatically derived
        from the image's dtype.

    threshold : None or number, optional
        A threshold to use in order to invert only numbers above or below
        the threshold. If ``None`` no thresholding will be used.

    invert_above_threshold : bool, optional
        If ``True``, only values ``>=threshold`` will be inverted.
        Otherwise, only values ``<threshold`` will be inverted.
        If `threshold` is ``None`` this parameter has no effect.

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

    >   r   r   r   r   r   r   r   r   NzaExpected min_value to be above or equal to dtype's min value, got %s (vs. min possible %s for %s)zaExpected max_value to be below or equal to dtype's max value, got %s (vs. max possible %s for %s)z7Expected min_value to be below max_value, got %s and %szJCan use custom min/max values only with the following dtypes: %s. Got: %s., r   )ro   r   r   rc   )r*   r   r,   r   r-   join_invert_uint8__invert_bool_invert_uint16_or_larger__invert_int__invert_floatrX   r(   r)   )r0   r   r   r   r   Zallow_dtypes_custom_minmaxZmin_value_dt_Zmax_value_dtZdtype_kind_to_invert_funcr   arr_invr   r2   r2   r3   r     sl   Y





r   c                 C   s&   |dkr|dksJ d||f |  S )Nr   r   zKmin_value and max_value must be 0 and 1 for bool arrays. Got %.4f and %.4f.r2   arrr   r   r2   r2   r3   r     s   r   c                 C   s   t ||||}t| |} | S N) _generate_table_for_invert_uint8r;   Z
apply_lut_)r   r   r   r   r   tabler2   r2   r3   r     s
   r   c                 C   s<   |dko|t | jjk}|r||  S tt | ||||S Nr   )r(   Ziinfor,   rm   _invert_by_distancerA   )r   r   r   Zmin_max_is_vrr2   r2   r3   r     s   r   c                 C   s\   |d| d kr#t | }||k}|||< d||   d || < |S tt | ||||S )Nr5   r   )r(   r)   r   rA   )r   r   r   r   r   r2   r2   r3   r     s   
	r   c                 C   s2   t j|d| ddrd|  S tt | ||||S )Nr5   r   )Zrtol)r(   iscloser   rA   r   r2   r2   r3   r     s   r   c                 C   sz   | }| j jdv rtt| gdd }t|| }|| }| j jdkr,t|||}| j jdv r;tj|| j dd}|S )N)r   rc   r   r   rc   F)rA   )	r,   rX   r*   Zincrease_array_resolutions_r(   r)   absrA   r\   )r   r   r   r   distance_from_minr2   r2   r3   r     s   r   c                 C   s   t dt j}| dko|dk}|r|d d d }nt ||  }|| }t || |t j}|d uri|t j}|rTt j|dt| |t|d  gdd}|S t j|dt| |t|d  gdd}|S )Nr8   r   r7   r5   )Zaxis)	r(   rD   rC   r   r   rA   r   Zconcatenater   )r   r   r   r   r   Zfull_value_rangeZ	table_invr   r2   r2   r3   r     s0   
r      c                 C   s   t t| |dS )an  Invert pixel values above a threshold.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.solarize_`.

    Parameters
    ----------
    image : ndarray
        See :func:`solarize_`.

    threshold : None or number, optional
        See :func:`solarize_`.

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

    r   )	solarize_r(   r)   r0   r   r2   r2   r3   solarize   s   r   c                 C   s   t | |dS )a  Invert pixel values above a threshold in-place.

    This function is a wrapper around :func:`invert`.

    This function performs the same transformation as
    :func:`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
        See :func:`invert_`.

    threshold : None or number, optional
        See :func:`invert_`.
        Note: The default threshold is optimized for ``uint8`` images.


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

    r   )r   r   r2   r2   r3   r   :  s   r   c              
   C   sn  ddl }| jdkrt| S d}d}| jjdks!J d| jjf d|  kr+dks3n J d|f | jdk}| jd	koC| jd
 dk}|rJ| d } |s]|s]| jd
 d	ks]J d| jf tt	t
||| d|d    ||}|j| }tjddd$}	|j|	|d |	d d}
|s|rd}
tj|	|
dd} W d   n1 sw   Y  |r| dtjf } | S )aD  Compress an image using jpeg compression.

    **Supported dtypes**:

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

    Parameters
    ----------
    image : ndarray
        Image of dtype ``uint8`` and shape ``(H,W,[C])``. If ``C`` is provided,
        it must be ``1`` or ``3``.

    compression : int
        Strength of the compression in the interval ``[0, 100]``.

    Returns
    -------
    ndarray
        Input image after applying jpeg compression to it and reloading
        the result into a new array. Same shape and dtype as the input.

    r   Nre   r   r   zCJpeg compression can only be applied to uint8 images. Got dtype %s.z>Expected compression to be in the interval [0, 100], got %.4f.r   r:   r5   rf   zkExpected either a grayscale image of shape (H,W) or (H,W,1) or an RGB image of shape (H,W,3). Got shape %s.r   e   zwb+z.jpg)modesuffix)qualityRGBLZjpeg)pilmodeformat.)Z	PIL.Imager'   r(   r)   r,   r-   r?   r@   r   rA   rB   ZImageZ	fromarraytempfileNamedTemporaryFilesaveseekimageioZimreadrF   )r0   compressionZPILZmaximum_qualityZminimum_qualityZhas_no_channelsZis_single_channelr   Z	image_pilrc   r   r2   r2   r3   compress_jpeg\  sb   #




r   c                       8   e Zd ZdZ			d fdd	Zdd	 Zd
d Z  ZS )AddaK  
    Add a value to all pixels in an image.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.add_scalar`.

    Parameters
    ----------
    value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Value to add to all pixels.

            * If a number, exactly that value will always be used.
            * If a tuple ``(a, b)``, then a value from the discrete
              interval ``[a..b]`` will be sampled per image.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then a value will be sampled per
              image from that parameter.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.Add(10)

    Always adds a value of 10 to all channels of all pixels of all input
    images.

    >>> aug = iaa.Add((-10, 10))

    Adds a value from the discrete interval ``[-10..10]`` to all pixels of
    input images. The exact value is sampled per image.

    >>> aug = iaa.Add((-10, 10), per_channel=True)

    Adds a value from the discrete interval ``[-10..10]`` to all pixels of
    input images. The exact value is sampled per image *and* channel,
    i.e. to a red-channel it might add 5 while subtracting 7 from the
    blue channel of the same image.

    >>> aug = iaa.Add((-10, 10), per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for 50 percent of all images.

    i   FN
deprecatedc                    @   t t| j||||d tj|dd ddd| _t|d| _d S Nr~   r-   r   deterministicr1   TrK   tuple_to_uniformlist_to_choicer   )superr   __init__iaphandle_continuous_paramr1   handle_probability_paramr   selfr1   r   r~   r-   r   r   	__class__r2   r3   r        

zAdd.__init__c                 C      |j d u r|S |j }t|}t|}|d}| jj|f|d d}	| jj||f|d d}
tt	||
|	}|D ]*\}\}}}|j
d }|dkrP|d| }n|jdkrY|d ng }t|||j |< q9|S Nr   r   r   r   r   )imagesrg   r   estimate_max_number_of_channels	duplicater   draw_samplesr1   	enumeratezipr@   r'   r4   )r   batchr   parentshooksr   	nb_imagesnb_channels_maxrssper_channel_samplesZvalue_samplesgenr   r0   Zvalue_samples_iper_channel_samples_irJ   r1   r2   r2   r3   _augment_batch_  s(   




zAdd._augment_batch_c                 C      | j | jgS z=See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`.r1   r   r   r2   r2   r3   get_parametersI     zAdd.get_parametersr   FNNr   r   __name__
__module____qualname____doc__r   r   r   __classcell__r2   r2   r   r3   r     s    K.r   c                       r   )AddElementwisea  
    Add to the pixels of images values that are pixelwise randomly sampled.

    While the ``Add`` Augmenter samples one value to add *per image* (and
    optionally per channel), this augmenter samples different values per image
    and *per pixel* (and optionally per channel), i.e. intensities of
    neighbouring pixels may be increased/decreased by different amounts.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.add_elementwise`.

    Parameters
    ----------
    value : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Value to add to the pixels.

            * If an int, exactly that value will always be used.
            * If a tuple ``(a, b)``, then values from the discrete interval
              ``[a..b]`` will be sampled per image and pixel.
            * If a list of integers, a random value will be sampled from the
              list per image and pixel.
            * If a ``StochasticParameter``, then values will be sampled per
              image and pixel from that parameter.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.AddElementwise(10)

    Always adds a value of 10 to all channels of all pixels of all input
    images.

    >>> aug = iaa.AddElementwise((-10, 10))

    Samples per image and pixel a value from the discrete interval
    ``[-10..10]`` and adds that value to the respective pixel.

    >>> aug = iaa.AddElementwise((-10, 10), per_channel=True)

    Samples per image, pixel *and also channel* a value from the discrete
    interval ``[-10..10]`` and adds it to the respective pixel's channel value.
    Therefore, added values may differ between channels of the same pixel.

    >>> aug = iaa.AddElementwise((-10, 10), per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for 50 percent of all images.

    r   FNr   c                    r   r   )r   r  r   r   r   r1   r   r   r   r   r2   r3   r     r   zAddElementwise.__init__c                 C   s   |j d u r|S |j }t|}|d| }| jj|f|d d}tt|||dd  }	|	D ](\}
\}}}|j\}}}|||dkrC|ndf}| jj||d}t	|||j |
< q.|S )Nr   r   r   r   )
r   rg   r   r   r   r   r   r@   r1   rb   )r   r   r   r   r   r   r   r   r   r   r   r0   r   rsr   r   rJ   sample_shapera   r2   r2   r3   r     s$   

zAddElementwise._augment_batch_c                 C   r   r   r   r   r2   r2   r3   r     r   zAddElementwise.get_parametersr   r   r2   r2   r   r3   r  O  s    Or  c                       (   e Zd ZdZ			d	 fdd	Z  ZS )
AdditiveGaussianNoiseas  
    Add noise sampled from gaussian distributions elementwise to images.

    This augmenter samples and adds noise elementwise, i.e. it can add
    different noise values to neighbouring pixels and is comparable
    to ``AddElementwise``.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.AddElementwise`.

    Parameters
    ----------
    loc : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Mean of the normal distribution from which the noise is sampled.

            * If a number, exactly that value will always be used.
            * If a tuple ``(a, b)``, a random value from the interval
              ``[a, b]`` will be sampled per image.
            * If a list, then a random value will be sampled from that list per
              image.
            * If a ``StochasticParameter``, a value will be sampled from the
              parameter per image.

    scale : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Standard deviation of the normal distribution that generates the noise.
        Must be ``>=0``. If ``0`` then `loc` will simply be added to all
        pixels.

            * If a number, exactly that value will always be used.
            * If a tuple ``(a, b)``, a random value from the interval
              ``[a, b]`` will be sampled per image.
            * If a list, then a random value will be sampled from that list per
              image.
            * If a ``StochasticParameter``, a value will be sampled from the
              parameter per image.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.AdditiveGaussianNoise(scale=0.1*255)

    Adds gaussian noise from the distribution ``N(0, 0.1*255)`` to images.
    The samples are drawn per image and pixel.

    >>> aug = iaa.AdditiveGaussianNoise(scale=(0, 0.1*255))

    Adds gaussian noise from the distribution ``N(0, s)`` to images,
    where ``s`` is sampled per image from the interval ``[0, 0.1*255]``.

    >>> aug = iaa.AdditiveGaussianNoise(scale=0.1*255, per_channel=True)

    Adds gaussian noise from the distribution ``N(0, 0.1*255)`` to images,
    where the noise value is different per image and pixel *and* channel (e.g.
    a different one for red, green and blue channels of the same pixel).
    This leads to "colorful" noise.

    >>> aug = iaa.AdditiveGaussianNoise(scale=0.1*255, per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for 50 percent of all images.

    r   r      FNr   c                    V   t j|dd ddd}t j|ddddd}	t j||	d}
tt| j|
|||||d d S NlocTr   scaler   N)r  r  r   r~   r-   r   r   )r   r   ZNormalr   r	  r   r   r  r  r   r~   r-   r   r   loc2Zscale2r1   r   r2   r3   r   )  s   

zAdditiveGaussianNoise.__init__r   r
  FNNr   r   r   r  r  r  r   r  r2   r2   r   r3   r	    s    [r	  c                       r  )
AdditiveLaplaceNoisea  
    Add noise sampled from laplace distributions elementwise to images.

    The laplace distribution is similar to the gaussian distribution, but
    puts more weight on the long tail. Hence, this noise will add more
    outliers (very high/low values). It is somewhere between gaussian noise and
    salt and pepper noise.

    Values of around ``255 * 0.05`` for `scale` lead to visible noise (for
    ``uint8``).
    Values of around ``255 * 0.10`` for `scale` lead to very visible
    noise (for ``uint8``).
    It is recommended to usually set `per_channel` to ``True``.

    This augmenter samples and adds noise elementwise, i.e. it can add
    different noise values to neighbouring pixels and is comparable
    to ``AddElementwise``.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.AddElementwise`.

    Parameters
    ----------
    loc : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Mean of the laplace distribution that generates the noise.

            * If a number, exactly that value will always be used.
            * If a tuple ``(a, b)``, a random value from the interval
              ``[a, b]`` will be sampled per image.
            * If a list, then a random value will be sampled from that list per
              image.
            * If a ``StochasticParameter``, a value will be sampled from the
              parameter per image.

    scale : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Standard deviation of the laplace distribution that generates the noise.
        Must be ``>=0``. If ``0`` then only `loc` will be used.
        Recommended to be around ``255*0.05``.

            * If a number, exactly that value will always be used.
            * If a tuple ``(a, b)``, a random value from the interval
              ``[a, b]`` will be sampled per image.
            * If a list, then a random value will be sampled from that list per
              image.
            * If a ``StochasticParameter``, a value will be sampled from the
              parameter per image.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.AdditiveLaplaceNoise(scale=0.1*255)

    Adds laplace noise from the distribution ``Laplace(0, 0.1*255)`` to images.
    The samples are drawn per image and pixel.

    >>> aug = iaa.AdditiveLaplaceNoise(scale=(0, 0.1*255))

    Adds laplace noise from the distribution ``Laplace(0, s)`` to images,
    where ``s`` is sampled per image from the interval ``[0, 0.1*255]``.

    >>> aug = iaa.AdditiveLaplaceNoise(scale=0.1*255, per_channel=True)

    Adds laplace noise from the distribution ``Laplace(0, 0.1*255)`` to images,
    where the noise value is different per image and pixel *and* channel (e.g.
    a different one for the red, green and blue channels of the same pixel).
    This leads to "colorful" noise.

    >>> aug = iaa.AdditiveLaplaceNoise(scale=0.1*255, per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for 50 percent of all images.

    r   r
  FNr   c                    r  r  )r   r   ZLaplacer   r  r   r  r   r2   r3   r     s   

zAdditiveLaplaceNoise.__init__r  r  r2   r2   r   r3   r  =  s    fr  c                       (   e Zd ZdZ			d fdd	Z  ZS )	AdditivePoissonNoisea  
    Add noise sampled from poisson distributions elementwise to images.

    Poisson noise is comparable to gaussian noise, as e.g. generated via
    ``AdditiveGaussianNoise``. As poisson distributions produce only positive
    numbers, the sign of the sampled values are here randomly flipped.

    Values of around ``10.0`` for `lam` lead to visible noise (for ``uint8``).
    Values of around ``20.0`` for `lam` lead to very visible noise (for
    ``uint8``).
    It is recommended to usually set `per_channel` to ``True``.

    This augmenter samples and adds noise elementwise, i.e. it can add
    different noise values to neighbouring pixels and is comparable
    to ``AddElementwise``.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.AddElementwise`.

    Parameters
    ----------
    lam : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Lambda parameter of the poisson distribution. Must be ``>=0``.
        Recommended values are around ``0.0`` to ``10.0``.

            * If a number, exactly that value will always be used.
            * If a tuple ``(a, b)``, a random value from the interval
              ``[a, b]`` will be sampled per image.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, a value will be sampled from the
              parameter per image.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.AdditivePoissonNoise(lam=5.0)

    Adds poisson noise sampled from a poisson distribution with a ``lambda``
    parameter of ``5.0`` to images.
    The samples are drawn per image and pixel.

    >>> aug = iaa.AdditivePoissonNoise(lam=(0.0, 15.0))

    Adds poisson noise sampled from ``Poisson(x)`` to images, where ``x`` is
    randomly sampled per image from the interval ``[0.0, 15.0]``.

    >>> aug = iaa.AdditivePoissonNoise(lam=5.0, per_channel=True)

    Adds poisson noise sampled from ``Poisson(5.0)`` to images,
    where the values are different per image and pixel *and* channel (e.g. a
    different one for red, green and blue channels for the same pixel).

    >>> aug = iaa.AdditivePoissonNoise(lam=(0.0, 15.0), per_channel=True)

    Adds poisson noise sampled from ``Poisson(x)`` to images,
    with ``x`` being sampled from ``uniform(0.0, 15.0)`` per image and
    channel. This is the *recommended* configuration.

    >>> aug = iaa.AdditivePoissonNoise(lam=(0.0, 15.0), per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for 50 percent of all images.

    r   g      .@FNr   c           	         sF   t j|ddddd}t t j|d}tt| j||||||d d S )Nlamr  Tr   )r  r  )r   r   Z
RandomSignZPoissonr   r  r   )	r   r  r   r~   r-   r   r   Zlam2r1   r   r2   r3   r     s   

zAdditivePoissonNoise.__init__)r  FNNr   r   r  r2   r2   r   r3   r    s    ^r  c                       r   )Multiplya  
    Multiply all pixels in an image with a random value sampled once per image.

    This augmenter can be used to make images lighter or darker.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.multiply_scalar`.

    Parameters
    ----------
    mul : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        The value with which to multiply the pixel values in each image.

            * If a number, then that value will always be used.
            * If a tuple ``(a, b)``, then a value from the interval ``[a, b]``
              will be sampled per image and used for all pixels.
            * If a list, then a random value will be sampled from that list per
              image.
            * If a ``StochasticParameter``, then that parameter will be used to
              sample a new value per image.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.Multiply(2.0)

    Multiplies all images by a factor of ``2``, making the images significantly
    brighter.

    >>> aug = iaa.Multiply((0.5, 1.5))

    Multiplies images by a random value sampled uniformly from the interval
    ``[0.5, 1.5]``, making some images darker and others brighter.

    >>> aug = iaa.Multiply((0.5, 1.5), per_channel=True)

    Identical to the previous example, but the sampled multipliers differ by
    image *and* channel, instead of only by image.

    >>> aug = iaa.Multiply((0.5, 1.5), per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for 50 percent of all images.

    g?g333333?FNr   c                    r   Nr   r   Tr   r   )r   r  r   r   r   r   r   r   r   r   r   r~   r-   r   r   r   r2   r3   r   t  r   zMultiply.__init__c                 C   r   r   )r   rg   r   r   r   r   r   r   r   r   r@   r'   rl   )r   r   r   r   r   r   r   r   r   r   Zmul_samplesr   r   r0   Zmul_samples_ir   rJ   r   r2   r2   r3   r     s(   




zMultiply._augment_batch_c                 C   r   r   r   r   r   r2   r2   r3   r     r   zMultiply.get_parametersr  FNNr   r   r   r2   r2   r   r3   r  (  s    K-r  c                       r   )MultiplyElementwisea  
    Multiply image pixels with values that are pixelwise randomly sampled.

    While the ``Multiply`` Augmenter uses a constant multiplier *per
    image* (and optionally channel), this augmenter samples the multipliers
    to use per image and *per pixel* (and optionally per channel).

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.multiply_elementwise`.

    Parameters
    ----------
    mul : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        The value with which to multiply pixel values in the image.

            * If a number, then that value will always be used.
            * If a tuple ``(a, b)``, then a value from the interval ``[a, b]``
              will be sampled per image and pixel.
            * If a list, then a random value will be sampled from that list
              per image and pixel.
            * If a ``StochasticParameter``, then that parameter will be used to
              sample a new value per image and pixel.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.MultiplyElementwise(2.0)

    Multiply all images by a factor of ``2.0``, making them significantly
    bighter.

    >>> aug = iaa.MultiplyElementwise((0.5, 1.5))

    Samples per image and pixel uniformly a value from the interval
    ``[0.5, 1.5]`` and multiplies the pixel with that value.

    >>> aug = iaa.MultiplyElementwise((0.5, 1.5), per_channel=True)

    Samples per image and pixel *and channel* uniformly a value from the
    interval ``[0.5, 1.5]`` and multiplies the pixel with that value. Therefore,
    used multipliers may differ between channels of the same pixel.

    >>> aug = iaa.MultiplyElementwise((0.5, 1.5), per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for 50 percent of all images.

    r  FNr   c                    r   r  )r   r!  r   r   r   r   r   r   r  r   r2   r3   r   	  s   

zMultiplyElementwise.__init__c                 C   s   |j d u r|S |j }t|}|d| }| jj|f|d d}t| jtjp5t| jtj	o5t| jj
tj}	tt|||dd  }
|
D ]7\}\}}}|j\}}}|||dkrY|ndf}| jj||d}|jjdkrs|	rs|jtdd}t|||j |< qD|S )Nr   r   r   r   ro   Frt   )r   rg   r   r   r   r   r   r   BinomialFromLowerResolutionother_paramr   r   r@   r,   rX   rC   r   rs   )r   r   r   r   r   r   r   r   r   Zis_mul_binomialr   r   r0   r   r  r   r   rJ   r  r   r2   r2   r3   r   	  s0   

z#MultiplyElementwise._augment_batch_c                 C   r   r   r  r   r2   r2   r3   r   3	  r   z"MultiplyElementwise.get_parametersr   r   r2   r2   r   r3   r!    s    N!r!  c                   @      e Zd Zdd ZdS )_CutoutSamplesc
           
      C   s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S r   	nb_iterationspos_xpos_ysize_hsize_wsquaredr{   r|   r}   )
r   r(  r)  r*  r+  r,  r-  r{   r|   r}   r2   r2   r3   r   ;	  s   
z_CutoutSamples.__init__Nr   r  r  r   r2   r2   r2   r3   r&  9	      r&  c                       sd   e Zd ZdZ										
d fdd	Zedd Zdd Zdd Zedd Z	dd Z
  ZS )Cutouta  Fill one or more rectangular areas in an image using a fill mode.

    See paper "Improved Regularization of Convolutional Neural Networks with
    Cutout" by DeVries and Taylor.

    In contrast to the paper, this implementation also supports replacing
    image sub-areas with gaussian noise, random intensities or random RGB
    colors. It also supports non-squared areas. While the paper uses
    absolute pixel values for the size and position, this implementation
    uses relative values, which seems more appropriate for mixed-size
    datasets. The position parameter furthermore allows more flexibility, e.g.
    gaussian distributions around the center.

    .. note::

        This augmenter affects only image data. Other datatypes (e.g.
        segmentation map pixels or keypoints within the filled areas)
        are not affected.

    .. note::

        Gaussian fill mode will assume that float input images contain values
        in the interval ``[0.0, 1.0]`` and hence sample values from a
        gaussian within that interval, i.e. from ``N(0.5, std=0.5/3)``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.cutout_`.

    Parameters
    ----------
    nb_iterations : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        How many rectangular areas to fill.

            * If ``int``: Exactly that many areas will be filled on all images.
            * If ``tuple`` ``(a, b)``: A value from the interval ``[a, b]``
              will be sampled per image.
            * If ``list``: A random value will be sampled from that ``list``
              per image.
            * If ``StochasticParameter``: That parameter will be used to
              sample ``(B,)`` values per batch of ``B`` images.

    position : {'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
        Defines the position of each area to fill.
        Analogous to the definition in e.g.
        :class:`~imgaug.augmenters.size.CropToFixedSize`.
        Usually, ``uniform`` (anywhere in the image) or ``normal`` (anywhere
        in the image with preference around the center) are sane values.

    size : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        The size of the rectangle to fill as a fraction of the corresponding
        image size, i.e. with value range ``[0.0, 1.0]``. The size is sampled
        independently per image axis.

            * If ``number``: Exactly that size is always used.
            * If ``tuple`` ``(a, b)``: A value from the interval ``[a, b]``
              will be sampled per area and axis.
            * If ``list``: A random value will be sampled from that ``list``
              per area and axis.
            * If ``StochasticParameter``: That parameter will be used to
              sample ``(N, 2)`` values per batch, where ``N`` is the total
              number of areas to fill within the whole batch.

    squared : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to generate only squared areas cutout areas or allow
        rectangular ones. If this evaluates to a true-like value, the
        first value from `size` will be converted to absolute pixels and used
        for both axes.

        If this value is a float ``p``, then for ``p`` percent of all areas
        to be filled `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    fill_mode : str or list of str or imgaug.parameters.StochasticParameter, optional
        Mode to use in order to fill areas. Corresponds to ``mode`` parameter
        in some other augmenters. Valid strings for the mode are:

            * ``contant``: Fill each area with a single value.
            * ``gaussian``: Fill each area with gaussian noise.

        Valid datatypes are:

            * If ``str``: Exactly that mode will alaways be used.
            * If ``list``: A random value will be sampled from that ``list``
              per area.
            * If ``StochasticParameter``: That parameter will be used to
              sample ``(N,)`` values per batch, where ``N`` is the total number
              of areas to fill within the whole batch.

    cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        The value to use (i.e. the color) to fill areas if `fill_mode` is
        ```constant``.

            * If ``number``: Exactly that value is used for all areas
              and channels.
            * If ``tuple`` ``(a, b)``: A value from the interval ``[a, b]``
              will be sampled per area (and channel if ``per_channel=True``).
            * If ``list``: A random value will be sampled from that ``list``
              per area (and channel if ``per_channel=True``).
            * If ``StochasticParameter``: That parameter will be used to
              sample ``(N, Cmax)`` values per batch, where ``N`` is the total
              number of areas to fill within the whole batch and ``Cmax``
              is the maximum number of channels in any image (usually ``3``).
              If ``per_channel=False``, only the first value of the second
              axis is used.

    fill_per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to fill each area in a channelwise fashion (``True``) or
        not (``False``).
        The behaviour per fill mode is:

            * ``constant``: Whether to fill all channels with the same value
              (i.e, grayscale) or different values (i.e. usually RGB color).
            * ``gaussian``: Whether to sample once from a gaussian and use the
              values for all channels (i.e. grayscale) or to sample
              channelwise (i.e. RGB colors)

        If this value is a float ``p``, then for ``p`` percent of all areas
        to be filled `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

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

    deterministic : bool, optional
        See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.

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

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.Cutout(nb_iterations=2)

    Fill per image two random areas, by default with grayish pixels.

    >>> aug = iaa.Cutout(nb_iterations=(1, 5), size=0.2, squared=False)

    Fill per image between one and five areas, each having ``20%``
    of the corresponding size of the height and width (for non-square
    images this results in non-square areas to be filled).

    >>> aug = iaa.Cutout(fill_mode="constant", cval=255)

    Fill all areas with white pixels.

    >>> aug = iaa.Cutout(fill_mode="constant", cval=(0, 255),
    >>>                  fill_per_channel=0.5)

    Fill ``50%`` of all areas with a random intensity value between
    ``0`` and ``256``. Fill the other ``50%`` of all areas with
    random colors.

    >>> aug = iaa.Cutout(fill_mode="gaussian", fill_per_channel=True)

    Fill areas with gaussian channelwise noise (i.e. usually RGB).

    r   uniform皙?Tr   r   FNr   c                    s   ddl m} ddlm} tt| j||	|
|d tj|dddddd	| _	||| _
tj|d
dddd| _ t|d| _| || _||| _t|d| _d S )Nr   )_handle_position_parameter)_handle_cval_argr   r(  r  TF)rK   r   r   Zallow_floatsr'   )r   gqh ?r   r-  r}   )r'   r3  Z	geometricr4  r   r0  r   r   Zhandle_discrete_paramr(  positionr   r   r-  _handle_fill_mode_paramr{   r|   r}   )r   r(  r5  r'   r-  r{   r|   r}   r~   r-   r   r   r3  r4  r   r2   r3   r   	  s*   




zCutout.__init__c                 C   sn   t |r|tv sJ dttt |f t|S t|tj	r$|S t 
|s2J dt|j t|S )Nz.Expected 'fill_mode' to be one of: %s. Got %s.zYExpected 'fill_mode' to be a string, StochasticParameter or list of strings. Got type %s.)r;   Z	is_stringr   r   r   r   r   ZDeterministicr   StochasticParameterr   typer   Choice)clsr{   r2   r2   r3   r6  
  s   



zCutout._handle_fill_mode_paramc                 C   s$  |j d u r|S | |j |}|jd }|jd }|j| }|j| }	|j| }
|j| }d}tt|j |j}|D ]V\}\}}|}|| }|j	dd \}}| 
|||| | |	|| | |
|| | ||| | |j|| |j|| |j|| |j|| |
|j |< ||7 }q9|S )Nr   r   )r   _draw_samplesr+  r,  r)  r*  r   r   r(  r@   _augment_image_by_samplesr-  r{   r|   r}   )r   r   r   r   r   samplesZcutout_height_halfZcutout_width_halfZx1_relZy1_relZx2_relZy2_relZnb_iterations_sumr   r   r0   r(  startendr   r   r2   r2   r3   r   
  s:   








zCutout._augment_batch_c                 C   s^  | d}t|}t|}| jj|f|d d}tt|}t	| j
trA| j
d j|f|d d}| j
d j|f|d d}	n| j
j|df|d d}
|
d d df }|
d d df }	| jj|df|d d}| jj|f|d d}| jj|f|d d}| jj||f|d	 d}| jj|f|d
 d}t|||	|d d df |d d df ||||d	S )N   r   r   r   r   r:               r'  )r   rg   r   r   r(  r   r   r(   sumr   r5  tupler'   r-  r{   r|   r}   r&  )r   r   r   Zrngsnb_rowsr   r(  Znb_dropped_areasr)  r*  posr'   r-  r{   r|   r}   r2   r2   r3   r;  F
  sZ   





zCutout._draw_samplesc                 C   s   t |D ]?\}}|| }|| dkr,|| ||  d }||| d  }|| }|| }t|||| ||| || || |	| |
d	}q|S )Nr   r   )rw   rx   ry   rz   r{   r|   r}   r~   )r   rv   )r:  r0   rw   rx   ry   rz   r-  r{   r|   r}   r   r   Zx1_iZx2_iZheight_hZx_centerr2   r2   r3   r<  t
  s&   
z Cutout._augment_image_by_samplesc                 C   s    | j | j| j| j| j| j| jgS r   )r(  r5  r'   r-  r{   r|   r}   r   r2   r2   r3   r   
  s   zCutout.get_parameters)r   r1  r2  Tr   r   FNNr   r   )r   r  r  r  r   classmethodr6  r   r;  r<  r   r  r2   r2   r   r3   r0  H	  s(     )
(.
r0  c                       r  )	Dropoutas  
    Set a fraction of pixels in images to zero.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.MultiplyElementwise`.

    Parameters
    ----------
    p : float or tuple of float or imgaug.parameters.StochasticParameter, optional
        The probability of any pixel being dropped (i.e. to set it to zero).

            * If a float, then that value will be used for all images. A value
              of ``1.0`` would mean that all pixels will be dropped
              and ``0.0`` that no pixels will be dropped. A value of ``0.05``
              corresponds to ``5`` percent of all pixels being dropped.
            * If a tuple ``(a, b)``, then a value ``p`` will be sampled from
              the interval ``[a, b]`` per image and be used as the pixel's
              dropout probability.
            * If a list, then a value will be sampled from that list per
              batch and used as the probability.
            * If a ``StochasticParameter``, then this parameter will be used to
              determine per pixel whether it should be *kept* (sampled value
              of ``>0.5``) or shouldn't be kept (sampled value of ``<=0.5``).
              If you instead want to provide the probability as a stochastic
              parameter, you can usually do ``imgaug.parameters.Binomial(1-p)``
              to convert parameter `p` to a 0/1 representation.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.Dropout(0.02)

    Drops ``2`` percent of all pixels.

    >>> aug = iaa.Dropout((0.0, 0.05))

    Drops in each image a random fraction of all pixels, where the fraction
    is uniformly sampled from the interval ``[0.0, 0.05]``.

    >>> aug = iaa.Dropout(0.02, per_channel=True)

    Drops ``2`` percent of all pixels in a channelwise fashion, i.e. it is
    unlikely for any pixel to have all channels set to zero (black pixels).

    >>> aug = iaa.Dropout(0.02, per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for ``50`` percent of all images.

    r   g?FNr   c                    s*   t |d}tt| j||||||d d S )Npr  )!_handle_dropout_probability_paramr   rJ  r   )r   rL  r   r~   r-   r   r   p_paramr   r2   r3   r   
  s   


zDropout.__init__rK  FNNr   r   r  r2   r2   r   r3   rJ  
  s    OrJ  c                 C   s  t | rtd|  }|S t| trst| dks#J d|t| f | d | d k s8J d|| d | d f d| d   krDdkrSn nd| d   krRdks`n J d|| d | d f ttd| d  d| d  }|S t | rt	dd	 | D sJ d
|dd	 | D f t	dd	 | D sJ d|d
dd	 | D f tdt|  }|S t| tjr| }|S td|t| jf )Nr   r   zPExpected `%s` to be given as a tuple containing exactly 2 values, got %d values.r   zfExpected `%s` to be given as a tuple containing exactly 2 values (a, b) with a < b. Got %.4f and %.4f.r   zbExpected `%s` given as tuple to only contain values in the interval [0.0, 1.0], got %.4f and %.4f.c                 S      g | ]}t |qS r2   )r;   r<   .0vr2   r2   r3   
<listcomp>      z5_handle_dropout_probability_param.<locals>.<listcomp>zAExpected iterable parameter '%s' to only contain numbers, got %s.c                 S   s   g | ]}t |qS r2   )r8  rQ  r2   r2   r3   rT    s    c                 S   s$   g | ]}d |  kodkn  qS )r   r   r2   rR  Zp_ir2   r2   r3   rT    s   $ ziExpected iterable parameter '%s' to only contain probabilities in the interval [0.0, 1.0], got values %s.r   c                 S   s   g | ]}d |f qS )z%.4fr2   rV  r2   r2   r3   rT    rU  zeExpected `%s` to be float or int or tuple (<number>, <number>) or StochasticParameter, got type '%s'.)r;   r<   r   r"  r   rF  rg   ZUniformr   allr   r9  r7  	Exceptionr8  r   )rL  r-   rN  r2   r2   r3   rM  
  sX   


8"
	
rM  c                       *   e Zd ZdZ				d	 fdd	Z  ZS )
CoarseDropouta  
    Set rectangular areas within images to zero.

    In contrast to ``Dropout``, these areas can have larger sizes.
    (E.g. you might end up with three large black rectangles in an image.)
    Note that the current implementation leads to correlated sizes,
    so if e.g. there is any thin and high rectangle that is dropped, there is
    a high likelihood that all other dropped areas are also thin and high.

    This method is implemented by generating the dropout mask at a
    lower resolution (than the image has) and then upsampling the mask
    before dropping the pixels.

    This augmenter is similar to Cutout. Usually, cutout is defined as an
    operation that drops exactly one rectangle from an image, while here
    ``CoarseDropout`` can drop multiple rectangles (with some correlation
    between the sizes of these rectangles).

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.MultiplyElementwise`.

    Parameters
    ----------
    p : float or tuple of float or imgaug.parameters.StochasticParameter, optional
        The probability of any pixel being dropped (i.e. set to zero) in
        the lower-resolution dropout mask.

            * If a float, then that value will be used for all pixels. A value
              of ``1.0`` would mean, that all pixels will be dropped. A value
              of ``0.0`` would lead to no pixels being dropped.
            * If a tuple ``(a, b)``, then a value ``p`` will be sampled from
              the interval ``[a, b]`` per image and be used as the dropout
              probability.
            * If a list, then a value will be sampled from that list per
              batch and used as the probability.
            * If a ``StochasticParameter``, then this parameter will be used to
              determine per pixel whether it should be *kept* (sampled value
              of ``>0.5``) or shouldn't be kept (sampled value of ``<=0.5``).
              If you instead want to provide the probability as a stochastic
              parameter, you can usually do ``imgaug.parameters.Binomial(1-p)``
              to convert parameter `p` to a 0/1 representation.

    size_px : None or int or tuple of int or imgaug.parameters.StochasticParameter, optional
        The size of the lower resolution image from which to sample the dropout
        mask in absolute pixel dimensions.
        Note that this means that *lower* values of this parameter lead to
        *larger* areas being dropped (as any pixel in the lower resolution
        image will correspond to a larger area at the original resolution).

            * If ``None`` then `size_percent` must be set.
            * If an integer, then that size will always be used for both height
              and width. E.g. a value of ``3`` would lead to a ``3x3`` mask,
              which is then upsampled to ``HxW``, where ``H`` is the image size
              and ``W`` the image width.
            * If a tuple ``(a, b)``, then two values ``M``, ``N`` will be
              sampled from the discrete interval ``[a..b]``. The dropout mask
              will then be generated at size ``MxN`` and upsampled to ``HxW``.
            * If a ``StochasticParameter``, then this parameter will be used to
              determine the sizes. It is expected to be discrete.

    size_percent : None or float or tuple of float or imgaug.parameters.StochasticParameter, optional
        The size of the lower resolution image from which to sample the dropout
        mask *in percent* of the input image.
        Note that this means that *lower* values of this parameter lead to
        *larger* areas being dropped (as any pixel in the lower resolution
        image will correspond to a larger area at the original resolution).

            * If ``None`` then `size_px` must be set.
            * If a float, then that value will always be used as the percentage
              of the height and width (relative to the original size). E.g. for
              value ``p``, the mask will be sampled from ``(p*H)x(p*W)`` and
              later upsampled to ``HxW``.
            * If a tuple ``(a, b)``, then two values ``m``, ``n`` will be
              sampled from the interval ``(a, b)`` and used as the size
              fractions, i.e the mask size will be ``(m*H)x(n*W)``.
            * If a ``StochasticParameter``, then this parameter will be used to
              sample the percentage values. It is expected to be continuous.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    min_size : int, optional
        Minimum height and width of the low resolution mask. If
        `size_percent` or `size_px` leads to a lower value than this,
        `min_size` will be used instead. This should never have a value of
        less than ``2``, otherwise one may end up with a ``1x1`` low resolution
        mask, leading easily to the whole image being dropped.

    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.CoarseDropout(0.02, size_percent=0.5)

    Drops ``2`` percent of all pixels on a lower-resolution image that has
    ``50`` percent of the original image's size, leading to dropped areas that
    have roughly ``2x2`` pixels size.

    >>> aug = iaa.CoarseDropout((0.0, 0.05), size_percent=(0.05, 0.5))

    Generates a dropout mask at ``5`` to ``50`` percent of each input image's
    size. In that mask, ``0`` to ``5`` percent of all pixels are marked as
    being dropped. The mask is afterwards projected to the input image's
    size to apply the actual dropout operation.

    >>> aug = iaa.CoarseDropout((0.0, 0.05), size_px=(2, 16))

    Same as the previous example, but the lower resolution image has ``2`` to
    ``16`` pixels size. On images of e.g. ``224x224` pixels in size this would
    lead to fairly large areas being dropped (height/width of ``224/2`` to
    ``224/16``).

    >>> aug = iaa.CoarseDropout(0.02, size_percent=0.5, per_channel=True)

    Drops ``2`` percent of all pixels at ``50`` percent resolution (``2x2``
    sizes) in a channel-wise fashion, i.e. it is unlikely for any pixel to
    have all channels set to zero (black pixels).

    >>> aug = iaa.CoarseDropout(0.02, size_percent=0.5, per_channel=0.5)

    Same as the previous example, but the `per_channel` feature is only active
    for ``50`` percent of all images.

    g{Gz?皙?NFr:   r   c
                    sn   t |d}
|d urtj|
||d}
n|d urtj|
||d}
ntj|
d|d}
tt| j|
|||||	d d S )NrL  r$  size_pxmin_sizer$  size_percentr_  r:   r@  r  )rM  r   r#  r   rZ  r   )r   rL  r^  ra  r   r_  r~   r-   r   r   rN  r   r2   r3   r     s*   


zCoarseDropout.__init__	r[  NNFr:   NNr   r   r  r2   r2   r   r3   rZ    s     rZ  c                       s@   e Zd ZdZ			d fdd	Zdd	 Zd
d Zdd Z  ZS )	Dropout2da4  Drop random channels from images.

    For image data, dropped channels will be filled with zeros.

    .. note::

        This augmenter may also set the arrays of heatmaps and segmentation
        maps to zero and remove all coordinate-based data (e.g. it removes
        all bounding boxes on images that were filled with zeros).
        It does so if and only if *all* channels of an image are dropped.
        If ``nb_keep_channels >= 1`` then that never happens.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    p : float or tuple of float or imgaug.parameters.StochasticParameter, optional
        The probability of any channel to be dropped (i.e. set to zero).

            * If a ``float``, then that value will be used for all channels.
              A value of ``1.0`` would mean, that all channels will be dropped.
              A value of ``0.0`` would lead to no channels being dropped.
            * If a tuple ``(a, b)``, then a value ``p`` will be sampled from
              the interval ``[a, b)`` per batch and be used as the dropout
              probability.
            * If a list, then a value will be sampled from that list per
              batch and used as the probability.
            * If a ``StochasticParameter``, then this parameter will be used to
              determine per channel whether it should be *kept* (sampled value
              of ``>=0.5``) or shouldn't be kept (sampled value of ``<0.5``).
              If you instead want to provide the probability as a stochastic
              parameter, you can usually do ``imgaug.parameters.Binomial(1-p)``
              to convert parameter `p` to a 0/1 representation.

    nb_keep_channels : int
        Minimum number of channels to keep unaltered in all images.
        E.g. a value of ``1`` means that at least one channel in every image
        will not be dropped, even if ``p=1.0``. Set to ``0`` to allow dropping
        all channels.

    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.Dropout2d(p=0.5)

    Create a dropout augmenter that drops on average half of all image
    channels. Dropped channels will be filled with zeros. At least one
    channel is kept unaltered in each image (default setting).

    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.Dropout2d(p=0.5, nb_keep_channels=0)

    Create a dropout augmenter that drops on average half of all image
    channels *and* may drop *all* channels in an image (i.e. images may
    contain nothing but zeros).

    r\  r   Nr   c                    sj   t t| j||||d t|d| _t|d| _d| _d| _d| _	d| _
d| _d| _d| _d| _d| _d S )Nr   rL  r   Tr   )r   rd  r   rM  rL  rm   nb_keep_channels_drop_images_drop_heatmaps_drop_segmentation_maps_drop_keypoints_drop_bounding_boxes_drop_polygons_drop_line_strings_heatmaps_cval_segmentation_maps_cval)r   rL  re  r~   r-   r   r   r   r2   r3   r   &  s   

zDropout2d.__init__c                 C   s  |  ||\}}|jd ur#t|j|D ]\}}d|d d d d |f< qt|dkr+|S |jd urC| jrC| j}	|D ]
}
|	|j|
 jd< q8|jd ur[| j	r[| j
}	|D ]
}
|	|j|
 jd< qPdD ]"}t| d|f }t||}|d ur|r|D ]
}
t||
 |g  qtq]|S Nr   .)Z	keypointsZbounding_boxesZpolygonsZline_stringsz_drop_%s)r;  r   r   rg   heatmapsrg  rm  arr_0to1segmentation_mapsrh  rn  r   r   setattr)r   r   r   r   r   Zimagewise_drop_channel_idsall_dropped_idsr0   drop_idsr|   drop_idx	attr_namedo_drop
attr_valuer2   r2   r3   r   ;  s4   

zDropout2d._augment_batch_c                 C   s   |  }dd |D }tjdd |D tjd}| jjtt|f|d}g }g }d}t|D ]D\}	}
||||
  }t	|dk d }t
|
| j d}t||kr^|| |d | }|| t||
k}|rp||	 ||
7 }q0||fS )Nc                 S   s.   g | ]}t |d kr|ntt|dg qS )r   r   )rg   rF  r   rR  r@   r2   r2   r3   rT  d  s    z+Dropout2d._draw_samples.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )r   r2   rz  r2   r2   r3   rT  h  s    r9   r   r   r   )Zget_rowwise_shapesr(   rU   r   rL  r   r   rE  r   nonzerorm   re  rg   shuffleappend)r   r   r   ZshapesZimagewise_channelsZ	p_samplesZimagewise_channels_to_droprt  Zchannel_idxr   rJ   Zp_samples_iru  Znb_dropableZall_droppedr2   r2   r3   r;  `  s8   
	



zDropout2d._draw_samplesc                 C   r   r   )rL  re  r   r2   r2   r3   r     r   zDropout2d.get_parameters)r\  r   NNr   r   )	r   r  r  r  r   r   r;  r   r  r2   r2   r   r3   rd    s    \%,rd  c                       sL   e Zd ZdZ			d fdd	Zdd Zd	d
 Zedd Zdd Z	  Z
S )TotalDropouta  Drop all channels of a defined fraction of all images.

    For image data, all components of dropped images will be filled with zeros.

    .. note::

        This augmenter also sets the arrays of heatmaps and segmentation
        maps to zero and removes all coordinate-based data (e.g. it removes
        all bounding boxes on images that were filled with zeros).

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    p : float or tuple of float or imgaug.parameters.StochasticParameter, optional
        The probability of an image to be filled with zeros.

            * If ``float``: The value will be used for all images.
              A value of ``1.0`` would mean that all images will be set to zero.
              A value of ``0.0`` would lead to no images being set to zero.
            * If ``tuple`` ``(a, b)``: A value ``p`` will be sampled from
              the interval ``[a, b)`` per batch and be used as the dropout
              probability.
            * If a list, then a value will be sampled from that list per
              batch and used as the probability.
            * If ``StochasticParameter``: The parameter will be used to
              determine per image whether it should be *kept* (sampled value
              of ``>=0.5``) or shouldn't be kept (sampled value of ``<0.5``).
              If you instead want to provide the probability as a stochastic
              parameter, you can usually do ``imgaug.parameters.Binomial(1-p)``
              to convert parameter `p` to a 0/1 representation.

    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.TotalDropout(1.0)

    Create an augmenter that sets *all* components of all images to zero.

    >>> aug = iaa.TotalDropout(0.5)

    Create an augmenter that sets *all* components of ``50%`` of all images to
    zero.

    r   Nr   c                    s^   t t| j||||d t|d| _d| _d| _d| _d| _d| _	d| _
d| _d| _d| _d S )Nr   rL  Tr   r   )r   r~  r   rM  rL  rf  rg  rh  ri  rj  rk  rl  rm  rn  r   rL  r~   r-   r   r   r   r2   r3   r     s   

zTotalDropout.__init__c                 C   s2  |  ||}d }|jd ur0| jr0t|jrd|j|df< n| ||}|D ]	}d|j| d< q&|jd urN| jrN| ||}| j}|D ]
}||j| j	d< qC|j
d url| jrl| ||}| j}|D ]
}||j
| jd< qadD ](}	t| d|	f }
t||	}|d ur|
r| ||}|D ]
}t|| |	g  qqn|S ro  )r;  r   rf  r;   r>   _generate_drop_ids_oncerp  rg  rm  rq  rr  rh  rn  r   r   rs  )r   r   r   r   r   	drop_maskru  rv  r|   rw  rx  ry  r2   r2   r3   r     s6   
zTotalDropout._augment_batch_c                 C   s    | j j|jf|d}|dk }|S )Nr   r   )rL  r   rG  )r   r   r   rL  r  r2   r2   r3   r;    s   zTotalDropout._draw_samplesc                 C   s   |d u rt |d }|S r   )r(   r{  )r:  r  ru  r2   r2   r3   r  "  s   z$TotalDropout._generate_drop_ids_oncec                 C      | j gS r   )rL  r   r2   r2   r3   r   )     zTotalDropout.get_parameters)r   NNr   r   )r   r  r  r  r   r   r;  rI  r  r   r  r2   r2   r   r3   r~    s    P&
r~  c                       8   e Zd ZdZ			d fdd	Zdd Zd	d
 Z  ZS )ReplaceElementwisea+  
    Replace pixels in an image with new values.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.replace_elementwise_`.

    Parameters
    ----------
    mask : float or tuple of float or list of float or imgaug.parameters.StochasticParameter
        Mask that indicates the pixels that are supposed to be replaced.
        The mask will be binarized using a threshold of ``0.5``. A value
        of ``1`` then indicates a pixel that is supposed to be replaced.

            * If this is a float, then that value will be used as the
              probability of being a ``1`` in the mask (sampled per image and
              pixel) and hence being replaced.
            * If a tuple ``(a, b)``, then the probability will be uniformly
              sampled per image from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image and pixel.
            * If a ``StochasticParameter``, then this parameter will be used to
              sample a mask per image.

    replacement : number or tuple of number or list of number or imgaug.parameters.StochasticParameter
        The replacement to use at all locations that are marked as ``1`` in
        the mask.

            * If this is a number, then that value will always be used as the
              replacement.
            * If a tuple ``(a, b)``, then the replacement will be sampled
              uniformly per image and pixel from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image and pixel.
            * If a ``StochasticParameter``, then this parameter will be used
              sample replacement values per image and pixel.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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 = ReplaceElementwise(0.05, [0, 255])

    Replaces ``5`` percent of all pixels in each image by either ``0``
    or ``255``.

    >>> import imgaug.augmenters as iaa
    >>> aug = ReplaceElementwise(0.1, [0, 255], per_channel=0.5)

    For ``50%`` of all images, replace ``10%`` of all pixels with either the
    value ``0`` or the value ``255`` (same as in the previous example). For
    the other ``50%`` of all images, replace *channelwise* ``10%`` of all
    pixels with either the value ``0`` or the value ``255``. So, it will be
    very rare for each pixel to have all channels replaced by ``255`` or
    ``0``.

    >>> import imgaug.augmenters as iaa
    >>> import imgaug.parameters as iap
    >>> aug = ReplaceElementwise(0.1, iap.Normal(128, 0.4*128), per_channel=0.5)

    Replace ``10%`` of all pixels by gaussian noise centered around ``128``.
    Both the replacement mask and the gaussian noise are sampled channelwise
    for ``50%`` of all images.

    >>> import imgaug.augmenters as iaa
    >>> import imgaug.parameters as iap
    >>> aug = ReplaceElementwise(
    >>>     iap.FromLowerResolution(iap.Binomial(0.1), size_px=8),
    >>>     iap.Normal(128, 0.4*128),
    >>>     per_channel=0.5)

    Replace ``10%`` of all pixels by gaussian noise centered around ``128``.
    Sample the replacement mask at a lower resolution (``8x8`` pixels) and
    upscale it to the image size, resulting in coarse areas being replaced by
    gaussian noise.

    FNr   c                    sL   t t| j||||d tj|dddd| _t|d| _t|d| _d S )Nr   r   Tr   r   replacementr   )	r   r  r   r   r   r   r   r  r   )r   r   r  r   r~   r-   r   r   r   r2   r3   r     s   

zReplaceElementwise.__init__c              	   C   s2  |j d u r|S |j }t|}|dd|  }| jj|f|d d}tt|||dd d |dd d }	|	D ]_\}
\}}}}|j\}}}|||dkrM|ndf}| jj||d}|dkr|jd }| j	jt
t|d d d d df f|d}t||}n| j	jt
t|f|d}t||||j |
< q7|S )Nr   r   r   r   r   r5   )r   rg   r   r   r   r   r   r@   r   r  r   r(   rE  repeatr   )r   r   r   r   r   r   r   r   r   r   r   r0   Zper_channel_iZrs_maskZrs_replacementr   r   rJ   Zsampling_shapeZmask_samplesr   r2   r2   r3   r     sD   

&
 	z"ReplaceElementwise._augment_batch_c                 C   s   | j | j| jgS r   )r   r  r   r   r2   r2   r3   r     s   z!ReplaceElementwise.get_parameters)FNNr   r   r   r2   r2   r   r3   r  .  s    i,r  c                       r  )	SaltAndPeppera:  
    Replace pixels in images with salt/pepper noise (white/black-ish colors).

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.ReplaceElementwise`.

    Parameters
    ----------
    p : float or tuple of float or list of float or imgaug.parameters.StochasticParameter, optional
        Probability of replacing a pixel to salt/pepper noise.

            * If a float, then that value will always be used as the
              probability.
            * If a tuple ``(a, b)``, then a probability will be sampled
              uniformly per image from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then a image-sized mask will be
              sampled from that parameter per image. Any value ``>0.5`` in
              that mask will be replaced with salt and pepper noise.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.SaltAndPepper(0.05)

    Replace ``5%`` of all pixels with salt and pepper noise.

    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.SaltAndPepper(0.05, per_channel=True)

    Replace *channelwise* ``5%`` of all pixels with salt and pepper
    noise.

    r   gQ?FNr   c              	      s.   t t| j|tddd |||||d d S )Nr   r7   r   r  r   r~   r-   r   r   )r   r  r   r   Beta)r   rL  r   r~   r-   r   r   r   r2   r3   r     s   

zSaltAndPepper.__init__r  FNNr   r   r  r2   r2   r   r3   r    s    @r  c                       s(   e Zd ZdZ			d fdd	Z  ZS )ImpulseNoisea  
    Add impulse noise to images.

    This is identical to ``SaltAndPepper``, except that `per_channel` is
    always set to ``True``.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.SaltAndPepper`.

    Parameters
    ----------
    p : float or tuple of float or list of float or imgaug.parameters.StochasticParameter, optional
        Probability of replacing a pixel to impulse noise.

            * If a float, then that value will always be used as the
              probability.
            * If a tuple ``(a, b)``, then a probability will be sampled
              uniformly per image from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then a image-sized mask will be
              sampled from that parameter per image. Any value ``>0.5`` in
              that mask will be replaced with impulse noise noise.

    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.ImpulseNoise(0.1)

    Replace ``10%`` of all pixels with impulse noise.

    r  Nr   c                    s    t t| j|d||||d d S )NT)rL  r   r~   r-   r   r   )r   r  r   r  r   r2   r3   r   X  s   

zImpulseNoise.__init__)r  NNr   r   r  r2   r2   r   r3   r  $  s    3r  c                       rY  )
CoarseSaltAndPeppera  
    Replace rectangular areas in images with white/black-ish pixel noise.

    This adds salt and pepper noise (noisy white-ish and black-ish pixels) to
    rectangular areas within the image. Note that this means that within these
    rectangular areas the color varies instead of each rectangle having only
    one color.

    See also the similar ``CoarseDropout``.

    TODO replace dtype support with uint8 only, because replacement is
         geared towards that value range

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.ReplaceElementwise`.

    Parameters
    ----------
    p : float or tuple of float or list of float or imgaug.parameters.StochasticParameter, optional
        Probability of changing a pixel to salt/pepper noise.

            * If a float, then that value will always be used as the
              probability.
            * If a tuple ``(a, b)``, then a probability will be sampled
              uniformly per image from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then a lower-resolution mask will
              be sampled from that parameter per image. Any value ``>0.5`` in
              that mask will denote a spatial location that is to be replaced
              by salt and pepper noise.

    size_px : int or tuple of int or imgaug.parameters.StochasticParameter, optional
        The size of the lower resolution image from which to sample the
        replacement mask in absolute pixel dimensions.
        Note that this means that *lower* values of this parameter lead to
        *larger* areas being replaced (as any pixel in the lower resolution
        image will correspond to a larger area at the original resolution).

            * If ``None`` then `size_percent` must be set.
            * If an integer, then that size will always be used for both height
              and width. E.g. a value of ``3`` would lead to a ``3x3`` mask,
              which is then upsampled to ``HxW``, where ``H`` is the image size
              and ``W`` the image width.
            * If a tuple ``(a, b)``, then two values ``M``, ``N`` will be
              sampled from the discrete interval ``[a..b]``. The mask
              will then be generated at size ``MxN`` and upsampled to ``HxW``.
            * If a ``StochasticParameter``, then this parameter will be used to
              determine the sizes. It is expected to be discrete.

    size_percent : float or tuple of float or imgaug.parameters.StochasticParameter, optional
        The size of the lower resolution image from which to sample the
        replacement mask *in percent* of the input image.
        Note that this means that *lower* values of this parameter lead to
        *larger* areas being replaced (as any pixel in the lower resolution
        image will correspond to a larger area at the original resolution).

            * If ``None`` then `size_px` must be set.
            * If a float, then that value will always be used as the percentage
              of the height and width (relative to the original size). E.g. for
              value ``p``, the mask will be sampled from ``(p*H)x(p*W)`` and
              later upsampled to ``HxW``.
            * If a tuple ``(a, b)``, then two values ``m``, ``n`` will be
              sampled from the interval ``(a, b)`` and used as the size
              fractions, i.e the mask size will be ``(m*H)x(n*W)``.
            * If a ``StochasticParameter``, then this parameter will be used to
              sample the percentage values. It is expected to be continuous.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    min_size : int, optional
        Minimum height and width of the low resolution mask. If
        `size_percent` or `size_px` leads to a lower value than this,
        `min_size` will be used instead. This should never have a value of
        less than ``2``, otherwise one may end up with a ``1x1`` low resolution
        mask, leading easily to the whole image being replaced.

    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.CoarseSaltAndPepper(0.05, size_percent=(0.01, 0.1))

    Marks ``5%`` of all pixels in a mask to be replaced by salt/pepper
    noise. The mask has ``1%`` to ``10%`` the size of the input image.
    The mask is then upscaled to the input image size, leading to large
    rectangular areas being marked as to be replaced. These areas are then
    replaced in the input image by salt/pepper noise.

    >>> aug = iaa.CoarseSaltAndPepper(0.05, size_px=(4, 16))

    Same as in the previous example, but the replacement mask before upscaling
    has a size between ``4x4`` and ``16x16`` pixels (the axis sizes are sampled
    independently, i.e. the mask may be rectangular).

    >>> aug = iaa.CoarseSaltAndPepper(
    >>>    0.05, size_percent=(0.01, 0.1), per_channel=True)

    Same as in the first example, but mask and replacement are each sampled
    independently per image channel.

    r[  NFr:   r   c
              	      s   t j|dddd}
|d urt j|
||d}n|d ur#t j|
||d}nt j|
d|d}t ddd }tt| j|||||||	d	 d S )
NrL  Tr  r]  r`  rb  r   r7   r  )r   r   r#  r  r   r  r   )r   rL  r^  ra  r   r_  r~   r-   r   r   r   mask_lowr  r   r2   r3   r     s,   

zCoarseSaltAndPepper.__init__rc  r  r2   r2   r   r3   r  b  s     r  c                       r  )	Salta
  
    Replace pixels in images with salt noise, i.e. white-ish pixels.

    This augmenter is similar to ``SaltAndPepper``, but adds no pepper noise to
    images.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.ReplaceElementwise`.

    Parameters
    ----------
    p : float or tuple of float or list of float or imgaug.parameters.StochasticParameter, optional
        Probability of replacing a pixel with salt noise.

            * If a float, then that value will always be used as the
              probability.
            * If a tuple ``(a, b)``, then a probability will be sampled
              uniformly per image from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then a image-sized mask will be
              sampled from that parameter per image. Any value ``>0.5`` in
              that mask will be replaced with salt noise.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.Salt(0.05)

    Replace ``5%`` of all pixels with salt noise (white-ish colors).

    r  FNr   c           	   	      J   t jt ddd dddd }|d }tt| j|||||||d d S )Nr   Tr   Zpositiver   r7   r  )r   	ForceSignr  r   r  r   	r   rL  r   r~   r-   r   r   replacement01r  r   r2   r3   r   >  s   

zSalt.__init__r  r  r2   r2   r   r3   r    s    >r  c                       rY  )

CoarseSaltav  
    Replace rectangular areas in images with white-ish pixel noise.

    See also the similar ``CoarseSaltAndPepper``.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.ReplaceElementwise`.

    Parameters
    ----------
    p : float or tuple of float or list of float or imgaug.parameters.StochasticParameter, optional
        Probability of changing a pixel to salt noise.

            * If a float, then that value will always be used as the
              probability.
            * If a tuple ``(a, b)``, then a probability will be sampled
              uniformly per image from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then a lower-resolution mask will
              be sampled from that parameter per image. Any value ``>0.5`` in
              that mask will denote a spatial location that is to be replaced
              by salt noise.

    size_px : int or tuple of int or imgaug.parameters.StochasticParameter, optional
        The size of the lower resolution image from which to sample the
        replacement mask in absolute pixel dimensions.
        Note that this means that *lower* values of this parameter lead to
        *larger* areas being replaced (as any pixel in the lower resolution
        image will correspond to a larger area at the original resolution).

            * If ``None`` then `size_percent` must be set.
            * If an integer, then that size will always be used for both height
              and width. E.g. a value of ``3`` would lead to a ``3x3`` mask,
              which is then upsampled to ``HxW``, where ``H`` is the image size
              and ``W`` the image width.
            * If a tuple ``(a, b)``, then two values ``M``, ``N`` will be
              sampled from the discrete interval ``[a..b]``. The mask
              will then be generated at size ``MxN`` and upsampled to ``HxW``.
            * If a ``StochasticParameter``, then this parameter will be used to
              determine the sizes. It is expected to be discrete.

    size_percent : float or tuple of float or imgaug.parameters.StochasticParameter, optional
        The size of the lower resolution image from which to sample the
        replacement mask *in percent* of the input image.
        Note that this means that *lower* values of this parameter lead to
        *larger* areas being replaced (as any pixel in the lower resolution
        image will correspond to a larger area at the original resolution).

            * If ``None`` then `size_px` must be set.
            * If a float, then that value will always be used as the percentage
              of the height and width (relative to the original size). E.g. for
              value ``p``, the mask will be sampled from ``(p*H)x(p*W)`` and
              later upsampled to ``HxW``.
            * If a tuple ``(a, b)``, then two values ``m``, ``n`` will be
              sampled from the interval ``(a, b)`` and used as the size
              fractions, i.e the mask size will be ``(m*H)x(n*W)``.
            * If a ``StochasticParameter``, then this parameter will be used to
              sample the percentage values. It is expected to be continuous.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    min_size : int, optional
        Minimum height and width of the low resolution mask. If
        `size_percent` or `size_px` leads to a lower value than this,
        `min_size` will be used instead. This should never have a value of
        less than ``2``, otherwise one may end up with a ``1x1`` low resolution
        mask, leading easily to the whole image being replaced.

    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.CoarseSalt(0.05, size_percent=(0.01, 0.1))

    Mark ``5%`` of all pixels in a mask to be replaced by salt
    noise. The mask has ``1%`` to ``10%`` the size of the input image.
    The mask is then upscaled to the input image size, leading to large
    rectangular areas being marked as to be replaced. These areas are then
    replaced in the input image by salt noise.

    r[  NFr:   r   c
              	      s   t j|dddd}
|d urt j|
||d}n|d ur#t j|
||d}nt j|
d|d}t jt ddd ddd	d }|d
 }tt| j|||||||	d d S )NrL  Tr  r]  r`  rb  r   r   r  r7   r  )r   r   r#  r  r  r   r  r   r   rL  r^  ra  r   r_  r~   r-   r   r   r   r  r  r  r   r2   r3   r     :   

zCoarseSalt.__init__rc  r  r2   r2   r   r3   r  Q  s    mr  c                       r  )	Peppera@  
    Replace pixels in images with pepper noise, i.e. black-ish pixels.

    This augmenter is similar to ``SaltAndPepper``, but adds no salt noise to
    images.

    This augmenter is similar to ``Dropout``, but slower and the black pixels
    are not uniformly black.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.ReplaceElementwise`.

    Parameters
    ----------
    p : float or tuple of float or list of float or imgaug.parameters.StochasticParameter, optional
        Probability of replacing a pixel with pepper noise.

            * If a float, then that value will always be used as the
              probability.
            * If a tuple ``(a, b)``, then a probability will be sampled
              uniformly per image from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then a image-sized mask will be
              sampled from that parameter per image. Any value ``>0.5`` in
              that mask will be replaced with pepper noise.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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.Pepper(0.05)

    Replace ``5%`` of all pixels with pepper noise (black-ish colors).

    rK  FNr   c           	   	      r  )Nr   Fr   r  r7   r  )r   r  r  r   r  r   r  r   r2   r3   r   !  s   

zPepper.__init__rO  r  r2   r2   r   r3   r    s    Ar  c                       rY  )
CoarsePepperaT  
    Replace rectangular areas in images with black-ish pixel noise.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.ReplaceElementwise`.

    Parameters
    ----------
    p : float or tuple of float or list of float or imgaug.parameters.StochasticParameter, optional
        Probability of changing a pixel to pepper noise.

            * If a float, then that value will always be used as the
              probability.
            * If a tuple ``(a, b)``, then a probability will be sampled
              uniformly per image from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then a lower-resolution mask will
              be sampled from that parameter per image. Any value ``>0.5`` in
              that mask will denote a spatial location that is to be replaced
              by pepper noise.

    size_px : int or tuple of int or imgaug.parameters.StochasticParameter, optional
        The size of the lower resolution image from which to sample the
        replacement mask in absolute pixel dimensions.
        Note that this means that *lower* values of this parameter lead to
        *larger* areas being replaced (as any pixel in the lower resolution
        image will correspond to a larger area at the original resolution).

            * If ``None`` then `size_percent` must be set.
            * If an integer, then that size will always be used for both height
              and width. E.g. a value of ``3`` would lead to a ``3x3`` mask,
              which is then upsampled to ``HxW``, where ``H`` is the image size
              and ``W`` the image width.
            * If a tuple ``(a, b)``, then two values ``M``, ``N`` will be
              sampled from the discrete interval ``[a..b]``. The mask
              will then be generated at size ``MxN`` and upsampled to ``HxW``.
            * If a ``StochasticParameter``, then this parameter will be used to
              determine the sizes. It is expected to be discrete.

    size_percent : float or tuple of float or imgaug.parameters.StochasticParameter, optional
        The size of the lower resolution image from which to sample the
        replacement mask *in percent* of the input image.
        Note that this means that *lower* values of this parameter lead to
        *larger* areas being replaced (as any pixel in the lower resolution
        image will correspond to a larger area at the original resolution).

            * If ``None`` then `size_px` must be set.
            * If a float, then that value will always be used as the percentage
              of the height and width (relative to the original size). E.g. for
              value ``p``, the mask will be sampled from ``(p*H)x(p*W)`` and
              later upsampled to ``HxW``.
            * If a tuple ``(a, b)``, then two values ``m``, ``n`` will be
              sampled from the interval ``(a, b)`` and used as the size
              fractions, i.e the mask size will be ``(m*H)x(n*W)``.
            * If a ``StochasticParameter``, then this parameter will be used to
              sample the percentage values. It is expected to be continuous.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    min_size : int, optional
        Minimum size of the low resolution mask, both width and height. If
        `size_percent` or `size_px` leads to a lower value than this, `min_size`
        will be used instead. This should never have a value of less than 2,
        otherwise one may end up with a ``1x1`` low resolution mask, leading
        easily to the whole image being replaced.

    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.CoarsePepper(0.05, size_percent=(0.01, 0.1))

    Mark ``5%`` of all pixels in a mask to be replaced by pepper
    noise. The mask has ``1%`` to ``10%`` the size of the input image.
    The mask is then upscaled to the input image size, leading to large
    rectangular areas being marked as to be replaced. These areas are then
    replaced in the input image by pepper noise.

    r[  NFr:   r   c
              	      s   t j|dddd}
|d urt j|
||d}n|d ur#t j|
||d}nt j|
d|d}t jt ddd dd	d
d }|d }tt| j|||||||	d d S )NrL  Tr  r]  r`  rb  r   Fr   r  r7   r  )r   r   r#  r  r  r   r  r   r  r   r2   r3   r     r  zCoarsePepper.__init__rc  r  r2   r2   r   r3   r  3  s    kr  c                	       sp   e Zd ZdZdd ejejejejej	ej
ejejfD Z				d fd	d
	Zdd Zdd Zdd Z  ZS )Inverta  
    Invert all values in images, e.g. turn ``5`` into ``255-5=250``.

    For the standard value range of 0-255 it converts ``0`` to ``255``,
    ``255`` to ``0`` and ``10`` to ``(255-10)=245``.
    Let ``M`` be the maximum value possible, ``m`` the minimum value possible,
    ``v`` a value. Then the distance of ``v`` to ``m`` is ``d=abs(v-m)`` and
    the new value is given by ``v'=M-d``.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.invert_`.

    Parameters
    ----------
    p : float or imgaug.parameters.StochasticParameter, optional
        The probability of an image to be inverted.

            * If a float, then that probability will be used for all images,
              i.e. `p` percent of all images will be inverted.
            * If a ``StochasticParameter``, then that parameter will be queried
              per image and is expected to return values in the interval
              ``[0.0, 1.0]``, where values ``>0.5`` mean that the image
              is supposed to be inverted. Recommended to be some form of
              ``imgaug.parameters.Binomial``.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    min_value : None or number, optional
        Minimum of the value range of input images, e.g. ``0`` for ``uint8``
        images. If set to ``None``, the value will be automatically derived
        from the image's dtype.

    max_value : None or number, optional
        Maximum of the value range of input images, e.g. ``255`` for ``uint8``
        images. If set to ``None``, the value will be automatically derived
        from the image's dtype.

    threshold : None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        A threshold to use in order to invert only numbers above or below
        the threshold. If ``None`` no thresholding will be used.

            * If ``None``: No thresholding will be used.
            * 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.

    invert_above_threshold : bool or float or imgaug.parameters.StochasticParameter, optional
        If ``True``, only values ``>=threshold`` will be inverted.
        Otherwise, only values ``<threshold`` will be inverted.
        If a ``number``, then expected to be in the interval ``[0.0, 1.0]`` and
        denoting an imagewise probability. If a ``StochasticParameter`` then
        ``(N,)`` values will be sampled from the parameter per batch of size
        ``N`` and interpreted as ``True`` if ``>0.5``.
        If `threshold` is ``None`` this parameter has no effect.

    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.Invert(0.1)

    Inverts the colors in ``10`` percent of all images.

    >>> aug = iaa.Invert(0.1, per_channel=True)

    Inverts the colors in ``10`` percent of all image channels. This may or
    may not lead to multiple channels in an image being inverted.

    >>> aug = iaa.Invert(0.1, per_channel=0.5)

    Identical to the previous example, but the `per_channel` feature is only
    active for 50 percent of all images.

    c                 C   rP  r2   )r(   r,   )rR  dtr2   r2   r3   rT  2  s    
zInvert.<listcomp>r   FNr   r   c                    sx   t t| j|||	|
d t|d| _t|d| _|| _|| _|d u r(d | _	ntj
|dd ddd| _	t|d| _d S )Nr   rL  r   r   Tr   r   )r   r  r   r   r   rL  r   r   r   r   r   r   r   rL  r   r   r   r   r   r~   r-   r   r   r   r2   r3   r   :  s&   

zInvert.__init__c                 C   s   |j d u r|S | ||}t|j D ][\}}d|jv rq|j| |j| |j| |j| d}|j| rS|jd }	|j	|d |	f }
t
|d|
f fi ||d|
f< q|j	|df rmt
|fi ||d d d d d d f< q|S )Nr   r   r   .)r   r;  r   r@   r   r   r   r   r   rL  r   )r   r   r   r   r   r=  r   r0   kwargsrJ   r   r2   r2   r3   r   S  s&   



"&zInvert._augment_batch_c                 C   s   |j }t|j}| jj||f|d}|dk}| jj|f|d}|dk}| jg| }| jg| }| j	d u r;d g| }	n	| j	j|f|d}	| j
j|f|d}
|
dk}
t|||||	|
dS )Nr   r   rL  r   r   r   r   r   )rG  r   r   r   rL  r   r   r   r   r   r   _InvertSamples)r   r   r   r   rJ   rL  r   r   r   r   r   r2   r2   r3   r;  o  s:   

zInvert._draw_samplesc                 C   s   | j | j| j| j| j| jgS r   r  r   r2   r2   r3   r     s   zInvert.get_parameters)
r   FNNNr   NNr   r   )r   r  r  r  r(   r   r   r   r   r   r   r   r   ZALLOW_DTYPES_CUSTOM_MINMAXr   r   r;  r   r  r2   r2   r   r3   r    s     rr  c                   @   r%  )r  c                 C   s(   || _ || _|| _|| _|| _|| _d S r   r  )r   rL  r   r   r   r   r   r2   r2   r3   r     s   
z_InvertSamples.__init__Nr.  r2   r2   r2   r3   r    r/  r  c                       s*   e Zd ZdZ				d
 fdd		Z  ZS )Solarizea  Invert all pixel values above a threshold.

    This is the same as :class:`Invert`, but sets a default threshold around
    ``128`` (+/- 64, decided per image) and default `invert_above_threshold`
    to ``True`` (i.e. only values above the threshold will be inverted).

    See :class:`Invert` for more details.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.arithmetic.Invert`.

    Parameters
    ----------
    p : float or imgaug.parameters.StochasticParameter
        See :class:`Invert`.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        See :class:`Invert`.

    min_value : None or number, optional
        See :class:`Invert`.

    max_value : None or number, optional
        See :class:`Invert`.

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

    invert_above_threshold : bool or float or imgaug.parameters.StochasticParameter, optional
        See :class:`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   FN@      Tr   c                    s(   t t| j|||||||||	|
d
 d S )N)
rL  r   r   r   r   r   r~   r-   r   r   )r   r  r   r  r   r2   r3   r     s   

zSolarize.__init__)
r   FNNr  TNNr   r   r  r2   r2   r   r3   r    s    =r  zimgaug.contrast.LinearContrastr   r   c                 C   s"   ddl m} |j| |||||dS )aZ  
    Change the contrast of images.

    dtype support:

        See ``imgaug.augmenters.contrast.LinearContrast``.

    Deprecated since 0.3.0.

    Parameters
    ----------
    alpha : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Strength of the contrast normalization. Higher values than 1.0
        lead to higher contrast, lower values decrease the contrast.

            * If a number, then that value will be used for all images.
            * If a tuple ``(a, b)``, then a value will be sampled per image
              uniformly from the interval ``[a, b]`` and be used as the alpha
              value.
            * If a list, then a random value will be picked per image from
              that list.
            * If a ``StochasticParameter``, then this parameter will be used to
              sample the alpha value per image.

    per_channel : bool or float or imgaug.parameters.StochasticParameter, optional
        Whether to use (imagewise) the same sample(s) for all
        channels (``False``) or to sample value(s) for each channel (``True``).
        Setting this to ``True`` will therefore lead to different
        transformations per image *and* channel, otherwise only per image.
        If this value is a float ``p``, then for ``p`` percent of all images
        `per_channel` will be treated as ``True``.
        If it is a ``StochasticParameter`` it is expected to produce samples
        with values between ``0.0`` and ``1.0``, where values ``>0.5`` will
        lead to per-channel behaviour (i.e. same as ``True``).

    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
    >>> iaa.ContrastNormalization((0.5, 1.5))

    Decreases oder improves contrast per image by a random factor between
    ``0.5`` and ``1.5``. The factor ``0.5`` means that any difference from
    the center value (i.e. 128) will be halved, leading to less contrast.

    >>> iaa.ContrastNormalization((0.5, 1.5), per_channel=0.5)

    Same as before, but for 50 percent of all images the normalization is done
    independently per channel (i.e. factors can vary per channel for the same
    image). In the other 50 percent of all images, the factor is the same for
    all channels.

    r   )contrast)alphar   r~   r-   r   r   ) r  ZLinearContrast)r  r   r~   r-   r   r   Zcontrast_libr2   r2   r3   ContrastNormalization  s
   Lr  c                       r  )JpegCompressiona  
    Degrade the quality of images by JPEG-compressing them.

    During JPEG compression, high frequency components (e.g. edges) are removed.
    With low compression (strength) only the highest frequency components are
    removed, while very high compression (strength) will lead to only the
    lowest frequency components "surviving". This lowers the image quality.
    For more details, see https://en.wikipedia.org/wiki/Compression_artifact.

    Note that this augmenter still returns images as numpy arrays (i.e. saves
    the images with JPEG compression and then reloads them into arrays). It
    does not return the raw JPEG file content.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.arithmetic.compress_jpeg`.

    Parameters
    ----------
    compression : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Degree of compression used during JPEG compression within value range
        ``[0, 100]``. Higher values denote stronger compression and will cause
        low-frequency components to disappear. Note that JPEG's compression
        strength is also often set as a *quality*, which is the inverse of this
        parameter. Common choices for the *quality* setting are around 80 to 95,
        depending on the image. This translates here to a *compression*
        parameter of around 20 to 5.

            * If a single number, then that value always will be used as the
              compression.
            * If a tuple ``(a, b)``, then the compression will be
              a value sampled uniformly from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image and used as the compression.
            * If a ``StochasticParameter``, then ``N`` samples will be drawn
              from that parameter per ``N`` input images, each representing the
              compression for the ``n``-th image.

    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.JpegCompression(compression=(70, 99))

    Remove high frequency components in images via JPEG compression with
    a *compression strength* between ``70`` and ``99`` (randomly and
    uniformly sampled per image). This corresponds to a (very low) *quality*
    setting of ``1`` to ``30``.

    r   re   Nr   c                    s2   t t| j||||d tj|ddddd| _d S )Nr   r   r  Tr   )r   r  r   r   r   r   )r   r   r~   r-   r   r   r   r2   r3   r     s   
zJpegCompression.__init__c                 C   sb   |j d u r|S |j }t|}| jj|f|d}tt||D ]\}\}	}
t|	t|
|j |< q|S )Nr   )r   rg   r   r   r   r   r   r   )r   r   r   r   r   r   r   r=  r   r0   sampler2   r2   r3   r     s   

zJpegCompression._augment_batch_c                 C   r  r   )r   r   r2   r2   r3   r     r  zJpegCompression.get_parameters)r  NNr   r   r   r2   r2   r   r3   r  ?  s    Cr  )r   r   FN)NNNT)r   )r   FNNr   r   )Or  
__future__r   r   r   r   r   numpyr(   Zimgaugr;   r  r   r   r   r	   r*   r
   r   r   r4   r.   r/   rb   r_   r`   rl   ri   rj   rs   rp   rq   r   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Z	Augmenterr   r  r	  r  r  r  r!  objectr&  r0  rJ  rM  rZ  rd  r~  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r2   r2   r2   r3   <module>   s    =++9*K*2I.
=
]B.o
$
 	(	

"e ~p|o    O]% 3 I  +L> R T  WKR