o
    e                     @   s  d Z ddlmZmZmZ ddlZddlmZ ddl	Z	ddl
m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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j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jZ%dS )#z
Augmenters that blur images.

List of augmenters:

    * :class:`GaussianBlur`
    * :class:`AverageBlur`
    * :class:`MedianBlur`
    * :class:`BilateralBlur`
    * :class:`MotionBlur`
    * :class:`MeanShiftBlur`

    )print_functiondivisionabsolute_importN)ndimage)_normalize_cv2_input_arr_   )meta)convolutional   )
parameters)dtypesautoMbP?c                 C   s  | j dk}|d| krZ|sZ| j}tj| g dg ddd g d}|}|dkr4| jj|vr1dnd	}n|dkrH| jj|vsGJ d
| jjf n|d	krM	 |d	kr|jdkr_| jtjdd} n|jdkrl| jtjdd} |durut	d | j
dkrtj| ddddf |dd| ddddf< n| jd }	t|	D ]}
tj| dddd|
f |dd| dddd|
f< qn|jdkr| jtjdd} n)|jdkr| jtjdd} n|jdkr| jtjdd} n|jdkr| jtjdd} |du rt|}nt|s
J dt|f |d dkr|d n|}|dkr@tjt| ||f||tjd}| j
dkr>|j
dkr>|dtjf n|} |jdkrL| dk} | S |j| jjkrZt| |} | S )a\  Blur an image using gaussian blurring in-place.

    This operation *may* change the input image in-place.

    **Supported dtypes**:

    if (backend="auto"):

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

        - (1) Handled by ``cv2``. See ``backend="cv2"``.
        - (2) Handled by ``scipy``. See ``backend="scipy"``.

    if (backend="cv2"):

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

        - (1) Mapped internally to ``float32``. Otherwise causes
              ``TypeError: src data type = 0 is not supported``.
        - (2) Causes ``TypeError: src data type = 6 is not supported``.
        - (3) Causes ``cv2.error: OpenCV(3.4.5) (...)/filter.cpp:2957:
              error: (-213:The function/feature is not implemented)
              Unsupported combination of source format (=4), and buffer
              format (=5) in function 'getLinearRowFilter'``.
        - (4) Mapped internally to ``int16``. Otherwise causes
              ``cv2.error: OpenCV(3.4.5) (...)/filter.cpp:2957: error:
              (-213:The function/feature is not implemented) Unsupported
              combination of source format (=1), and buffer format (=5)
              in function 'getLinearRowFilter'``.
        - (5) Mapped internally to ``float64``. Otherwise causes
              ``cv2.error: OpenCV(3.4.5) (...)/filter.cpp:2957: error:
              (-213:The function/feature is not implemented) Unsupported
              combination of source format (=4), and buffer format (=5)
              in function 'getLinearRowFilter'``.
        - (6) Causes ``cv2.error: OpenCV(3.4.5) (...)/filter.cpp:2957:
              error: (-213:The function/feature is not implemented)
              Unsupported combination of source format (=4), and buffer
              format (=5) in function 'getLinearRowFilter'``.
        - (7) Mapped internally to ``float32``. Otherwise causes
              ``TypeError: src data type = 23 is not supported``.
        - (8) Causes ``TypeError: src data type = 13 is not supported``.

    if (backend="scipy"):

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

        - (1) Mapped internally to ``float32``. Otherwise causes
              ``RuntimeError: array type dtype('float16') not supported``.
        - (2) Causes ``RuntimeError: array type dtype('float128') not
              supported``.
        - (3) Mapped internally to ``float32``. Otherwise too inaccurate.

    Parameters
    ----------
    image : numpy.ndarray
        The image to blur. Expected to be of shape ``(H, W)`` or ``(H, W, C)``.

    sigma : number
        Standard deviation of the gaussian blur. Larger numbers result in
        more large-scale blurring, which is overall slower than small-scale
        blurring.

    ksize : None or int, optional
        Size in height/width of the gaussian kernel. This argument is only
        understood by the ``cv2`` backend. If it is set to ``None``, an
        appropriate value for `ksize` will automatically be derived from
        `sigma`. The value is chosen tighter for larger sigmas to avoid as
        much as possible very large kernel sizes and therey improve
        performance.

    backend : {'auto', 'cv2', 'scipy'}, optional
        Backend library to use. If ``auto``, then the likely best library
        will be automatically picked per image. That is usually equivalent
        to ``cv2`` (OpenCV) and it will fall back to ``scipy`` for datatypes
        not supported by OpenCV.

    eps : number, optional
        A threshold used to decide whether `sigma` can be considered zero.

    Returns
    -------
    numpy.ndarray
        The blurred image. Same shape and dtype as the input.
        (Input image *might* have been altered in-place.)

    r   )booluint8uint16uint32int8int16int32int64uint64float16float32float64)uint128uint256int128int256float96float128float256NallowedZ
