o
    &j}                    @   s  d Z ddlmZmZmZ ddl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lmZ ddlmZ dd Zd[ddZdd Zdd ZG dd dejZ G dd dejZ!G dd de!Z"G dd de"Z#G dd de"Z$G d d! d!e!Z%G d"d# d#e!Z&G d$d% d%e!Z'G d&d' d'e!Z(G d(d) d)e!Z)G d*d+ d+e!Z*G d,d- d-e!Z+e
,eG d.d/ d/e-Z.G d0d1 d1e.Z/G d2d3 d3e.Z0G d4d5 d5e.Z1G d6d7 d7e1Z2G d8d9 d9e1Z3G d:d; d;e.Z4G d<d= d=e.Z5G d>d? d?e.Z6G d@dA dAe.Z7G dBdC dCe.Z8ej9dDdEdF	G		Hd\dIdDZ:ej9dJdKdF	G		Hd\dLdJZ;ej9ddMdF	G		P			Hd]dRdSZ<ej9ddTdFdUdddGdVddOdWdPgdXddddHdHfdYdZZ=dS )^a  
Augmenters that blend two images with each other.

List of augmenters:

    * :class:`BlendAlpha`
    * :class:`BlendAlphaMask`
    * :class:`BlendAlphaElementwise`
    * :class:`BlendAlphaSimplexNoise`
    * :class:`BlendAlphaFrequencyNoise`
    * :class:`BlendAlphaSomeColors`
    * :class:`BlendAlphaHorizontalLinearGradient`
    * :class:`BlendAlphaVerticalLinearGradient`
    * :class:`BlendAlphaSegMapClassIds`
    * :class:`BlendAlphaBoundingBoxes`
    * :class:`BlendAlphaRegularGrid`
    * :class:`BlendAlphaCheckerboard`

    )print_functiondivisionabsolute_import)ABCMetaabstractmethodN)_normalize_cv2_input_arr_   )meta   )
parameters)dtypes)random)utilsc                 C   s4   g }d}|D ]}| | |||   ||7 }q|S Nr   )append)arrsizesresultisize r   X/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/imgaug/augmenters/blend.py_split_1d_array_to_list%   s   
r   {Gz?c           
      C   s  | j |j ksJ d| j |j f | jj|jjks$J d| jj|jjf | jjdvs.J d|jjdvs8J d| jdk}|rM| dtjf } |dtjf }d}| jjd	krcd
}| tj} |tj}tj	|tj
d}|jdkrqne|jdkr|j | j dd ksJ d|j | j f ||j d |j d df}n'|jdkr|j | j ks|j | j dd d ksJ d|j | j f n|d}|j d | j d krt|dd| j d f}|st|d| kr|r| d } t| S t||kr|r|d }t|S |jdkr"d|d  krdks"n J dt|t|f t| |g}|jd }t|d}td|f }|jj|jkrH||}| jj|jkrU| |} |jj|jkrb||}||| |   }	|rr|	dk}	n	tj|	|dd
d}	|r|	dddddf S |	S )a
  
    Blend two images using an alpha blending.

    In alpha blending, the two images are naively mixed using a multiplier.
    Let ``A`` be the foreground image and ``B`` the background image and
    ``a`` is the alpha value. Each pixel intensity is then computed as
    ``a * A_ij + (1-a) * B_ij``.

    **Supported dtypes**:

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

        - (1) Tests show that these dtypes work, but a conversion to
              ``float128`` happens, which only has 96 bits of size instead of
              true 128 bits and hence not twice as much resolution. It is
              possible that these dtypes result in inaccuracies, though the
              tests did not indicate that.
        - (2) Not available due to the input dtype having to be increased to
              an equivalent float dtype with two times the input resolution.
        - (3) Mapped internally to ``float16``.

    Parameters
    ----------
    image_fg : (H,W,[C]) ndarray
        Foreground image. Shape and dtype kind must match the one of the
        background image.

    image_bg : (H,W,[C]) ndarray
        Background image. Shape and dtype kind must match the one of the
        foreground image.

    alpha : number or iterable of number or ndarray
        The blending factor, between ``0.0`` and ``1.0``. Can be interpreted
        as the opacity of the foreground image. Values around ``1.0`` result
        in only the foreground image being visible. Values around ``0.0``
        result in only the background image being visible. Multiple alphas
        may be provided. In these cases, there must be exactly one alpha per
        channel in the foreground/background image. Alternatively, for
        ``(H,W,C)`` images, either one ``(H,W)`` array or an ``(H,W,C)``
        array of alphas may be provided, denoting the elementwise alpha value.

    eps : number, optional
        Controls when an alpha is to be interpreted as exactly ``1.0`` or
        exactly ``0.0``, resulting in only the foreground/background being
        visible and skipping the actual computation.

    Returns
    -------
    image_blend : (H,W,C) ndarray
        Blend of foreground and background image.

    zPExpected foreground and background images to have the same shape. Got %s and %s.zUExpected foreground and background images to have the same dtype kind. Got %s and %s.)Zfloat128zJForeground image was float128, but blend_alpha() cannot handle that dtype.zJBackground image was float128, but blend_alpha() cannot handle that dtype.r
   .FbTdtyper   r   z'alpha' given as an array must match the height and width of the foreground and background image. Got shape %s vs foreground/background shape %s.   )r   )r   r         ?).r   zVExpected 'alpha' value(s) to be in the interval [0.0, 1.0]. Got min %.4f and max %.4f.   zf%d      ?)cliproundN)shaper   kindnamendimnpnewaxisastypefloat32arrayZfloat64r   reshapetileallcopyitemminmaxiadtZget_minimal_dtypeitemsizeZrestore_dtypes_)
Zimage_fgZimage_bgalphaepsZinput_was_2dZinput_was_boolZ	dt_imagesisizeZdt_blendZimage_blendr   r   r   blend_alpha.   s   A







"





r9   c                 C   s   || g }|}| j d ur5| }|| || | j d ur&| j j|||d}W d    n1 s0w   Y  |}| jd urc| }|| || | jj|||d}W d    ||fS 1 s^w   Y  ||fS )N)parentshooks)
foregrounddeepcopyZpropagation_hooks_ctxZaugment_batch_
background)	augmenterbatchr;   r:   Zparents_extendedZ
outputs_fgZ
outputs_bgr   r   r   _generate_branch_outputs   s4   




rA   c                 C   sR   |   }|jd ur|j nd |_|jd ur|j nd |_d|_| j |_|S )NT)r0   r<   Zto_deterministicr>   deterministicrandom_stateZderive_rng_)r?   augr   r   r   _to_deterministic   s   



rE   c                       sR   e Zd ZdZ				d fdd	Zdd	 Zd
d Zdd Zdd Zdd Z	  Z
S )
BlendAlphaa+  
    Alpha-blend two image sources using an alpha/opacity value.

    The two image sources can be imagined as branches.
    If a source is not given, it is automatically the same as the input.
    Let ``FG`` be the foreground branch and ``BG`` be the background branch.
    Then the result images are defined as ``factor * FG + (1-factor) * BG``,
    where ``factor`` is an overlay factor.

    .. note::

        It is not recommended to use ``BlendAlpha`` with augmenters
        that change the geometry of images (e.g. horizontal flips, affine
        transformations) if you *also* want to augment coordinates (e.g.
        keypoints, polygons, ...), as it is unclear which of the two
        coordinate results (foreground or background branch) should be used
        as the coordinates after augmentation.

        Currently, if ``factor >= 0.5`` (per image), the results of the
        foreground branch are used as the new coordinates, otherwise the
        results of the background branch.

    Added in 0.4.0. (Before that named `Alpha`.)

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.blend.blend_alpha`.

    Parameters
    ----------
    factor : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Opacity of the results of the foreground branch. Values close to
        ``0.0`` mean that the results from the background branch (see
        parameter `background`) make up most of the final image.

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

    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

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

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

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

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

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

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.BlendAlpha(0.5, iaa.Grayscale(1.0))

    Convert each image to pure grayscale and alpha-blend the result with the
    original image using an alpha of ``50%``, thereby removing about ``50%`` of
    all color. This is equivalent to ``iaa.Grayscale(0.5)``.

    >>> aug = iaa.BlendAlpha((0.0, 1.0), iaa.Grayscale(1.0))

    Same as in the previous example, but the alpha factor is sampled uniformly
    from the interval ``[0.0, 1.0]`` once per image, thereby removing a random
    fraction of all colors. This is equivalent to
    ``iaa.Grayscale((0.0, 1.0))``.

    >>> aug = iaa.BlendAlpha(
    >>>     (0.0, 1.0),
    >>>     iaa.Affine(rotate=(-20, 20)),
    >>>     per_channel=0.5)

    First, rotate each image by a random degree sampled uniformly from the
    interval ``[-20, 20]``. Then, alpha-blend that new image with the original
    one using a random factor sampled uniformly from the interval
    ``[0.0, 1.0]``. For ``50%`` of all images, the blending happens
    channel-wise and the factor is sampled independently per channel
    (``per_channel=0.5``). As a result, e.g. the red channel may look visibly
    rotated (factor near ``1.0``), while the green and blue channels may not
    look rotated (factors near ``0.0``).

    >>> aug = iaa.BlendAlpha(
    >>>     (0.0, 1.0),
    >>>     foreground=iaa.Add(100),
    >>>     background=iaa.Multiply(0.2))

    Apply two branches of augmenters -- ``A`` and ``B`` -- *independently*
    to input images and alpha-blend the results of these branches using a
    factor ``f``. Branch ``A`` increases image pixel intensities by ``100``
    and ``B`` multiplies the pixel intensities by ``0.2``. ``f`` is sampled
    uniformly from the interval ``[0.0, 1.0]`` per image. The resulting images
    contain a bit of ``A`` and a bit of ``B``.

    >>> aug = iaa.BlendAlpha([0.25, 0.75], iaa.MedianBlur(13))

    Apply median blur to each image and alpha-blend the result with the
    original image using an alpha factor of either exactly ``0.25`` or
    exactly ``0.75`` (sampled once per image).

            r   NF
deprecatedc	           	         s   t t| j||||d tj|ddddd| _|d us#|d us#J dtj|| jdd d| _	tj|| jd	d d| _
t|d
| _d| _d S )Nseedr&   rC   rB   factorr   r   Tvalue_rangetuple_to_uniformlist_to_choicepExpected 'foreground' and/or 'background' to not be None (i.e. at least one Augmenter), but got two None values.r<   defaultr>   per_channelr   )superrF   __init__iaphandle_continuous_paramrL   r	   handle_children_listr&   r<   r>   handle_probability_paramrU   epsilon)	selfrL   r<   r>   rU   rK   r&   rC   rB   	__class__r   r   rW     s*   



zBlendAlpha.__init__c                 C   sP  t | |||\}}|j}| }t|}	tdd |D }
|d}| jj|	|d d}| jj|	|
f|d d}t	|D ]i\}}|| dkr[t|dkrP|d nd}||d|f }n|| j
dkrh||df nd}t|}|dk}|jd urt|j| |j| || jd|j|< |D ]}|jd	kr|r|n|}t||j| |j|< qq<|S )
Nc                 S   s$   g | ]}t |d kr|d  ndqS )r
   r   )len).0r$   r   r   r   
<listcomp>  s    z.BlendAlpha._augment_batch_.<locals>.<listcomp>r
   r   rC   r   r!   r7   images)rA   columnsget_rowwise_shapesr`   r3   Z	duplicaterU   draw_samplesrL   	enumerater   r(   averagere   r9   r\   r&   getattr	attr_namevalue)r]   r@   rC   r:   r;   batch_fgbatch_bgrf   shapes	nb_imagesZnb_channels_maxZrngsrU   alphasr   r$   Znb_channelsalphas_iZalphas_i_avgZuse_fg_branchcolumnZ	batch_user   r   r   _augment_batch_  sJ   




