o
    &j
*                    @   s  d Z ddlmZmZmZ ddlZddlZddlZddl	Z	ddl
ZddlmZ ddlmZ ddlmZ dsd
dZdsddZ		dtddZ	duddZ	dtddZ		dvddZdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zdwd)d*Z 		dtd+d,Z!		dtd-d.Z"d/d0 Z#d1d2 Z$d3d4 Z%d5d6 Z&	dxd7d8Z'	dxd9d:Z(ej)d;d<d=d>d? Z*G d@d; d;ej+Z,G dAdB dBe-Z.G dCdD dDej+Z/G dEdF dFe/Z0G dGdH dHe/Z1G dIdJ dJej+Z2G dKdL dLe2Z3G dMdN dNej+Z4G dOdP dPe4Z5G dQdR dRe4Z6G dSdT dTe6Z7G dUdV dVe2Z8G dWdX dXe8Z9G dYdZ dZe4Z:G d[d\ d\e:Z;G d]d^ d^e2Z<G d_d` d`e<Z=G dadb dbe4Z>G dcdd dde>Z?G dedf dfe2Z@G dgdh dhe@ZAG didj dje>ZBG dkdl dleBZCG dmdn dne@ZDG dodp dpeDZEG dqdr drej+ZFdS )yad  
Augmenters that somehow change the size of the images.

List of augmenters:

    * :class:`Resize`
    * :class:`CropAndPad`
    * :class:`Crop`
    * :class:`Pad`
    * :class:`PadToFixedSize`
    * :class:`CenterPadToFixedSize`
    * :class:`CropToFixedSize`
    * :class:`CenterCropToFixedSize`
    * :class:`CropToMultiplesOf`
    * :class:`CenterCropToMultiplesOf`
    * :class:`PadToMultiplesOf`
    * :class:`CenterPadToMultiplesOf`
    * :class:`CropToPowersOf`
    * :class:`CenterCropToPowersOf`
    * :class:`PadToPowersOf`
    * :class:`CenterPadToPowersOf`
    * :class:`CropToAspectRatio`
    * :class:`CenterCropToAspectRatio`
    * :class:`PadToAspectRatio`
    * :class:`CenterPadToAspectRatio`
    * :class:`CropToSquare`
    * :class:`CenterCropToSquare`
    * :class:`PadToSquare`
    * :class:`CenterPadToSquare`
    * :class:`KeepSizeByResize`

    )print_functiondivisionabsolute_importN)_normalize_cv2_input_arr_   )meta   )
parametersTc                 C   sn   |rt | d | d ||||\}}}}| dd \}}|}|| }	|}
|| }t|	|}	t||
}||
|	|fS )Nr   r   r   )_crop_prevent_zero_sizemax)shapetoprightbottomleftprevent_zero_sizeheightwidthx1x2y1y2 r   W/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/imgaug/augmenters/size.py_crop_trbl_to_xyxy/   s   

r   c           
      C   s4   t | j|||||d\}}}}	| ||	||df S )N)r   .)r   r   )
arrr   r   r   r   r   r   r   r   r   r   r   r   
_crop_arr_E   s   r   constantFc           
   	   C   s`   | j dd \}}t| g|R  }t||d |d |d |d ||d}	|r.t|	||f}	|	S )Nr   r   r      r   r   r   r   modecval)r   r   padiaimresize_single_image)
r   	croppingspaddingspad_modepad_cval	keep_sizer   r   Zimage_crimage_cr_par   r   r   _crop_and_pad_arrK   s   r+           c                 C      t | |||||S N_crop_and_pad_hms_or_segmaps_)Zheatmapcroppings_imgpaddings_imgr'   r(   r)   r   r   r   _crop_and_pad_heatmap_]      r3   c                 C   r-   r.   r/   )Zsegmapr1   r2   r'   r(   r)   r   r   r   _crop_and_pad_segmap_d   r4   r5   c              	   C   s"  t | tjrd}|d ur|nd}nt | tjsJ dt|  d}|d ur'|nd}t| |}|j}| j}	t||	|j}
t||	|j}t|jd |jd g|
R  }
t	||
d |
d |
d |
d }t
||d |d |d |d ||d	}t| || |r| |dd } | S t| j||| _| S )
Narr_0to1r,   z<Expected HeatmapsOnImage or SegmentationMapsOnImage, got %s.r   r   r   r   r   r   )
isinstancer#   ZHeatmapsOnImageZSegmentationMapsOnImagetypegetattrr   _project_size_changesr
   r   r"   setattrresize!_compute_shape_after_crop_and_pad)augmentabler1   r2   r'   r(   r)   arr_attr_namer   arr_shape_origZ
augm_shapeZcroppings_projZpaddings_projZarr_crZ	arr_cr_par   r   r   r0   k   sJ   
r0   c                 C   sj   t | jg|R  \}}}}|}|}	| j}
| j| |d  |	 |d  d}t|
|||_|r3||
}|S )Nr   r   )xy)r   r   Zshift_r=   on_)kpsoir1   r2   r)   r   r   Z_x2Z_y2	crop_leftcrop_topZ
shape_origZshiftedr   r   r   _crop_and_pad_kpsoi_   s   
rG   c                 C   s`   t | g|R  \}}}}t| }|| |d  |d  |d< || |d  |d  |d< t|S )Nr   r   r   r   )r   listtuple)Z	old_shaper%   r&   r   r   r   r   	new_shaper   r   r   r=      s
   r=   c                 C   s@  | ||  }|||  }|dk rMt |d }|d }	|d }
|	|
 |k r(|	d7 }	|	|kr7|	| }|}	|
|7 }
n|
|krE|
| }|}
|	|7 }	||	 }||
 }|dk rt |d }|d }|d }|| |k ri|d7 }||krx|| }|}||7 }n||kr|| }|}||7 }|| }|| }t|dt|dt|dt|dfS )Nr   r   r   )absr   )r   r   rF   
crop_rightcrop_bottomrE   Zremaining_heightZremaining_widthZregainZ
regain_topZregain_bottomdiffZregain_rightZregain_leftr   r   r   r
      sJ   

r
   c                 C   s   |dd |dd kr| S |d }|d }|d }|d }| d }| d }| d }	| d }
t |||  d }t |||  d }t ||	|  d }	t ||
|  d }
|||	|
fS )Nr   r   r   r   g-C6?)_int_r)ZtrblZ
from_shapeZto_shapeZ	height_toZwidth_toZheight_fromZ
width_fromr   r   r   r   r   r   r   r:      s   r:   c                 C   s   t t| S r.   )intnproundvaluer   r   r   rO      s   rO   c                    s   h d | t jkrtt S t | r)|  v s$J d| d f t| S t| trKt	 fdd| D sFJ dt
| d f t| S t| tjrS| S tdt| f )N>
   maximum	symmetricmeanmedianlinear_rampminimumwrapedger   reflectz<Value '%s' is not a valid pad mode. Valid pad modes are: %s., c                       g | ]}| v qS r   r   .0vZpad_modes_availabler   r   
<listcomp>      z*_handle_pad_mode_param.<locals>.<listcomp>zIAt least one in list %s is not a valid pad mode. Valid pad modes are: %s.z[Expected pad_mode to be ia.ALL or string or list of strings or StochasticParameter, got %s.)r#   ALLiapChoicerH   	is_stringjoinDeterministicr7   allstrStochasticParameter	Exceptionr8   )r'   r   rc   r   _handle_pad_mode_param  s0   






rp   c                 C   s  | dkrt ddt ddfS | dkr.t jt jddddddt jt jddddddfS | d	kr<t dt dfS t| rgtd
| rgdddddd}t || 	dd  t || 	dd  fS t
| t jro| S t
| trt| dksJ dt| tdd | D f | D ]}t|r|dk s|dkrtdt||f qdd | D } tdd | D }|sJ dtdd | D  t| S tdt| tt| dk rt| f t| dd d f )Nuniformr,         ?normalg      ?gffffff?)locscale)minvalmaxvalcenterz)^(left|center|right)-(top|center|bottom)$)r   rx   r   r   r   -r   r   r   zUExpected tuple with two entries as position parameter. Got %d entries with types %s..c                 S      g | ]}t |qS r   r8   ra   itemr   r   r   rd   7  re   z._handle_position_parameter.<locals>.<listcomp>z\Both position values must be within the value range [0.0, 1.0]. Got type %s with value %.8f.c                 S   s$   g | ]}t |rt|n|qS r   )r#   is_single_numberrg   rk   r|   r   r   r   rd   >  s    c                 S   s   g | ]}t |tjqS r   )r7   rg   rn   r|   r   r   r   rd   B  s    zdExpected tuple with two entries that are both either StochasticParameter or float/int. Got types %s.c                 S   rz   r   r{   r|   r   r   r   rd   G  re   aB  Expected one of the following as position parameter: string 'uniform', string 'normal', string 'center', a string matching regex ^(left|center|right)-(top|center|bottom)$, a single StochasticParameter or a tuple of two entries, both being either StochasticParameter or floats or int. Got instead type %s with content '%s'.   z...)rg   UniformZClipZNormalrk   r#   ri   rematchsplitr7   rn   rI   lenrm   r~   ro   r8   rl   )positionmappingr}   Zonly_sparamsr   r   r   _handle_position_parameter  s   


r   c                 C   s4   t | dr| j} t| dv sJ dt| | f d S )Nr   )r   r   zPExpected image with two or three dimensions, but got %d dimensions and shape %s.)hasattrr   r   r   r   r   r   _assert_two_or_three_dims[  s   

r   c                    s  ddl m} t  tdd ||||fD s!J d||||f t}|dks7|dks7|dks7|dkr| j\}	}
} jjdkrKt	
|rUt	|	|ntt||	tdd  jD }|rkddtjd	tjd
ddddddddddtjdtjddtjtjtjtjtjtjtjtji}|ddu } jjdv } jdko jd dk}|ss|ss|ss jj|rȇfddD ndkrtnt jdks jd dkr jdkr|stg jd  tjt ||||| d} jdkr|jdkr|dt	jf }|S g }d}|r n	tg jd  | jd k rj d||d f }||d  }tjt|||||| |d}t	|}|| |d7 }| jd k s2t	j |dd}|S ||f||fg jdkrd dkr jdkr|r fddt	! jd D }t	j"|dd}|S t	j# d}|S d
kr jdkr|r fddt	! jd D }t	j"|dd}|S t	j# d }|S t	j# d!}|S t	$ S )"a	  Pad an image-like array on its top/right/bottom/left side.

    This function is a wrapper around :func:`numpy.pad`.

    Added in 0.4.0. (Previously named ``imgaug.imgaug.pad()``.)

    **Supported dtypes**:

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

        - (1) Uses ``cv2`` if `mode` is one of: ``"constant"``, ``"edge"``,
              ``"reflect"``, ``"symmetric"``. Otherwise uses ``numpy``.
        - (2) Uses ``numpy``.
        - (3) Rejected by ``cv2``.

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray
        Image-like array to pad.

    top : int, optional
        Amount of pixels to add to the top side of the image.
        Must be ``0`` or greater.

    right : int, optional
        Amount of pixels to add to the right side of the image.
        Must be ``0`` or greater.

    bottom : int, optional
        Amount of pixels to add to the bottom side of the image.
        Must be ``0`` or greater.

    left : int, optional
        Amount of pixels to add to the left side of the image.
        Must be ``0`` or greater.

    mode : str, optional
        Padding mode to use. See :func:`numpy.pad` for details.
        In case of mode ``constant``, the parameter `cval` will be used as
        the ``constant_values`` parameter to :func:`numpy.pad`.
        In case of mode ``linear_ramp``, the parameter `cval` will be used as
        the ``end_values`` parameter to :func:`numpy.pad`.

    cval : number or iterable of number, optional
        Value to use for padding if `mode` is ``constant``.
        See :func:`numpy.pad` for details. The cval is expected to match the
        input array's dtype and value range. If an iterable is used, it is
        expected to contain one value per channel. The number of values
        and number of channels are expected to match.

    Returns
    -------
    (H',W') ndarray or (H',W',C) ndarray
        Padded array with height ``H'=H+top+bottom`` and width
        ``W'=W+left+right``.

    r   Nc                 S   s   g | ]}|d kqS r   r   r`   r   r   r   rd     re   zpad.<locals>.<listcomp>zXExpected padding amounts that are >=0, but got %d, %d, %d, %d (top, right, bottom, left)float128c                 S   s   g | ]}|d kqS r   r   )ra   axisr   r   r   rd     re   r   r\   rY   rU   rW   rX   rZ   r]   rV   r[   )Zuint32Zuint64Zint64Zfloat16r   boolr   c                    s$   g | ]} d krt |nt|qS )f)floatrP   )ra   cval_c)kindr   r   rd     s    r   r      )r   r   r   r   Z
borderTyperT   .)r   r   r   c                    2   g | ]}t j d |f dd | dqS ).r   r   r    Zconstant_valuesrQ   r"   ra   cr   r!   r    paddings_npr   r   rd         r   c                    r   ).r   r   r    Z
end_valuesr   r   r   r   r   rd     r   r   )r    )%Zimgaug.dtypesZdtypesr   rl   r#   is_iterableZget_value_range_of_dtypedtypenamerQ   r   Zclipr   minanyr   cv2ZBORDER_CONSTANTZBORDER_REPLICATEZBORDER_REFLECT_101ZBORDER_REFLECTgetndimr   r   rP   rI   ZcopyMakeBorderr   ZnewaxisZ
atleast_3dappendZconcatenateZarangestackr"   copy)r   r   r   r   r   r    r!   ZiadtZis_multi_cvalZ	min_value_Z	max_valueZhas_zero_sized_axisZmapping_mode_np_to_cv2Zbad_mode_cv2Zbad_datatype_cv2Zbad_shape_cv2Zarr_padresultZchannel_start_idxZarr_cr   Z	arr_pad_cZarr_pad_chansr   )r   r!   r   r    r   r   r"   c  s   F

"

/


 





r"   c           
   	   C   s@   t | |\}}}}t| ||||||d}	|r|	||||ffS |	S )a  Pad an image array on its sides so that it matches a target aspect ratio.

    See :func:`~imgaug.imgaug.compute_paddings_for_aspect_ratio` for an
    explanation of how the required padding amounts are distributed per
    image axis.

    Added in 0.4.0. (Previously named ``imgaug.imgaug.pad_to_aspect_ratio()``.)

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.size.pad`.

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray
        Image-like array to pad.

    aspect_ratio : float
        Target aspect ratio, given as width/height. E.g. ``2.0`` denotes the
        image having twice as much width as height.

    mode : str, optional
        Padding mode to use. See :func:`~imgaug.imgaug.pad` for details.

    cval : number, optional
        Value to use for padding if `mode` is ``constant``.
        See :func:`numpy.pad` for details.

    return_pad_amounts : bool, optional
        If ``False``, then only the padded image will be returned. If
        ``True``, a ``tuple`` with two entries will be returned, where the
        first entry is the padded image and the second entry are the amounts
        by which each image side was padded. These amounts are again a
        ``tuple`` of the form ``(top, right, bottom, left)``, with each value
        being an ``int``.

    Returns
    -------
    (H',W') ndarray or (H',W',C) ndarray
        Padded image as ``(H',W')`` or ``(H',W',C)`` ndarray, fulfilling the
        given `aspect_ratio`.

    tuple of int
        Amounts by which the image was padded on each side, given as a
        ``tuple`` ``(top, right, bottom, left)``.
        This ``tuple`` is only returned if `return_pad_amounts` was set to
        ``True``.

    r   )&compute_paddings_to_reach_aspect_ratior"   )