disallowedZ	augmenter)r   r   r   r    r   cv2scipyzRequested 'cv2' backend, but provided %s input image, which cannot be handled by that backend. Choose a different backend or set backend to 'auto' or use a different datatype.r   Fcopyr   zRequested 'scipy' backend or picked it automatically by backend='auto' n blur_gaussian_(), but also provided 'ksize' argument, which is not understood by that backend and will be ignored.r
   Zmirror)moder   r   z1Expected 'ksize' argument to be a number, got %s.r   )ZsigmaXZsigmaYZ
borderType   .      ?)sizedtypeiadtgate_dtypesnameastypenpr   iawarnndimr   Zgaussian_filtershapesmxranger   r   _compute_gaussian_blur_ksizeis_single_integertyper$   GaussianBlurr   ZBORDER_REFLECT_101newaxisrestore_dtypes_)imagesigmaksizebackendepshas_zero_sized_axesr,   Zdts_not_supported_by_cv2Zbackend_to_usenb_channelsZchannelZimage_warped rE   FD:\Projects\ConvertPro\env\Lib\site-packages\imgaug/augmenters/blur.pyblur_gaussian_   s   
{












rG   c                 C   s  d| j dd v r| S | jjdksJ d| jjf | jdk}| jdko*| j d dk}| jdko6| j d dk}|sE|sE|sEJ d| j f |rSt| d	tjf d
} n|r[t| d
} t|d}t|d}t| } t	j
| ||| d} |rz| d } | S |r| d	ddf } | S )a  Apply a pyramidic mean shift filter to the input image in-place.

    This produces an output image that has similarity with one modified by
    a bilateral filter. That is different from mean shift *segmentation*,
    which averages the colors in segments found by mean shift clustering.

    This function is a thin wrapper around ``cv2.pyrMeanShiftFiltering``.

    .. note::

        This function does *not* change the image's colorspace to ``RGB``
        before applying the mean shift filter. A non-``RGB`` colorspace will
        hence influence the results.

    .. note::

        This function is quite slow.

    Added in 0.4.0.

    **Supported dtypes**:

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

        - (1) Not supported by ``cv2.pyrMeanShiftFiltering``.

    Parameters
    ----------
    image : ndarray
        ``(H,W)`` or ``(H,W,1)`` or ``(H,W,3)`` image to blur.
        Images with no or one channel will be temporarily tiled to have
        three channels.

    spatial_window_radius : number
        Spatial radius for pixels that are assumed to be similar.

    color_window_radius : number
        Color radius for pixels that are assumed to be similar.

    Returns
    -------
    ndarray
        Blurred input image. Same shape and dtype as the input.
        (Input image *might* have been altered in-place.)

    r   r
   r   z,Expected image with dtype "uint8", got "%s".r)   r   z9Expected (H,W) or (H,W,1) or (H,W,3) image, got shape %s..)r   r   r)   )spsrdst).r   )r5   r,   r/   r4   r1   Ztiler<   maxr   r$   ZpyrMeanShiftFiltering)r>   spatial_window_radiuscolor_window_radiusZshape_is_hwZshape_is_hw1Zshape_is_hw3rE   rE   rF   blur_mean_shift_  sD   ;


rO   c                 C   s>   | dk r	d|  }n| dk rd|  }nd|  }t t|d}|S )N      @gffffff
@      @g333333@g@   )intrL   )r?   r@   rE   rE   rF   r8   r  s   