zBlendAlpha._augment_batch_c                 C      t | S NrE   r]   r   r   r   rE        zBlendAlpha._to_deterministicc                 C   s   | j | jgS z=See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`.)rL   rU   ry   r   r   r   get_parameters  s   zBlendAlpha.get_parametersc                 C      dd | j | jfD S )ASee :func:`~imgaug.augmenters.meta.Augmenter.get_children_lists`.c                 S      g | ]}|d ur|qS rw   r   ra   lstr   r   r   rb         z1BlendAlpha.get_children_lists.<locals>.<listcomp>r<   r>   ry   r   r   r   get_children_lists     zBlendAlpha.get_children_listsc                 C   s*   d}|| j j| j| j| j| j| j| jf S )NzV%s(factor=%s, per_channel=%s, name=%s, foreground=%s, background=%s, deterministic=%s))r_   __name__rL   rU   r&   r<   r>   rB   r]   patternr   r   r   __str__  s   zBlendAlpha.__str__rG   NNFNNrI   rI   )r   
__module____qualname____doc__rW   ru   rE   r|   r   r   __classcell__r   r   r^   r   rF     s     
2rF   c                       sx   e Zd ZdZdZdZeegZ			d fdd	Zdd	 Ze	d
d Z
e	dd Zdd Zdd Zdd Zdd Z  ZS )BlendAlphaMaska  
    Alpha-blend two image sources using non-binary masks generated per image.

    This augmenter queries for each image a mask generator to generate
    a ``(H,W)`` or ``(H,W,C)`` channelwise mask ``[0.0, 1.0]``, where
    ``H`` is the image height and ``W`` the width.
    The mask will then be used to alpha-blend pixel- and possibly channel-wise
    between a foreground branch of augmenters and a background branch.
    (Both branches default to the identity operation if not provided.)

    See also :class:`~imgaug.augmenters.blend.BlendAlpha`.

    .. note::

        It is not recommended to use ``BlendAlphaMask`` with augmenters
        that change the geometry of images (e.g. horizontal flips, affine
        transformations) if you *also* want to augment coordinates (e.g.
        keypoints, polygons, ...), as it is unclear which of the two
        coordinate results (foreground or background branch) should be used
        as the final output coordinates after augmentation.

        Currently, for keypoints the results of the
        foreground and background branch will be mixed. That means that for
        each coordinate the augmented result will be picked from the
        foreground or background branch based on the average alpha mask value
        at the corresponding spatial location.

        For bounding boxes, line strings and polygons, either all objects
        (on an image) of the foreground or all of the background branch will
        be used, based on the average over the whole alpha mask.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.blend.blend_alpha`.

    Parameters
    ----------
    mask_generator : IBatchwiseMaskGenerator
        A generator that will be queried per image to generate a mask.

    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch (i.e. identity function).
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch (i.e. identity function).
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    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.BlendAlphaMask(
    >>>     iaa.InvertMaskGen(0.5, iaa.VerticalLinearGradientMaskGen()),
    >>>     iaa.Sequential([
    >>>         iaa.Clouds(),
    >>>         iaa.WithChannels([1, 2], iaa.Multiply(0.5))
    >>>     ])
    >>> )

    Create an augmenter that sometimes adds clouds at the bottom and sometimes
    at the top of the image.

    z	either-orZ	pointwiseNrI   c                    s   t t| j||||d || _|d us|d usJ dtj|| jdd d| _tj|| jdd d| _| j	| j
| j
| j
d| _d| _d S )NrJ   rR   r<   rS   r>   )	keypointspolygonsline_stringsbounding_boxesr   )rV   r   rW   mask_generatorr	   rZ   r&   r<   r>   _MODE_POINTWISE_MODE_EITHER_OR_coord_modesr\   )r]   r   r<   r>   rK   r&   rC   rB   r^   r   r   rW   d  s(   



zBlendAlphaMask.__init__c              
   C   st  t | |||\}}| j||}t|D ]\}}	|jd ur/t|j| |j| |	| jd|j|< |jd ur_|j| j}
|
j	dd \}}| 
|	||}t|j| j|j| j|| jd|j| _|jd ur|j| j}
|
j	dd \}}| 
|	||}t|j| j|j| j|| jd|j| _dD ]%}t||}|d ur| || t||| t||| |	| j| ||< qq|S )Nrd   r   r
   )r   r   r   r   )rA   r   
draw_masksri   re   r9   r\   ZheatmapsZarr_0to1r$   _binarize_masksegmentation_mapsr   rk   _blend_coordinatesr   )r]   r@   rC   r:   r;   rn   ro   masksr   maskr   
arr_height	arr_widthZmask_binarizedZaugm_attr_nameZ
augm_valuer   r   r   ru     sZ   








zBlendAlphaMask._augment_batch_c           	      C   st   t |}|jdkrt j||ft jd}n|jd dkr#t j|ddnd}t|||f}t	
|dd}|dk}|S )Nr   r   r
   axisr   r!   )r(   Z
atleast_3dr   zerosr+   r$   rj   iaimresize_single_imager4   Zclip_)	clsr   r   r   Zmask_3dZmask_rsZmask_avgZmask_arrZmask_arr_binarizedr   r   r   r     s   


zBlendAlphaMask._binarize_maskc                 C   s  t |}t |}t |}| }| }| }|j|j  kr(|jks5n J d|j|j|jf |jdd \}	}
|| jkrt|t|ksZJ dt|t|t|f g }t|||}|D ]Y\}}}tt	|d }tt	|d }d|  kr|	k rn n/d|  kr|
k rn n#|||df }|j
dkrt|nd}|dkr|| qd|| qd|||f qdn|j
dkrt|nd}|dkr|}n|}tjj||jd	}t ||S )
Na  Expected number of coordinates to not be changed by foreground or background branch in BlendAlphaMask. But input coordinates of shape %s were changed to %s (foreground) and %s (background). Make sure to not use any augmenters that affect the existence of coordinates.r   r
   zGot different numbers of coordinates before/after augmentation in BlendAlphaMask. The number of coordinates is currently not allowed to change for this augmenter. Input contained %d coordinates, foreground branch %d, backround branch %d.r   .r   r!   )r$   )
augm_utilsZconvert_cbaois_to_kpsoisZto_xy_arrayr$   r   r`   zipintr(   r#   r   rj   r   r   ZKeypointsOnImageZfrom_xy_arrayZ invert_convert_cbaois_to_kpsois_)r   ZcbaoiZcbaoi_fgZcbaoi_bgZ
mask_imagemodeZcoordsZ	coords_fgZ	coords_bgZh_imgZw_imgZ
coords_augZsubgenZcoordZcoord_fgZcoord_bgZx_intZy_intrs   r6   Zmask_image_avgZ	kpsoi_augr   r   r   r     sV   



0z!BlendAlphaMask._blend_coordinatesc                 C   rv   rw   rx   ry   r   r   r   rE     rz   z BlendAlphaMask._to_deterministicc                 C   s   | j gS r{   )r   ry   r   r   r   r|        zBlendAlphaMask.get_parametersc                 C   r}   )r~   c                 S   r   rw   r   r   r   r   r   rb     r   z5BlendAlphaMask.get_children_lists.<locals>.<listcomp>r   ry   r   r   r   r     r   z!BlendAlphaMask.get_children_listsc                 C   s&   d}|| j j| j| j| j| j| jf S )NzN%s(mask_generator=%s, name=%s, foreground=%s, background=%s, deterministic=%s))r_   r   r   r&   r<   r>   rB   r   r   r   r   r   #  s   zBlendAlphaMask.__str__NNNNrI   rI   )r   r   r   r   r   r   Z_MODESrW   ru   classmethodr   r   rE   r|   r   r   r   r   r   r^   r   r     s$    f'/

Br   c                       s6   e Zd ZdZ				d
 fdd	Zedd	 Z  ZS )BlendAlphaElementwisea  
    Alpha-blend two image sources using alpha/opacity values sampled per pixel.

    This is the same as :class:`BlendAlpha`, except that the opacity factor is
    sampled once per *pixel* instead of once per *image* (or a few times per
    image, if ``BlendAlpha.per_channel`` is set to ``True``).

    See :class:`BlendAlpha` for more details.

    This class is a wrapper around
    :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    .. note::

        Avoid using augmenters as children that affect pixel locations (e.g.
        horizontal flips). See
        :class:`~imgaug.augmenters.blend.BlendAlphaMask` for details.

    Added in 0.4.0. (Before that named `AlphaElementwise`.)

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    Parameters
    ----------
    factor : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Opacity of the results of the foreground branch. Values close to
        ``0.0`` mean that the results from the background branch (see
        parameter `background`) make up most of the final image.

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

    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

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

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

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

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

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

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.BlendAlphaElementwise(0.5, iaa.Grayscale(1.0))

    Convert each image to pure grayscale and alpha-blend the result with the
    original image using an alpha of ``50%`` for all pixels, thereby removing
    about ``50%`` of all color. This is equivalent to ``iaa.Grayscale(0.5)``.
    This is also equivalent to ``iaa.BlendAlpha(0.5, iaa.Grayscale(1.0))``, as
    the opacity has a fixed value of ``0.5`` and is hence identical for all
    pixels.

    >>> aug = iaa.BlendAlphaElementwise((0, 1.0), iaa.AddToHue(100))

    Same as in the previous example, but here with hue-shift instead
    of grayscaling and additionally the alpha factor is sampled uniformly
    from the interval ``[0.0, 1.0]`` once per pixel, thereby shifting the
    hue by a random fraction for each pixel.

    >>> aug = iaa.BlendAlphaElementwise(
    >>>     (0.0, 1.0),
    >>>     iaa.Affine(rotate=(-20, 20)),
    >>>     per_channel=0.5)

    First, rotate each image by a random degree sampled uniformly from the
    interval ``[-20, 20]``. Then, alpha-blend that new image with the original
    one using a random factor sampled uniformly from the interval
    ``[0.0, 1.0]`` per pixel. For ``50%`` of all images, the blending happens
    channel-wise and the factor is sampled independently per pixel *and*
    channel (``per_channel=0.5``). As a result, e.g. the red channel may look
    visibly rotated (factor near ``1.0``), while the green and blue channels
    may not look rotated (factors near ``0.0``).

    >>> aug = iaa.BlendAlphaElementwise(
    >>>     (0.0, 1.0),
    >>>     foreground=iaa.Add(100),
    >>>     background=iaa.Multiply(0.2))

    Apply two branches of augmenters -- ``A`` and ``B`` -- *independently*
    to input images and alpha-blend the results of these branches using a
    factor ``f``. Branch ``A`` increases image pixel intensities by ``100``
    and ``B`` multiplies the pixel intensities by ``0.2``. ``f`` is sampled
    uniformly from the interval ``[0.0, 1.0]`` per pixel. The resulting images
    contain a bit of ``A`` and a bit of ``B``.

    >>> aug = iaa.BlendAlphaElementwise([0.25, 0.75], iaa.MedianBlur(13))

    Apply median blur to each image and alpha-blend the result with the
    original image using an alpha factor of either exactly ``0.25`` or
    exactly ``0.75`` (sampled once per pixel).

    rG   NFrI   c	           
   	      s@   t j|ddddd}t||}	tt| j|	||||||d d S )NrL   rM   TrN   rJ   )rX   rY   StochasticParameterMaskGenrV   r   rW   )
r]   rL   r<   r>   rU   rK   r&   rC   rB   Zmask_genr^   r   r   rW     s   


zBlendAlphaElementwise.__init__c                 C      | j jS rw   )r   	parameterry   r   r   r   rL     r   zBlendAlphaElementwise.factorr   )r   r   r   r   rW   propertyrL   r   r   r   r^   r   r   1  s     	r   c                       s.   e Zd ZdZ						d fd	d
	Z  ZS )BlendAlphaSimplexNoiseap#  Alpha-blend two image sources using simplex noise alpha masks.

    The alpha masks are sampled using a simplex noise method, roughly creating
    connected blobs of 1s surrounded by 0s. If nearest neighbour
    upsampling is used, these blobs can be rectangular with sharp edges.

    Added in 0.4.0. (Before that named `SimplexNoiseAlpha`.)

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaElementwise`.

    Parameters
    ----------
    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

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

    size_px_max : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        The simplex noise is always generated in a low resolution environment.
        This parameter defines the maximum size of that environment (in
        pixels). The environment is initialized at the same size as the input
        image and then downscaled, so that no side exceeds `size_px_max`
        (aspect ratio is kept).

            * If int, then that number will be used as the size for all
              iterations.
            * If tuple of two ``int`` s ``(a, b)``, then a value will be
              sampled per iteration from the discrete interval ``[a..b]``.
            * If a list of ``int`` s, then a value will be picked per iteration
              at random from that list.
            * If a ``StochasticParameter``, then a value will be sampled from
              that parameter per iteration.

    upscale_method : None or imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        After generating the noise maps in low resolution environments, they
        have to be upscaled to the input image size. This parameter controls
        the upscaling method.

            * If ``None``, then either ``nearest`` or ``linear`` or ``cubic``
              is picked. Most weight is put on ``linear``, followed by
              ``cubic``.
            * If ``imgaug.ALL``, then either ``nearest`` or ``linear`` or
              ``area`` or ``cubic`` is picked per iteration (all same
              probability).
            * If a string, then that value will be used as the method (must be
              ``nearest`` or ``linear`` or ``area`` or ``cubic``).
            * If list of string, then a random value will be picked from that
              list per iteration.
            * If ``StochasticParameter``, then a random value will be sampled
              from that parameter per iteration.

    iterations : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        How often to repeat the simplex noise generation process per image.

            * If ``int``, then that number will be used as the iterations for
              all images.
            * If tuple of two ``int`` s ``(a, b)``, then a value will be
              sampled per image from the discrete interval ``[a..b]``.
            * If a list of ``int`` s, then a value will be picked per image at
              random from that list.
            * If a ``StochasticParameter``, then a value will be sampled from
              that parameter per image.

    aggregation_method : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        The noise maps (from each iteration) are combined to one noise map
        using an aggregation process. This parameter defines the method used
        for that process. Valid methods are ``min``, ``max`` or ``avg``,
        where ``min`` combines the noise maps by taking the (elementwise)
        minimum over all iteration's results, ``max`` the (elementwise)
        maximum and ``avg`` the (elementwise) average.

            * If ``imgaug.ALL``, then a random value will be picked per image
              from the valid ones.
            * If a string, then that value will always be used as the method.
            * If a list of string, then a random value will be picked from
              that list per image.
            * If a ``StochasticParameter``, then a random value will be
              sampled from that paramter per image.

    sigmoid : bool or number, optional
        Whether to apply a sigmoid function to the final noise maps, resulting
        in maps that have more extreme values (close to 0.0 or 1.0).

            * If ``bool``, then a sigmoid will always (``True``) or never
              (``False``) be applied.
            * If a number ``p`` with ``0<=p<=1``, then a sigmoid will be
              applied to ``p`` percent of all final noise maps.

    sigmoid_thresh : None or number or tuple of number or imgaug.parameters.StochasticParameter, optional
        Threshold of the sigmoid, when applied. Thresholds above zero
        (e.g. ``5.0``) will move the saddle point towards the right, leading
        to more values close to 0.0.

            * If ``None``, then ``Normal(0, 5.0)`` will be used.
            * If number, then that threshold will be used for all images.
            * If tuple of two numbers ``(a, b)``, then a random value will
              be sampled per image from the interval ``[a, b]``.
            * If ``StochasticParameter``, then a random value will be sampled
              from that parameter per 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.BlendAlphaSimplexNoise(iaa.EdgeDetect(1.0))

    Detect per image all edges, mark them in a black and white image and
    then alpha-blend the result with the original image using simplex noise
    masks.

    >>> aug = iaa.BlendAlphaSimplexNoise(
    >>>     iaa.EdgeDetect(1.0),
    >>>     upscale_method="nearest")

    Same as in the previous example, but using only nearest neighbour
    upscaling to scale the simplex noise masks to the final image sizes, i.e.
    no nearest linear upsampling is used. This leads to rectangles with sharp
    edges.

    >>> aug = iaa.BlendAlphaSimplexNoise(
    >>>     iaa.EdgeDetect(1.0),
    >>>     upscale_method="linear")

    Same as in the previous example, but using only linear upscaling to
    scale the simplex noise masks to the final image sizes, i.e. no nearest
    neighbour upsampling is used. This leads to rectangles with smooth edges.

    >>> aug = iaa.BlendAlphaSimplexNoise(
    >>>     iaa.EdgeDetect(1.0),
    >>>     sigmoid_thresh=iap.Normal(10.0, 5.0))

    Same as in the first example, but using a threshold for the sigmoid
    function that is further to the right. This is more conservative, i.e.
    the generated noise masks will be mostly black (values around ``0.0``),
    which means that most of the original images (parameter/branch
    `background`) will be kept, rather than using the results of the
    augmentation (parameter/branch `foreground`).

    NFr
      r   r   r3   TrI   c              
      s   t jg dg dd}t dd}t j||d ur|n|d}|dkr*t j|||d}|d	u p6t|o6|d