r   aspect_ratior    r!   return_pad_amountspad_top	pad_right
pad_bottompad_left
arr_paddedr   r   r   pad_to_aspect_ratio,  s   4

r   c              	   C   sB   t | ||\}}}}	t| ||||	||d}
|r|
||||	ffS |
S )a  Pad an image array until its side lengths are multiples of given values.

    See :func:`~imgaug.imgaug.compute_paddings_for_aspect_ratio` for an
    explanation of how the required padding amounts are distributed per
    image axis.

    Added in 0.4.0. (Previously named ``imgaug.imgaug.pad_to_multiples_of()``.)

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.size.pad`.

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray
        Image-like array to pad.

    height_multiple : None or int
        The desired multiple of the height. The computed padding amount will
        reflect a padding that increases the y axis size until it is a multiple
        of this value.

    width_multiple : None or int
        The desired multiple of the width. The computed padding amount will
        reflect a padding that increases the x axis size until it is a multiple
        of this value.

    mode : str, optional
        Padding mode to use. See :func:`~imgaug.imgaug.pad` for details.

    cval : number, optional
        Value to use for padding if `mode` is ``constant``.
        See :func:`numpy.pad` for details.

    return_pad_amounts : bool, optional
        If ``False``, then only the padded image will be returned. If
        ``True``, a ``tuple`` with two entries will be returned, where the
        first entry is the padded image and the second entry are the amounts
        by which each image side was padded. These amounts are again a
        ``tuple`` of the form ``(top, right, bottom, left)``, with each value
        being an integer.

    Returns
    -------
    (H',W') ndarray or (H',W',C) ndarray
        Padded image as ``(H',W')`` or ``(H',W',C)`` ndarray.

    tuple of int
        Amounts by which the image was padded on each side, given as a
        ``tuple`` ``(top, right, bottom, left)``.
        This ``tuple`` is only returned if `return_pad_amounts` was set to
        ``True``.

    r   )&compute_paddings_to_reach_multiples_ofr"   )r   height_multiplewidth_multipler    r!   r   r   r   r   r   r   r   r   r   pad_to_multiples_ofp  s    9

r   c                 C   s  t |  |dksJ d|f d}d}d}d}t| dr| jn| }|dd \}}|dkr3d}|d7 }|dkr=d}|d7 }|| }	|	|k rb|| | }
|tt|
d 7 }|tt|
d 7 }n"|	|krd| | | }
|tt|
d 7 }|tt|
d 7 }||||fS )ai  Compute pad amounts required to fulfill an aspect ratio.

    "Pad amounts" here denotes the number of pixels that have to be added to
    each side to fulfill the desired constraint.

    The aspect ratio is given as ``ratio = width / height``.
    Depending on which dimension is smaller (height or width), only the
    corresponding sides (top/bottom or left/right) will be padded.

    The axis-wise padding amounts are always distributed equally over the
    sides of the respective axis (i.e. left and right, top and bottom). For
    odd pixel amounts, one pixel will be left over after the equal
    distribution and could be added to either side of the axis. This function
    will always add such a left over pixel to the bottom (y-axis) or
    right (x-axis) side.

    Added in 0.4.0. (Previously named
    ``imgaug.imgaug.compute_paddings_to_reach_aspect_ratio()``.)

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray or tuple of int
        Image-like array or shape tuple for which to compute pad amounts.

    aspect_ratio : float
        Target aspect ratio, given as width/height. E.g. ``2.0`` denotes the
        image having twice as much width as height.

    Returns
    -------
    tuple of int
        Required padding amounts to reach the target aspect ratio, given as a
        ``tuple`` of the form ``(top, right, bottom, left)``.

    r   -Expected to get an aspect ratio >0, got %.4f.r   r   r   )r   r   r   rP   rQ   ceilfloor)r   r   r   r   r   r   r   r   r   aspect_ratio_currentrN   r   r   r   r     s4   $
r   c                 C   s  t |  |dksJ d|f t| dr| jn| }|d dks&J d|f |dd \}}|| }d}d}d}d}	||k r^|||  }
t|
|d }
tt|
d }tt|
d }n#||kr|||  }
t|
|d }
tt|
d }	tt|
d }||||	fS )a  Compute crop amounts required to fulfill an aspect ratio.

    "Crop amounts" here denotes the number of pixels that have to be removed
    from each side to fulfill the desired constraint.

    The aspect ratio is given as ``ratio = width / height``.
    Depending on which dimension is smaller (height or width), only the
    corresponding sides (top/bottom or left/right) will be cropped.

    The axis-wise padding amounts are always distributed equally over the
    sides of the respective axis (i.e. left and right, top and bottom). For
    odd pixel amounts, one pixel will be left over after the equal
    distribution and could be added to either side of the axis. This function
    will always add such a left over pixel to the bottom (y-axis) or
    right (x-axis) side.

    If an aspect ratio cannot be reached exactly, this function will return
    rather one pixel too few than one pixel too many.

    Added in 0.4.0.

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray or tuple of int
        Image-like array or shape tuple for which to compute crop amounts.

    aspect_ratio : float
        Target aspect ratio, given as width/height. E.g. ``2.0`` denotes the
        image having twice as much width as height.

    Returns
    -------
    tuple of int
        Required cropping amounts to reach the target aspect ratio, given as a
        ``tuple`` of the form ``(top, right, bottom, left)``.

    r   r   r   z6Expected to get an array with height >0, got shape %s.r   r   )r   r   r   r   rP   rQ   r   r   )r   r   r   r   r   r   r   r   r   r   Zcrop_amountr   r   r   'compute_croppings_to_reach_aspect_ratio  s2   &
r   c                 C      dd }t |  |dur|dksJ d|f |dur&|dks&J d|f t| dr.| jn| }|dd \}}|||\}}|||\}	}
||
||	fS )ag  Compute pad amounts until img height/width are multiples of given values.

    See :func:`~imgaug.imgaug.compute_paddings_for_aspect_ratio` for an
    explanation of how the required padding amounts are distributed per
    image axis.

    Added in 0.4.0. (Previously named
    ``imgaug.imgaug.compute_paddings_to_reach_multiples_of()``.)

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray or tuple of int
        Image-like array or shape tuple for which to compute pad amounts.

    height_multiple : None or int
        The desired multiple of the height. The computed padding amount will
        reflect a padding that increases the y axis size until it is a multiple
        of this value.

    width_multiple : None or int
        The desired multiple of the width. The computed padding amount will
        reflect a padding that increases the x axis size until it is a multiple
        of this value.

    Returns
    -------
    tuple of int
        Required padding amounts to reach multiples of the provided values,
        given as a ``tuple`` of the form ``(top, right, bottom, left)``.

    c                 S   s\   |d u rdS | dkr|}n| | dkrd}n|| |  }t t|d t t|d fS Nr   r   r   rP   rQ   r   r   )	axis_sizemultipleto_padr   r   r   _compute_axis_valuej  s   $zCcompute_paddings_to_reach_multiples_of.<locals>._compute_axis_valueNr   z1Can only pad to multiples of 1 or larger, got %d.r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   I  s&   !

r   c                 C   r   )a  Compute croppings to reach multiples of given heights/widths.

    See :func:`~imgaug.imgaug.compute_paddings_for_aspect_ratio` for an
    explanation of how the required cropping amounts are distributed per
    image axis.

    Added in 0.4.0.

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray or tuple of int
        Image-like array or shape tuple for which to compute crop amounts.

    height_multiple : None or int
        The desired multiple of the height. The computed croppings will
        reflect a crop operation that decreases the y axis size until it is
        a multiple of this value.

    width_multiple : None or int
        The desired multiple of the width. The computed croppings amount will
        reflect a crop operation that decreases the x axis size until it is
        a multiple of this value.

    Returns
    -------
    tuple of int
        Required cropping amounts to reach multiples of the provided values,
        given as a ``tuple`` of the form ``(top, right, bottom, left)``.

    c                 S   sX   |d u rdS | dkrd}n| | dkrd}n| | }t t|d t t|d fS r   r   )r   r   to_cropr   r   r   r     s   $zDcompute_croppings_to_reach_multiples_of.<locals>._compute_axis_valueNr   z2Can only crop to multiples of 1 or larger, got %d.r   r   r   r   r   r   r   'compute_croppings_to_reach_multiples_of  s&    

r   c                        fdd}t |  |dur|dksJ d|f |dur(|dks(J d|f t| dr0| jn| }|dd \}}|||\}}	|||\}
}|||	|
fS )	aK  Compute paddings to reach powers of given base values.

    For given axis size ``S``, padded size ``S'`` (``S' >= S``) and base ``B``
    this function computes paddings that fulfill ``S' = B^E``, where ``E``
    is any exponent from the discrete interval ``[0 .. inf)``.

    See :func:`~imgaug.imgaug.compute_paddings_for_aspect_ratio` for an
    explanation of how the required padding amounts are distributed per
    image axis.

    Added in 0.4.0. (Previously named
    ``imgaug.imgaug.compute_paddings_to_reach_exponents_of()``.)

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray or tuple of int
        Image-like array or shape tuple for which to compute pad amounts.

    height_base : None or int
        The desired base of the height.

    width_base : None or int
        The desired base of the width.

    allow_zero_exponent : bool, optional
        Whether ``E=0`` in ``S'=B^E`` is a valid value. If ``True``, axes
        with size ``0`` or ``1`` will be padded up to size ``B^0=1`` and
        axes with size ``1 < S <= B`` will be padded up to ``B^1=B``.
        If ``False``, the minimum output axis size is always at least ``B``.

    Returns
    -------
    tuple of int
        Required padding amounts to fulfill ``S' = B^E`` given as a
        ``tuple`` of the form ``(top, right, bottom, left)``.

    c                    s   |d u rdS | dkr rdn|}n| |kr||  }nt | t | }|tt | |  }tt |d tt |d fS Nr   r   r   r   )rQ   logrP   r   r   )r   baser   exponentallow_zero_exponentr   r   r     s   
$z@compute_paddings_to_reach_powers_of.<locals>._compute_axis_valueNr   z+Can only pad to base larger than 1, got %d.r   r   r   r   r   height_base
width_baser   r   r   r   r   r   r   r   r   r   r   r   #compute_paddings_to_reach_powers_of  s   '

r   c                    r   )	aZ  Compute croppings to reach powers of given base values.

    For given axis size ``S``, cropped size ``S'`` (``S' <= S``) and base ``B``
    this function computes croppings that fulfill ``S' = B^E``, where ``E``
    is any exponent from the discrete interval ``[0 .. inf)``.

    See :func:`~imgaug.imgaug.compute_paddings_for_aspect_ratio` for an
    explanation of how the required cropping amounts are distributed per
    image axis.

    .. note::

        For axes where ``S == 0``, this function alwayws returns zeros as
        croppings.

        For axes where ``1 <= S < B`` see parameter `allow_zero_exponent`.

    Added in 0.4.0.

    Parameters
    ----------
    arr : (H,W) ndarray or (H,W,C) ndarray or tuple of int
        Image-like array or shape tuple for which to compute crop amounts.

    height_base : None or int
        The desired base of the height.

    width_base : None or int
        The desired base of the width.

    allow_zero_exponent : bool
        Whether ``E=0`` in ``S'=B^E`` is a valid value. If ``True``, axes
        with size ``1 <= S < B`` will be cropped to size ``B^0=1``.
        If ``False``, axes with sizes ``S < B`` will not be changed.

    Returns
    -------
    tuple of int
        Required cropping amounts to fulfill ``S' = B^E`` given as a
        ``tuple`` of the form ``(top, right, bottom, left)``.

    c                    s|   |d u rdS | dkrd}n| |k r r| d nd}nt | t | }| |t|  }tt |d tt |d fS r   )rQ   r   rP   r   r   )r   r   r   r   r   r   r   r   <  s   $zAcompute_croppings_to_reach_powers_of.<locals>._compute_axis_valueNr   z,Can only crop to base larger than 1, got %d.r   r   r   r   r   r   r   r   $compute_croppings_to_reach_powers_of  s   ,

r   Resizez/Resize has the exactly same interface as Scale.)Zalt_funccommentc                  O   s   t | i |S )z>Augmenter that resizes images to specified heights and widths.)r   )argskwargsr   r   r   Scale^  s   r   c                       s|   e Zd ZdZ			d fdd	Zedd Zed	d
 Zdd Zdd Z	dd Z
dd Zdd Zedd Zdd Z  ZS )r   a  Augmenter that resizes images to specified heights and widths.

    **Supported dtypes**:

    See :func:`~imgaug.imgaug.imresize_many_images`.

    Parameters
    ----------
    size : 'keep' or int or float or tuple of int or tuple of float or list of int or list of float or imgaug.parameters.StochasticParameter or dict
        The new size of the images.

            * If this has the string value ``keep``, the original height and
              width values will be kept (image is not resized).
            * If this is an ``int``, this value will always be used as the new
              height and width of the images.
            * If this is a ``float`` ``v``, then per image the image's height
              ``H`` and width ``W`` will be changed to ``H*v`` and ``W*v``.
            * If this is a ``tuple``, it is expected to have two entries
              ``(a, b)``. If at least one of these are ``float`` s, a value
              will be sampled from range ``[a, b]`` and used as the ``float``
              value to resize the image (see above). If both are ``int`` s, a
              value will be sampled from the discrete range ``[a..b]`` and
              used as the integer value to resize the image (see above).
            * If this is a ``list``, a random value from the ``list`` will be
              picked to resize the image. All values in the ``list`` must be
              ``int`` s or ``float`` s (no mixture is possible).
            * If this is a ``StochasticParameter``, then this parameter will
              first be queried once per image. The resulting value will be used
              for both height and width.
            * If this is a ``dict``, it may contain the keys ``height`` and
              ``width`` or the keys ``shorter-side`` and ``longer-side``. Each
              key may have the same datatypes as above and describes the
              scaling on x and y-axis or the shorter and longer axis,
              respectively. Both axis are sampled independently. Additionally,
              one of the keys may have the value ``keep-aspect-ratio``, which
              means that the respective side of the image will be resized so
              that the original aspect ratio is kept. This is useful when only
              resizing one image size by a pixel value (e.g. resize images to
              a height of ``64`` pixels and resize the width so that the
              overall aspect ratio is maintained).

    interpolation : imgaug.ALL or int or str or list of int or list of str or imgaug.parameters.StochasticParameter, optional
        Interpolation to use.

            * If ``imgaug.ALL``, then a random interpolation from ``nearest``,
              ``linear``, ``area`` or ``cubic`` will be picked (per image).
            * If ``int``, then this interpolation will always be used.
              Expected to be any of the following:
              ``cv2.INTER_NEAREST``, ``cv2.INTER_LINEAR``, ``cv2.INTER_AREA``,
              ``cv2.INTER_CUBIC``
            * If string, then this interpolation will always be used.
              Expected to be any of the following:
              ``nearest``, ``linear``, ``area``, ``cubic``
            * If ``list`` of ``int`` / ``str``, then a random one of the values
              will be picked per image as the interpolation.
            * If a ``StochasticParameter``, then this parameter will be
              queried per image and is expected to return an ``int`` or
              ``str``.

    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.Resize(32)

    Resize all images to ``32x32`` pixels.

    >>> aug = iaa.Resize(0.5)

    Resize all images to ``50`` percent of their original size.

    >>> aug = iaa.Resize((16, 22))

    Resize all images to a random height and width within the discrete
    interval ``[16..22]`` (uniformly sampled per image).

    >>> aug = iaa.Resize((0.5, 0.75))

    Resize all any input image so that its height (``H``) and width (``W``)
    become ``H*v`` and ``W*v``, where ``v`` is uniformly sampled from the
    interval ``[0.5, 0.75]``.

    >>> aug = iaa.Resize([16, 32, 64])

    Resize all images either to ``16x16``, ``32x32`` or ``64x64`` pixels.

    >>> aug = iaa.Resize({"height": 32})

    Resize all images to a height of ``32`` pixels and keeps the original
    width.

    >>> aug = iaa.Resize({"height": 32, "width": 48})

    Resize all images to a height of ``32`` pixels and a width of ``48``.

    >>> aug = iaa.Resize({"height": 32, "width": "keep-aspect-ratio"})

    Resize all images to a height of ``32`` pixels and resizes the
    x-axis (width) so that the aspect ratio is maintained.

    >>> aug = iaa.Resize(
    >>>     {"shorter-side": 224, "longer-side": "keep-aspect-ratio"})

    Resize all images to a height/width of ``224`` pixels, depending on which
    axis is shorter and resize the other axis so that the aspect ratio is
    maintained.

    >>> aug = iaa.Resize({"height": (0.5, 0.75), "width": [16, 32, 64]})

    Resize all images to a height of ``H*v``, where ``H`` is the original
    height and ``v`` is a random value sampled from the interval
    ``[0.5, 0.75]``. The width/x-axis of each image is resized to either
    ``16`` or ``32`` or ``64`` pixels.

    >>> aug = iaa.Resize(32, interpolation=["linear", "cubic"])

    Resize all images to ``32x32`` pixels. Randomly use either ``linear``
    or ``cubic`` interpolation.

    cubicN
deprecatedc                    s<   t t| j||||d | |d\| _| _| || _d S )Nseedr   random_statedeterministicF)superr   __init___handle_size_argsize
size_order_handle_interpolation_arginterpolation)selfr   r   r   r   r   r   	__class__r   r   r     s   
zResize.__init__c                    sZ   fdd}dd }d}|dkrt d}nt|r-|dks'J d|f t |}n|st|trt| dkrBt d}n||d	d
gr[|d	d}|d
d}|||}n||ddgrv|dd}	|dd}
||	|
}d}nt	dt
| f t|trt|dksJ dt|f |d dkr|d dksJ d|d |d f t|d st|d rt |d |d }n^t |d |d }nSt|trt|dkrt d}nAtdd |D }tdd |D }|s|sJ dtdd |D sJ dt |}nt|t jr|}n	t	dt|f |r)|S ||fS )Nc                    sd   d}| |kp	||k}|sJ dg }| |fD ]}|dv r"t |}n |d}|| qt|S )Nkeep-aspect-ratiozPExpected at least one value to not be "keep-aspect-ratio", but got it two times.)r   keepT)rg   rk   r   r   rI   )Zval1Zval2ZkaaZnot_both_kaaZ
size_tuplekentryclsr   r   _dict_to_size_tuple  s   z4Resize._handle_size_arg.<locals>._dict_to_size_tuplec                    s   t  fdd|D S )Nc                    r_   r   r   )ra   keydict_r   r   rd     re   zFResize._handle_size_arg.<locals>._contains_any_key.<locals>.<listcomp>)r   )r   keysr   r   r   _contains_any_key  s   z2Resize._handle_size_arg.<locals>._contains_any_keyZHWr   r   z Expected only values > 0, got %sr   r   zshorter-sidezlonger-sideSLzExpected dictionary containing no keys, the keys "height" and/or "width", or the keys "shorter-side" and/or "longer-side". Got keys: %s.r   z8Expected size tuple to contain exactly 2 values, got %d.r   z=Expected size tuple to only contain values >0, got %d and %d.c                 S      g | ]}t |qS r   r#   is_single_integerr`   r   r   r   rd   9      z+Resize._handle_size_arg.<locals>.<listcomp>c                 S   r   r   )r#   is_single_floatr`   r   r   r   rd   :  r   z(Expected to get only integers or floats.c                 S      g | ]}|d kqS r   r   r`   r   r   r   rd   =  re   zExpected all values to be >0.a(  Expected number, tuple of two numbers, list of numbers, dictionary of form {'height': number/tuple/list/'keep-aspect-ratio'/'keep', 'width': <analogous>}, dictionary of form {'shorter-side': number/tuple/list/'keep-aspect-ratio'/'keep', 'longer-side': <analogous>} or StochasticParameter, got %s.)rg   rk   r#   r~   r7   dictr   r   r   
ValueErrorrm   rI   r   r   DiscreteUniformrH   rl   rh   rn   r8   )r   r   Zsubcallr   r   r   r   r   r   ZshorterZlongerZall_intZ	all_floatr   r   r   r     sz   