r8   c                       8   e Zd ZdZ			d fdd	Zdd Zd	d
 Z  ZS )r;   a  Augmenter to blur images using gaussian kernels.

    **Supported dtypes**:

    See ``~imgaug.augmenters.blur.blur_gaussian_(backend="auto")``.

    Parameters
    ----------
    sigma : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Standard deviation of the gaussian kernel.
        Values in the range ``0.0`` (no blur) to ``3.0`` (strong blur) are
        common.

            * If a single ``float``, that value will always be used as the
              standard deviation.
            * If a tuple ``(a, b)``, then a random value from the interval
              ``[a, b]`` will be picked per image.
            * If a list, then a random value will be sampled per image from
              that list.
            * If a ``StochasticParameter``, then ``N`` samples will be drawn
              from that parameter per ``N`` input images.

    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.GaussianBlur(sigma=1.5)

    Blur all images using a gaussian kernel with a standard deviation of
    ``1.5``.

    >>> aug = iaa.GaussianBlur(sigma=(0.0, 3.0))

    Blur images using a gaussian kernel with a random standard deviation
    sampled uniformly (per image) from the interval ``[0.0, 3.0]``.

    g        rP   N
deprecatedc                    s8   t t| j||||d tj|ddddd| _d| _d S )Nseedr/   random_statedeterministicr?   )r   NTvalue_rangetuple_to_uniformlist_to_choicer   )superr;   __init__iaphandle_continuous_paramr?   rB   )selfr?   rX   r/   rY   rZ   	__class__rE   rF   r`     s   

zGaussianBlur.__init__c           
      C   sZ   |j d u r|S |j }t|}| jj|f|d}t||D ]\}}	t||	| jd|d< q|S )NrY   )r?   rB   .)imageslenr?   draw_samplesziprG   rB   )
rc   batchrY   parentshooksrg   	nb_imagessamplesr>   sigrE   rE   rF   _augment_batch_  s   

zGaussianBlur._augment_batch_c                 C      | j gS z=See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`.)r?   rc   rE   rE   rF   get_parameters     zGaussianBlur.get_parameters)rU   NNrV   rV   __name__
__module____qualname____doc__r`   rq   ru   __classcell__rE   rE   rd   rF   r;     s    6r;   c                       rT   )AverageBlura  Blur an image by computing simple means over neighbourhoods.

    The padding behaviour around the image borders is cv2's
    ``BORDER_REFLECT_101``.

    **Supported dtypes**:

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

        - (1) rejected by ``cv2.blur()``
        - (2) loss of resolution in ``cv2.blur()`` (result is ``int32``)
        - (3) ``int8`` is mapped internally to ``int16``, ``int8`` itself
              leads to cv2 error "Unsupported combination of source format
              (=1), and buffer format (=4) in function 'getRowSumFilter'" in
              ``cv2``
        - (4) results too inaccurate
        - (5) loss of resolution in ``cv2.blur()`` (result is ``int32``)
        - (6) ``float16`` is mapped internally to ``float32``
        - (7) ``bool`` is mapped internally to ``float32``

    Parameters
    ----------
    k : int or tuple of int or tuple of tuple of int or imgaug.parameters.StochasticParameter or tuple of StochasticParameter, optional
        Kernel size to use.

            * If a single ``int``, then that value will be used for the height
              and width of the kernel.
            * If a tuple of two ``int`` s ``(a, b)``, then the kernel size will
              be sampled from the interval ``[a..b]``.
            * If a tuple of two tuples of ``int`` s ``((a, b), (c, d))``,
              then per image a random kernel height will be sampled from the
              interval ``[a..b]`` and a random kernel width will be sampled
              from the interval ``[c..d]``.
            * If a ``StochasticParameter``, then ``N`` samples will be drawn
              from that parameter per ``N`` input images, each representing
              the kernel size for the n-th image.
            * If a tuple ``(a, b)``, where either ``a`` or ``b`` is a tuple,
              then ``a`` and ``b`` will be treated according to the rules
              above. This leads to different values for height and width of
              the kernel.

    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.AverageBlur(k=5)

    Blur all images using a kernel size of ``5x5``.

    >>> aug = iaa.AverageBlur(k=(2, 5))

    Blur images using a varying kernel size, which is sampled (per image)
    uniformly from the interval ``[2..5]``.

    >>> aug = iaa.AverageBlur(k=((5, 7), (1, 3)))

    Blur images using a varying kernel size, which's height is sampled
    (per image) uniformly from the interval ``[5..7]`` and which's width is
    sampled (per image) uniformly from ``[1..3]``.

    r      NrV   c                    s  t t| j||||d d| _t|rtt|| _	d S t
|rt|dks2J dt|f tdd |D rLtt|d t|d | _	d S td	d |D rcd
| _|d |d f| _	d S d d g}t|d rztt|d |d< n2t
|d rtdd |d D rtt|d d t|d d |d< ntdt|d f t|d rtt|d |d< n2t
|d rtdd |d D rtt|d d t|d d |d< ntdt|d f d
| _|| _	d S t|tjr|| _	d S tdt|f )NrW   singler
   z;Expected iterable 'k' to contain exactly 2 entries, got %d.c                 S      g | ]}t |qS rE   r2   is_single_number.0ZkirE   rE   rF   
<listcomp>F      z(AverageBlur.__init__.<locals>.<listcomp>r   r   c                 S   s   g | ]}t |tjqS rE   )
isinstancera   StochasticParameterr   rE   rE   rF   r   H      twoc                 S   r   rE   r   r   rE   rE   rF   r   P  r   z4k[0] expected to be int or tuple of two ints, got %sc                 S   r   rE   r   r   rE   rE   rF   r   [  r   z4k[1] expected to be int or tuple of two ints, got %szGExpected int, tuple/list with 2 entries or StochasticParameter. Got %s.)r_   r}   r`   r(   r2   r   ra   ZDeterministicrS   kis_iterablerh   allZDiscreteUniform	Exceptionr:   r   r   )rc   r   rX   r/   rY   rZ   Zk_tuplerd   rE   rF   r`   7  sl   


"



zAverageBlur.__init__c                    s  |j d u r|S |j }tj|g dg d| d t|}| jdkr.| jj|f|d}||f}n|d}| jd j|f|d d| jd j|f|d df}tt	||d |d }	|	D ]\}
\ dkpidk}dkoqdk} j
dk}|s|s|s j} jjd	v r jtjd
d n jjdkr jtjd
d  jdks jd dkrtt f}|jdkr|dtjf }n fddt jd D }tj|dd}|jdkr|dk}n|jdv rt||}||j |
< q[|S )N)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r    r!   r"   r   rf   r
   r   r   )r   r   Fr&   r   rH      .c                    s(   g | ]}t t d |f fqS .)r$   blurr   r   cr>   Zksize_hZksize_wrE   rF   r     s    z/AverageBlur._augment_batch_.<locals>.<listcomp>Zaxisr   r*   )r   r   )rg   r-   r.   rh   r(   r   ri   	duplicate	enumeraterj   r+   r,   r/   r0   r1   r   r   r4   r5   r$   r   r   r<   r6   r7   stackr=   )rc   rk   rY   rl   rm   rg   rn   ro   rssgeniZkernel_impossibleZkernel_does_nothingrC   Zinput_dtype	image_augchannelsrE   r   rF   rq   m  sf   











zAverageBlur._augment_batch_c                 C   rr   rs   r   rt   rE   rE   rF   ru     rv   zAverageBlur.get_parametersr~   NNrV   rV   rw   rE   rE   rd   rF   r}     s    Z6Cr}   c                       rT   )
MedianBlura
  Blur an image by computing median values over neighbourhoods.

    Median blurring can be used to remove small dirt from images.
    At larger kernel sizes, its effects have some similarity with Superpixels.

    **Supported dtypes**:

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

    Parameters
    ----------
    k : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Kernel size.

            * If a single ``int``, then that value will be used for the
              height and width of the kernel. Must be an odd value.
            * If a tuple of two ints ``(a, b)``, then the kernel size will be
              an odd value sampled from the interval ``[a..b]``. ``a`` and
              ``b`` must both be odd values.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then ``N`` samples will be drawn
              from that parameter per ``N`` input images, each representing
              the kernel size for the nth image. Expected to be discrete. If
              a sampled value is not odd, then that value will be increased
              by ``1``.

    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.MedianBlur(k=5)

    Blur all images using a kernel size of ``5x5``.

    >>> aug = iaa.MedianBlur(k=(3, 7))

    Blur images using varying kernel sizes, which are sampled uniformly from
    the interval ``[3..7]``. Only odd values will be sampled, i.e. ``3``
    or ``5`` or ``7``.

    r~   NrV   c                    s   t t| j||||d tj|dddddd| _t|r.|d dks,J d	t|f d S t	|r@t
d
d |D sBJ dd S d S )NrW   r   r   NTFr\   r]   r^   Zallow_floatsr
   r   z0Expected k to be odd, got %d. Add or subtract 1.c                 S   s   g | ]}|d  dkqS )r
   r   rE   r   rE   rE   rF   r     r   z'MedianBlur.__init__.<locals>.<listcomp>zlExpected all values in iterable k to be odd, but at least one was not. Add or subtract 1 to/from that value.)r_   r   r`   ra   handle_discrete_paramr   r2   r9   rS   r   r   )rc   r   rX   r/   rY   rZ   rd   rE   rF   r`     s(   


zMedianBlur.__init__c                    s   |j d u r|S |j }t|}| jj|f|d}tt||D ]Z\}\  jdk}	dkrx|	sxd dkr9d n jdksG jd dkr\t	
t }
|
jdkr[|
dtjf }
n fdd	t jd D }tj|dd
}
|
|j |< q|S )Nrf   r   r   r
   rH   r   .c                    s$   g | ]}t t d |f qS r   )r$   
medianBlurr   r   r>   r@   rE   rF   r   '  s    z.MedianBlur._augment_batch_.<locals>.<listcomp>r   )rg   rh   r   ri   r   rj   r+   r4   r5   r$   r   r   r1   r<   r6   r7   r   )rc   rk   rY   rl   rm   rg   rn   ro   r   rC   r   r   rE   r   rF   rq     s.   



zMedianBlur._augment_batch_c                 C   rr   rs   r   rt   rE   rE   rF   ru   1  rv   zMedianBlur.get_parametersr   rw   rE   rE   rd   rF   r     s    Gr   c                       s8   e Zd ZdZ			d fdd	Zdd	 Zd
d Z  ZS )BilateralBluraR  Blur/Denoise an image using a bilateral filter.

    Bilateral filters blur homogenous and textured areas, while trying to
    preserve edges.

    See
    http://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html#bilateralfilter
    for more information regarding the parameters.

    **Supported dtypes**:

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

    Parameters
    ----------
    d : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Diameter of each pixel neighborhood with value range ``[1 .. inf)``.
        High values for `d` lead to significantly worse performance. Values
        equal or less than ``10`` seem to be good. Use ``<5`` for real-time
        applications.

            * If a single ``int``, then that value will be used for the
              diameter.
            * If a tuple of two ``int`` s ``(a, b)``, then the diameter will
              be a value sampled from the interval ``[a..b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then ``N`` samples will be drawn
              from that parameter per ``N`` input images, each representing
              the diameter for the n-th image. Expected to be discrete.

    sigma_color : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Filter sigma in the color space with value range ``[1, inf)``. A
        large value of the parameter means that farther colors within the
        pixel neighborhood (see `sigma_space`) will be mixed together,
        resulting in larger areas of semi-equal color.

            * If a single ``int``, then that value will be used for the
              diameter.
            * If a tuple of two ``int`` s ``(a, b)``, then the diameter will
              be a value sampled from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then ``N`` samples will be drawn
              from that parameter per ``N`` input images, each representing
              the diameter for the n-th image. Expected to be discrete.

    sigma_space : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Filter sigma in the coordinate space with value range ``[1, inf)``. A
        large value of the parameter means that farther pixels will influence
        each other as long as their colors are close enough (see
        `sigma_color`).

            * If a single ``int``, then that value will be used for the
              diameter.
            * If a tuple of two ``int`` s ``(a, b)``, then the diameter will
              be a value sampled from the interval ``[a, b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then ``N`` samples will be drawn
              from that parameter per ``N`` input images, each representing
              the diameter for the n-th image. Expected to be discrete.

    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.BilateralBlur(
    >>>     d=(3, 10), sigma_color=(10, 250), sigma_space=(10, 250))

    Blur all images using a bilateral filter with a `max distance` sampled
    uniformly from the interval ``[3, 10]`` and wide ranges for `sigma_color`
    and `sigma_space`.

    r   	   
      NrV   c                    s`   t t| j||||d tj|dddddd| _tj|ddddd| _tj|d	dddd| _d S )