k}|rHt jj||	d urC|	n||d}t	t
| j|||||
|||d d S )NnearestZlinearZcubicg?g333333?gffffff?prH         @)size_px_maxupscale_methodr   
iterationsaggregation_methodTr   	thresholdZ	activatedrL   r<   r>   rU   rK   r&   rC   rB   )rX   ChoiceNormalZSimplexNoiseIterativeNoiseAggregatorr   is_single_numberSigmoidcreate_for_noiserV   r   rW   )r]   r<   r>   rU   r   r   r   r   sigmoidsigmoid_threshrK   r&   rC   rB   upscale_method_defaultsigmoid_thresh_defaultnoiseuse_sigmoidr^   r   r   rW     sB   


zBlendAlphaSimplexNoise.__init__NNFr   Nr   r3   TNNNrI   rI   r   r   r   r   rW   r   r   r   r^   r   r     s     5r   c                       sB   e Zd ZdZdddddddddgd	dddd
d
f fdd	Z  ZS )BlendAlphaFrequencyNoiseaT(  Alpha-blend two image sources using frequency noise masks.

    The alpha masks are sampled using frequency noise of varying scales,
    which can sometimes create large connected blobs of ``1`` s surrounded
    by ``0`` s and other times results in smaller patterns. If nearest
    neighbour upsampling is used, these blobs can be rectangular with sharp
    edges.

    Added in 0.4.0. (Before that named `FrequencyNoiseAlpha`.)

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaElementwise`.

    Parameters
    ----------
    exponent : number or tuple of number of list of number or imgaug.parameters.StochasticParameter, optional
        Exponent to use when scaling in the frequency domain.
        Sane values are in the range ``-4`` (large blobs) to ``4`` (small
        patterns). To generate cloud-like structures, use roughly ``-2``.

            * If number, then that number will be used as the exponent for all
              iterations.
            * If tuple of two numbers ``(a, b)``, then a value will be sampled
              per iteration from the interval ``[a, b]``.
            * If a list of numbers, then a value will be picked per iteration
              at random from that list.
            * If a ``StochasticParameter``, then a value will be sampled from
              that parameter per iteration.

    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

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

    size_px_max : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        The noise is generated in a low resolution environment.
        This parameter defines the maximum size of that environment (in
        pixels). The environment is initialized at the same size as the input
        image and then downscaled, so that no side exceeds `size_px_max`
        (aspect ratio is kept).

            * If ``int``, then that number will be used as the size for all
              iterations.
            * If tuple of two ``int`` s ``(a, b)``, then a value will be
              sampled per iteration from the discrete interval ``[a..b]``.
            * If a list of ``int`` s, then a value will be picked per
              iteration at random from that list.
            * If a ``StochasticParameter``, then a value will be sampled from
              that parameter per iteration.

    upscale_method : None or imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        After generating the noise maps in low resolution environments, they
        have to be upscaled to the input image size. This parameter controls
        the upscaling method.

            * If ``None``, then either ``nearest`` or ``linear`` or ``cubic``
              is picked. Most weight is put on ``linear``, followed by
              ``cubic``.
            * If ``imgaug.ALL``, then either ``nearest`` or ``linear`` or
              ``area`` or ``cubic`` is picked per iteration (all same
              probability).
            * If string, then that value will be used as the method (must be
              ``nearest`` or ``linear`` or ``area`` or ``cubic``).
            * If list of string, then a random value will be picked from that
              list per iteration.
            * If ``StochasticParameter``, then a random value will be sampled
              from that parameter per iteration.

    iterations : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        How often to repeat the simplex noise generation process per
        image.

            * If ``int``, then that number will be used as the iterations for
              all images.
            * If tuple of two ``int`` s ``(a, b)``, then a value will be
              sampled per image from the discrete interval ``[a..b]``.
            * If a list of ``int`` s, then a value will be picked per image at
              random from that list.
            * If a ``StochasticParameter``, then a value will be sampled from
              that parameter per image.

    aggregation_method : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        The noise maps (from each iteration) are combined to one noise map
        using an aggregation process. This parameter defines the method used
        for that process. Valid methods are ``min``, ``max`` or ``avg``,
        where 'min' combines the noise maps by taking the (elementwise) minimum
        over all iteration's results, ``max`` the (elementwise) maximum and
        ``avg`` the (elementwise) average.

            * If ``imgaug.ALL``, then a random value will be picked per image
              from the valid ones.
            * If a string, then that value will always be used as the method.
            * If a list of string, then a random value will be picked from
              that list per image.
            * If a ``StochasticParameter``, then a random value will be sampled
              from that parameter per image.

    sigmoid : bool or number, optional
        Whether to apply a sigmoid function to the final noise maps, resulting
        in maps that have more extreme values (close to ``0.0`` or ``1.0``).

            * If ``bool``, then a sigmoid will always (``True``) or never
              (``False``) be applied.
            * If a number ``p`` with ``0<=p<=1``, then a sigmoid will be applied to
              ``p`` percent of all final noise maps.

    sigmoid_thresh : None or number or tuple of number or imgaug.parameters.StochasticParameter, optional
        Threshold of the sigmoid, when applied. Thresholds above zero
        (e.g. ``5.0``) will move the saddle point towards the right, leading to
        more values close to ``0.0``.

            * If ``None``, then ``Normal(0, 5.0)`` will be used.
            * If number, then that threshold will be used for all images.
            * If tuple of two numbers ``(a, b)``, then a random value will
              be sampled per image from the range ``[a, b]``.
            * If ``StochasticParameter``, then a random value will be sampled
              from that parameter per 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.BlendAlphaFrequencyNoise(foreground=iaa.EdgeDetect(1.0))

    Detect per image all edges, mark them in a black and white image and
    then alpha-blend the result with the original image using frequency noise
    masks.

    >>> aug = iaa.BlendAlphaFrequencyNoise(
    >>>     foreground=iaa.EdgeDetect(1.0),
    >>>     upscale_method="nearest")

    Same as the first example, but using only linear upscaling to
    scale the frequency noise masks to the final image sizes, i.e. no nearest
    neighbour upsampling is used. This results in smooth edges.

    >>> aug = iaa.BlendAlphaFrequencyNoise(
    >>>     foreground=iaa.EdgeDetect(1.0),
    >>>     upscale_method="linear")

    Same as the first example, but using only linear upscaling to
    scale the frequency noise masks to the final image sizes, i.e. no nearest
    neighbour upsampling is used. This results in smooth edges.

    >>> aug = iaa.BlendAlphaFrequencyNoise(
    >>>     foreground=iaa.EdgeDetect(1.0),
    >>>     upscale_method="linear",
    >>>     exponent=-2,
    >>>     sigmoid=False)

    Same as in the previous example, but with the exponent set to a constant
    ``-2`` and the sigmoid deactivated, resulting in cloud-like patterns
    without sharp edges.

    >>> aug = iaa.BlendAlphaFrequencyNoise(
    >>>     foreground=iaa.EdgeDetect(1.0),
    >>>     sigmoid_thresh=iap.Normal(10.0, 5.0))

    Same as the first example, but using a threshold for the sigmoid function
    that is further to the right. This is more conservative, i.e. the generated
    noise masks will be mostly black (values around ``0.0``), which means that
    most of the original images (parameter/branch `background`) will be kept,
    rather than using the results of the augmentation (parameter/branch
    `foreground`).

    r    NFr    r   r   avgr3   r!   rI   c              
      s   t jg dg dd}t dd}t j|||d ur|n|d}|dkr+t j|||d}|	d	u p7t|	o7|	d
k}|rIt jj||
d urD|
n||	d}t	t
| j||||||||d d S )Nr   r   r   rH   r   )exponentr   r   r   r   Tr   r   r   )rX   r   r   ZFrequencyNoiser   r   r   r   r   rV   r   rW   )r]   r   r<   r>   rU   r   r   r   r   r   r   rK   r&   rC   rB   r   r   r   r   r^   r   r   rW   |  sD   


z!BlendAlphaFrequencyNoise.__init__r   r   r   r^   r   r     s     Or   c                       s<   e Zd ZdZddddddgddddd	d	f fd
d	Z  ZS )BlendAlphaSomeColorsa  Blend images from two branches using colorwise masks.

    This class generates masks that "mark" a few colors and replace the
    pixels within these colors with the results of the foreground branch.
    The remaining pixels are replaced with the results of the background
    branch (usually the identity function). That allows to e.g. selectively
    grayscale a few colors, while keeping other colors unchanged.

    This class is a thin wrapper around
    :class:`~imgaug.augmenters.blend.BlendAlphaMask` together with
    :class:`~imgaug.augmenters.blend.SomeColorsMaskGen`.

    .. note::

        The underlying mask generator will produce an ``AssertionError`` for
        batches that contain no images.

    .. note::

        Avoid using augmenters as children that affect pixel locations (e.g.
        horizontal flips). See
        :class:`~imgaug.augmenters.blend.BlendAlphaMask` for details.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    nb_bins : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.SomeColorsMaskGen`.

    smoothness : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.SomeColorsMaskGen`.

    alpha : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.SomeColorsMaskGen`.

    rotation_deg : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.SomeColorsMaskGen`.

    from_colorspace : str, optional
        See :class:`~imgaug.augmenters.blend.SomeColorsMaskGen`.

    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.BlendAlphaSomeColors(iaa.Grayscale(1.0))

    Create an augmenter that turns randomly removes some colors in images by
    grayscaling them.

    >>> aug = iaa.BlendAlphaSomeColors(iaa.TotalDropout(1.0))

    Create an augmenter that removes some colors in images by replacing them
    with black pixels.

    >>> aug = iaa.BlendAlphaSomeColors(
    >>>     iaa.MultiplySaturation(0.5), iaa.MultiplySaturation(1.5))

    Create an augmenter that desaturates some colors and increases the
    saturation of the remaining ones.

    >>> aug = iaa.BlendAlphaSomeColors(
    >>>     iaa.AveragePooling(7), alpha=[0.0, 1.0], smoothness=0.0)

    Create an augmenter that applies average pooling to some colors.
    Each color tune is either selected (alpha of ``1.0``) or not
    selected (``0.0``). There is no gradual change between similar colors.

    >>> aug = iaa.BlendAlphaSomeColors(
    >>>     iaa.AveragePooling(7), nb_bins=2, smoothness=0.0)

    Create an augmenter that applies average pooling to some colors.
    Choose on average half of all colors in images for the blending operation.

    >>> aug = iaa.BlendAlphaSomeColors(
    >>>     iaa.AveragePooling(7), from_colorspace="BGR")

    Create an augmenter that applies average pooling to some colors with
    input images being in BGR colorspace.

    N      g?g333333?rH   r   r   h  RGBrI   c              	      s0   t t| jt|||||d||||	|
|d d S )N)nb_bins
smoothnessr6   rotation_degfrom_colorspacer<   r>   rK   r&   rC   rB   )rV   r   rW   SomeColorsMaskGen)r]   r<   r>   r   r   r6   r   r   rK   r&   rC   rB   r^   r   r   rW   &  s   

zBlendAlphaSomeColors.__init__r   r   r   r^   r   r     s    |r   c                       ,   e Zd ZdZ					d fdd	Z  ZS )	"BlendAlphaHorizontalLinearGradientaK  Blend images from two branches along a horizontal linear gradient.

    This class generates a horizontal linear gradient mask (i.e. usually a
    mask with low values on the left and high values on the right) and
    alphas-blends between foreground and background branch using that
    mask.

    This class is a thin wrapper around
    :class:`~imgaug.augmenters.blend.BlendAlphaMask` together with
    :class:`~imgaug.augmenters.blend.HorizontalLinearGradientMaskGen`.

    .. note::

        Avoid using augmenters as children that affect pixel locations (e.g.
        horizontal flips). See
        :class:`~imgaug.augmenters.blend.BlendAlphaMask` for details.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    Parameters
    ----------
    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    min_value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.HorizontalLinearGradientMaskGen`.

    max_value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.HorizontalLinearGradientMaskGen`.

    start_at : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.HorizontalLinearGradientMaskGen`.

    end_at : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.HorizontalLinearGradientMaskGen`.

    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.BlendAlphaHorizontalLinearGradient(iaa.AddToHue((-100, 100)))

    Create an augmenter that randomizes the hue towards the right of the
    image.

    >>> aug = iaa.BlendAlphaHorizontalLinearGradient(
    >>>     iaa.TotalDropout(1.0),
    >>>     min_value=0.2, max_value=0.8)

    Create an augmenter that replaces pixels towards the right with darker
    and darker values. However it always keeps at least
    20% (``1.0 - max_value``) of the original pixel value on the far right
    and always replaces at least 20% on the far left (``min_value=0.2``).

    >>> aug = iaa.BlendAlphaHorizontalLinearGradient(
    >>>     iaa.AveragePooling(11),
    >>>     start_at=(0.0, 1.0), end_at=(0.0, 1.0))

    Create an augmenter that blends with an average-pooled image according
    to a horizontal gradient that starts at a random x-coordinate and reaches
    its maximum at another random x-coordinate. Due to that randomness,
    the gradient may increase towards the left or right.

    NrH   g?g?r   rI   c              	      .   t t| jt||||d|||||	|
d d S N)	min_value	max_valuestart_atend_atr   )rV   r   rW   HorizontalLinearGradientMaskGenr]   r<   r>   r   r   r   r   rK   r&   rC   rB   r^   r   r   rW        

z+BlendAlphaHorizontalLinearGradient.__init__
NNr   r   r   r   NNrI   rI   r   r   r   r^   r   r   ;  s    gr   c                       r   )	 BlendAlphaVerticalLinearGradienta  Blend images from two branches along a vertical linear gradient.

    This class generates a vertical linear gradient mask (i.e. usually a
    mask with low values on the left and high values on the right) and
    alphas-blends between foreground and background branch using that
    mask.

    This class is a thin wrapper around
    :class:`~imgaug.augmenters.blend.BlendAlphaMask` together with
    :class:`~imgaug.augmenters.blend.VerticalLinearGradientMaskGen`.

    .. note::

        Avoid using augmenters as children that affect pixel locations (e.g.
        horizontal flips). See
        :class:`~imgaug.augmenters.blend.BlendAlphaMask` for details.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    Parameters
    ----------
    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    min_value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.VerticalLinearGradientMaskGen`.

    max_value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.VerticalLinearGradientMaskGen`.

    start_at : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.VerticalLinearGradientMaskGen`.

    end_at : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.VerticalLinearGradientMaskGen`.

    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.BlendAlphaVerticalLinearGradient(iaa.AddToHue((-100, 100)))

    Create an augmenter that randomizes the hue towards the bottom of the
    image.

    >>> aug = iaa.BlendAlphaVerticalLinearGradient(
    >>>     iaa.TotalDropout(1.0),
    >>>     min_value=0.2, max_value=0.8)

    Create an augmenter that replaces pixels towards the bottom with darker
    and darker values. However it always keeps at least
    20% (``1.0 - max_value``) of the original pixel value on the far bottom
    and always replaces at least 20% on the far top (``min_value=0.2``).

    >>> aug = iaa.BlendAlphaVerticalLinearGradient(
    >>>     iaa.AveragePooling(11),
    >>>     start_at=(0.0, 1.0), end_at=(0.0, 1.0))

    Create an augmenter that blends with an average-pooled image according
    to a vertical gradient that starts at a random y-coordinate and reaches
    its maximum at another random y-coordinate. Due to that randomness,
    the gradient may increase towards the bottom or top.

    >>> aug = iaa.BlendAlphaVerticalLinearGradient(
    >>>     iaa.Clouds(),
    >>>     start_at=(0.15, 0.35), end_at=0.0)

    Create an augmenter that draws clouds in roughly the top quarter of the
    image.

    Nr   r   rI   c              	      r   r   )rV   r   rW   VerticalLinearGradientMaskGenr   r^   r   r   rW   $  r   z)BlendAlphaVerticalLinearGradient.__init__r   r   r   r   r^   r   r     s    nr   c                       s4   e Zd ZdZddddgddddf fdd	Z  ZS )BlendAlphaRegularGridaE  Blend images from two branches according to a regular grid.

    This class generates for each image a mask that splits the image into a
    grid-like pattern of ``H`` rows and ``W`` columns. Each cell is then
    filled with an alpha value, sampled randomly per cell.

    The difference to :class:`AlphaBlendCheckerboard` is that this class
    samples random alpha values per grid cell, while in the checkerboard the
    alpha values follow a fixed pattern.

    This class is a thin wrapper around
    :class:`~imgaug.augmenters.blend.BlendAlphaMask` together with
    :class:`~imgaug.augmenters.blend.RegularGridMaskGen`.

    .. note::

        Avoid using augmenters as children that affect pixel locations (e.g.
        horizontal flips). See
        :class:`~imgaug.augmenters.blend.BlendAlphaMask` for details.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    Parameters
    ----------
    nb_rows : int or tuple of int or list of int or imgaug.parameters.StochasticParameter
        Number of rows of the checkerboard.
        See :class:`~imgaug.augmenters.blend.CheckerboardMaskGen` for details.

    nb_cols : int or tuple of int or list of int or imgaug.parameters.StochasticParameter
        Number of columns of the checkerboard. Analogous to `nb_rows`.
        See :class:`~imgaug.augmenters.blend.CheckerboardMaskGen` for details.

    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    alpha : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Alpha value of each cell.

        * If ``number``: Exactly that value will be used for all images.
        * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
          per image from the interval ``[a, b]``.
        * If ``list``: A random value will be picked per image from that list.
        * If ``StochasticParameter``: That parameter will be queried once
          per batch for ``(N,)`` values -- one per 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.BlendAlphaRegularGrid(nb_rows=(4, 6), nb_cols=(1, 4),
    >>>                                 foreground=iaa.Multiply(0.0))

    Create an augmenter that places a ``HxW`` grid on each image, where
    ``H`` (rows) is randomly and uniformly sampled from the interval ``[4, 6]``
    and ``W`` is analogously sampled from the interval ``[1, 4]``. Roughly
    half of the cells in the grid are filled with ``0.0``, the remaining ones
    are unaltered. Which cells exactly are "dropped" is randomly decided
    per image. The resulting effect is similar to
    :class:`~imgaug.augmenters.arithmetic.CoarseDropout`.

    >>> aug = iaa.BlendAlphaRegularGrid(nb_rows=2, nb_cols=2,
    >>>                                 foreground=iaa.Multiply(0.0),
    >>>                                 background=iaa.AveragePooling(8),
    >>>                                 alpha=[0.0, 0.0, 1.0])

    Create an augmenter that always placed ``2x2`` cells on each image
    and sets about ``1/3`` of them to zero (foreground branch) and
    the remaining ``2/3`` to a pixelated version (background branch).

    NrH   r   rI   c
           
   	      s,   t t| jt|||d||||||	d d S )Nnb_rowsnb_colsr6   r   )rV   r   rW   RegularGridMaskGen)
r]   r   r   r<   r>   r6   rK   r&   rC   rB   r^   r   r   rW     s   

zBlendAlphaRegularGrid.__init__r   r   r   r^   r   r   6  s    nr   c                       s(   e Zd ZdZ			d fdd	Z  ZS )BlendAlphaCheckerboardat  Blend images from two branches according to a checkerboard pattern.

    This class generates for each image a mask following a checkboard layout of
    ``H`` rows and ``W`` columns. Each cell is then filled with either
    ``1.0`` or ``0.0``. The cell at the top-left is always ``1.0``. Its right
    and bottom neighbour cells are ``0.0``. The 4-neighbours of any cell always
    have a value opposite to the cell's value (``0.0`` vs. ``1.0``).

    This class is a thin wrapper around
    :class:`~imgaug.augmenters.blend.BlendAlphaMask` together with
    :class:`~imgaug.augmenters.blend.CheckerboardMaskGen`.

    .. note::

        Avoid using augmenters as children that affect pixel locations (e.g.
        horizontal flips). See
        :class:`~imgaug.augmenters.blend.BlendAlphaMask` for details.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    Parameters
    ----------
    nb_rows : int or tuple of int or list of int or imgaug.parameters.StochasticParameter
        Number of rows of the checkerboard.
        See :class:`~imgaug.augmenters.blend.CheckerboardMaskGen` for details.

    nb_cols : int or tuple of int or list of int or imgaug.parameters.StochasticParameter
        Number of columns of the checkerboard. Analogous to `nb_rows`.
        See :class:`~imgaug.augmenters.blend.CheckerboardMaskGen` for details.

    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    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.BlendAlphaCheckerboard(nb_rows=2, nb_cols=(1, 4),
    >>>                                  foreground=iaa.AddToHue((-100, 100)))

    Create an augmenter that places a ``HxW`` grid on each image, where
    ``H`` (rows) is always ``2`` and ``W`` is randomly and uniformly sampled
    from the interval ``[1, 4]``. For half of the cells in the grid the hue
    is randomly modified, the other half of the cells is unaltered.

    NrI   c	           	   	      s*   t t| jt||d||||||d d S )N)r   r   r   )rV   r   rW   CheckerboardMaskGen)	r]   r   r   r<   r>   rK   r&   rC   rB   r^   r   r   rW     s   

zBlendAlphaCheckerboard.__init__r   r   r   r   r^   r   r     s    Vr   c                       *   e Zd ZdZ				d fdd	Z  ZS )BlendAlphaSegMapClassIdsa  Blend images from two branches based on segmentation map ids.

    This class generates masks that are ``1.0`` at pixel locations covered
    by specific classes in segmentation maps.

    This class is a thin wrapper around
    :class:`~imgaug.augmenters.blend.BlendAlphaMask` together with
    :class:`~imgaug.augmenters.blend.SegMapClassIdsMaskGen`.

    .. note::

        Avoid using augmenters as children that affect pixel locations (e.g.
        horizontal flips). See
        :class:`~imgaug.augmenters.blend.BlendAlphaMask` for details.

    .. note::

        Segmentation maps can have multiple channels. If that is the case
        then for each position ``(x, y)`` it is sufficient that any class id
        in any channel matches one of the desired class ids.

    .. note::

        This class will produce an ``AssertionError`` if there are no
        segmentation maps in a batch.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    Parameters
    ----------
    class_ids : int or tuple of int or list of int or imgaug.parameters.StochasticParameter
        See :class:`~imgaug.augmenters.blend.SegMapClassIdsMaskGen`.

    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    nb_sample_classes : None or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.SegMapClassIdsMaskGen`.

    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.BlendAlphaSegMapClassIds(
    >>>     [1, 3],
    >>>     foreground=iaa.AddToHue((-100, 100)))

    Create an augmenter that randomizes the hue wherever the segmentation maps
    contain the classes ``1`` or ``3``.

    >>> aug = iaa.BlendAlphaSegMapClassIds(
    >>>     [1, 2, 3, 4],
    >>>     nb_sample_classes=2,
    >>>     foreground=iaa.GaussianBlur(3.0))

    Create an augmenter that randomly picks ``2`` classes from the
    list ``[1, 2, 3, 4]`` and blurs the image content wherever these classes
    appear in the segmentation map. Note that as the sampling of class ids
    happens *with replacement*, it is not guaranteed to sample two *unique*
    class ids.

    >>> aug = iaa.Sometimes(0.2,
    >>>     iaa.BlendAlphaSegMapClassIds(
    >>>         2,
    >>>         background=iaa.TotalDropout(1.0)))

    Create an augmenter that zeros for roughly every fifth image all
    image pixels that do *not* belong to class id ``2`` (note that the
    `background` branch was used, not the `foreground` branch).
    Example use case: Human body landmark detection where both the
    landmarks/keypoints and the body segmentation map are known. Train the
    model to detect landmarks and sometimes remove all non-body information
    to force the model to become more independent of the background.

    NrI   c	           	   	      *   t t| jt||d||||||d d S )N)	class_idsnb_sample_classesr   )rV   r   rW   SegMapClassIdsMaskGen)	r]   r   r<   r>   r  rK   r&   rC   rB   r^   r   r   rW        