zResize._handle_size_argc                 C   s   |t jkrtg d}|S t |rt|}|S t |r&t|}|S t |r2t|}|S t|tj	r;	 |S t
dt|f )N)nearestZlinearZarear   zBExpected int or string or iterable or StochasticParameter, got %s.)r#   rf   rg   rh   r   rk   ri   r   r7   rn   ro   r8   )r   r   r   r   r   r   Q  s,   




	

z Resize._handle_interpolation_argc                 C   s   |j }| ||}|jd ur| |j||_|jd ur$| |jd||_|jd ur<| |jd|d |d d g| f|_dD ]}t||}|d ur]tj	| j
|d}	| ||	}
t|||
 q>|S )Nr6   r   r   r   Z	keypointsZbounding_boxesZpolygonsZline_stringssamples)nb_rows_draw_samplesimages_augment_images_by_samplesheatmaps_augment_maps_by_samplessegmentation_mapsr9   	functoolspartial_augment_keypoints_by_samples_apply_to_cbaois_as_keypointsr;   )r   batchr   parentshooksr  r  	augm_name
augm_valuefunccbaoisr   r   r   _augment_batch_e  s4   



zResize._augment_batch_c                 C   s   d}d }t |rd}|j}|\}}}g }t|D ]%\}	}
| |
j||	 ||	 | j\}}t j|
||f||	 d}|| q|rUt	dd |D dk}|rUt
j||d}|S )NFTr   c                 S      h | ]}|j qS r   r   ra   imager   r   r   	<setcomp>      z4Resize._augment_images_by_samples.<locals>.<setcomp>r   r   )r#   is_np_arrayr   	enumerate_compute_height_widthr   r   r$   r   r   rQ   array)r   r  r  Zinput_was_arrayZinput_dtype	samples_a	samples_b
samples_ipr   ir  hwZimage_rsZall_same_sizer   r   r   r    s(   


z!Resize._augment_images_by_samplesc                 C   s   g }|\}}}t |D ]o\}}	t|	|}
|
j}|	j}| ||| || | j\}}tt||d |d   }tt||d |d   }t|d}t|d}|d d urc|	j	||f|| d}n|		||f}||f|dd   |_|
| q|S )Nr   r   r  r   )r  r9   r   r   r   rP   rQ   rR   r   r<   r   )r   augmentablesr?   r  r   	samples_h	samples_wr$  r%  r>   r   Z	arr_shapeZ	img_shapeZh_imgZw_imgr&  r'  Zaugmentable_resizer   r   r   r	    s*   



zResize._augment_maps_by_samplesc                 C   sn   g }|\}}}t |D ])\}}| |j|| || | j\}	}
|	|
f|jdd   }||}|| q|S )Nr   )r  r   r   r   rC   r   )r   kpsoisr  r   r"  r#  Z_samples_ipr%  rD   r&  r'  rJ   Zkeypoints_on_image_rsr   r   r   r    s   

z$Resize._augment_keypoints_by_samplesc                 C   s~   | d}t| jtr$| jd j||d d}| jd j||d d}n| jj||d d}|}| jj||d d}|||fS )Nr   r   r   r   r   )	duplicater7   r   rI   draw_samplesr   )r   	nb_imagesr   rngsr)  r*  r$  r   r   r   r    s   

zResize._draw_samplesc                 C   s.  |dd \}}|dkr||k r||}}n||}}n||}}t |rC|dks1J d|f tt|| }|dkr@|nd}n|dkrI|}t |rk|dksYJ d|f tt|| }|dkrh|nd}n|dkrq|}|dkr|| }	tt||	 }|dkr|| }
tt||
 }||fS )	Nr   r   r   zExpected 'h' to be >0, got %.4fr   r   zExpected 'w' to be >0, got %.4fr   )r#   r   rP   rQ   rR   )r   Zimage_shapeZsample_aZsample_br   ZimhZimwr&  r'  Zh_per_w_origZw_per_h_origr   r   r   r     s2   


zResize._compute_height_widthc                 C      | j | j| jgS =See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`.)r   r   r   r   r   r   r   get_parameters     zResize.get_parameters)r   NNr   r   )__name__
__module____qualname____doc__r   classmethodr   r   r  r  r	  r  r  r   r5  __classcell__r   r   r   r   r   f  s&     


V
 
&c                   @   s,   e Zd Zdd Zedd Zedd ZdS )_CropAndPadSamplingResultc                 C   s@   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	d S r.   
rF   rL   rM   rE   r   r   r   r   r'   r(   )r   rF   rL   rM   rE   r   r   r   r   r'   r(   r   r   r   r     s   
z"_CropAndPadSamplingResult.__init__c                 C      | j | j| j| jfS )z8Get absolute pixel amounts of croppings as a TRBL tuple.)rF   rL   rM   rE   r4  r   r   r   r%        z#_CropAndPadSamplingResult.croppingsc                 C   r?  )z7Get absolute pixel amounts of paddings as a TRBL tuple.)r   r   r   r   r4  r   r   r   r&     r@  z"_CropAndPadSamplingResult.paddingsN)r7  r8  r9  r   propertyr%   r&   r   r   r   r   r=     s    
r=  c                       s~   e Zd ZdZ				d fdd	Zed	d
 Zedd Zedd Zdd Z	dd Z
dd Zdd Zdd Zdd Z  ZS )
CropAndPada-  Crop/pad images by pixel amounts or fractions of image sizes.

    Cropping removes pixels at the sides (i.e. extracts a subimage from
    a given full image). Padding adds pixels to the sides (e.g. black pixels).

    This augmenter will never crop images below a height or width of ``1``.

    .. note::

        This augmenter automatically resizes images back to their original size
        after it has augmented them. To deactivate this, add the
        parameter ``keep_size=False``.

    **Supported dtypes**:

    if (keep_size=False):

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

    if (keep_size=True):

        minimum of (
            ``imgaug.augmenters.size.CropAndPad(keep_size=False)``,
            :func:`~imgaug.imgaug.imresize_many_images`
        )

    Parameters
    ----------
    px : None or int or imgaug.parameters.StochasticParameter or tuple, optional
        The number of pixels to crop (negative values) or pad (positive values)
        on each side of the image. Either this or the parameter `percent` may
        be set, not both at the same time.

            * If ``None``, then pixel-based cropping/padding will not be used.
            * If ``int``, then that exact number of pixels will always be
              cropped/padded.
            * If ``StochasticParameter``, then that parameter will be used for
              each image. Four samples will be drawn per image (top, right,
              bottom, left), unless `sample_independently` is set to ``False``,
              as then only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of two ``int`` s with values ``a`` and ``b``,
              then each side will be cropped/padded by a random amount sampled
              uniformly per image and side from the inteval ``[a, b]``. If
              however `sample_independently` is set to ``False``, only one
              value will be sampled per image and used for all sides.
            * If a ``tuple`` of four entries, then the entries represent top,
              right, bottom, left. Each entry may be a single ``int`` (always
              crop/pad by exactly that value), a ``tuple`` of two ``int`` s
              ``a`` and ``b`` (crop/pad by an amount within ``[a, b]``), a
              ``list`` of ``int`` s (crop/pad by a random value that is
              contained in the ``list``) or a ``StochasticParameter`` (sample
              the amount to crop/pad from that parameter).

    percent : None or number or imgaug.parameters.StochasticParameter or tuple, optional
        The number of pixels to crop (negative values) or pad (positive values)
        on each side of the image given as a *fraction* of the image
        height/width. E.g. if this is set to ``-0.1``, the augmenter will
        always crop away ``10%`` of the image's height at both the top and the
        bottom (both ``10%`` each), as well as ``10%`` of the width at the
        right and left.
        Expected value range is ``(-1.0, inf)``.
        Either this or the parameter `px` may be set, not both
        at the same time.

            * If ``None``, then fraction-based cropping/padding will not be
              used.
            * If ``number``, then that fraction will always be cropped/padded.
            * If ``StochasticParameter``, then that parameter will be used for
              each image. Four samples will be drawn per image (top, right,
              bottom, left). If however `sample_independently` is set to
              ``False``, only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of two ``float`` s with values ``a`` and ``b``,
              then each side will be cropped/padded by a random fraction
              sampled uniformly per image and side from the interval
              ``[a, b]``. If however `sample_independently` is set to
              ``False``, only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of four entries, then the entries represent top,
              right, bottom, left. Each entry may be a single ``float``
              (always crop/pad by exactly that percent value), a ``tuple`` of
              two ``float`` s ``a`` and ``b`` (crop/pad by a fraction from
              ``[a, b]``), a ``list`` of ``float`` s (crop/pad by a random
              value that is contained in the list) or a ``StochasticParameter``
              (sample the percentage to crop/pad from that parameter).

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        Padding mode to use. The available modes match the numpy padding modes,
        i.e. ``constant``, ``edge``, ``linear_ramp``, ``maximum``, ``median``,
        ``minimum``, ``reflect``, ``symmetric``, ``wrap``. The modes
        ``constant`` and ``linear_ramp`` use extra values, which are provided
        by ``pad_cval`` when necessary. See :func:`~imgaug.imgaug.pad` for
        more details.

            * If ``imgaug.ALL``, then a random mode from all available modes
              will be sampled per image.
            * If a ``str``, it will be used as the pad mode for all images.
            * If a ``list`` of ``str``, a random one of these will be sampled
              per image and used as the mode.
            * If ``StochasticParameter``, a random mode will be sampled from
              this parameter per image.

    pad_cval : number or tuple of number list of number or imgaug.parameters.StochasticParameter, optional
        The constant value to use if the pad mode is ``constant`` or the end
        value to use if the mode is ``linear_ramp``.
        See :func:`~imgaug.imgaug.pad` for more details.

            * If ``number``, then that value will be used.
            * If a ``tuple`` of two ``number`` s and at least one of them is
              a ``float``, then a random number will be uniformly sampled per
              image from the continuous interval ``[a, b]`` and used as the
              value. If both ``number`` s are ``int`` s, the interval is
              discrete.
            * If a ``list`` of ``number``, then a random value will be chosen
              from the elements of the ``list`` and used as the value.
            * If ``StochasticParameter``, a random value will be sampled from
              that parameter per image.

    keep_size : bool, optional
        After cropping and padding, the result image will usually have a
        different height/width compared to the original input image. If this
        parameter is set to ``True``, then the cropped/padded image will be
        resized to the input image's size, i.e. the augmenter's output shape
        is always identical to the input shape.

    sample_independently : bool, optional
        If ``False`` *and* the values for `px`/`percent` result in exactly
        *one* probability distribution for all image sides, only one single
        value will be sampled from that probability distribution and used for
        all sides. I.e. the crop/pad amount then is the same for all sides.
        If ``True``, four values will be sampled independently, one per side.

    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.CropAndPad(px=(-10, 0))

    Crop each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[-10..0]``.

    >>> aug = iaa.CropAndPad(px=(0, 10))

    Pad each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[0..10]``. The padding happens by
    zero-padding, i.e. it adds black pixels (default setting).

    >>> aug = iaa.CropAndPad(px=(0, 10), pad_mode="edge")

    Pad each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[0..10]``. The padding uses the
    ``edge`` mode from numpy's pad function, i.e. the pixel colors around
    the image sides are repeated.

    >>> aug = iaa.CropAndPad(px=(0, 10), pad_mode=["constant", "edge"])

    Similar to the previous example, but uses zero-padding (``constant``) for
    half of the images and ``edge`` padding for the other half.

    >>> aug = iaa.CropAndPad(px=(0, 10), pad_mode=ia.ALL, pad_cval=(0, 255))

    Similar to the previous example, but uses any available padding mode.
    In case the padding mode ends up being ``constant`` or ``linear_ramp``,
    and random intensity is uniformly sampled (once per image) from the
    discrete interval ``[0..255]`` and used as the intensity of the new
    pixels.

    >>> aug = iaa.CropAndPad(px=(0, 10), sample_independently=False)

    Pad each side by a random pixel value sampled uniformly once per image
    from the discrete interval ``[0..10]``. Each sampled value is used
    for *all* sides of the corresponding image.

    >>> aug = iaa.CropAndPad(px=(0, 10), keep_size=False)

    Pad each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[0..10]``. Afterwards, do **not**
    resize the padded image back to the input image's size. This will increase
    the image's height and width by a maximum of ``20`` pixels.

    >>> aug = iaa.CropAndPad(px=((0, 10), (0, 5), (0, 10), (0, 5)))

    Pad the top and bottom by a random pixel value sampled uniformly from the
    discrete interval ``[0..10]``. Pad the left and right analogously by
    a random value sampled from ``[0..5]``. Each value is always sampled
    independently.

    >>> aug = iaa.CropAndPad(percent=(0, 0.1))

    Pad each side by a random fraction sampled uniformly from the continuous
    interval ``[0.0, 0.10]``. The fraction is sampled once per image and
    side. E.g. a sampled fraction of ``0.1`` for the top side would pad by
    ``0.1*H``, where ``H`` is the height of the input image.

    >>> aug = iaa.CropAndPad(
    >>>     percent=([0.05, 0.1], [0.05, 0.1], [0.05, 0.1], [0.05, 0.1]))

    Pads each side by either ``5%`` or ``10%``. The values are sampled
    once per side and image.

    >>> aug = iaa.CropAndPad(px=(-10, 10))

    Sample uniformly per image and side a value ``v`` from the discrete range
    ``[-10..10]``. Then either crop (negative sample) or pad (positive sample)
    the side by ``v`` pixels.

    Nr   r   Tr   c                    s   t t| j|||	|
d |d u r|d u rd}| ||\| _| _| _| _| _| _	t
|| _tj|dd dddd| _|| _|| _d| _d| _d| _d| _d S )	Nr   )g皙?r(   TZvalue_rangeZtuple_to_uniformZlist_to_choiceZallow_floatsr   r,   r   )r   rB  r   _handle_px_and_percent_argsr    	all_sidesr   r   r   r   rp   r'   rg   handle_discrete_paramr(   r)   sample_independently_pad_mode_heatmaps_pad_mode_segmentation_maps_pad_cval_heatmaps_pad_cval_segmentation_mapsr   pxpercentr'   r(   r)   rH  r   r   r   r   r   r   r   r     s(   



zCropAndPad.__init__c           	      C   s   d }d\}}}}|d u r|d u rd}n)|d ur|d urt d|d ur0d}| |\}}}}}nd}| |\}}}}}||||||fS )NNNNNnoopz,Can only pad by pixels or percent, not both.rN  rO  )ro   _handle_px_arg_handle_percent_arg)	r   rN  rO  rF  r   r   r   r   r    r   r   r   rE  &  s   z&CropAndPad._handle_px_and_percent_argsc                 C   s   d }d\}}}}t |rt|}nTt|trOt|dv s'J dt|f dd }t|dkr6||}n1||d }||d }||d }||d	 }nt|tjr^| } } }}n	td
t	|f |||||fS )NrP  r   r   zAExpected 'px' given as a tuple to contain 2 or 4 entries, got %d.c                 S   s  t | r
t| S t| trGt| dksJ dt|  t | d o*t | d }|s=J dt| d t| d f t| d | d S t| t	rrt| dksVJ dt
dd | D smJ d	d
dd | D  t| S t| tjrz| S tdt| f )Nr   #Expected tuple of 2 values, got %d.r   r   z*Expected tuple of integers, got %s and %s.+Expected non-empty list, but got empty one.c                 S   r   r   r   ra   valr   r   r   rd   V  r   zCCropAndPad._handle_px_arg.<locals>.handle_param.<locals>.<listcomp>z$Expected list of ints, got types %s.r^   c                 S      g | ]}t t|qS r   rm   r8   r`   r   r   r   rd   X      RExpected int, tuple of two ints, list of ints or StochasticParameter, got type %s.)r#   r   rg   rk   r7   rI   r   r8   r   rH   rl   rj   rh   rn   ro   )pZ	only_intsr   r   r   handle_paramF  s@   