NrW   dr   TFr   sigma_colorr[   sigma_space)	r_   r   r`   ra   r   r   rb   r   r   )rc   r   r   r   rX   r/   rY   rZ   rd   rE   rF   r`     s    
zBilateralBlur.__init__c                 C   s   |j d u r|S |j }tdd |D sJ ddd |D f t|}|d}| jj|f|d d}| jj|f|d d}	| jj|f|d	 d}
tt	|||	|
}|D ] \}\}}}}|j
dk}|dkrt|sttt|||||j |< qT|S )
Nc                 S   s   g | ]	}|j d  dkqS )r
   r)   r5   r   r>   rE   rE   rF   r     s    z1BilateralBlur._augment_batch_.<locals>.<listcomp>zWBilateralBlur can currently only be applied to images with 3 channels. Got channels: %sc                 S   s   g | ]}|j d  qS )r
   r   r   rE   rE   rF   r     r   r)   r   rf   r   r
   )rg   r   rh   r   r   ri   r   r   r   rj   r+   r$   ZbilateralFilterr   )rc   rk   rY   rl   rm   rg   rn   r   Z	samples_dZsamples_sigma_colorZsamples_sigma_spacer   r   r>   ZdiZsigma_color_iZsigma_space_irC   rE   rE   rF   rq     s<   