z!BlendAlphaSegMapClassIds.__init__NNNNNrI   rI   r   r   r   r^   r   r     s    tr   c                       r   )BlendAlphaBoundingBoxesa(  Blend images from two branches based on areas enclosed in bounding boxes.

    This class generates masks that are ``1.0`` within bounding boxes of given
    labels. A mask pixel will be set to ``1.0`` if *at least* one bounding box
    covers the area and has one of the requested labels.

    This class is a thin wrapper around
    :class:`~imgaug.augmenters.blend.BlendAlphaMask` together with
    :class:`~imgaug.augmenters.blend.BoundingBoxesMaskGen`.

    .. note::

        Avoid using augmenters as children that affect pixel locations (e.g.
        horizontal flips). See
        :class:`~imgaug.augmenters.blend.BlendAlphaMask` for details.

    .. note::

        This class will produce an ``AssertionError`` if there are no
        bounding boxes in a batch.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    Parameters
    ----------
    labels : None or str or list of str or imgaug.parameters.StochasticParameter
        See :class:`~imgaug.augmenters.blend.BoundingBoxesMaskGen`.

    foreground : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the foreground branch.
        High alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the foreground branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    background : None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional
        Augmenter(s) that make up the background branch.
        Low alpha values will show this branch's results.

            * If ``None``, then the input images will be reused as the output
              of the background branch.
            * If ``Augmenter``, then that augmenter will be used as the branch.
            * If iterable of ``Augmenter``, then that iterable will be
              converted into a ``Sequential`` and used as the augmenter.

    nb_sample_labels : None or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        See :class:`~imgaug.augmenters.blend.BoundingBoxesMaskGen`.

    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.BlendAlphaBoundingBoxes("person",
    >>>                                   foreground=iaa.Grayscale(1.0))

    Create an augmenter that removes color within bounding boxes having the
    label ``person``.

    >>> aug = iaa.BlendAlphaBoundingBoxes(["person", "car"],
    >>>                                   foreground=iaa.AddToHue((-255, 255)))

    Create an augmenter that randomizes the hue within bounding boxes that
    have the label ``person`` or ``car``.

    >>> aug = iaa.BlendAlphaBoundingBoxes(["person", "car"],
    >>>                                   foreground=iaa.AddToHue((-255, 255)),
    >>>                                   nb_sample_labels=1)

    Create an augmenter that randomizes the hue within bounding boxes that
    have either the label ``person`` or ``car``. Only one label is picked per
    image. Note that the sampling happens with replacement, so if
    ``nb_sample_classes`` would be ``>1``, it could still lead to only one
    *unique* label being sampled.

    >>> aug = iaa.BlendAlphaBoundingBoxes(None,
    >>>                                   background=iaa.Multiply(0.0))

    Create an augmenter that zeros all pixels (``Multiply(0.0)``)
    that are *not* (``background`` branch) within bounding boxes of
    *any* (``None``) label. In other words, all pixels outside of bounding
    boxes become black.
    Note that we don't use ``TotalDropout`` here, because by default it will
    also remove all coordinate-based augmentables, which will break the
    blending of such inputs.

    NrI   c	           	   	      r   )N)labelsnb_sample_labelsr   )rV   r  rW   BoundingBoxesMaskGen)	r]   r  r<   r>   r  rK   r&   rC   rB   r^   r   r   rW   	  r  z BlendAlphaBoundingBoxes.__init__r  r   r   r   r^   r   r    s    qr  c                   @   s   e Zd ZdZdddZdS )IBatchwiseMaskGeneratora3  Interface for classes generating masks for batches.

    Child classes are supposed to receive a batch and generate an iterable
    of masks, one per row (i.e. image), matching the row shape (i.e. image
    shape). This is used in :class:`~imgaug.augmenters.blend.BlendAlphaMask`.

    Added in 0.4.0.

    Nc                 C      dS )a  Generate a mask with given shape.

        Parameters
        ----------
        batch : imgaug.augmentables.batches._BatchInAugmentation
            Shape of the mask to sample.

        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
            A seed or random number generator to use during the sampling
            process. If ``None``, the global RNG will be used.
            See also :func:`~imgaug.augmenters.meta.Augmenter.__init__`
            for a similar parameter with more details.

        Returns
        -------
        iterable of ndarray
            Masks, one per row in the batch.
            Each mask must be a ``float32`` array in interval ``[0.0, 1.0]``.
            It must either have the same shape as the row (i.e. the image)
            or shape ``(H, W)`` if all channels are supposed to have the
            same mask.

        Nr   r]   r@   rC   r   r   r   r   -	      z"IBatchwiseMaskGenerator.draw_masksrw   )r   r   r   r   r   r   r   r   r   r	   	  s    r	  c                       s2   e Zd ZdZ fddZd	ddZdd Z  ZS )