z/CropAndPad._handle_px_arg.<locals>.handle_paramr   r   r   r   zdExpected int, tuple of 4 ints/tuples/lists/StochasticParameters or StochasticParameter, got type %s.)
r#   r   rg   rk   r7   rI   r   rn   ro   r8   )r   rN  rF  r   r   r   r   r^  r   r   r   rR  9  s2   


zCropAndPad._handle_px_argc                 C   s   d }d\}}}}t |r|dksJ d|f t|}nTt|trZt|dv s2J dt|f dd }t|dkrA||}n1||d	 }||d
 }||d }||d }nt|tjri| } } }}n	tdt	|f |||||fS )NrP        z)Expected 'percent' to be >-1.0, got %.4f.rT  zFExpected 'percent' given as a tuple to contain 2 or 4 entries, got %d.c                 S   sf  t | r
t| S t| tr`t| dksJ dt| f t | d o+t | d }|s>J dt| d t| d f | d dkrJ| d dksVJ d| d | d f t| d | d S t| t	rt| dksoJ dt
d	d
 | D sJ dddd
 | D  t
dd
 | D sJ dddd
 | D  t| S t| tjr| S tdt| f )Nr   rU  r   r   z)Expected tuple of numbers, got %s and %s.r_  z2Expected tuple of values >-1.0, got %.4f and %.4f.rV  c                 S   r   r   )r#   r~   rW  r   r   r   rd     r   zHCropAndPad._handle_percent_arg.<locals>.handle_param.<locals>.<listcomp>z'Expected list of numbers, got types %s.r^   c                 S   rY  r   rZ  r`   r   r   r   rd     r[  c                 S   r   )r_  r   rW  r   r   r   rd     re   z-Expected list of values >-1.0, got values %s.c                 S   s   g | ]}d |f qS )z%.4fr   r`   r   r   r   rd     r   r\  )r#   r~   rg   rk   r7   rI   r   r8   r   rH   rl   rj   rh   rn   ro   )r]  Zonly_numbersr   r   r   r^  ~  sT   




z4CropAndPad._handle_percent_arg.<locals>.handle_paramr   r   r   r   zjExpected number, tuple of 4 numbers/tuples/lists/StochasticParameters or StochasticParameter, got type %s.)
r#   r~   rg   rk   r7   rI   r   rn   ro   r8   )r   rO  rF  r   r   r   r   r^  r   r   r   rS  p  s8   


 
zCropAndPad._handle_percent_argc                 C   s   |  }| ||}|jd ur| |j||_|jd ur(| |j| j| j||_|jd ur9| |j| j	| j
||_dD ]}t||}|d urZtj| j|d}	| ||	}
t|||
 q;|S Nr  r  )get_rowwise_shapesr  r  r  r  r	  rI  rK  r
  rJ  rL  r9   r  r  r  r  r;   )r   r  r   r  r  shapesr  r  r  r  r  r   r   r   r    s:   



zCropAndPad._augment_batch_c           	      C   s   g }t |D ]\}}|| }t||j|j|j|j| j}|| qt	|rI| jr4t
j||jd}|S tdd |D }|dkrIt
j||jd}|S )Nr  c                 S   r  r   r   r  r   r   r   r    r  z8CropAndPad._augment_images_by_samples.<locals>.<setcomp>r   )r  r+   r%   r&   r'   r(   r)   r   r#   r  rQ   r!  r   r   )	r   r  r  r   r%  r  	samples_ir*   	nb_shapesr   r   r   r    s    

z%CropAndPad._augment_images_by_samplesc           	   	   C   sb   g }t |D ](\}}|| }t||j|j|d ur|n|j|d ur"|n|j| jd}|| q|S )N)r1   r2   r'   r(   r)   )r  r0   r%   r&   r'   r(   r)   r   )	r   r(  r'   r(   r  r   r%  r>   Zsamples_imgr   r   r   r	    s"   z#CropAndPad._augment_maps_by_samplesc                 C   sB   g }t |D ]\}}|| }t||j|j| jd}|| q|S )N)r1   r2   r)   )r  rG   r%   r&   r)   r   )r   keypoints_on_imagesr  r   r%  Zkeypoints_on_imagerc  	kpsoi_augr   r   r   r    s   z(CropAndPad._augment_keypoints_by_samplesc           #      C   s8  t |}| jdkrtj|fdtjd } } }}n| jd ur_| jrM| jj|df|d}|d d df }|d d df }|d d df }|d d df }n6| jj|f|d}	|	 } } }}n$| jj|f|d}| j	j|f|d}| j
j|f|d}| jj|f|d}| jd	krnS| jd
krtjdd |D tjd}
|
d d df }|
d d df }t|| tj}t|| tj}t|| tj}t|| tj}ntddd }|d| }|d| }|d| }|d| }||}||}||}||}| jj|f|d}| jj|f|d}g }t|D ]y\}}|dd \}}t|||| || || || \}}}} |dkpI|dk}!|!r^|| |kr^td|||f  | dkpf|dk}"|"r{| | |kr{td| ||f  |t|||| || || || || || || d
 q |S )NrQ  r   r  r   r,  r   r   r   rN  rO  c                 S   s   g | ]}|d d qS )r   r   r   )ra   r   r   r   r   rd   ,  r[  z,CropAndPad._draw_samples.<locals>.<listcomp>zInvalid modec                 S   s   t | } | dk }d| |< | S Nr   )rQ   r   )r   maskr   r   r   _only_above_zero7  s   
z2CropAndPad._draw_samples.<locals>._only_above_zeror   a  Expected generated crop amounts in CropAndPad for top and bottom image side to be less than the image's height, but got %d (top) and %d (bottom) vs. image height %d. This will result in an image with output height=1 (if input height was >=1) or output height=0 (if input height was 0).a  Expected generated crop amounts in CropAndPad for left and right image side to be less than the image's width, but got %d (left) and %d (right) vs. image width %d. This will result in an image with output width=1 (if input width was >=1) or output width=0 (if input width was 0).r>  )r   r    rQ   fullZint32rF  rH  r.  r   r   r   r   r!  Zfloat32rR   Zastypero   r'   r(   r  r
   r#   warnr   r=  )#r   r   rb  r  r   r   r   r   r  sampleZ
shapes_arrZheightswidthsri  rF   rL   rM   rE   r   r   r   r   r'   r(   r   r%  r   r   r   Z
crop_top_iZcrop_right_iZcrop_bottom_iZcrop_left_iZ
any_crop_yZ
any_crop_xr   r   r   r  
  s   








zCropAndPad._draw_samplesc                 C   s    | j | j| j| j| j| j| jgS r2  )rF  r   r   r   r   r'   r(   r4  r   r   r   r5  {  s   zCropAndPad.get_parameters
NNr   r   TTNNr   r   )r7  r8  r9  r:  r   r;  rE  rR  rS  r  r  r	  r  r  r5  r<  r   r   r   r   rB    s(     n

6
>!qrB  c                       s*   e Zd ZdZ				d	 fdd	Z  ZS )
Pada&  Pad images, i.e. adds columns/rows of pixels to them.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropAndPad`.

    Parameters
    ----------
    px : None or int or imgaug.parameters.StochasticParameter or tuple, optional
        The number of pixels to pad on each side of the image.
        Expected value range is ``[0, inf)``.
        Either this or the parameter `percent` may be set, not both at the same
        time.

            * If ``None``, then pixel-based padding will not be used.
            * If ``int``, then that exact number of pixels will always be
              padded.
            * If ``StochasticParameter``, then that parameter will be used for
              each image. Four samples will be drawn per image (top, right,
              bottom, left), unless `sample_independently` is set to ``False``,
              as then only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of two ``int`` s with values ``a`` and ``b``,
              then each side will be padded by a random amount sampled
              uniformly per image and side from the inteval ``[a, b]``. If
              however `sample_independently` is set to ``False``, only one
              value will be sampled per image and used for all sides.
            * If a ``tuple`` of four entries, then the entries represent top,
              right, bottom, left. Each entry may be a single ``int`` (always
              pad by exactly that value), a ``tuple`` of two ``int`` s
              ``a`` and ``b`` (pad by an amount within ``[a, b]``), a
              ``list`` of ``int`` s (pad by a random value that is
              contained in the ``list``) or a ``StochasticParameter`` (sample
              the amount to pad from that parameter).

    percent : None or int or float or imgaug.parameters.StochasticParameter or tuple, optional
        The number of pixels to pad
        on each side of the image given as a *fraction* of the image
        height/width. E.g. if this is set to ``0.1``, the augmenter will
        always pad ``10%`` of the image's height at both the top and the
        bottom (both ``10%`` each), as well as ``10%`` of the width at the
        right and left.
        Expected value range is ``[0.0, inf)``.
        Either this or the parameter `px` may be set, not both
        at the same time.

            * If ``None``, then fraction-based padding will not be
              used.
            * If ``number``, then that fraction will always be padded.
            * If ``StochasticParameter``, then that parameter will be used for
              each image. Four samples will be drawn per image (top, right,
              bottom, left). If however `sample_independently` is set to
              ``False``, only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of two ``float`` s with values ``a`` and ``b``,
              then each side will be padded by a random fraction
              sampled uniformly per image and side from the interval
              ``[a, b]``. If however `sample_independently` is set to
              ``False``, only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of four entries, then the entries represent top,
              right, bottom, left. Each entry may be a single ``float``
              (always pad by exactly that fraction), a ``tuple`` of
              two ``float`` s ``a`` and ``b`` (pad by a fraction from
              ``[a, b]``), a ``list`` of ``float`` s (pad by a random
              value that is contained in the list) or a ``StochasticParameter``
              (sample the percentage to pad from that parameter).

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        Padding mode to use. The available modes match the numpy padding modes,
        i.e. ``constant``, ``edge``, ``linear_ramp``, ``maximum``, ``median``,
        ``minimum``, ``reflect``, ``symmetric``, ``wrap``. The modes
        ``constant`` and ``linear_ramp`` use extra values, which are provided
        by ``pad_cval`` when necessary. See :func:`~imgaug.imgaug.pad` for
        more details.

            * If ``imgaug.ALL``, then a random mode from all available modes
              will be sampled per image.
            * If a ``str``, it will be used as the pad mode for all images.
            * If a ``list`` of ``str``, a random one of these will be sampled
              per image and used as the mode.
            * If ``StochasticParameter``, a random mode will be sampled from
              this parameter per image.

    pad_cval : number or tuple of number list of number or imgaug.parameters.StochasticParameter, optional
        The constant value to use if the pad mode is ``constant`` or the end
        value to use if the mode is ``linear_ramp``.
        See :func:`~imgaug.imgaug.pad` for more details.

            * If ``number``, then that value will be used.
            * If a ``tuple`` of two ``number`` s and at least one of them is
              a ``float``, then a random number will be uniformly sampled per
              image from the continuous interval ``[a, b]`` and used as the
              value. If both ``number`` s are ``int`` s, the interval is
              discrete.
            * If a ``list`` of ``number``, then a random value will be chosen
              from the elements of the ``list`` and used as the value.
            * If ``StochasticParameter``, a random value will be sampled from
              that parameter per image.

    keep_size : bool, optional
        After padding, the result image will usually have a
        different height/width compared to the original input image. If this
        parameter is set to ``True``, then the padded image will be
        resized to the input image's size, i.e. the augmenter's output shape
        is always identical to the input shape.

    sample_independently : bool, optional
        If ``False`` *and* the values for `px`/`percent` result in exactly
        *one* probability distribution for all image sides, only one single
        value will be sampled from that probability distribution and used for
        all sides. I.e. the pad amount then is the same for all sides.
        If ``True``, four values will be sampled independently, one per side.

    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.Pad(px=(0, 10))

    Pad each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[0..10]``. The padding happens by
    zero-padding, i.e. it adds black pixels (default setting).

    >>> aug = iaa.Pad(px=(0, 10), pad_mode="edge")

    Pad each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[0..10]``. The padding uses the
    ``edge`` mode from numpy's pad function, i.e. the pixel colors around
    the image sides are repeated.

    >>> aug = iaa.Pad(px=(0, 10), pad_mode=["constant", "edge"])

    Similar to the previous example, but uses zero-padding (``constant``) for
    half of the images and ``edge`` padding for the other half.

    >>> aug = iaa.Pad(px=(0, 10), pad_mode=ia.ALL, pad_cval=(0, 255))

    Similar to the previous example, but uses any available padding mode.
    In case the padding mode ends up being ``constant`` or ``linear_ramp``,
    and random intensity is uniformly sampled (once per image) from the
    discrete interval ``[0..255]`` and used as the intensity of the new
    pixels.

    >>> aug = iaa.Pad(px=(0, 10), sample_independently=False)

    Pad each side by a random pixel value sampled uniformly once per image
    from the discrete interval ``[0..10]``. Each sampled value is used
    for *all* sides of the corresponding image.

    >>> aug = iaa.Pad(px=(0, 10), keep_size=False)

    Pad each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[0..10]``. Afterwards, do **not**
    resize the padded image back to the input image's size. This will increase
    the image's height and width by a maximum of ``20`` pixels.

    >>> aug = iaa.Pad(px=((0, 10), (0, 5), (0, 10), (0, 5)))

    Pad the top and bottom by a random pixel value sampled uniformly from the
    discrete interval ``[0..10]``. Pad the left and right analogously by
    a random value sampled from ``[0..5]``. Each value is always sampled
    independently.

    >>> aug = iaa.Pad(percent=(0, 0.1))

    Pad each side by a random fraction sampled uniformly from the continuous
    interval ``[0.0, 0.10]``. The fraction is sampled once per image and
    side. E.g. a sampled fraction of ``0.1`` for the top side would pad by
    ``0.1*H``, where ``H`` is the height of the input image.

    >>> aug = iaa.Pad(
    >>>     percent=([0.05, 0.1], [0.05, 0.1], [0.05, 0.1], [0.05, 0.1]))

    Pads each side by either ``5%`` or ``10%``. The values are sampled
    once per side and image.

    Nr   r   Tr   c                    sX    fdd |d u r|d u rd} |} |}t t| j|||||||||	|