zBilateralBlur._augment_batch_c                 C   s   | j | j| jgS rs   )r   r   r   rt   rE   rE   rF   ru     s   zBilateralBlur.get_parameters)r   r   r   NNrV   rV   rw   rE   rE   rd   rF   r   7  s    hr   c                       s(   e Zd ZdZ			d
 fdd		Z  ZS )
MotionBlura  Blur images in a way that fakes camera or object movements.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.convolutional.Convolve`.

    Parameters
    ----------
    k : int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional
        Kernel size to use.

            * If a single ``int``, then that value will be used for the height
              and width of the kernel.
            * If a tuple of two ``int`` s ``(a, b)``, then the kernel size
              will be sampled from the interval ``[a..b]``.
            * If a list, then a random value will be sampled from that list
              per image.
            * If a ``StochasticParameter``, then ``N`` samples will be drawn
              from that parameter per ``N`` input images, each representing
              the kernel size for the n-th image.

    angle : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Angle of the motion blur in degrees (clockwise, relative to top center
        direction).

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

    direction : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Forward/backward direction of the motion blur. Lower values towards
        ``-1.0`` will point the motion blur towards the back (with angle
        provided via `angle`). Higher values towards ``1.0`` will point the
        motion blur forward. A value of ``0.0`` leads to a uniformly (but
        still angled) motion blur.

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

    order : int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional
        Interpolation order to use when rotating the kernel according to
        `angle`.
        See :func:`~imgaug.augmenters.geometric.Affine.__init__`.
        Recommended to be ``0`` or ``1``, with ``0`` being faster, but less
        continuous/smooth as `angle` is changed, particularly around multiple
        of ``45`` degrees.

    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.MotionBlur(k=15)

    Apply motion blur with a kernel size of ``15x15`` pixels to images.

    >>> aug = iaa.MotionBlur(k=15, angle=[-45, 45])

    Apply motion blur with a kernel size of ``15x15`` pixels and a blur angle
    of either ``-45`` or ``45`` degrees (randomly picked per image).

    r)   r   r   ih              ?r   NrV   c	                    sj   t j|dddddd}	t j|dd ddd}
t j|dd	ddd}t|	|
||}tt| j|||||d
 d S )Nr   )r)   NTFr   angler[   	direction)gzo gzo ?rW   )ra   r   rb   _MotionBlurMatrixGeneratorr_   r   r`   )rc   r   r   r   orderrX   r/   rY   rZ   Zk_paramZangle_paramZdirection_paramZ