r   a  Mask generator that queries stochastic parameters for mask values.

    This class receives batches for which to generate masks, iterates over
    the batch rows (i.e. images) and generates one mask per row.
    For a row with shape ``(H, W, C)`` (= image shape), it generates
    either a ``(H, W)`` mask (if ``per_channel`` is false-like) or a
    ``(H, W, C)`` mask (if ``per_channel`` is true-like).
    The ``per_channel`` is sampled per batch for each row/image.

    Added in 0.4.0.

    Parameters
    ----------
    parameter : imgaug.parameters.StochasticParameter
        Stochastic parameter to draw mask samples from.
        Expected to return values in interval ``[0.0, 1.0]`` (not all
        stochastic parameters do that) and must be able to handle sampling
        shapes ``(H, W)`` and ``(H, W, C)`` (all stochastic parameters should
        do that).

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

    c                    s&   t t|   || _t|d| _d S )NrU   )rV   r   rW   r   rX   r[   rU   )r]   r   rU   r^   r   r   rW   f	  s
   
z#StochasticParameterMaskGen.__init__Nc                    sB   |  }t  jjt|f d} fddt||D S )[
        See :func:`~imgaug.augmenters.blend.IBatchwiseMaskGenerator.draw_masks`.

        rc   c                    s   g | ]\}} | |qS r   
_draw_mask)ra   r$   Zper_channel_irC   r]   r   r   rb   w	      z9StochasticParameterMaskGen.draw_masks.<locals>.<listcomp>)rg   iarandomRNGrU   rh   r`   r   )r]   r@   rC   rp   rU   r   r  r   r   m	  s   
z%StochasticParameterMaskGen.draw_masksc                 C   s   t |dks
|dkr| jj||d}n| jj|dd |d}|jdkr@d|d  kr1dks@n J dt|t|f |S )Nr
   r!   rc   r   r   zYExpected 'parameter' samples to be in the interval [0.0, 1.0]. Got min %.4f and max %.4f.)r`   r   rh   r   r1   r(   r2   r3   )r]   r$   rC   rU   r   r   r   r   r  |	  s   
z%StochasticParameterMaskGen._draw_maskrw   )r   r   r   r   rW   r   r  r   r   r   r^   r   r   G	  s
    