d
 d S )Nc                    s   | d u r| S t | r| dksJ d| f | S t| tjr | S t| tr0t fdd| D S t| tr> fdd| D S tdt| f )Nr   zExpected value >0, got %.4fc                       g | ]} |qS r   r   ra   Zv_recursive_validater   r   rd   R	  re   z<Pad.__init__.<locals>.recursive_validate.<locals>.<listcomp>c                    rp  r   r   rq  rr  r   r   rd   T	  re   NExpected None or int or float or StochasticParameter or list or tuple, got %s.)	r#   r~   r7   rg   rn   rI   rH   ro   r8   rS   rr  r   r   rs  I	  s    


z(Pad.__init__.<locals>.recursive_validater,   rC  )
rN  rO  r'   r(   r)   rH  r   r   r   r   )r   ro  r   rM  r   rr  r   r   E	  s   

zPad.__init__rn  r7  r8  r9  r:  r   r<  r   r   r   r   ro    s     Dro  c                       s*   e Zd ZdZ				d fdd	Z  ZS )Cropa  Crop images, i.e. remove columns/rows of pixels at the sides of images.

    This augmenter allows to extract smaller-sized subimages from given
    full-sized input images. The number of pixels to cut off may be defined
    in absolute values or as fractions of the image sizes.

    This augmenter will never crop images below a height or width of ``1``.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropAndPad`.

    Parameters
    ----------
    px : None or int or imgaug.parameters.StochasticParameter or tuple, optional
        The number of pixels to crop on each side of the image.
        Expected value range is ``[0, inf)``.
        Either this or the parameter `percent` may be set, not both at the same
        time.

            * If ``None``, then pixel-based cropping will not be used.
            * If ``int``, then that exact number of pixels will always be
              cropped.
            * If ``StochasticParameter``, then that parameter will be used for
              each image. Four samples will be drawn per image (top, right,
              bottom, left), unless `sample_independently` is set to ``False``,
              as then only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of two ``int`` s with values ``a`` and ``b``,
              then each side will be cropped by a random amount sampled
              uniformly per image and side from the inteval ``[a, b]``. If
              however `sample_independently` is set to ``False``, only one
              value will be sampled per image and used for all sides.
            * If a ``tuple`` of four entries, then the entries represent top,
              right, bottom, left. Each entry may be a single ``int`` (always
              crop by exactly that value), a ``tuple`` of two ``int`` s
              ``a`` and ``b`` (crop by an amount within ``[a, b]``), a
              ``list`` of ``int`` s (crop by a random value that is
              contained in the ``list``) or a ``StochasticParameter`` (sample
              the amount to crop from that parameter).

    percent : None or int or float or imgaug.parameters.StochasticParameter or tuple, optional
        The number of pixels to crop
        on each side of the image given as a *fraction* of the image
        height/width. E.g. if this is set to ``0.1``, the augmenter will
        always crop ``10%`` of the image's height at both the top and the
        bottom (both ``10%`` each), as well as ``10%`` of the width at the
        right and left.
        Expected value range is ``[0.0, 1.0)``.
        Either this or the parameter `px` may be set, not both
        at the same time.

            * If ``None``, then fraction-based cropping will not be
              used.
            * If ``number``, then that fraction will always be cropped.
            * If ``StochasticParameter``, then that parameter will be used for
              each image. Four samples will be drawn per image (top, right,
              bottom, left). If however `sample_independently` is set to
              ``False``, only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of two ``float`` s with values ``a`` and ``b``,
              then each side will be cropped by a random fraction
              sampled uniformly per image and side from the interval
              ``[a, b]``. If however `sample_independently` is set to
              ``False``, only one value will be sampled per image and used for
              all sides.
            * If a ``tuple`` of four entries, then the entries represent top,
              right, bottom, left. Each entry may be a single ``float``
              (always crop by exactly that fraction), a ``tuple`` of
              two ``float`` s ``a`` and ``b`` (crop by a fraction from
              ``[a, b]``), a ``list`` of ``float`` s (crop by a random
              value that is contained in the list) or a ``StochasticParameter``
              (sample the percentage to crop from that parameter).

    keep_size : bool, optional
        After cropping, the result image will usually have a
        different height/width compared to the original input image. If this
        parameter is set to ``True``, then the cropped image will be
        resized to the input image's size, i.e. the augmenter's output shape
        is always identical to the input shape.

    sample_independently : bool, optional
        If ``False`` *and* the values for `px`/`percent` result in exactly
        *one* probability distribution for all image sides, only one single
        value will be sampled from that probability distribution and used for
        all sides. I.e. the crop amount then is the same for all sides.
        If ``True``, four values will be sampled independently, one per side.

    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.Crop(px=(0, 10))

    Crop each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[0..10]``.

    >>> aug = iaa.Crop(px=(0, 10), sample_independently=False)

    Crop each side by a random pixel value sampled uniformly once per image
    from the discrete interval ``[0..10]``. Each sampled value is used
    for *all* sides of the corresponding image.

    >>> aug = iaa.Crop(px=(0, 10), keep_size=False)

    Crop each side by a random pixel value sampled uniformly per image and
    side from the discrete interval ``[0..10]``. Afterwards, do **not**
    resize the cropped image back to the input image's size. This will decrease
    the image's height and width by a maximum of ``20`` pixels.

    >>> aug = iaa.Crop(px=((0, 10), (0, 5), (0, 10), (0, 5)))

    Crop the top and bottom by a random pixel value sampled uniformly from the
    discrete interval ``[0..10]``. Crop the left and right analogously by
    a random value sampled from ``[0..5]``. Each value is always sampled
    independently.

    >>> aug = iaa.Crop(percent=(0, 0.1))

    Crop each side by a random fraction sampled uniformly from the continuous
    interval ``[0.0, 0.10]``. The fraction is sampled once per image and
    side. E.g. a sampled fraction of ``0.1`` for the top side would crop by
    ``0.1*H``, where ``H`` is the height of the input image.

    >>> aug = iaa.Crop(
    >>>     percent=([0.05, 0.1], [0.05, 0.1], [0.05, 0.1], [0.05, 0.1]))

    Crops each side by either ``5%`` or ``10%``. The values are sampled
    once per side and image.

    NTr   c	           	   
      sT    fdd |d u r|d u rd} |} |}t t| j||||||||d d S )Nc                    s   | d u r| S t | r| dksJ d| f |  S t| tjr%t| dS t| tr5t fdd| D S t| trC fdd| D S tdt	| f )Nr   zExpected value >0, got %.4f.r   c                    rp  r   r   rq  recursive_negater   r   rd   
  re   z;Crop.__init__.<locals>.recursive_negate.<locals>.<listcomp>c                    rp  r   r   rq  rx  r   r   rd   
  re   rt  )
r#   r~   r7   rg   rn   ZMultiplyrI   rH   ro   r8   rS   rx  r   r   ry  
  s    


z'Crop.__init__.<locals>.recursive_negateru  )rN  rO  r)   rH  r   r   r   r   )r   rw  r   )	r   rN  rO  r)   rH  r   r   r   r   r   rx  r   r   	  s   

zCrop.__init__)NNTTNNr   r   rv  r   r   r   r   rw  j	  s     rw  c                       sf   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	e
dd Zdd Z  ZS )PadToFixedSizeav  Pad images to a predefined minimum width and/or height.

    If images are already at the minimum width/height or are larger, they will
    not be padded. Note that this also means that images will not be cropped if
    they exceed the required width/height.

    The augmenter randomly decides per image how to distribute the required
    padding amounts over the image axis. E.g. if 2px have to be padded on the
    left or right to reach the required width, the augmenter will sometimes
    add 2px to the left and 0px to the right, sometimes add 2px to the right
    and 0px to the left and sometimes add 1px to both sides. Set `position`
    to ``center`` to prevent that.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.size.pad`.

    Parameters
    ----------
    width : int or None
        Pad images up to this minimum width.
        If ``None``, image widths will not be altered.

    height : int or None
        Pad images up to this minimum height.
        If ``None``, image heights will not be altered.

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.CropAndPad.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.CropAndPad.__init__`.

    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        Sets the center point of the padding, which determines how the
        required padding amounts are distributed to each side. For a ``tuple``
        ``(a, b)``, both ``a`` and ``b`` are expected to be in range
        ``[0.0, 1.0]`` and describe the fraction of padding applied to the
        left/right (low/high values for ``a``) and the fraction of padding
        applied to the top/bottom (low/high values for ``b``). A padding
        position at ``(0.5, 0.5)`` would be the center of the image and
        distribute the padding equally to all sides. A padding position at
        ``(0.0, 1.0)`` would be the left-bottom and would apply 100% of the
        required padding to the bottom and left sides of the image so that
        the bottom left corner becomes more and more the new image
        center (depending on how much is padded).

            * If string ``uniform`` then the share of padding is randomly and
              uniformly distributed over each side.
              Equivalent to ``(Uniform(0.0, 1.0), Uniform(0.0, 1.0))``.
            * If string ``normal`` then the share of padding is distributed
              based on a normal distribution, leading to a focus on the
              center of the images.
              Equivalent to
              ``(Clip(Normal(0.5, 0.45/2), 0, 1),
              Clip(Normal(0.5, 0.45/2), 0, 1))``.
            * If string ``center`` then center point of the padding is
              identical to the image center.
              Equivalent to ``(0.5, 0.5)``.
            * If a string matching regex
              ``^(left|center|right)-(top|center|bottom)$``, e.g. ``left-top``
              or ``center-bottom`` then sets the center point of the padding
              to the X-Y position matching that description.
            * If a tuple of float, then expected to have exactly two entries
              between ``0.0`` and ``1.0``, which will always be used as the
              combination the position matching (x, y) form.
            * If a ``StochasticParameter``, then that parameter will be queried
              once per call to ``augment_*()`` to get ``Nx2`` center positions
              in ``(x, y)`` form (with ``N`` the number of images).
            * If a ``tuple`` of ``StochasticParameter``, then expected to have
              exactly two entries that will both be queried per call to
              ``augment_*()``, each for ``(N,)`` values, to get the center
              positions. First parameter is used for ``x`` coordinates,
              second for ``y`` coordinates.

    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.PadToFixedSize(width=100, height=100)

    For image sides smaller than ``100`` pixels, pad to ``100`` pixels. Do
    nothing for the other edges. The padding is randomly (uniformly)
    distributed over the sides, so that e.g. sometimes most of the required
    padding is applied to the left, sometimes to the right (analogous
    top/bottom).

    >>> aug = iaa.PadToFixedSize(width=100, height=100, position="center")

    For image sides smaller than ``100`` pixels, pad to ``100`` pixels. Do
    nothing for the other image sides. The padding is always equally
    distributed over the left/right and top/bottom sides.

    >>> aug = iaa.PadToFixedSize(width=100, height=100, pad_mode=ia.ALL)

    For image sides smaller than ``100`` pixels, pad to ``100`` pixels and
    use any possible padding mode for that. Do nothing for the other image
    sides. The padding is always equally distributed over the left/right and
    top/bottom sides.

    >>> aug = iaa.Sequential([
    >>>     iaa.PadToFixedSize(width=100, height=100),
    >>>     iaa.CropToFixedSize(width=100, height=100)
    >>> ])

    Pad images smaller than ``100x100`` until they reach ``100x100``.
    Analogously, crop images larger than ``100x100`` until they reach
    ``100x100``. The output images therefore have a fixed size of ``100x100``.

    r   r   rq   Nr   c
           
         sj   t t| j||||	d ||f| _t|| _t|| _tj	|dd dddd| _
d| _d| _d| _d| _d S )Nr   r(   TrD  r   r,   r   )r   rz  r   r   r   r   rp   r'   rg   rG  r(   rI  rJ  rK  rL  )
r   r   r   r'   r(   r   r   r   r   r   r   r   r   r   
  s   


	

zPadToFixedSize.__init__c           
      C   s   |  ||}|jd ur| |j||_|jd ur$| |j|| j| j|_|jd ur5| |j|| j| j|_dD ]}t||}|d urVt	j
| j|d}| ||}	t|||	 q7|S r`  )r  r  r  r  r	  rI  rK  r
  r9   r  r  r  r  r;   