matrix_genrd   rE   rF   r`   /  s(   

zMotionBlur.__init__)r   r   r   r   NNrV   rV   )rx   ry   rz   r{   r`   r|   rE   rE   rd   rF   r     s    Wr   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 C   s   || _ || _|| _|| _d S )N)r   r   r   r   )rc   r   r   r   r   rE   rE   rF   r`   I  s   
z#_MotionBlurMatrixGenerator.__init__c           
      C   s   ddl m} t| jj|d}| jj|d}| jj|d}|d dkr%|n|d }t|dd}|d d }tj	||ftj
d	}tjt|dt| |d
|d d |d f< |j|| jd}	|	|d tjtj
d }|t| g| S )Nr   )	geometricrf   r
   r   r   r   g       @)r,   )num)rotater      g     o@) r   rS   r   Zdraw_sampler   r   r1   ZclipZzerosr   ZlinspacefloatZAffiner   Zaugment_imager0   r   sum)
rc   Z_imagerD   rY   Ziaa_geometricZk_sampleZangle_sampleZdirection_samplematrixZrotrE   rE   rF   __call__P  s6   

z#_MotionBlurMatrixGenerator.__call__N)rx   ry   rz   r`   r   rE   rE   rE   rF   r   G  s    r   c                       s@   e Zd ZdZ			d fdd	Zdd Zd	d
 Zdd Z  ZS )MeanShiftBlura
  Apply a pyramidic mean shift filter to each image.

    See also :func:`blur_mean_shift_` for details.

    This augmenter expects input images of shape ``(H,W)`` or ``(H,W,1)``
    or ``(H,W,3)``.

    .. note::

        This augmenter is quite slow.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.blur.blur_mean_shift_`.

    Parameters
    ----------
    spatial_radius : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Spatial radius for pixels that are assumed to be similar.

            * 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 sampled from that ``list``
              per image.
            * If ``StochasticParameter``: The parameter will be queried once
              per batch for ``(N,)`` values with ``N`` denoting the number of
              images.

    color_radius : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Color radius for pixels that are assumed to be similar.

            * 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 sampled from that ``list``
              per image.
            * If ``StochasticParameter``: The parameter will be queried once
              per batch for ``(N,)`` values with ``N`` denoting the number of
              images.

    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.MeanShiftBlur()

    Create a mean shift blur augmenter.

    rQ   g      D@NrV   c                    sH   t t| j||||d tj|ddddd| _tj|ddddd| _d S )NrW   spatial_radius)g{Gz?NTr[   color_radius)r_   r   r`   ra   rb   rM   rN   )rc   r   r   rX   r/   rY   rZ   rd   rE   rF   r`     s   
zMeanShiftBlur.__init__c                 C   sR   |j d ur'| ||}t|j D ]\}}t||d | |d | d|j |< q|S )Nr   r   rM   rN   )rg   _draw_samplesr   rO   )rc   rk   rY   rl   rm   ro   r   r>   rE   rE   rF   rq     s   


zMeanShiftBlur._augment_batch_c                 C   s*   |j }| jj|f|d| jj|f|dfS )Nrf   )nb_rowsrM   ri   rN   )rc   rk   rY   r   rE   rE   rF   r     s   

zMeanShiftBlur._draw_samplesc                 C   s   | j | jgS rs   r   rt   rE   rE   rF   ru     s   zMeanShiftBlur.get_parameters)r   r   NNrV   rV   )	rx   ry   rz   r{   r`   rq   r   ru   r|   rE   rE   rd   rF   r   s  s    F
r   )Nr   r   )&r{   
__future__r   r   r   numpyr1   r%   r   r$   Z	six.movesmovesr6   Zimgaugr2   Zimgaug.imgaugr   r   r   r	   Ziaa_convolutionalr   ra   r   r-   rG   rO   r8   Z	Augmenterr;   r}   r   r   ZConvolver   objectr   r   rE   rE   rE   rF   <module>   s4    
 qdX Z  !p,