r   c                       s   e Zd ZdZddddgddf fdd		ZdddZdd Zdd Zedd Z	edd Z
edd Zedd Zedd Z  ZS )r   a  Generator that produces masks based on some similar colors in images.

    This class receives batches for which to generate masks, iterates over
    the batch rows (i.e. images) and generates one mask per row.
    The mask contains high alpha values for some colors, while other colors
    get low mask values. Which colors are chosen is random. How wide or
    narrow the selection is (e.g. very specific blue tone or all blue-ish
    colors) is determined by the hyperparameters.

    The color selection method performs roughly the following steps:

      1. Split the full color range of the hue in ``HSV`` into ``nb_bins``
         bins (i.e. ``256/nb_bins`` different possible hue tones).
      2. Shift the bins by ``rotation_deg`` degrees. (This way, the ``0th``
         bin does not always start at exactly ``0deg`` of hue.)
      3. Sample ``alpha`` values for each bin.
      4. Repeat the ``nb_bins`` bins until there are ``256`` bins.
      5. Smoothen the alpha values of neighbouring bins using a gaussian
         kernel. The kernel's ``sigma`` is derived from ``smoothness``.
      6. Associate all hue values in the image with the corresponding bin's
         alpha value. This results in the alpha mask.

    .. note::

        This mask generator will produce an ``AssertionError`` for batches
        that contain no images.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    nb_bins : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Number of bins. For ``B`` bins, each bin denotes roughly ``360/B``
        degrees of colors in the hue channel. Lower values lead to a coarser
        selection of colors. Expected value range is ``[2, 256]``.

            * If ``int``: Exactly that value will be used for all images.
            * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
              per image from the discrete interval ``[a..b]``.
            * If ``list``: A random value will be picked per image from that
              list.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(N,)`` values -- one per image.

    smoothness : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Strength of the 1D gaussian kernel applied to the sampled binwise
        alpha values. Larger values will lead to more similar grayscaling of
        neighbouring colors. Expected value range is ``[0.0, 1.0]``.

            * If ``number``: Exactly that value will be used for all images.
            * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
              per image from the interval ``[a, b]``.
            * If ``list``: A random value will be picked per image from that
              list.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(N,)`` values -- one per image.

    alpha : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Parameter to sample binwise alpha blending factors from. Expected
        value range is ``[0.0, 1.0]``.  Note that the alpha values will be
        smoothed between neighbouring bins. Hence, it is usually a good idea
        to set this so that the probability distribution peaks are around
        ``0.0`` and ``1.0``, e.g. via a list ``[0.0, 1.0]`` or a ``Beta``
        distribution.
        It is not recommended to set this to a deterministic value, otherwise
        all bins and hence all pixels in the generated mask will have the
        same value.

            * If ``number``: Exactly that value will be used for all bins.
            * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
              per bin from the interval ``[a, b]``.
            * If ``list``: A random value will be picked per bin from that list.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(N*B,)`` values -- one per image and bin.

    rotation_deg : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Rotiational shift of each bin as a fraction of ``360`` degrees.
        E.g. ``0.0`` will not shift any bins, while a value of ``0.5`` will
        shift by around ``180`` degrees. This shift is mainly used so that
        the ``0th`` bin does not always start at ``0deg``. Expected value
        range is ``[-360, 360]``. This parameter can usually be kept at the
        default value.

            * If ``number``: Exactly that value will be used for all images.
            * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
              per image from the interval ``[a, b]``.
            * If ``list``: A random value will be picked per image from that
              list.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(N,)`` values -- one per image.

    from_colorspace : str, optional
        The source colorspace (of the input images).
        See :func:`~imgaug.augmenters.color.change_colorspace_`.

    r   r   rH   r   r   r   c                    sv   t t|   tj|ddddd| _tj|ddddd| _tj|ddddd| _tj|dd	ddd| _	|| _
d
| _d S )Nr   )r      TrN   r   rG   r6   r   )ir   g      $@)rV   r   rW   rX   handle_discrete_paramr   rY   r   r6   r   r   	sigma_max)r]   r   r   r6   r   r   r^   r   r   rW   	  s&   
zSomeColorsMaskGen.__init__Nc                    sD   |j dus	J dt|}j||d  fddt|j D S )r  NzXCan only generate masks for batches that contain images, but got a batch without images.rc   c                       g | ]\}} || qS r   r  )ra   r   imagesamplesr]   r   r   rb    
  r  z0SomeColorsMaskGen.draw_masks.<locals>.<listcomp>)re   r  r  _draw_samplesri   r  r   r  r   r   
  s   
zSomeColorsMaskGen.draw_masksc                 C   s2   |  ||d | |d | | j |d | | jS )Nr   r   r
   )generate_maskr  r   )r]   r  	image_idxr  r   r   r   r  %
  s   

zSomeColorsMaskGen._draw_maskc           
      C   s   |j }| jj|f|d}| jj|f|d}| jjt|f|d}| jj|f|d}t|dd}t|dd}t|dd}t	t
|d tjd}t||}	|	||fS )Nrc   r   r  rH   r   gll?)r   r   rh   r   r6   r(   sumr   r"   modr#   r*   Zint32r   )
r]   r@   rC   r   r   r   r6   r   rotation_binsbinwise_alphasr   r   r   r  .
  s,   



zSomeColorsMaskGen._draw_samplesc           
      C   s   ddl m} |jt||j|d}d|jdd v r(tj|jdd tjdS | 	|}| 
||}| ||}| ||}	|	S )aG  Generate a colorwise alpha mask for a single image.

        Added in 0.4.0.

        Parameters
        ----------
        image : ndarray
            Image for which to generate the mask. Must have shape ``(H,W,3)``
            in colorspace `from_colorspace`.

        binwise_alphas : ndarray
            Alpha values of shape ``(B,)`` with ``B`` in ``[1, 256]``
            and values in interval ``[0.0, 1.0]``. Will be upscaled to
            256 bins by simple repetition. Each bin represents ``1/256`` th
            of the hue.

        sigma : float
            Sigma of the 1D gaussian kernel applied to the upscaled binwise
            alpha value array.

        rotation_bins : int
            By how much to rotate the 256 bin alpha array. The rotation is
            given in number of bins.

        from_colorspace : str
            Colorspace of the input image. One of
            ``imgaug.augmenters.color.CSPACE_*``.

        Returns
        -------
        ndarray
            ``float32`` mask array of shape ``(H, W)`` with values in
            ``[0.0, 1.0]``

        r   )color)Zto_colorspacer   r   r
   r   ) r"  Zchange_colorspace_r(   r0   Z
CSPACE_HSVr$   r   r+   _upscale_to_256_alpha_bins_rotate_alpha_bins_smoothen_alphas_generate_pixelwise_alpha_mask)
r   r  r!  sigmar   r   Zcolorlib	image_hsvZbinwise_alphas_smoothr   r   r   r   r  D
  s   '
zSomeColorsMaskGen.generate_maskc                 C   s8   t |}ttd| }t||f}|dd }|S )Nr  r   )r`   r   r(   ceilrepeat)r   rr   r   Znb_repeats_per_binr   r   r   r$  
  s
   z,SomeColorsMaskGen._upscale_to_256_alpha_binsc                 C   s   |dkrt || }|S r   )r(   Zroll)r   rr   r   r   r   r   r%  
  s   z$SomeColorsMaskGen._rotate_alpha_binsc                 C   s   |dkr|S t t|d d}d|}}|d dkr|d7 }t|| d  ||d | g}tjt|tjd d f ||f||tjddd d f }|||  }|S )Nr   g      @r   r   r
   r   )ksizeZsigmaXZsigmaYZ
borderType)	r3   r   r(   concatenatecv2ZGaussianBlurr   r)   ZBORDER_REPLICATE)r   rr   r(  r,  Zksize_yZksize_xr   r   r   r&  
  s*   


z"SomeColorsMaskGen._smoothen_alphasc                 C   sV   |d d d d df }|d }t t |ddt j}t||}|t jd S )Nr      g     o@)r(   r"   r#   r*   Zuint8r   Z	apply_lutr+   )r   r)  Zhue_to_alphahuetabler   r   r   r   r'  
  s
   z0SomeColorsMaskGen._generate_pixelwise_alpha_maskrw   )r   r   r   r   rW   r   r  r  r   r  r$  r%  r&  r'  r   r   r   r^   r   r   	  s&    g
	
:
	

r   c                   @   sP   e Zd Z		dddZdddZdd	 Zd
d Zeedd Z	edd Z
dS )_LinearGradientMaskGenrH   r   c                 C   sb   || _ tj|ddddd| _tj|ddddd| _tj|ddddd| _tj|ddddd| _d S )Nr   rG   TrN   r   r   r   )r   rX   rY   r   r   r   r   )r]   r   r   r   r   r   r   r   r   rW   
  s"   z_LinearGradientMaskGen.__init__Nc                    s<   t |}| }jt||d  fddt|D S )t
        See :func:`~imgaug.augmenters.blend.IBatchwiseMaskGenerator.draw_masks`.

        Added in 0.4.0.

        rc   c                    r  r   r  )ra   r   r$   r  r   r   rb   
  r  z5_LinearGradientMaskGen.draw_masks.<locals>.<listcomp>)r  r  rg   r  r`   ri   )r]   r@   rC   rp   r   r  r   r   
  s   
z!_LinearGradientMaskGen.draw_masksc                 C   s2   |  ||d | |d | |d | |d | S )Nr   r   r
   r   r  )r]   r$   r  r  r   r   r   r  
  s   



z!_LinearGradientMaskGen._draw_maskc                 C   sT   | j j|f|d}| jj|f|d}| jj|f|d}| jj|f|d}||||fS Nrc   )r   rh   r   r   r   )r]   r   rC   r   r   r   r   r   r   r   r  
  s   

z$_LinearGradientMaskGen._draw_samplesc                 C   r
  )a  Generate a horizontal gradient mask.

        Added in 0.4.0.

        Parameters
        ----------
        shape : tuple of int
            Shape of the image. The mask will have the same height and
            width.

        min_value : number
            Minimum value of the gradient in interval ``[0.0, 1.0]``.

        max_value : number
            Maximum value of the gradient in interval ``[0.0, 1.0]``.

        start_at : number
            Position on the x-axis where the linear gradient starts, given as
            a fraction of the axis size. Interval is ``[0.0, 1.0]``.

        end_at : number
            Position on the x-axis where the linear gradient ends, given as
            a fraction of the axis size. Interval is ``[0.0, 1.0]``.

        Returns
        -------
        ndarray
            ``float32`` mask array with same height and width as the image.
            Values are in ``[0.0, 1.0]``.

        Nr   r   r$   r   r   r   r   r   r   r   r  
  r  z$_LinearGradientMaskGen.generate_maskc                 C   s:  |dd \}}|| }	t t|dd}t t|dd}t tt||	 d|	}
t tt||	 d|	}d}||
k rAd}||
}
}tj|
f|tjd}tj||||
 tjd}tj|	| f|tjd}tj|||fdd	}|rsd| }|dkr|d d tjf }t	|d
|f}|S |tjd d f }t	||d
f}|S )Nr   r
   rH   r   FTr   )startstopnumr   r   r   )
r2   r3   r   r(   fullr+   Zlinspacer-  r)   r.   )r   r$   r   r   r   r   r   heightwidthZ	axis_sizeZstart_at_pxZ	end_at_pxinvertedZbefore_gradZgradZ
after_gradr   r   r   r   _generate_mask  sJ   

z%_LinearGradientMaskGen._generate_mask)rH   r   rH   r   rw   )r   r   r   rW   r   r  r  r   r   r  r>  r   r   r   r   r2  
  s    

	"r2  c                       2   e Zd ZdZ		d fdd	Zedd Z  ZS )	r   a2
  Generator that produces horizontal linear gradient masks.

    This class receives batches and produces for each row (i.e. image)
    a horizontal linear gradient that matches the row's shape (i.e. image
    shape). The gradient increases linearly from a minimum value to a
    maximum value along the x-axis. The start and end points (i.e. where the
    minimum value starts to increase and where it reaches the maximum)
    may be defines as fractions of the width. E.g. for width ``100`` and
    ``start=0.25``, ``end=0.75``, the gradient would have its minimum
    in interval ``[0px, 25px]`` and its maximum in interval ``[75px, 100px]``.

    Note that this has nothing to do with a *derivative* along the x-axis.

    Added in 0.4.0.

    Parameters
    ----------
    min_value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Minimum value that the mask will have up to the start point of the
        linear gradient.
        Note that `min_value` is allowed to be larger than `max_value`,
        in which case the gradient will start at the (higher) `min_value`
        and decrease towards the (lower) `max_value`.

        * If ``number``: Exactly that value will be used for all images.
        * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
          per image from the interval ``[a, b]``.
        * If ``list``: A random value will be picked per image from that list.
        * If ``StochasticParameter``: That parameter will be queried once
          per batch for ``(N,)`` values -- one per image.

    max_value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Maximum value that the mask will have at the end of the
        linear gradient.

        Datatypes are analogous to `min_value`.

    start_at : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Position on the x-axis where the linear gradient starts, given as a
        fraction of the axis size. Interval is ``[0.0, 1.0]``, where ``0.0``
        is at the left of the image.
        If ``end_at < start_at`` the gradient will be inverted.

        Datatypes are analogous to `min_value`.

    end_at : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Position on the x-axis where the linear gradient ends, given as a
        fraction of the axis size. Interval is ``[0.0, 1.0]``, where ``0.0``
        is at the right of the image.

        Datatypes are analogous to `min_value`.

    r   r   c                       t t| jd||||d d S )Nr   r   r   r   r   r   )rV   r   rW   r]   r   r   r   r   r^   r   r   rW   |     