r   r  r   r  r  r  r  r  r  r  r   r   r   r  
  s4   





zPadToFixedSize._augment_batch_c              
   C   s   g }|\}}}}}t t||D ]4\}	\}
}|\}}|
jd d \}}| ||||||	 ||	 }t|
d|||	 ||	 dd}
||
 q|S Nr   r   r   r   r   Fr)   )r  zipr   _calculate_paddingsr+   r   )r   r  r  r   sizespad_xspad_ys	pad_modes	pad_cvalsr%  r  r   	width_min
height_minheight_imagewidth_imager&   r   r   r   r  
  s   z)PadToFixedSize._augment_images_by_samplesc              
   C   s   g }|\}}}}}t t||D ].\}\}	}
|
\}}|	jd d \}}| |||||| || }t|	d|dd}|| q|S r|  )r  r  r   r  rG   r   )r   re  r  r   r  r  r  r   r%  rD   r   r  r  r  r  r2   Zkeypoints_paddedr   r   r   r  
  s   z,PadToFixedSize._augment_keypoints_by_samplesc              
   C   s   |\}}}}}	t t||D ]?\}
\}}|\}}|jd d \}}| ||||||
 ||
 }t||
 d||d ur;|n||
 |d urD|n|	|
 dd||
< q|S )Nr   r}  F)r'   r(   r)   )r  r  r   r  r0   )r   r(  r  r'   r(   r  r  r  r  r  r%  r>   r   r  r  Z
height_imgZ	width_imgr2   r   r   r   r	    s"   z'PadToFixedSize._augment_maps_by_samplesc           
      C   s   |j }|d}t| jtr'| jd j||d d}| jd j||d d}n| jj|df|d d}|d d df }|d d df }| jj||d d}| jj||d d}	| jg| ||||	fS )Nr   r   r,  r   r   r   )	r  r-  r7   r   rI   r.  r'   r(   r   )
r   r  r   r/  r0  r  r  Zpadsr  r  r   r   r   r  .  s*   
zPadToFixedSize._draw_samplesc                 C   s|   d}d}d}	d}
|d ur ||k r || }t d| | }
||
 }|d ur8||k r8|| }t d| | }|| }	|||	|
fS )Nr   r   rP   )r   r  r  r  r  Zpad_xs_iZpad_ys_ir   r   r   r   Zpad_total_xZpad_total_yr   r   r   r  F  s   z"PadToFixedSize._calculate_paddingsc                 C   s    | j d | j d | j| j| jgS r3  r   r   )r   r'   r(   r   r4  r   r   r   r5  Z  s   zPadToFixedSize.get_parametersr   r   rq   NNr   r   )r7  r8  r9  r:  r   r  r  r  r	  r  r;  r  r5  r<  r   r   r   r   rz  '
  s     "
rz  c                       (   e Zd ZdZ			d fdd	Z  ZS )	CenterPadToFixedSizea,  Pad images equally on all sides up to given minimum heights/widths.

    This is an alias for :class:`~imgaug.augmenters.size.PadToFixedSize`
    with ``position="center"``. It spreads the pad amounts equally over
    all image sides, while :class:`~imgaug.augmenters.size.PadToFixedSize`
    by defaults spreads them randomly.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

    Parameters
    ----------
    width : int or None
        See :func:`PadToFixedSize.__init__`.

    height : int or None
        See :func:`PadToFixedSize.__init__`.

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`PadToFixedSize.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`PadToFixedSize.__init__`.

    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.CenterPadToFixedSize(height=20, width=30)

    Create an augmenter that pads images up to ``20x30``, with the padded
    rows added *equally* on the top and bottom (analogous for the padded
    columns).

    r   r   Nr   c	           	         &   t t| j||||d||||d	 d S )Nrx   	r   r   r'   r(   r   r   r   r   r   )r   r  r   )	r   r   r   r'   r(   r   r   r   r   r   r   r   r     s   

zCenterPadToFixedSize.__init__r   r   NNr   r   rv  r   r   r   r   r  `  s    8r  c                       sd   e Zd ZdZ			d fdd	Zdd Zd	d
 Zdd Zdd Ze	dd Z
dd Zdd Z  ZS )CropToFixedSizea  Crop images down to a predefined maximum width and/or height.

    If images are already at the maximum width/height or are smaller, they
    will not be cropped. Note that this also means that images will not be
    padded if they are below the required width/height.

    The augmenter randomly decides per image how to distribute the required
    cropping amounts over the image axis. E.g. if 2px have to be cropped on
    the left or right to reach the required width, the augmenter will
    sometimes remove 2px from the left and 0px from the right, sometimes
    remove 2px from the right and 0px from the left and sometimes remove 1px
    from both sides. Set `position` to ``center`` to prevent that.

    **Supported dtypes**:

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

    Parameters
    ----------
    width : int or None
        Crop images down to this maximum width.
        If ``None``, image widths will not be altered.

    height : int or None
        Crop images down to this maximum height.
        If ``None``, image heights will not be altered.

    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
         Sets the center point of the cropping, which determines how the
         required cropping amounts are distributed to each side. For a
         ``tuple`` ``(a, b)``, both ``a`` and ``b`` are expected to be in
         range ``[0.0, 1.0]`` and describe the fraction of cropping applied
         to the left/right (low/high values for ``a``) and the fraction
         of cropping applied to the top/bottom (low/high values for ``b``).
         A cropping position at ``(0.5, 0.5)`` would be the center of the
         image and distribute the cropping equally over all sides. A cropping
         position at ``(1.0, 0.0)`` would be the right-top and would apply
         100% of the required cropping to the right and top sides of the image.

            * If string ``uniform`` then the share of cropping is randomly
              and uniformly distributed over each side.
              Equivalent to ``(Uniform(0.0, 1.0), Uniform(0.0, 1.0))``.
            * If string ``normal`` then the share of cropping is distributed
              based on a normal distribution, leading to a focus on the center
              of the images.
              Equivalent to
              ``(Clip(Normal(0.5, 0.45/2), 0, 1),
              Clip(Normal(0.5, 0.45/2), 0, 1))``.
            * If string ``center`` then center point of the cropping is
              identical to the image center.
              Equivalent to ``(0.5, 0.5)``.
            * If a string matching regex
              ``^(left|center|right)-(top|center|bottom)$``, e.g.
              ``left-top`` or ``center-bottom`` then sets the center point of
              the cropping to the X-Y position matching that description.
            * If a tuple of float, then expected to have exactly two entries
              between ``0.0`` and ``1.0``, which will always be used as the
              combination the position matching (x, y) form.
            * If a ``StochasticParameter``, then that parameter will be queried
              once per call to ``augment_*()`` to get ``Nx2`` center positions
              in ``(x, y)`` form (with ``N`` the number of images).
            * If a ``tuple`` of ``StochasticParameter``, then expected to have
              exactly two entries that will both be queried per call to
              ``augment_*()``, each for ``(N,)`` values, to get the center
              positions. First parameter is used for ``x`` coordinates,
              second for ``y`` coordinates.

    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.CropToFixedSize(width=100, height=100)

    For image sides larger than ``100`` pixels, crop to ``100`` pixels. Do
    nothing for the other sides. The cropping amounts are randomly (and
    uniformly) distributed over the sides of the image.

    >>> aug = iaa.CropToFixedSize(width=100, height=100, position="center")

    For sides larger than ``100`` pixels, crop to ``100`` pixels. Do nothing
    for the other sides. The cropping amounts are always equally distributed
    over the left/right sides of the image (and analogously for top/bottom).

    >>> aug = iaa.Sequential([
    >>>     iaa.PadToFixedSize(width=100, height=100),
    >>>     iaa.CropToFixedSize(width=100, height=100)
    >>> ])

    Pad images smaller than ``100x100`` until they reach ``100x100``.
    Analogously, crop images larger than ``100x100`` until they reach
    ``100x100``. The output images therefore have a fixed size of ``100x100``.

    rq   Nr   c                    s0   t t| j||||d ||f| _t|| _d S )Nr   )r   r  r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   "  s   

	zCropToFixedSize.__init__c           
      C   s   |  ||}|jd ur| |j||_|jd ur | |j||_|jd ur-| |j||_dD ]}t||}|d urNtj| j	|d}| 
||}	t|||	 q/|S r`  )r  r  r  r  r	  r
  r9   r  r  r  r  r;   r{  r   r   r   r  4  s0   



zCropToFixedSize._augment_batch_c              
   C   ~   g }|\}}}t t||D ].\}\}}	|	\}
}|jdd \}}| ||||
|| || }t||ddd}|| q|S Nr   r   r}  Fr~  )r  r  r   _calculate_crop_amountsr+   r   )r   r  r  r   r  	offset_xs	offset_ysr%  r  r   r'  r&  r  r  r%   Zimage_croppedr   r   r   r  T  s   
z*CropToFixedSize._augment_images_by_samplesc              
   C   r  r  )r  r  r   r  rG   r   )r   r+  r  r   r  r  r  r%  rD   r   r'  r&  r  r  r1   Zkpsoi_croppedr   r   r   r  f  s   
z-CropToFixedSize._augment_keypoints_by_samplesc              
   C   st   |\}}}t t||D ]+\}\}}|\}	}
|jdd \}}| |||
|	|| || }t||ddd||< q|S r  )r  r  r   r  r0   )r   r(  r  r  r  r  r%  r>   r   r'  r&  r  r  r1   r   r   r   r	  x  s   
z(CropToFixedSize._augment_maps_by_samplesc                 C   st   d}d}d}	d}
|d ur||krt |||  }|| | }	|d ur4||kr4t |||  }
|| |
 }|||	|
fS rg  r  )r   r  r  Z
height_maxZ	width_maxZoffset_yZoffset_xrF   rL   rM   rE   r   r   r   r    s   z'CropToFixedSize._calculate_crop_amountsc                 C   s   |j }|d}t| jtr'| jd j||d d}| jd j||d d}n| jj|df|d d}|d d df }|d d df }d| }d| }| jg| ||fS )Nr   r   r,  r   rr   )r  r-  r7   r   rI   r.  r   )r   r  r   r/  r0  r  r  offsetsr   r   r   r    s"   
zCropToFixedSize._draw_samplesc                 C   s   | j d | j d | jgS r  )r   r   r4  r   r   r   r5    s   zCropToFixedSize.get_parametersrq   NNr   r   )r7  r8  r9  r:  r   r  r  r  r	  r;  r  r  r5  r<  r   r   r   r   r    s    z 
r  c                       &   e Zd ZdZ		d fdd	Z  ZS )CenterCropToFixedSizea  Take a crop from the center of each image.

    This is an alias for :class:`~imgaug.augmenters.size.CropToFixedSize` with
    ``position="center"``.

    .. note::

        If images already have a width and/or height below the provided
        width and/or height then this augmenter will do nothing for the
        respective axis. Hence, resulting images can be smaller than the
        provided axis sizes.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

    Parameters
    ----------
    width : int or None
        See :func:`CropToFixedSize.__init__`.

    height : int or None
        See :func:`CropToFixedSize.__init__`.

    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
    >>> crop = iaa.CenterCropToFixedSize(height=20, width=10)

    Create an augmenter that takes ``20x10`` sized crops from the center of
    images.

    Nr   c              	      "   t t| j||d||||d d S )Nrx   r   r   r   r   r   r   r   )r   r  r   )r   r   r   r   r   r   r   r   r   r   r     
   

zCenterCropToFixedSize.__init__NNr   r   rv  r   r   r   r   r    s
    7r  c                       <   e Zd ZdZ			d fdd	Z fddZd	d
 Z  ZS )CropToMultiplesOfa	  Crop images down until their height/width is a multiple of a value.

    .. note::

        For a given axis size ``A`` and multiple ``M``, if ``A`` is in the
        interval ``[0 .. M]``, the axis will not be changed.
        As a result, this augmenter can still produce axis sizes that are
        not multiples of the given values.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

    Parameters
    ----------
    width_multiple : int or None
        Multiple for the width. Images will be cropped down until their
        width is a multiple of this value.
        If ``None``, image widths will not be altered.

    height_multiple : int or None
        Multiple for the height. Images will be cropped down until their
        height is a multiple of this value.
        If ``None``, image heights will not be altered.

    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        See :func:`CropToFixedSize.__init__`.

    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.CropToMultiplesOf(height_multiple=10, width_multiple=6)

    Create an augmenter that crops images to multiples of ``10`` along
    the y-axis (i.e. 10, 20, 30, ...) and to multiples of ``6`` along the
    x-axis (i.e. 6, 12, 18, ...).
    The rows to be cropped will be spread *randomly* over the top and bottom
    sides (analogous for the left/right sides).

    rq   Nr   c              	      .   t t| jd d |||||d || _|| _d S Nr  )r   r  r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   2     

zCropToMultiplesOf.__init__c                       t t| ||\}}}| }g }|D ],}|dd \}	}
t|| j| jd}|
|d  |d  |	|d  |d  f}|| q|||fS Nr   r   )r   r   r   r   )r   r  r  ra  r   r   r   r   r   r  r   _sizesr  r  rb  r  r   r   r   r%   new_sizer   r   r   r  =  &   	
zCropToMultiplesOf._draw_samplesc                 C   r1  r2  )r   r   r   r4  r   r   r   r5  W  r6  z CropToMultiplesOf.get_parametersr  r7  r8  r9  r:  r   r  r5  r<  r   r   r   r   r    s    =r  c                       r  )CenterCropToMultiplesOfa  Crop images equally on all sides until H/W are multiples of given values.

    This is the same as :class:`~imgaug.augmenters.size.CropToMultiplesOf`,
    but uses ``position="center"`` by default, which spreads the crop amounts
    equally over all image sides, while
    :class:`~imgaug.augmenters.size.CropToMultiplesOf` by default spreads
    them randomly.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

    Parameters
    ----------
    width_multiple : int or None
        See :func:`CropToMultiplesOf.__init__`.

    height_multiple : int or None
        See :func:`CropToMultiplesOf.__init__`.

    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.CenterCropToMultiplesOf(height_multiple=10, width_multiple=6)

    Create an augmenter that crops images to multiples of ``10`` along
    the y-axis (i.e. 10, 20, 30, ...) and to multiples of ``6`` along the
    x-axis (i.e. 6, 12, 18, ...).
    The rows to be cropped will be spread *equally* over the top and bottom
    sides (analogous for the left/right sides).

    Nr   c              	      r  )Nrx   )r   r   r   r   r   r   r   )r   r  r   )r   r   r   r   r   r   r   r   r   r   r     s   

z CenterCropToMultiplesOf.__init__r  rv  r   r   r   r   r  \  
    6r  c                       >   e Zd ZdZ				d fdd	Z fd	d
Zdd Z  ZS )PadToMultiplesOfa&
  Pad images until their height/width is a multiple of a value.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

    Parameters
    ----------
    width_multiple : int or None
        Multiple for the width. Images will be padded until their
        width is a multiple of this value.
        If ``None``, image widths will not be altered.

    height_multiple : int or None
        Multiple for the height. Images will be padded until their
        height is a multiple of this value.
        If ``None``, image heights will not be altered.

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToFixedSize.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToFixedSize.__init__`.

    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        See :func:`PadToFixedSize.__init__`.

    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.PadToMultiplesOf(height_multiple=10, width_multiple=6)

    Create an augmenter that pads images to multiples of ``10`` along
    the y-axis (i.e. 10, 20, 30, ...) and to multiples of ``6`` along the
    x-axis (i.e. 6, 12, 18, ...).
    The rows to be padded will be spread *randomly* over the top and bottom
    sides (analogous for the left/right sides).

    r   r   rq   Nr   c
           
         2   t t| jd d |||||||	d	 || _|| _d S Nr  )r   r  r   r   r   )