z(HorizontalLinearGradientMaskGen.__init__c                 C      | j d|||||dS )  Generate a linear horizontal gradient mask.

        Added in 0.4.0.

        Parameters
        ----------
        shape : tuple of int
            Shape of the image. The mask will have the same height and
            width.

        min_value : number
            Minimum value of the gradient in interval ``[0.0, 1.0]``.

        max_value : number
            Maximum value of the gradient in interval ``[0.0, 1.0]``.

        start_at : number
            Position on the x-axis where the linear gradient starts, given as
            a fraction of the axis size. Interval is ``[0.0, 1.0]``.

        end_at : number
            Position on the x-axis where the linear gradient ends, given as
            a fraction of the axis size. Interval is ``[0.0, 1.0]``.

        Returns
        -------
        ndarray
            ``float32`` mask array with same height and width as the image.
            Values are in ``[0.0, 1.0]``.

        r   r   r$   r   r   r   r   r>  r6  r   r   r   r       !z-HorizontalLinearGradientMaskGen.generate_maskr   r   r   r   r   r   r   r   rW   r   r  r   r   r   r^   r   r   D  s    7	r   c                       r?  )	r   a  Generator that produces vertical linear gradient masks.

    See :class:`~imgaug.augmenters.blend.HorizontalLinearGradientMaskGen`
    for details.

    Added in 0.4.0.

    Parameters
    ----------
    min_value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Minimum value that the mask will have up to the start point of the
        linear gradient.
        Note that `min_value` is allowed to be larger than `max_value`,
        in which case the gradient will start at the (higher) `min_value`
        and decrease towards the (lower) `max_value`.

        * If ``number``: Exactly that value will be used for all images.
        * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
          per image from the interval ``[a, b]``.
        * If ``list``: A random value will be picked per image from that list.
        * If ``StochasticParameter``: That parameter will be queried once
          per batch for ``(N,)`` values -- one per image.

    max_value : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Maximum value that the mask will have at the end of the
        linear gradient.

        Datatypes are analogous to `min_value`.

    start_at : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Position on the y-axis where the linear gradient starts, given as a
        fraction of the axis size. Interval is ``[0.0, 1.0]``, where ``0.0``
        is at the top of the image.
        If ``end_at < start_at`` the gradient will be inverted.

        Datatypes are analogous to `min_value`.

    end_at : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Position on the x-axis where the linear gradient ends, given as a
        fraction of the axis size. Interval is ``[0.0, 1.0]``, where ``1.0``
        is at the bottom of the image.

        Datatypes are analogous to `min_value`.

    r   r   c                    r@  )Nr   rA  )rV   r   rW   rB  r^   r   r   rW     rC  z&VerticalLinearGradientMaskGen.__init__c                 C   rD  )rE  r   rF  rG  r6  r   r   r   r    rH  z+VerticalLinearGradientMaskGen.generate_maskrI  rJ  r   r   r^   r   r     s    /	r   c                   @   s>   e Zd ZdZddgfddZdddZd	d
 Zedd ZdS )r   a  Generate masks following a regular grid pattern.

    This mask generator splits each image into a grid-like pattern of
    ``H`` rows and ``W`` columns. Each cell is then filled with an alpha
    value, sampled randomly per cell.

    The difference to :class:`CheckerboardMaskGen` is that this mask generator
    samples random alpha values per cell, while in the checkerboard the
    alpha values follow a fixed pattern.

    Added in 0.4.0.

    Parameters
    ----------
    nb_rows : int or tuple of int or list of int or imgaug.parameters.StochasticParameter
        Number of rows of the regular grid.

            * If ``int``: Exactly that value will be used for all images.
            * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
              per image from the discrete interval ``[a..b]``.
            * If ``list``: A random value will be picked per image from that
              list.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(N,)`` values -- one per image.

    nb_cols : int or tuple of int or list of int or imgaug.parameters.StochasticParameter
        Number of columns of the checkerboard. Analogous to `nb_rows`.

    alpha : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Alpha value of each cell.

        * If ``number``: Exactly that value will be used for all images.
        * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
          per image from the interval ``[a, b]``.
        * If ``list``: A random value will be picked per image from that list.
        * If ``StochasticParameter``: That parameter will be queried once
          per batch for ``(N,)`` values -- one per image.

    rH   r   c                 C   sJ   t j|dddddd| _t j|dddddd| _t j|ddddd	| _d S )
Nr   )r   NTFrO   rP   rQ   Zallow_floatsr   r6   rG   rN   )rX   r  r   r   rY   r6   )r]   r   r   r6   r   r   r   rW   <  s   zRegularGridMaskGen.__init__Nc                    sF   t |}| } jt||d\}}} fddt||||D S )r3  rc   c                    s$   g | ]\}}}}  ||||qS r   r4  )ra   r$   	nb_rows_i	nb_cols_iZalpha_iry   r   r   rb   V  s    
z1RegularGridMaskGen.draw_masks.<locals>.<listcomp>)r  r  rg   r  r`   r   )r]   r@   rC   rp   r   r   r6   r   ry   r   r   J  s   


zRegularGridMaskGen.draw_masksc                 C   sX   | j j|f|d}| jj|f|d}|| }| jjt|f|d}t||}|||fS r5  )r   rh   r   r6   r(   r  r   )r]   rq   rC   r   r   Znb_alphas_per_imgZ	alpha_rawr6   r   r   r   r  [  s   




z RegularGridMaskGen._draw_samplesc                 C   sh  ddl m} |dd \}}d||fv rtj||ftjdS tt|d|}tt|d|}t|| }t|| }	|jd||  }|j|| ksZJ d|j|| ||||ff |	tj
||f}
tj|
|dd}
tj|
|	dd}
||
jd  }||
jd  }tt|d }tt|d }tt|d }tt|d }|j|
||||dd	}
|
S )
a  Generate a mask following a checkerboard pattern.

        Added in 0.4.0.

        Parameters
        ----------
        shape : tuple of int
            Height and width of the output mask.

        nb_rows : int
            Number of rows of the checkerboard pattern.

        nb_cols : int
            Number of columns of the checkerboard pattern.

        alphas : ndarray
            1D or 2D array containing for each cell the alpha value, i.e.
            ``nb_rows*nb_cols`` values.

        Returns
        -------
        ndarray
            ``float32`` mask array with same height and width as
            ``segmap.shape``. Values are in ``[0.0, 1.0]``.

        r   )r   r   r
   r   zExpected `alphas` to not contain less values than `nb_rows * nb_cols` (both clipped to [1, height] and [1, width] respectively). Got %d alpha values vs %d expected values (nb_rows=%d, nb_cols=%d) for requested mask shape %s.r   Zreflect)toprightbottomleftr   )r#  r   r(   r   r+   r2   r3   r   Zflatr*   r-   r+  r$   floorr*  pad)r   r$   r   r   rr   Zsizelibr;  r<  Zcell_height
cell_widthr   Zmissing_heightZmissing_widthrN  rP  rQ  rO  r   r   r   r  i  s<   z RegularGridMaskGen.generate_maskrw   	r   r   r   r   rW   r   r  r   r  r   r   r   r   r     s    )
r   c                   @   sF   e Zd ZdZdd Zedd Zedd Zdd	d
Ze	dd Z
dS )r   a  Generate masks following a checkerboard-like pattern.

    This mask generator splits each image into a regular grid of
    ``H`` rows and ``W`` columns. Each cell is then filled with either
    ``1.0`` or ``0.0``. The cell at the top-left is always ``1.0``. Its right
    and bottom neighbour cells are ``0.0``. The 4-neighbours of any cell always
    have a value opposite to the cell's value (``0.0`` vs. ``1.0``).

    Added in 0.4.0.

    Parameters
    ----------
    nb_rows : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Number of rows of the checkerboard.

            * If ``int``: Exactly that value will be used for all images.
            * If ``tuple`` ``(a, b)``: A random value will be uniformly sampled
              per image from the discrete interval ``[a..b]``.
            * If ``list``: A random value will be picked per image from that
              list.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(N,)`` values -- one per image.

    nb_cols : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Number of columns of the checkerboard. Analogous to `nb_rows`.

    c                 C   s   t ||dd| _d S )Nr   r   )r   grid)r]   r   r   r   r   r   rW     s   zCheckerboardMaskGen.__init__c                 C   r   )zGet the number of rows of the checkerboard grid.

        Added in 0.4.0.

        Returns
        -------
        int
            The number of rows.

        )rV  r   ry   r   r   r   r        zCheckerboardMaskGen.nb_rowsc                 C   r   )zGet the number of columns of the checkerboard grid.

        Added in 0.4.0.

        Returns
        -------
        int
            The number of columns.

        )rV  r   ry   r   r   r   r     rW  zCheckerboardMaskGen.nb_colsNc                    sF   t |}| } jjt||d\}}} fddt|||D S )r3  rc   c                    s    g | ]\}}}  |||qS r   r4  )ra   r$   rL  rM  ry   r   r   rb     s    z2CheckerboardMaskGen.draw_masks.<locals>.<listcomp>)r  r  rg   rV  r  r`   r   )r]   r@   rC   rp   r   r   Z_alphar   ry   r   r     s   


zCheckerboardMaskGen.draw_masksc                 C   s   |dd \}}d||fv rt j||ft jdS tt|d|}tt|d|}t j|fdt jd}d|ddd< t |t jddf |df}d|dddddf  |dddddf< t	||||S )a  Generate a mask following a checkerboard pattern.

        Added in 0.4.0.

        Parameters
        ----------
        shape : tuple of int
            Height and width of the output mask.

        nb_rows : int
            Number of rows of the checkerboard pattern.

        nb_cols : int
            Number of columns of the checkerboard pattern.

        Returns
        -------
        ndarray
            ``float32`` mask array with same height and width as
            ``segmap.shape``. Values are in ``[0.0, 1.0]``.

        r   r
   r   r   r   rH   N)
r(   r   r+   r2   r3   r:  r.   r)   r   r  )r   r$   r   r   r;  r<  rr   r   r   r   r    s   ,z!CheckerboardMaskGen.generate_maskrw   )r   r   r   r   rW   r   r   r   r   r   r  r   r   r   r   r     s    


r   c                   @   s8   e Zd ZdZdddZdddZdd Zed	d
 ZdS )r  as  Generator that produces masks highlighting segmentation map classes.

    This class produces for each segmentation map in a batch a mask in which
    the locations of a set of provided classes are highlighted (i.e. ``1.0``).
    The classes may be provided as a fixed list of class ids or a stochastic
    parameter from which class ids will be sampled.

    The produced masks are initially of the same height and width as the
    segmentation map arrays and later upscaled to the image height and width.

    .. note::

        Segmentation maps can have multiple channels. If that is the case
        then for each position ``(x, y)`` it is sufficient that any class id
        in any channel matches one of the desired class ids.

    .. note::

        This class will produce an ``AssertionError`` if there are no
        segmentation maps in a batch.

    Added in 0.4.0.

    Parameters
    ----------
    class_ids : int or tuple of int or list of int or imgaug.parameters.StochasticParameter
        Segmentation map classes to mark in the produced mask.

        If `nb_sample_classes` is ``None`` then this is expected to be either
        a single ``int`` (always mark this one class id) or a ``list`` of
        ``int`` s (always mark these class ids).

        If `nb_sample_classes` is set, then this parameter will be treated
        as a stochastic parameter with the following valid types:

            * If ``int``: Exactly that class id will be used for all
              segmentation maps.
            * If ``tuple`` ``(a, b)``: ``N`` random values will be uniformly
              sampled per segmentation map from the discrete interval
              ``[a..b]`` and used as the class ids.
            * If ``list``: ``N`` random values will be picked per segmentation
              map from that list and used as the class ids.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(sum(N),)`` values.

        ``N`` denotes the number of classes to sample per segmentation
        map (derived from `nb_sample_classes`) and ``sum(N)`` denotes the
        sum of ``N`` s over all segmentation maps.

    nb_sample_classes : None or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Number of class ids to sample (with replacement) per segmentation map.
        As sampling happens with replacement, fewer *unique* class ids may be
        sampled.

            * If ``None``: `class_ids` is expected to be a fixed value of
              class ids to be used for all segmentation maps.
            * If ``int``: Exactly that many class ids will be sampled for all
              segmentation maps.
            * If ``tuple`` ``(a, b)``: A random value will be uniformly
              sampled per segmentation map from the discrete interval
              ``[a..b]``.
            * If ``list`` or ``int``: A random value will be picked per
              segmentation map from that list.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(B,)`` values, where ``B`` is the number of
              segmentation maps.

    Nc                 C   sz   |d u r#t |r|g}t|tsJ dt|jf || _d | _d S tj	|dddddd| _tj	|dddddd| _d S )NzExpected `class_ids` to be a single integer or a list of integers if `nb_sample_classes` is None. Got type `%s`. Set `nb_sample_classes` to e.g. an integer to enable stochastic parameters for `class_ids`.r   r   NTFrK  r  )
r   Zis_single_integer
isinstancelisttyper   r   r  rX   r  )r]   r   r  r   r   r   rW   i  s*   

zSegMapClassIdsMaskGen.__init__c                    sF   |j dus	J dt|} j|j|d} fddt|j |D S )r3  NzaCan only generate masks for batches that contain segmentation maps, but got a batch without them.rc   c                       g | ]
\}}  ||qS r   r4  )ra   segmapZclass_ids_iry   r   r   rb         z4SegMapClassIdsMaskGen.draw_masks.<locals>.<listcomp>)r   r  r  r  r   r   )r]   r@   rC   r   r   ry   r   r     s   


z SegMapClassIdsMaskGen.draw_masksc                 C      | j }|d u rt| jtsJ dt| jjf | jg| S |j|f|d}t|dd }| jjt	|f|d}t
||}|S NzExpected list got %s.rc   r   )r  rY  r   rZ  r[  r   rh   r(   r"   r  r   )r]   r   rC   r  Zclass_ids_rawr   r   r   r   r        

z#SegMapClassIdsMaskGen._draw_samplesc                 C   sj   t j|jjdd td}|D ]}t j|j|kdd}t ||}q|t j}t	
||jdd }|S )a  Generate a mask of where the segmentation map has the given classes.

        Added in 0.4.0.

        Parameters
        ----------
        segmap : imgaug.augmentables.segmap.SegmentationMapsOnImage
            The segmentation map for which to generate the mask.

        class_ids : iterable of int
            IDs of the classes to set to ``1.0``.
            For an ``(x, y)`` position, it is enough that *any* channel
            at the given location to have one of these class ids to be marked
            as ``1.0``.

        Returns
        -------
        ndarray
            ``float32`` mask array with same height and width as
            ``segmap.shape``. Values are in ``[0.0, 1.0]``.

        r   r
   r   r   )r(   r   r   r$   boolany
logical_orr*   r+   r   r   )r   r]  r   r   Zclass_idZmask_ir   r   r   r    s   z#SegMapClassIdsMaskGen.generate_maskrw   rU  r   r   r   r   r  "  s    
F
r  c                   @   s8   e Zd ZdZdddZdddZdd Zed	d
 ZdS )r  a]  Generator that produces masks highlighting bounding boxes.

    This class produces for each row (i.e. image + bounding boxes) in a batch
    a mask in which the inner areas of bounding box rectangles with given
    labels are marked (i.e. set to ``1.0``). The labels may be provided as a
    fixed list of strings or a stochastic parameter from which labels will be
    sampled. If no labels are provided, all bounding boxes will be marked.

    A pixel will be set to ``1.0`` if *at least* one bounding box at that
    location has one of the requested labels, even if there is *also* one
    bounding box at that location with a not requested label.

    .. note::

        This class will produce an ``AssertionError`` if there are no
        bounding boxes in a batch.

    Added in 0.4.0.

    Parameters
    ----------
    labels : None or str or list of str or imgaug.parameters.StochasticParameter
        Labels of bounding boxes to select for.

        If `nb_sample_labels` is ``None`` then this is expected to be either
        also ``None`` (select all BBs) or a single ``str`` (select BBs with
        this one label) or a ``list`` of ``str`` s (always select BBs with
        these labels).

        If `nb_sample_labels` is set, then this parameter will be treated
        as a stochastic parameter with the following valid types:

            * If ``None``: Ignore the sampling count  and always use all
              bounding boxes.
            * If ``str``: Exactly that label will be used for all
              images.
            * If ``list`` of ``str``: ``N`` random values will be picked per
              image from that list and used as the labels.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(sum(N),)`` values.

        ``N`` denotes the number of labels to sample per segmentation
        map (derived from `nb_sample_labels`) and ``sum(N)`` denotes the
        sum of ``N`` s over all images.

    nb_sample_labels : None or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Number of labels to sample (with replacement) per image.
        As sampling happens with replacement, fewer *unique* labels may be
        sampled.

            * If ``None``: `labels` is expected to also be ``None`` or a fixed
              value of labels to be used for all images.
            * If ``int``: Exactly that many labels will be sampled for all
              images.
            * If ``tuple`` ``(a, b)``: A random value will be uniformly
              sampled per image from the discrete interval ``[a..b]``.
            * If ``list``: A random value will be picked per image from
              that list.
            * If ``StochasticParameter``: That parameter will be queried once
              per batch for ``(B,)`` values, where ``B`` is the number of
              images.

    Nc                 C   s   |d u rd | _ d | _d S |d u r/t|r|g}t|ts'J dt|jf || _ d | _d S t	|d| _ tj
|dddddd| _d S )NzExpected `labels` a single string or a list of strings if `nb_sample_labels` is None. Got type `%s`. Set `nb_sample_labels` to e.g. an integer to enable stochastic parameters for `labels`.r  r  rX  TFrK  )r  r  r   Z	is_stringrY  rZ  r[  r   rX   Zhandle_categorical_string_paramr  )r]   r  r  r   r   r   rW     s(   


zBoundingBoxesMaskGen.__init__c                    sd   |j dus	J dt|} jdu r fdd|j D S  j|j|d} fddt|j |D S )r3  Nz^Can only generate masks for batches that contain bounding boxes, but got a batch without them.c                    s   g | ]}  |d qS rw   r4  )ra   bbsoiry   r   r   rb   0  s    z3BoundingBoxesMaskGen.draw_masks.<locals>.<listcomp>rc   c                    r\  r   r4  )ra   re  Zlabels_iry   r   r   rb   5  r^  )r   r  r  r  r  r   r   )r]   r@   rC   r  r   ry   r   r   #  s   




zBoundingBoxesMaskGen.draw_masksc                 C   r_  r`  )r  rY  r  rZ  r[  r   rh   r(   r"   r  r   )r]   r   rC   r  Z
labels_rawr  r   r   r   r  :  ra  z"BoundingBoxesMaskGen._draw_samplesc                 C   s   |durt |nd}|jdd \}}tj||ftjd}|D ]I}|du s*|j|v rhttt|j	d|}ttt|j
d|}ttt|jd|}	ttt|jd|}
||	k rh||
k rhd|||
||	f< q|S )a  Generate a mask of the areas of bounding boxes with given labels.

        Added in 0.4.0.

        Parameters
        ----------
        bbsoi : imgaug.augmentables.bbs.BoundingBoxesOnImage
            The bounding boxes for which to generate the mask.

        labels : None or iterable of str
            Labels of the bounding boxes to set to ``1.0``.
            For an ``(x, y)`` position, it is enough that *any* bounding box
            at the given location has one of the labels.
            If this is ``None``, all bounding boxes will be marked.

        Returns
        -------
        ndarray
            ``float32`` mask array with same height and width as
            ``segmap.shape``. Values are in ``[0.0, 1.0]``.

        Nr   r
   r   r   )setr$   r(   r   r+   labelr2   r3   r   x1y1x2y2)r   re  r  r;  r<  r   Zbbrh  ri  rj  rk  r   r   r   r  N  s   z"BoundingBoxesMaskGen.generate_mask)NNrw   rU  r   r   r   r   r    s    
A
r  c                   @   s"   e Zd ZdZdd ZdddZdS )InvertMaskGena5  Generator that inverts the outputs of other mask generators.

    This class receives batches and calls for each row (i.e. image)
    a child mask generator to produce a mask. That mask is then inverted
    for ``p%`` of all rows, i.e. converted to ``1.0 - mask``.

    Added in 0.4.0.

    Parameters
    ----------
    p : bool or float or imgaug.parameters.StochasticParameter, optional
        Probability of inverting each mask produced by the other mask
        generator.

    child : IBatchwiseMaskGenerator
        The other mask generator to invert.

    c                 C   s   t |d| _|| _d S )Nr   )rX   r[   r   child)r]   r   rm  r   r   r   rW     s   
zInvertMaskGen.__init__Nc                 C   sZ   t |}| jj||d}| jjt||d}t||D ]\}}|dkr*d| |d< q|S )r3  rc   r!   r   .)r  r  rm  r   r   rh   r`   r   )r]   r@   rC   r   r   r   Zp_ir   r   r   r     s   
zInvertMaskGen.draw_masksrw   )r   r   r   r   rW   r   r   r   r   r   rl  v  s    rl  AlphazAlpha is deprecated. Use BlendAlpha instead. The order of parameters is the same. Parameter 'first' was renamed to 'foreground'. Parameter 'second' was renamed to 'background'.)Zalt_funccommentFrI   c              
   C      t | |||||||dS )z;See :class:`BlendAlpha`.

    Deprecated since 0.4.0.

    r   )rF   rL   firstsecondrU   rK   r&   rC   rB   r   r   r   rn       AlphaElementwisezAlphaElementwise is deprecated. Use BlendAlphaElementwise instead. The order of parameters is the same. Parameter 'first' was renamed to 'foreground'. Parameter 'second' was renamed to 'background'.c              
   C   rp  )zFSee :class:`BlendAlphaElementwise`.

    Deprecated since 0.4.0.

    r   )r   rq  r   r   r   ru    rt  zSimplexNoiseAlpha is deprecated. Use BlendAlphaSimplexNoise instead. The order of parameters is the same. Parameter 'first' was renamed to 'foreground'. Parameter 'second' was renamed to 'background'.r   r   r3   Tc                 C   s"   t | |||||||||	|
||dS )zGSee :class:`BlendAlphaSimplexNoise`.

    Deprecated since 0.4.0.

    )r<   r>   rU   r   r   r   r   r   r   rK   r&   rC   rB   )r   )rr  rs  rU   r   r   r   r   r   r   rK   r&   rC   rB   r   r   r   SimplexNoiseAlpha  s   rv  zFrequencyNoiseAlpha is deprecated. Use BlendAlphaFrequencyNoise instead. The order of parameters is the same. Parameter 'first' was renamed to 'foreground'. Parameter 'second' was renamed to 'background'.r   r   r   r!   c                 C   s$   t | |||||||||	|
|||dS )zISee :class:`BlendAlphaFrequencyNoise`.

    Deprecated since 0.4.0.

    )r   r<   r>   rU   r   r   r   r   r   r   rK   r&   rC   rB   )r   )r   rr  rs  rU   r   r   r   r   r   r   rK   r&   rC   rB   r   r   r   FrequencyNoiseAlpha  s   rw  )r   )r   NNFNNrI   rI   r   )>r   
__future__r   r   r   abcr   r   numpyr(   sixr.  Zimgaugr   Zimgaug.imgaugr   r#  r	   r   rX   r   r4   r   r  Zaugmentablesr   r   r   r9   rA   rE   Z	AugmenterrF   r   r   r   r   r   r   r   r   r   r   r  Zadd_metaclassobjectr	  r   r   r2  r   r   r   r   r  r  rl  rI   rn  ru  rv  rw  r   r   r   r   <module>   s    
	 * t  ;  a } z  e  &O  ( 	kc u * ,)