r   r   r   r'   r(   r   r   r   r   r   r   r   r   r        

zPadToMultiplesOf.__init__c                       t t| ||\}}}}}| }g }	|D ],}
|
dd \}}t|
| j| jd}||d  |d  ||d  |d  f}|	| q|	||||fS r  )r   r  r  ra  r   r   r   r   r   r  r   r  r  r  r  r  rb  r  r   r   r   r&   r  r   r   r   r    &   	zPadToMultiplesOf._draw_samplesc                 C      | j | j| j| j| jgS r2  )r   r   r'   r(   r   r4  r   r   r   r5       zPadToMultiplesOf.get_parametersr  r  r   r   r   r   r    s    =r  c                       r  )	CenterPadToMultiplesOfa3	  Pad images equally on all sides until H/W are multiples of given values.

    This is the same as :class:`~imgaug.augmenters.size.PadToMultiplesOf`, but
    uses ``position="center"`` by default, which spreads the pad amounts
    equally over all image sides, while
    :class:`~imgaug.augmenters.size.PadToMultiplesOf` by default spreads them
    randomly.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

    Parameters
    ----------
    width_multiple : int or None
        See :func:`PadToMultiplesOf.__init__`.

    height_multiple : int or None
        See :func:`PadToMultiplesOf.__init__`.

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToMultiplesOf.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToMultiplesOf.__init__`.

    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.CenterPadToMultiplesOf(height_multiple=10, width_multiple=6)

    Create an augmenter that pads images to multiples of ``10`` along
    the y-axis (i.e. 10, 20, 30, ...) and to multiples of ``6`` along the
    x-axis (i.e. 6, 12, 18, ...).
    The rows to be padded will be spread *equally* over the top and bottom
    sides (analogous for the left/right sides).

    r   r   Nr   c	           	         r  )Nrx   )	r   r   r'   r(   r   r   r   r   r   )r   r  r   )	r   r   r   r'   r(   r   r   r   r   r   r   r   r   E  s   

zCenterPadToMultiplesOf.__init__r  rv  r   r   r   r   r  	  s    <r  c                       r  )CropToPowersOfa#  Crop images until their height/width is a power of a base.

    This augmenter removes pixels from an axis with size ``S`` leading to the
    new size ``S'`` until ``S' = B^E`` is fulfilled, where ``B`` is a
    provided base (e.g. ``2``) and ``E`` is an exponent from the discrete
    interval ``[1 .. inf)``.

    .. note::

        This augmenter does nothing for axes with size less than ``B^1 = B``.
        If you have images with ``S < B^1``, it is recommended
        to combine this augmenter with a padding augmenter that pads each
        axis up to ``B``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

    Parameters
    ----------
    width_base : int or None
        Base for the width. Images will be cropped down until their
        width fulfills ``width' = width_base ^ E`` with ``E`` being any
        natural number.
        If ``None``, image widths will not be altered.

    height_base : int or None
        Base for the height. Images will be cropped down until their
        height fulfills ``height' = height_base ^ E`` with ``E`` being any
        natural number.
        If ``None``, image heights will not be altered.

    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        See :func:`CropToFixedSize.__init__`.

    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.CropToPowersOf(height_base=3, width_base=2)

    Create an augmenter that crops each image down to powers of ``3`` along
    the y-axis (i.e. 3, 9, 27, ...) and powers of ``2`` along the x-axis (i.e.
    2, 4, 8, 16, ...).
    The rows to be cropped will be spread *randomly* over the top and bottom
    sides (analogous for the left/right sides).

    rq   Nr   c              	      r  r  )r   r  r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r     r  zCropToPowersOf.__init__c                    r  Nr   r   )r   r   r   r   )r   r  r  ra  r   r   r   r   r  r   r   r   r    r  zCropToPowersOf._draw_samplesc                 C   r1  r2  )r   r   r   r4  r   r   r   r5    r6  zCropToPowersOf.get_parametersr  r  r   r   r   r   r  S  s    Dr  c                       r  )CenterCropToPowersOfa  Crop images equally on all sides until H/W is a power of a base.

    This is the same as :class:`~imgaug.augmenters.size.CropToPowersOf`, but
    uses ``position="center"`` by default, which spreads the crop amounts
    equally over all image sides, while
    :class:`~imgaug.augmenters.size.CropToPowersOf` by default spreads them
    randomly.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

    Parameters
    ----------
    width_base : int or None
        See :func:`CropToPowersOf.__init__`.

    height_base : int or None
        See :func:`CropToPowersOf.__init__`.

    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.CropToPowersOf(height_base=3, width_base=2)

    Create an augmenter that crops each image down to powers of ``3`` along
    the y-axis (i.e. 3, 9, 27, ...) and powers of ``2`` along the x-axis (i.e.
    2, 4, 8, 16, ...).
    The rows to be cropped will be spread *equally* over the top and bottom
    sides (analogous for the left/right sides).

    Nr   c              	      r  )Nrx   )r   r   r   r   r   r   r   )r   r  r   )r   r   r   r   r   r   r   r   r   r   r     r  zCenterCropToPowersOf.__init__r  rv  r   r   r   r   r    r  r  c                       r  )PadToPowersOfah  Pad images until their height/width is a power of a base.

    This augmenter adds pixels to an axis with size ``S`` leading to the
    new size ``S'`` until ``S' = B^E`` is fulfilled, where ``B`` is a
    provided base (e.g. ``2``) and ``E`` is an exponent from the discrete
    interval ``[1 .. inf)``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

    Parameters
    ----------
    width_base : int or None
        Base for the width. Images will be padded down until their
        width fulfills ``width' = width_base ^ E`` with ``E`` being any
        natural number.
        If ``None``, image widths will not be altered.

    height_base : int or None
        Base for the height. Images will be padded until their
        height fulfills ``height' = height_base ^ E`` with ``E`` being any
        natural number.
        If ``None``, image heights will not be altered.

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToFixedSize.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToFixedSize.__init__`.

    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        See :func:`PadToFixedSize.__init__`.

    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.PadToPowersOf(height_base=3, width_base=2)

    Create an augmenter that pads each image to powers of ``3`` along the
    y-axis (i.e. 3, 9, 27, ...) and powers of ``2`` along the x-axis (i.e. 2,
    4, 8, 16, ...).
    The rows to be padded will be spread *randomly* over the top and bottom
    sides (analogous for the left/right sides).

    r   r   rq   Nr   c
           
         r  r  )r   r  r   r   r   )
r   r   r   r'   r(   r   r   r   r   r   r   r   r   r   E  r  zPadToPowersOf.__init__c                    r  r  )r   r  r  ra  r   r   r   r   r  r   r   r   r  S  r  zPadToPowersOf._draw_samplesc                 C   r  r2  )r   r   r'   r(   r   r4  r   r   r   r5  m  r  zPadToPowersOf.get_parametersr  r  r   r   r   r   r    s    Dr  c                       r  )	CenterPadToPowersOfa  Pad images equally on all sides until H/W is a power of a base.

    This is the same as :class:`~imgaug.augmenters.size.PadToPowersOf`, but uses
    ``position="center"`` by default, which spreads the pad amounts equally
    over all image sides, while :class:`~imgaug.augmenters.size.PadToPowersOf`
    by default spreads them randomly.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

    Parameters
    ----------
    width_base : int or None
        See :func:`PadToPowersOf.__init__`.

    height_base : int or None
        See :func:`PadToPowersOf.__init__`.

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToPowersOf.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToPowersOf.__init__`.

    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.CenterPadToPowersOf(height_base=5, width_base=2)

    Create an augmenter that pads each image to powers of ``3`` along the
    y-axis (i.e. 3, 9, 27, ...) and powers of ``2`` along the x-axis (i.e. 2,
    4, 8, 16, ...).
    The rows to be padded will be spread *equally* over the top and bottom
    sides (analogous for the left/right sides).

    r   r   Nr   c	           	         r  )Nrx   )	r   r   r'   r(   r   r   r   r   r   )r   r  r   )	r   r   r   r'   r(   r   r   r   r   r   r   r   r     s   

zCenterPadToPowersOf.__init__r  rv  r   r   r   r   r  t  s    ;r  c                       r  )CropToAspectRatioa.	  Crop images until their width/height matches an aspect ratio.

    This augmenter removes either rows or columns until the image reaches
    the desired aspect ratio given in ``width / height``. The cropping
    operation is stopped once the desired aspect ratio is reached or the image
    side to crop reaches a size of ``1``. If any side of the image starts
    with a size of ``0``, the image will not be changed.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

    Parameters
    ----------
    aspect_ratio : number
        The desired aspect ratio, given as ``width/height``. E.g. a ratio
        of ``2.0`` denotes an image that is twice as wide as it is high.

    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        See :func:`CropToFixedSize.__init__`.

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

    Create an augmenter that crops each image until its aspect ratio is as
    close as possible to ``2.0`` (i.e. two times as many pixels along the
    x-axis than the y-axis).
    The rows to be cropped will be spread *randomly* over the top and bottom
    sides (analogous for the left/right sides).

    rq   Nr   c              	      s(   t t| jd d |||||d || _d S r  )r   r  r   r   )r   r   r   r   r   r   r   r   r   r   r     s   

zCropToAspectRatio.__init__c                    s   t t| ||\}}}| }g }|D ]5}|dd \}	}
|	dks&|
dkr)d}nt|| jd}|
|d  |d  |	|d  |d  f}|| q|||fS )Nr   r   r}  r   r   r   )r   r  r  ra  r   r   r   r  r   r   r   r    s(   
zCropToAspectRatio._draw_samplesc                 C      | j | jgS r2  )r   r   r4  r   r   r   r5       z CropToAspectRatio.get_parametersr  r  r   r   r   r   r    s    6
r  c                       r  )CenterCropToAspectRatioaY  Crop images equally on all sides until they reach an aspect ratio.

    This is the same as :class:`~imgaug.augmenters.size.CropToAspectRatio`, but
    uses ``position="center"`` by default, which spreads the crop amounts
    equally over all image sides, while
    :class:`~imgaug.augmenters.size.CropToAspectRatio` by default spreads
    them randomly.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

    Parameters
    ----------
    aspect_ratio : number
        See :func:`CropToAspectRatio.__init__`.

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

    Create an augmenter that crops each image until its aspect ratio is as
    close as possible to ``2.0`` (i.e. two times as many pixels along the
    x-axis than the y-axis).
    The rows to be cropped will be spread *equally* over the top and bottom
    sides (analogous for the left/right sides).

    Nr   c                    s    t t| j|d||||d d S )Nrx   r   r   r   r   r   r   )r   r  r   )r   r   r   r   r   r   r   r   r   r   Q  
   

z CenterCropToAspectRatio.__init__r  rv  r   r   r   r   r    s
    3r  c                       r  )PadToAspectRatioa	  Pad images until their width/height matches an aspect ratio.

    This augmenter adds either rows or columns until the image reaches
    the desired aspect ratio given in ``width / height``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

    Parameters
    ----------
    aspect_ratio : number
        The desired aspect ratio, given as ``width/height``. E.g. a ratio
        of ``2.0`` denotes an image that is twice as wide as it is high.

    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        See :func:`PadToFixedSize.__init__`.

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToFixedSize.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToFixedSize.__init__`.

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

    Create an augmenter that pads each image until its aspect ratio is as
    close as possible to ``2.0`` (i.e. two times as many pixels along the
    x-axis than the y-axis).
    The rows to be padded will be spread *randomly* over the top and bottom
    sides (analogous for the left/right sides).

    r   r   rq   Nr   c	           	         s,   t t| jd d |||||||d	 || _d S r  )r   r  r   r   )	r   r   r'   r(   r   r   r   r   r   r   r   r   r     s   

zPadToAspectRatio.__init__c                    s   t t| ||\}}}}}| }g }	|D ]*}
|
dd \}}t|
| jd}||d  |d  ||d  |d  f}|	| q|	||||fS )Nr   r   r  r   r   )r   r  r  ra  r   r   r   r  r   r   r   r    s$   zPadToAspectRatio._draw_samplesc                 C   s   | j | j| j| jgS r2  )r   r'   r(   r   r4  r   r   r   r5    s   zPadToAspectRatio.get_parametersr  r  r   r   r   r   r  Z  s    9r  c                       r  )	CenterPadToAspectRatioa  Pad images equally on all sides until H/W matches an aspect ratio.

    This is the same as :class:`~imgaug.augmenters.size.PadToAspectRatio`, but
    uses ``position="center"`` by default, which spreads the pad amounts
    equally over all image sides, while
    :class:`~imgaug.augmenters.size.PadToAspectRatio` by default spreads them
    randomly.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

    Parameters
    ----------
    aspect_ratio : number
        See :func:`PadToAspectRatio.__init__`.

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

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToAspectRatio.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToAspectRatio.__init__`.

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

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

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.PadToAspectRatio(2.0)

    Create am augmenter that pads each image until its aspect ratio is as
    close as possible to ``2.0`` (i.e. two times as many pixels along the
    x-axis than the y-axis).
    The rows to be padded will be spread *equally* over the top and bottom
    sides (analogous for the left/right sides).

    r   r   Nr   c              
      s$   t t| j|d||||||d d S )Nrx   )r   r   r'   r(   r   r   r   r   )r   r  r   )r   r   r'   r(   r   r   r   r   r   r   r   r     s   

zCenterPadToAspectRatio.__init__r  rv  r   r   r   r   r        0r  c                       s(   e Zd ZdZ			d fdd	Z  ZS )CropToSquareac  Crop images until their width and height are identical.

    This is identical to :class:`~imgaug.augmenters.size.CropToAspectRatio`
    with ``aspect_ratio=1.0``.

    Images with axis sizes of ``0`` will not be altered.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

    Parameters
    ----------
    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        See :func:`CropToFixedSize.__init__`.

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

    Create an augmenter that crops each image until its square, i.e. height
    and width match.
    The rows to be cropped will be spread *randomly* over the top and bottom
    sides (analogous for the left/right sides).

    rq   Nr   c                    s    t t| jd|||||d d S )Nrr   r  )r   r  r   )r   r   r   r   r   r   r   r   r   r   ,  r  zCropToSquare.__init__r  rv  r   r   r   r   r    r  r  c                       r  )CenterCropToSquarea  Crop images equally on all sides until their height/width are identical.

    In contrast to :class:`~imgaug.augmenters.size.CropToSquare`, this
    augmenter always tries to spread the columns/rows to remove equally over
    both sides of the respective axis to be cropped.
    :class:`~imgaug.augmenters.size.CropToAspectRatio` by default spreads the
    croppings randomly.

    This augmenter is identical to :class:`~imgaug.augmenters.size.CropToSquare`
    with ``position="center"``, and thereby the same as
    :class:`~imgaug.augmenters.size.CropToAspectRatio` with
    ``aspect_ratio=1.0, position="center"``.

    Images with axis sizes of ``0`` will not be altered.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.CropToFixedSize`.

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

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

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

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

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.CenterCropToSquare()

    Create an augmenter that crops each image until its square, i.e. height
    and width match.
    The rows to be cropped will be spread *equally* over the top and bottom
    sides (analogous for the left/right sides).

    Nr   c                    s   t t| jd||||d d S )Nrx   )r   r   r   r   r   )r   r  r   )r   r   r   r   r   r   r   r   r   k  s
   

zCenterCropToSquare.__init__r  rv  r   r   r   r   r  5  s
    5r  c                       s(   e Zd ZdZ			d	 fdd	Z  ZS )
PadToSquarea  Pad images until their height and width are identical.

    This augmenter is identical to
    :class:`~imgaug.augmenters.size.PadToAspectRatio` with ``aspect_ratio=1.0``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

    Parameters
    ----------
    position : {'uniform', 'normal', 'center', 'left-top', 'left-center', 'left-bottom', 'center-top', 'center-center', 'center-bottom', 'right-top', 'right-center', 'right-bottom'} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional
        See :func:`PadToFixedSize.__init__`.

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToFixedSize.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToFixedSize.__init__`.

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

    Create an augmenter that pads each image until its square, i.e. height
    and width match.
    The rows to be padded will be spread *randomly* over the top and bottom
    sides (analogous for the left/right sides).

    r   r   rq   Nr   c              
      s$   t t| jd|||||||d d S )Nrr   )r   r'   r(   r   r   r   r   r   )r   r  r   )r   r'   r(   r   r   r   r   r   r   r   r   r     s   

zPadToSquare.__init__r  rv  r   r   r   r   r  s  s    4r  c                       r  )	CenterPadToSquarea  Pad images equally on all sides until their height & width are identical.

    This is the same as :class:`~imgaug.augmenters.size.PadToSquare`, but uses
    ``position="center"`` by default, which spreads the pad amounts equally
    over all image sides, while :class:`~imgaug.augmenters.size.PadToSquare`
    by default spreads them randomly. This augmenter is thus also identical to
    :class:`~imgaug.augmenters.size.PadToAspectRatio` with
    ``aspect_ratio=1.0, position="center"``.

    Added in 0.4.0.

    **Supported dtypes**:

    See :class:`~imgaug.augmenters.size.PadToFixedSize`.

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

    pad_mode : imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToAspectRatio.__init__`.

    pad_cval : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        See :func:`~imgaug.augmenters.size.PadToAspectRatio.__init__`.

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

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

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.CenterPadToSquare()

    Create an augmenter that pads each image until its square, i.e. height
    and width match.
    The rows to be padded will be spread *equally* over the top and bottom
    sides (analogous for the left/right sides).

    r   r   Nr   c              	      r  )Nrx   )r'   r(   r   r   r   r   r   )r   r  r   )r   r'   r(   r   r   r   r   r   r   r   r     r  zCenterPadToSquare.__init__r  rv  r   r   r   r   r    s    -r  c                       s   e Zd ZdZdZdZdedddddf fdd		Zd
d Zedd Z	edd Z
edd Zedd Zdd Zdd Zdd Zdd Zdd Z  ZS )KeepSizeByResizea  Resize images back to their input sizes after applying child augmenters.

    Combining this with e.g. a cropping augmenter as the child will lead to
    images being resized back to the input size after the crop operation was
    applied. Some augmenters have a ``keep_size`` argument that achieves the
    same goal (if set to ``True``), though this augmenter offers control over
    the interpolation mode and which augmentables to resize (images, heatmaps,
    segmentation maps).

    **Supported dtypes**:

    See :func:`~imgaug.imgaug.imresize_many_images`.

    Parameters
    ----------
    children : Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional
        One or more augmenters to apply to images. These augmenters may change
        the image size.

    interpolation : KeepSizeByResize.NO_RESIZE or {'nearest', 'linear', 'area', 'cubic'} or {cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC} or list of str or list of int or StochasticParameter, optional
        The interpolation mode to use when resizing images.
        Can take any value that :func:`~imgaug.imgaug.imresize_single_image`
        accepts, e.g. ``cubic``.

            * If this is ``KeepSizeByResize.NO_RESIZE`` then images will not
              be resized.
            * If this is a single ``str``, it is expected to have one of the
              following values: ``nearest``, ``linear``, ``area``, ``cubic``.
            * If this is a single integer, it is expected to have a value
              identical to one of: ``cv2.INTER_NEAREST``,
              ``cv2.INTER_LINEAR``, ``cv2.INTER_AREA``, ``cv2.INTER_CUBIC``.
            * If this is a ``list`` of ``str`` or ``int``, it is expected that
              each ``str``/``int`` is one of the above mentioned valid ones.
              A random one of these values will be sampled per image.
            * If this is a ``StochasticParameter``, it will be queried once per
              call to ``_augment_images()`` and must return ``N`` ``str`` s or
              ``int`` s (matching the above mentioned ones) for ``N`` images.

    interpolation_heatmaps : KeepSizeByResize.SAME_AS_IMAGES or KeepSizeByResize.NO_RESIZE or {'nearest', 'linear', 'area', 'cubic'} or {cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC} or list of str or list of int or StochasticParameter, optional
        The interpolation mode to use when resizing heatmaps.
        Meaning and valid values are similar to `interpolation`. This
        parameter may also take the value ``KeepSizeByResize.SAME_AS_IMAGES``,
        which will lead to copying the interpolation modes used for the
        corresponding images. The value may also be returned on a per-image
        basis if `interpolation_heatmaps` is provided as a
        ``StochasticParameter`` or may be one possible value if it is
        provided as a ``list`` of ``str``.

    interpolation_segmaps : KeepSizeByResize.SAME_AS_IMAGES or KeepSizeByResize.NO_RESIZE or {'nearest', 'linear', 'area', 'cubic'} or {cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC} or list of str or list of int or StochasticParameter, optional
        The interpolation mode to use when resizing segmentation maps.
        Similar to `interpolation_heatmaps`.
        **Note**: For segmentation maps, only ``NO_RESIZE`` or nearest
        neighbour interpolation (i.e. ``nearest``) make sense in the vast
        majority of all cases.

    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.KeepSizeByResize(
    >>>     iaa.Crop((20, 40), keep_size=False)
    >>> )

    Apply random cropping to input images, then resize them back to their
    original input sizes. The resizing is done using this augmenter instead
    of the corresponding internal resizing operation in ``Crop``.

    >>> aug = iaa.KeepSizeByResize(
    >>>     iaa.Crop((20, 40), keep_size=False),
    >>>     interpolation="nearest"
    >>> )

    Same as in the previous example, but images are now always resized using
    nearest neighbour interpolation.

    >>> aug = iaa.KeepSizeByResize(
    >>>     iaa.Crop((20, 40), keep_size=False),
    >>>     interpolation=["nearest", "cubic"],
    >>>     interpolation_heatmaps=iaa.KeepSizeByResize.SAME_AS_IMAGES,
    >>>     interpolation_segmaps=iaa.KeepSizeByResize.NO_RESIZE
    >>> )

    Similar to the previous example, but images are now sometimes resized
    using linear interpolation and sometimes using nearest neighbour
    interpolation. Heatmaps are resized using the same interpolation as was
    used for the corresponding image. Segmentation maps are not resized and
    will therefore remain at their size after cropping.

    	NO_RESIZESAME_AS_IMAGESr   r   Nr   c	           
         sd   t t j||||d | _ fdd}	t| jd _|	|d _|	|d _|	|d _	d S )Nr   c                    s   t jtjg }|r| jkrjS | |v rt| S t| trQt	| dks)J d| |r3 tjg  t
 fdd| D }|sLJ dt t| f t| S t| tjrY| S tdtt jt| f )Nr   zHExpected a list of at least one interpolation method. Got an empty list.c                    r_   r   r   ra   ipZvalid_ips_herer   r   rd   q  re   zFKeepSizeByResize.__init__.<locals>._validate_param.<locals>.<listcomp>z9Expected each interpolations to be one of '%s', got '%s'.ziExpected interpolation to be one of '%s' or a list of these values or a StochasticParameter. Got type %s.)r#   ZIMRESIZE_VALID_INTERPOLATIONSr  r  r  rg   rk   r7   rH   r   rl   rm   rh   rn   ro   r8   )rX  Zallow_same_as_imagesZvalid_ips_and_resizeZonly_valid_ipsr4  r  r   _validate_paramb  s>   


z2KeepSizeByResize.__init__.<locals>._validate_paramZthenFT)
r   r  r   childrenr   Zhandle_children_listr   r   interpolation_heatmapsinterpolation_segmaps)
r   r  r   r  r  r   r   r   r   r  r   r4  r   r   W  s   

zKeepSizeByResize.__init__c                 C   sB  | | || d }|jd urt|j}| |}| |j|}| jj||| g |d}|jd ur>| 	|j|d |||_|j
d urS| |j
|d |d |d |_
|jd urh| |j|d |d |d |_d	D ]$}t||}	|	d urtj| j|| |d
 d}
| |	|
}t||| qjW d    |S 1 sw   Y  |S )N)r  r  r  r  heatmaps_arrr   r
  segmentation_maps_arrr   r  r   )shapes_originterpolations)Zpropagation_hooks_ctxr  r#   r  _get_shapesr  r  r  Zaugment_batch__keep_size_imagesr  _keep_size_mapsr
  r9   r  r  _keep_size_keypointsr  r;   )r   r  r   r  r  images_were_arrayr  r  r  r  r  r  r   r   r   r    sT   








''z KeepSizeByResize._augment_batch_c              	   C   s   |\}}}t |||}g }|D ]\}	}
}|
tjkr||	 q|t|	|dd |
 q|rGtdd |D }|dkrGtj||d j	d}|S )Nr   r   c                 S   r  r   r   r  r   r   r   r    r  z5KeepSizeByResize._keep_size_images.<locals>.<setcomp>r   r  )
r  r  r  r   r#   r$   r   rQ   r!  r   )r   r  r  r  r  r  r   genr   r  r   input_shaperd  r   r   r   r    s    

z"KeepSizeByResize._keep_size_imagesc                 C   sb   g }t ||||}|D ]#\}}}	}
|dkr|| q|j|	dd |d}|
|_|| q|S )Nr  r   r   r  )r  r   r<   r   )r   r(  Zshapes_orig_imagesZshapes_orig_arrsr  r   r  r>   r   r@   Zimg_shape_origr   r   r   r    s   z KeepSizeByResize._keep_size_mapsc           	      C   sJ   g }t |||}|D ]\}}}|tjkr|| q
||| q
|S r.   )r  r  r  r   rC   )	r   Z
kpsois_augr  r  r   r  rf  r   r  r   r   r   r    s   
z%KeepSizeByResize._keep_size_keypointsc                 C   sh   t  }|jD ]}dd |jD ||j< q|jd ur#dd |jD |d< |jd ur2dd |jD |d< |S )Nc                 S   s   g | ]}|j qS r   r   ra   cellr   r   r   rd     r  z0KeepSizeByResize._get_shapes.<locals>.<listcomp>c                 S      g | ]}|j jqS r   )r6   r   r  r   r   r   rd         r  c                 S   r  r   )r   r   r  r   r   r   rd     r  r  )r   columnsrT   r   r  r
  )r   r  r   columnr   r   r   r    s   




zKeepSizeByResize._get_shapesc                    s   | d} jj|f|d d} jtjkrt|}n jj|f|d d} fdd|D }|| ||<  jtjkrBt|}n jj|f|d d} fdd|D }|| ||< |||fS )	Nr   r   r,  r   c                       g | ]}| j kqS r   r  r  r4  r   r   rd   
      z2KeepSizeByResize._draw_samples.<locals>.<listcomp>r   c                    r  r   r  r  r4  r   r   rd     r  )	r-  r   r.  r  r  r  rQ   r   r  )r   r/  r   r0  r  Zinterpolations_heatmapsZsame_as_imgs_idxZinterpolations_segmapsr   r4  r   r    s2   



	

	
zKeepSizeByResize._draw_samplesc                 C   s*   |   }|j |_d|_| j |_|S )NT)r   r  Zto_deterministicr   r   Zderive_rng_)r   augr   r   r   _to_deterministic'  s
   z"KeepSizeByResize._to_deterministicc                 C   r  r2  )r   r  r4  r   r   r   r5  .  r  zKeepSizeByResize.get_parametersc                 C   s   | j gS )zASee :func:`~imgaug.augmenters.meta.Augmenter.get_children_lists`.)r  r4  r   r   r   get_children_lists2  s   z#KeepSizeByResize.get_children_listsc                 C   s&   d}|| j j| j| j| j| j| jf S )NzW%s(interpolation=%s, interpolation_heatmaps=%s, name=%s, children=%s, deterministic=%s))r   r7  r   r  r   r  r   )r   patternr   r   r   __str__6  s   
zKeepSizeByResize.__str__)r7  r8  r9  r:  r  r  r   r  r;  r  r  r  r  r  r  r5  r  r  r<  r   r   r   r   r    s0    j.+



.r  )T)r   r   F)r   r,   F)r   NF)r   r   r   r   r   r   )F)Gr:  
__future__r   r   r   r   r  numpyrQ   r   Zimgaugr#   Zimgaug.imgaugr    r   r	   rg   r   r   r+   r3   r5   r0   rG   r=   r
   r:   rO   rp   r   r   r"   r   r   r   r   r   r   r   r   r   r   Z	Augmenterr   objectr=  rB  ro  rw  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   <module>   s     





+/ ?
 J
D
JGH@@
I
N
       l j >  ;G  @hAlJo?sGc<f;:>?7