o
    &jΘ                     @   s(  d Z ddlmZmZm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ZddlmZ ddlmZ dd	lmZ dd
lmZ dZeZdd ZeeG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#G dd deZ$			dHddZ%dd Z&d d! Z'd"d# Z(d$d% Z)d&d' Z*d(d) Z+d*d+ Z,d,d- Z-d.d/ Z.d0d1 Z/d2d3 Z0d4d5 Z1d6d7 Z2G d8d9 d9eZ3eeG d:d; d;eZ4G d<d= d=e4Z5G d>d? d?e4Z6eeG d@dA dAeZ7G dBdC dCe7Z8G dDdE dEej9Z:G dFdG dGe:Z;dS )IzxAugmenters that help with debugging.

List of augmenters:

    * :class:`SaveDebugImageEveryNBatches`

Added in 0.4.0.

    )print_functiondivisionabsolute_import)ABCMetaabstractmethodabstractpropertyN   dtypes   )meta)size)blend)         c                 C   s  |d }|d }| j d }| j d }|| }|| }|| }	||	k r)|}
|| }n|| }
|}ttt|
d}
ttt|d}t| |
|f}||
 }|| }tt|d }tt|d }tt|d }tt|d }t	j
||||||d}||||f}||
|f|fS )zResize and pad and image to given size.

    This first resizes until one image size matches one size in `size` (while
    retaining the aspect ratio).
    Then it pads the other side until both sides match `size`.

    Added in 0.4.0.

    r   r   r   toprightbottomleftcval)shapemaxintnproundiaimresize_single_imagefloorceilsizelibpad)imager   r   heightwidthZ	height_imZwidth_imZaspect_ratio_imZheight_diffZ
width_diffZheight_im_rsZwidth_im_rsZimage_rsZpad_yZpad_xpad_top	pad_rightZ
pad_bottompad_leftZimage_rs_padpaddings r*   X/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/imgaug/augmenters/debug.py_resizepad_to_size   s8   


r,   c                   @   s4   e Zd ZdZedd Zedd Zedd ZdS )	_IDebugGridCellzA single cell within a debug image's grid.

    Usually corresponds to one image, but can also be e.g. a title/description.

    Added in 0.4.0.

    c                 C      dS )zRMinimum width in pixels that the cell requires.

        Added in 0.4.0.

        Nr*   selfr*   r*   r+   	min_width[       z_IDebugGridCell.min_widthc                 C   r.   )zSMinimum height in pixels that the cell requires.

        Added in 0.4.0.

        Nr*   r/   r*   r*   r+   
min_heightc   r2   z_IDebugGridCell.min_heightc                 C   r.   )ab  Draw the debug image grid cell's content.

        Added in 0.4.0.

        Parameters
        ----------
        height : int
            Expected height of the drawn cell image/array.

        width : int
            Expected width of the drawn cell image/array.

        Returns
        -------
        ndarray
            ``(H,W,3)`` Image.

        Nr*   )r0   r$   r%   r*   r*   r+   drawk   r2   z_IDebugGridCell.drawN)	__name__
__module____qualname____doc__r   r1   r3   r   r4   r*   r*   r*   r+   r-   Q   s    

r-   c                   @   8   e Zd ZdZdd Zedd Zedd Zdd	 Zd
S )_DebugGridBorderCellz\Helper to add a border around a cell within the debug image grid.

    Added in 0.4.0.

    c                 C      || _ || _|| _d S N)r   colorchild)r0   r   r=   r>   r*   r*   r+   __init__      
z_DebugGridBorderCell.__init__c                 C      | j jS r<   )r>   r3   r/   r*   r*   r+   r3         z_DebugGridBorderCell.min_heightc                 C   rA   r<   )r>   r1   r/   r*   r*   r+   r1      rB   z_DebugGridBorderCell.min_widthc              	   C   s4   | j ||}tj|| j| j| j| jd| jd}|S )Nconstantr   r   r   r   moder   )r>   r4   r!   r"   r   r=   )r0   r$   r%   contentr*   r*   r+   r4      s   z_DebugGridBorderCell.drawN	r5   r6   r7   r8   r?   propertyr3   r1   r4   r*   r*   r*   r+   r:      s    

r:   c                   @   r9   )_DebugGridTextCellz0Cell containing text.

    Added in 0.4.0.

    c                 C   
   || _ d S r<   )text)r0   rK   r*   r*   r+   r?         
z_DebugGridTextCell.__init__c                 C   s   t dt| jdd S )N   
   )r   lenrK   splitr/   r*   r*   r+   r3      s   z_DebugGridTextCell.min_heightc                 C   s<   | j d}t|dkrdS tdtdtdd |D  S )NrN   r   rM      c                 S      g | ]}t |qS r*   rP   ).0liner*   r*   r+   
<listcomp>       z0_DebugGridTextCell.min_width.<locals>.<listcomp>)rK   rQ   rP   r   r   )r0   linesr*   r*   r+   r1      s    z_DebugGridTextCell.min_widthc                 C   s4   t j||dfdt jd}tj|dd| jddd}|S )N   r   dtyper   )r   r   r      )r=   r   )r   fulluint8r   Z	draw_textrK   )r0   r$   r%   r#   r*   r*   r+   r4      s
   z_DebugGridTextCell.drawNrG   r*   r*   r*   r+   rI      s    

rI   c                   @   sF   e Zd ZdZdddZedd Zedd	 Zd
d Ze	dd Z
dS )_DebugGridImageCellz_Cell containing an image, possibly with an different-shaped overlay.

    Added in 0.4.0.

    N      ?c                 C   r;   r<   )r#   overlayoverlay_alpha)r0   r#   rb   rc   r*   r*   r+   r?      r@   z_DebugGridImageCell.__init__c                 C      | j jd S Nr   r#   r   r/   r*   r*   r+   r3         z_DebugGridImageCell.min_heightc                 C   rd   Nr   rf   r/   r*   r*   r+   r1      rg   z_DebugGridImageCell.min_widthc                 C   s6  | j }|jj}|dkr|tjd }n1|dkr*t|j\}}}|tj| }n|dkrEt|j\}}}|| }||tj | }|jjdkrXt	|ddd tj}t
|||ftd\}	}
}|	}| jd ur| | j|jdd	 }| ||
}tj||d |d
 |d	 |d td}tj||	| jd}|S )Nbr   uifr   g      ?r   r   r   rZ   r   )alpha)r#   r\   kindZastyper   r_   iadtZget_value_range_of_dtypeZfloat64Zclipr,   _COLOR_GRID_BACKGROUNDrb   _resize_overlayr   r!   r"   blendlibZblend_alpharc   )r0   r$   r%   r#   ro   Z	min_value_Z	max_valueZdynamic_range	image_rspsize_rsr)   r   Z
overlay_rsZoverlay_rspr*   r*   r+   r4      s>   

z_DebugGridImageCell.drawc                 C   s   t j||dd}|S )Nnearest)interpolation)r   r   )clsarrr   Zarr_rsr*   r*   r+   rr      s   z#_DebugGridImageCell._resize_overlay)Nra   )r5   r6   r7   r8   r?   rH   r3   r1   r4   classmethodrr   r*   r*   r*   r+   r`      s    


#r`   c                   @   r9   )_DebugGridCBAsOICellzCell visualizing a coordinate-based augmentable.

    CBAsOI = coordinate-based augmentables on images,
    e.g. ``KeypointsOnImage``.

    Added in 0.4.0.

    c                 C   s   || _ || _d S r<   )cbasoir#   )r0   r}   r#   r*   r*   r+   r?        
z_DebugGridCBAsOICell.__init__c                 C   rd   re   rf   r/   r*   r*   r+   r3     rg   z_DebugGridCBAsOICell.min_heightc                 C   rd   rh   rf   r/   r*   r*   r+   r1     rg   z_DebugGridCBAsOICell.min_widthc                 C   sV   t | j||ftd\}}}| j }||}|j|d |d d}|j|_||S )Nrm   r   rZ   )yx)	r,   r#   rq   r}   deepcopyZon_Zshift_r   Zdraw_on_image)r0   r$   r%   ru   rv   r)   r}   r*   r*   r+   r4     s   


z_DebugGridCBAsOICell.drawNrG   r*   r*   r*   r+   r|     s    


r|   c                   @   sD   e Zd ZdZdd Zedd Zedd Zedd	 Zd
d Z	dS )_DebugGridColumnzGA single column within the debug image grid.

    Added in 0.4.0.

    c                 C   rJ   r<   cells)r0   r   r*   r*   r+   r?   0  rL   z_DebugGridColumn.__init__c                 C   s
   t | jS )zXNumber of rows in the column, i.e. examples in batch.

        Added in 0.4.0.

        )rP   r   r/   r*   r*   r+   nb_rows3  s   
z_DebugGridColumn.nb_rowsc                 C      t dd | jD S )zTWidth in pixels of the widest cell in the column.

        Added in 0.4.0.

        c                 S      g | ]}|j qS r*   )r1   rU   cellr*   r*   r+   rW   C      z3_DebugGridColumn.max_cell_width.<locals>.<listcomp>r   r   r/   r*   r*   r+   max_cell_width<     z_DebugGridColumn.max_cell_widthc                 C   r   )zVHeight in pixels of the tallest cell in the column.

        Added in 0.4.0.

        c                 S   r   r*   r3   r   r*   r*   r+   rW   L  r   z4_DebugGridColumn.max_cell_height.<locals>.<listcomp>r   r/   r*   r*   r+   max_cell_heightE  r   z _DebugGridColumn.max_cell_heightc                    s&   | j  t fddt| j|D S )zIConvert this column to an image array.

        Added in 0.4.0.

        c                    s   g | ]\}}|j | d qS ))r$   r%   r4   )rU   r   r$   r%   r*   r+   rW   U  s    z)_DebugGridColumn.draw.<locals>.<listcomp>)r   r   Zvstackzipr   r0   heightsr*   r   r+   r4   N  s   
z_DebugGridColumn.drawN)
r5   r6   r7   r8   r?   rH   r   r   r   r4   r*   r*   r*   r+   r   )  s    


r   c                   @       e Zd ZdZdd Zdd ZdS )
_DebugGridzA debug image grid.

    Columns correspond to the input datatypes (e.g. images, bounding boxes).
    Rows correspond to the examples within a batch.

    Added in 0.4.0.

    c                 C   s   t |dksJ || _d S re   )rP   columns)r0   r   r*   r*   r+   r?   e  s   
z_DebugGrid.__init__c                    s   dd | j D }tt|dksJ tj| j d jftjd | j D ]}dd |jD }t | q"t	 fdd| j D S )zGConvert this grid to an image array.

        Added in 0.4.0.

        c                 S   r   r*   )r   rU   columnr*   r*   r+   rW   o  r   z#_DebugGrid.draw.<locals>.<listcomp>r   r   r[   c                 S   r   r*   r   r   r*   r*   r+   rW   s  r   c                    s   g | ]}|j  d qS ))r   r   r   Zrowwise_heightsr*   r+   rW   u      )
r   rP   setr   Zzerosr   Zint32r   maximumZhstack)r0   Znb_rows_by_colr   r   r*   r   r+   r4   i  s   
z_DebugGrid.drawN)r5   r6   r7   r8   r?   r4   r*   r*   r*   r+   r   Z  s    
r   c           	   	   C   s   t | g}|dur|t||  |dur|t||  |dur*|t|| d |dur7|t|| d |durD|t|| d |durQ|t|| d t|}| }tj	|dddddt
d}|S )	a  Generate a debug image grid of a single batch and various datatypes.

    Added in 0.4.0.

    **Supported dtypes**:

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

    Parameters
    ----------
    images : ndarray or list of ndarray
        Images in the batch. Must always be provided. Batches without images
        cannot be visualized.

    heatmaps : None or list of imgaug.augmentables.heatmaps.HeatmapsOnImage, optional
        Heatmaps on the provided images.

    segmentation_maps : None or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage, optional
        Segmentation maps on the provided images.

    keypoints : None or list of imgaug.augmentables.kps.KeypointsOnImage, optional
        Keypoints on the provided images.

    bounding_boxes : None or list of imgaug.augmentables.bbs.BoundingBoxesOnImage, optional
        Bounding boxes on the provided images.

    polygons : None or list of imgaug.augmentables.polys.PolygonsOnImage, optional
        Polygons on the provided images.

    line_strings : None or list of imgaug.augmentables.lines.LineStringsOnImage, optional
        Line strings on the provided images.

    Returns
    -------
    ndarray
        Visualized batch as RGB image.

    Examples
    --------
    >>> import numpy as np
    >>> import imgaug.augmenters as iaa
    >>> image = np.zeros((64, 64, 3), dtype=np.uint8)
    >>> debug_image = iaa.draw_debug_image(images=[image, image])

    Generate a debug image for two empty images.

    >>> from imgaug.augmentables.kps import KeypointsOnImage
    >>> kpsoi = KeypointsOnImage.from_xy_array([(10.5, 20.5), (30.5, 30.5)],
    >>>                                        shape=image.shape)
    >>> debug_image = iaa.draw_debug_image(images=[image, image],
    >>>                                    keypoints=[kpsoi, kpsoi])

    Generate a debug image for two empty images, each having two keypoints
    drawn on them.

    >>> from imgaug.augmentables.batches import UnnormalizedBatch
    >>> segmap_arr = np.zeros((32, 32, 1), dtype=np.int32)
    >>> kp_tuples = [(10.5, 20.5), (30.5, 30.5)]
    >>> batch = UnnormalizedBatch(images=[image, image],
    >>>                           segmentation_maps=[segmap_arr, segmap_arr],
    >>>                           keypoints=[kp_tuples, kp_tuples])
    >>> batch = batch.to_normalized_batch()
    >>> debug_image = iaa.draw_debug_image(
    >>>     images=batch.images_unaug,
    >>>     segmentation_maps=batch.segmentation_maps_unaug,
    >>>     keypoints=batch.keypoints_unaug)

    Generate a debug image for two empty images, each having an empty
    segmentation map and two keypoints drawn on them. This example uses
    ``UnnormalizedBatch`` to show how to mostly evade going through imgaug
    classes.

    NZ	KeypointszBounding BoxesZPolygonszLine Stringsr   rC   rD   )_create_images_columnextend_create_heatmaps_columns_create_segmap_columnsappend_create_cbasois_columnr   r4   r!   r"   rq   )	imagesheatmapssegmentation_maps	keypointsbounding_boxespolygonsline_stringsr   resultr*   r*   r+   draw_debug_image~  s.   
X

r   c                 C   s   dd | D S )z"Add a border (cell) around a cell.c                 S   s   g | ]}t d t|qS r   )r:   rq   r   r*   r*   r+   rW     r   z _add_borders.<locals>.<listcomp>r*   r   r*   r*   r+   _add_borders  s   r   c                 C   s   t | g| S )z#Add a text cell before other cells.)rI   )titler   r*   r*   r+   _add_text_cell     r   c                 C   s2   dd | D }t | }tttdt||}|S )zCreate columns for image data.c                 S   rS   r*   )r`   )rU   r#   r*   r*   r+   rW     rX   z)_create_images_column.<locals>.<listcomp>ZImages)_generate_images_descriptionr   r   r   )r   r   Zimages_descrr   r*   r*   r+   r     s   
r   c           	            t dd  D }dd t|D }t| D ]\}}| }t|D ]\}}|| t||d q$q fddt|D }|S )z Create columns for heatmap data.c                 S      g | ]}|j jd  qS r   )arr_0to1r   rU   heatmapr*   r*   r+   rW     r   z,_create_heatmaps_columns.<locals>.<listcomp>c                 S      g | ]}g qS r*   r*   rU   rt   r*   r*   r+   rW         rb   c                    6   g | ]\}}t ttd tt ||dkd|qS )ZHeatmapsr   channel_idxshow_details)r   r   r   _generate_heatmaps_descriptionrU   cr   r   r*   r+   rW     s$    r   r   Zaranger   r4   	enumerater   r`   )	r   r   nb_map_channelsr   r#   r   Zheatmap_drawnr   Zheatmap_drawn_cr*   r   r+   r     s   

r   c           	         r   )z)Create columns for segmentation map data.c                 S   r   r   )rz   r   rU   segmapr*   r*   r+   rW   4  r   z*_create_segmap_columns.<locals>.<listcomp>c                 S   r   r*   r*   r   r*   r*   r+   rW   6  r   r   c                    r   )ZSegMapsr   r   )r   r   r   _generate_segmaps_descriptionr   r   r*   r+   rW   ?  s$    r   )	r   r   r   r   r#   r   Zsegmap_drawnr   Zsegmap_drawn_cr*   r   r+   r   2  s   

r   c                 C   s:   dd t | |D }t| |}ttt|t||}|S )z2Create a column for coordinate-based augmentables.c                 S   s   g | ]	\}}t ||qS r*   )r|   )rU   r}   r#   r*   r*   r+   rW   W  s    z*_create_cbasois_column.<locals>.<listcomp>)r   _generate_cbasois_descriptionr   r   r   )cbasoisr   Zcolumn_namer   descrr   r*   r*   r+   r   U  s   
r   c                 C   sT  t | r=dt| jf }d| jjf }t| dkrd}n| jjdv r0dt	| t
| f }nqdt	| t
| f }ndt| }|jrGd}n*|jrVdt| |jd f }nd	t| |j|j|j|j|j|j|d
|d
f	 }|jrwd}n|jrd|jd f }n	dd|jf }|jrd}nd}|jsd}||j|jf }|||g}t|S )z'Generate description for image columns.zarray, shape %11sz	dtype %8sr    rj   rk   ri   zvalue range: %3d to %3dzvalue range: %7.4f to %7.4fz!list of %3d arrays
all shape %11szlist of %3d arrays
varying shapes
smallest image: %11s
largest image: %11s
height: %3d to %3d
width: %3d to %3d
channels: %1s to %1sNonezall dtype %8sz
dtypes: %sz, zvalue range: %6.4f to %6.4f)r   Zis_np_arraystrr   r\   namerP   ro   r   minr   _ListOfArraysStatsemptyall_same_shapeshapessmallest_shapelargest_shape
height_min
height_max	width_min	width_maxget_channels_minget_channels_maxall_same_dtyper
   joinunique_dtype_namesall_dtypes_intlike	value_min	value_max_join_description_strs)r   
shapes_strZ
dtypes_strvalue_range_strstatsstrsr*   r*   r+   r   g  sV   

r   c                    sX   t | dkrdS t|  |} fdd| D }t|}d|j|j|jf }t||g S )z(Generate description for segmap columns.r   
empty listc                    $   g | ]}|j d d d d  f qS r<   )rz   r   r   r*   r+   rW        $ z1_generate_segmaps_description.<locals>.<listcomp>z5value range: %3d to %3d
number of unique classes: %2d)rP   _generate_sm_hm_descriptionr   r   r   nb_unique_valuesr   )Zsegmapsr   r   r   arrs_channelstats_channelr   r*   r   r+   r     s   r   c                    sT   t | dkrdS t|  |} fdd| D }t|}d|j|jf }t||g S )z)Generate description for heatmap columns.r   r   c                    r   r<   )r   r   r   r*   r+   rW     r   z2_generate_heatmaps_description.<locals>.<listcomp>z=value range: %6.4f to %6.4f
    (internal, max is [0.0, 1.0]))rP   r   r   r   r   r   )r   r   r   r   r   r   r   r*   r   r+   r     s   
r   c                 C   s   | du rdS t | dkrdS dd | D }t|}|ddkr,d|d	 |df }nd}|s3d}n*|jrBd
t | |jd f }ndt | |j|j|j|j|j	|j
|d|df	 }|sbd}nt| }|||gS )z0Generate description for SegMap/Heatmap columns.Nr   r   r   c                 S   s   g | ]}|  qS r*   )Zget_arrrU   Zaugmentabler*   r*   r+   rW     rX   z/_generate_sm_hm_description.<locals>.<listcomp>zChannel %1d of %1dr   z-items for %3d images
all arrays of shape %11szitems for %3d images
varying array shapes
smallest: %11s
largest: %11s
height: %3d to %3d
width: %3d to %3d
channels: %1s to %1sr   )rP   r   r   r   r   r   r   r   r   r   r   r   _generate_on_image_shapes_descr)augmentablesr   r   Zarrsr   Zchannel_strr   on_shapes_strr*   r*   r+   r     s<   
r   c                 C   s  dt | f }dd | D }t | dkr|ndg}t|}dt|t||f }dd | D }t | dkr7|ndg}dt|t|f }ttd	d | D }t|}	g }
|		d
D ]\}}|

d|||| d f  q\dt |	 d|
f }g }g }t| |D ]T\}}|jdd \}}|jD ]C}|j}|D ];}|\}}||d  d ||d  d  }|
d|  ko|k n  od|  ko|k n    |
||f|f qqqdd t|dd dD }t|}d||t | d |d d |d d f }t| }t||||||gS )z>Generate description for coordinate-based augmentable columns.zitems for %d imagesc                 S   s   g | ]}t |jqS r*   )rP   items)rU   r}   r*   r*   r+   rW         z1_generate_cbasois_description.<locals>.<listcomp>r   r   zDfewest items on image: %3d
most items on image: %3d
total items: %6dc                 S   ,   g | ]}|j D ]}t|d r|jndqqS )arear   )r   hasattrr   )rU   r}   cbar*   r*   r+   rW     s    z(smallest area: %7.4f
largest area: %7.4fc                 S   r   )labelN)r   r   r   )rU   r}   itemr*   r*   r+   rW     s    
   z
    - %s (%3d, %6.2f%%)d   z(unique labels: %2d
most common labels:%sr   r   c                 S   s   g | ]
\\}}}||fqS r*   r*   )rU   Zx_Zy_rt   r*   r*   r+   rW   *  s    
c                 S      | d S rh   r*   tr*   r*   r+   <lambda>,      z/_generate_cbasois_description.<locals>.<lambda>keyzDcoords out of image: %d (%6.2f%%)
most extreme coord: (%5.1f, %5.1f)r   )rP   sumr   r   listr   flattencollectionsCountermost_commonr   keysr   r   r   r   coordssortedr   r   )r   r   Z
images_strZnb_items_lstZnb_itemsZ	items_strareasZ	areas_strlabelsZ
labels_ctrZlabels_most_commonr   countZ
labels_strZ
coords_ooidistsr}   r#   hwr   r  Zcoordr   r   distZcoords_extremeZnb_ooiZooi_strr   r*   r*   r+   r     sh   



 8	r   c                 C   sN   dd | D }t dd |D }|jrd|jd f }|S d|j|jf }|S )zEGenerate text block for non-image data describing their image shapes.c                 S   r   r*   r   r   r*   r*   r+   rW   @  r   z3_generate_on_image_shapes_descr.<locals>.<listcomp>c                 S      g | ]}t |qS r*   )r   r   )rU   Zon_shaper*   r*   r+   rW   A  s    zall on image shape %11sr   z@on varying image shapes
smallest image: %11s
largest image: %11s)r   r   r   r   r   )r   Z	on_shapesZ
stats_imgsr   r*   r*   r+   r   >  s   
r   c                 C   s   dd | D } d | S )z9Join lines to a single string while removing empty lines.c                 S   s   g | ]
}t |d kr|qS r   rT   )rU   Zstr_ir*   r*   r+   rW   Q  s    z*_join_description_strs.<locals>.<listcomp>rN   )r   )r   r*   r*   r+   r   O  s   
r   c                   @   s0  e Zd ZdZdd Zedd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd Zedd Zedd Ze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ed$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Zd4S )5r   zClass to derive aggregated values from a list of arrays.

    E.g. shape of the largest array, number of unique dtypes etc.

    Added in 0.4.0.

    c                 C   rJ   r<   arrays)r0   r  r*   r*   r+   r?   ^  rL   z_ListOfArraysStats.__init__c                 C   s   t | jdkS re   )rP   r  r/   r*   r*   r+   r   b  r   z_ListOfArraysStats.emptyc                 C      dd | j D S )Nc                 S   s    g | ]}t |jd d qS )r   r   )r   prodr   rU   rz   r*   r*   r+   rW   i       z,_ListOfArraysStats.areas.<locals>.<listcomp>r  r/   r*   r*   r+   r  g     z_ListOfArraysStats.areasc                 C   s(   dd t t| j| jdd dD }|S )Nc                 S   s   g | ]\}}|qS r*   r*   )rU   rz   rt   r*   r*   r+   rW   n  s    z5_ListOfArraysStats.arrays_by_area.<locals>.<listcomp>c                 S   r  rh   r*   r  r*   r*   r+   r  p  r  z3_ListOfArraysStats.arrays_by_area.<locals>.<lambda>r  )r  r   r  r  )r0   arrays_by_arear*   r*   r+   r$  l  s   z!_ListOfArraysStats.arrays_by_areac                 C   r  )Nc                 S   r   r*   r  r!  r*   r*   r+   rW   w  r   z-_ListOfArraysStats.shapes.<locals>.<listcomp>r  r/   r*   r*   r+   r   u  r#  z_ListOfArraysStats.shapesc                 C   s   | j rdS tt| jdkS )NTr   )r   rP   r   r   r/   r*   r*   r+   r   z  s   z!_ListOfArraysStats.all_same_shapec                 C      | j rt S | jd jS re   r   tupler$  r   r/   r*   r*   r+   r        z!_ListOfArraysStats.smallest_shapec                 C   r%  Nr   r&  r/   r*   r*   r+   r     r(  z _ListOfArraysStats.largest_shapec                 C   s$   | j rt S t| jd dd S )Nr   r   r   )r   r'  r   r   r$  r/   r*   r*   r+   area_max  s   z_ListOfArraysStats.area_maxc                 C   r  )Nc                 S      g | ]}|j d  qS r  r  r!  r*   r*   r+   rW     r   z._ListOfArraysStats.heights.<locals>.<listcomp>r  r/   r*   r*   r+   r     r#  z_ListOfArraysStats.heightsc                 C      | j }t|dkrt|S dS re   )r   rP   r   r   r*   r*   r+   r        z_ListOfArraysStats.height_minc                 C   r,  re   )r   rP   r   r   r*   r*   r+   r     r-  z_ListOfArraysStats.height_maxc                 C   r  )Nc                 S   r+  r   r  r!  r*   r*   r+   rW     r   z-_ListOfArraysStats.widths.<locals>.<listcomp>r  r/   r*   r*   r+   widths  r#  z_ListOfArraysStats.widthsc                 C   r,  re   )r.  rP   r   r0   r.  r*   r*   r+   r     r-  z_ListOfArraysStats.width_minc                 C   r,  re   )r.  rP   r   r/  r*   r*   r+   r     r-  z_ListOfArraysStats.width_maxc                 C   s6   | j rdS tdd | jD r|S tdd | jD S )Nr   c                 S   s   g | ]}|j d kqS r   ndimr!  r*   r*   r+   rW     r   z7_ListOfArraysStats.get_channels_min.<locals>.<listcomp>c                 S       g | ]}|j d kr|jd  qS r   r1  r   r!  r*   r*   r+   rW     r"  )r   anyr  r   r0   defaultr*   r*   r+   r     
   z#_ListOfArraysStats.get_channels_minc                 C   s6   | j rdS tdd | jD s|S tdd | jD S )Nr   c                 S   s   g | ]}|j d kqS r   r0  r!  r*   r*   r+   rW     r   z7_ListOfArraysStats.get_channels_max.<locals>.<listcomp>c                 S   r2  r   r3  r!  r*   r*   r+   rW     r"  )r   r4  r  r   r5  r*   r*   r+   r     r7  z#_ListOfArraysStats.get_channels_maxc                 C   r  )Nc                 S   r   r*   r[   r!  r*   r*   r+   rW     r   z-_ListOfArraysStats.dtypes.<locals>.<listcomp>r  r/   r*   r*   r+   r
     r#  z_ListOfArraysStats.dtypesc                 C   r  )Nc                 S   r   r*   )r   )rU   r\   r*   r*   r+   rW     r   z2_ListOfArraysStats.dtype_names.<locals>.<listcomp>r	   r/   r*   r*   r+   dtype_names  r#  z_ListOfArraysStats.dtype_namesc                 C   s   t t| jdv S )N)r   r   )rP   r   r8  r/   r*   r*   r+   r     s   z!_ListOfArraysStats.all_same_dtypec                 C   s   | j rdS tdd | jD S )NTc                 S   s   g | ]}|j jd v qS )r   )r\   ro   r!  r*   r*   r+   rW     s    z9_ListOfArraysStats.all_dtypes_intlike.<locals>.<listcomp>)r   allr  r/   r*   r*   r+   r     s   z%_ListOfArraysStats.all_dtypes_intlikec                 C   s   t tdd | jD S )Nc                 S   s   h | ]}|j jqS r*   )r\   r   r!  r*   r*   r+   	<setcomp>  rX   z8_ListOfArraysStats.unique_dtype_names.<locals>.<setcomp>)r  r  r  r/   r*   r*   r+   r     s   z%_ListOfArraysStats.unique_dtype_namesc                 C   r   )Nc                 S   r  r*   )r   r   r!  r*   r*   r+   rW     r   z0_ListOfArraysStats.value_min.<locals>.<listcomp>)r   r  r/   r*   r*   r+   r        z_ListOfArraysStats.value_minc                 C   r   )Nc                 S   r  r*   )r   r   r!  r*   r*   r+   rW     r   z0_ListOfArraysStats.value_max.<locals>.<listcomp>)r   r  r/   r*   r*   r+   r     r;  z_ListOfArraysStats.value_maxc                 C   s*   t  }| jD ]
}|t| qt|S r<   )r   r  updater   uniquerP   )r0   Z	values_uqrz   r*   r*   r+   r     s   
z#_ListOfArraysStats.nb_unique_valuesN)r5   r6   r7   r8   r?   rH   r   r  r$  r   r   r   r   r*  r   r   r   r.  r   r   r   r   r
   r8  r   r   r   r   r   r   r*   r*   r*   r+   r   U  sb    




















r   c                   @   r   )_IImageDestinationz,A destination which receives images to save.c                 C   r.   )a[  Signal to the destination that a new batch is processed.

        This is intended to be used by the destination e.g. to count batches.

        Added in 0.4.0.

        Parameters
        ----------
        batch : imgaug.augmentables.batches._BatchInAugmentation
            A batch to which the next ``receive()`` call may correspond.

        Nr*   r0   batchr*   r*   r+   on_batch  r2   z_IImageDestination.on_batchc                 C   r.   )zReceive and handle an image.

        Added in 0.4.0.

        Parameters
        ----------
        image : ndarray
            Image to be handled by the destination.

        Nr*   r0   r#   r*   r*   r+   receive  r2   z_IImageDestination.receiveN)r5   r6   r7   r8   rA  rC  r*   r*   r*   r+   r>    s    r>  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_MultiDestinationz;A list of multiple destinations behaving like a single one.c                 C   rJ   r<   )destinations)r0   rE  r*   r*   r+   r?     rL   z_MultiDestination.__init__c                 C      | j D ]}|| qd S r<   )rE  rA  )r0   r@  destinationr*   r*   r+   rA       
z_MultiDestination.on_batchc                 C   rF  r<   )rE  rC  )r0   r#   rG  r*   r*   r+   rC  #  rH  z_MultiDestination.receiveN)r5   r6   r7   r8   r?   rA  rC  r*   r*   r*   r+   rD    s
    rD  c                       s4   e Zd ZdZ	d	 fdd	Zdd Zdd Z  ZS )
_FolderImageDestinationz0A destination which saves images to a directory.batch_{batch_id:06d}.pngc                    s*   t t|   || _|| _d| _d | _d S r)  )superrI  r?   folder_pathfilename_pattern	_batch_id	_filepath)r0   rL  rM  	__class__r*   r+   r?   -  s
   
z _FolderImageDestination.__init__c                 C   s0   |  j d7  _ tj| j| jj| j d| _d S )Nr   )Zbatch_id)rN  ospathr   rL  rM  formatrO  r?  r*   r*   r+   rA  6  s
   
z _FolderImageDestination.on_batchc                 C   s   t | j| d S r<   )imageioZimwriterO  rB  r*   r*   r+   rC  =  s   z_FolderImageDestination.receive)rJ  )r5   r6   r7   r8   r?   rA  rC  __classcell__r*   r*   rP  r+   rI  )  s    	rI  c                   @   s   e Zd ZdZdd ZdS )_IBatchwiseSchedulez<A schedule determining per batch whether a condition is met.c                 C   r.   )a@  Determine for the given batch whether the condition is met.

        Added in 0.4.0.

        Parameters
        ----------
        batch : _BatchInAugmentation
            Batch for which to evaluate the condition.

        Returns
        -------
        bool
            Signal whether the condition is met.

        Nr*   r?  r*   r*   r+   rA  F  r2   z_IBatchwiseSchedule.on_batchN)r5   r6   r7   r8   rA  r*   r*   r*   r+   rW  B  s    rW  c                   @   r   )_EveryNBatchesSchedulezA schedule that generates a signal at every ``N`` th batch.

    This schedule must be called for *every* batch in order to count them.

    Added in 0.4.0.

    c                 C   s   || _ d| _d S r)  )intervalrN  )r0   rY  r*   r*   r+   r?   b  r~   z_EveryNBatchesSchedule.__init__c                 C   s"   |  j d7  _ | j | j dk}|S )Nr   r   )rN  rY  )r0   r@  signalr*   r*   r+   rA  g  s   z_EveryNBatchesSchedule.on_batchN)r5   r6   r7   r8   r?   rA  r*   r*   r*   r+   rX  Y  s    rX  c                       .   e Zd ZdZ		d fdd	Zdd Z  ZS )	_SaveDebugImagea  Augmenter saving debug images to a destination according to a schedule.

    Added in 0.4.0.

    Parameters
    ----------
    destination : _IImageDestination
        The destination receiving debug images.

    schedule : _IBatchwiseSchedule
        The schedule to use to determine for which batches an image is
        supposed to be generated.

    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.

    N
deprecatedc                    s(   t t| j||||d || _|| _d S )N)seedr   random_statedeterministic)rK  r\  r?   rG  schedule)r0   rG  ra  r^  r   r_  r`  rP  r*   r+   r?     s   

z_SaveDebugImage.__init__c              	   C   sP   | j |}| j| |r&t|j|j|j|j|j|j	|j
d}| j| |S )N)r   r   r   r   r   r   r   )ra  rA  rG  r   r   r   r   r   r   r   r   rC  )r0   r@  r_  parentshookssaver#   r*   r*   r+   _augment_batch_  s   	z_SaveDebugImage._augment_batch_NNr]  r]  )r5   r6   r7   r8   r?   re  rV  r*   r*   rP  r+   r\  m  s    "
r\  c                       r[  )	SaveDebugImageEveryNBatchesa%  Visualize data in batches and save corresponding plots to a folder.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.debug.draw_debug_image`.

    Parameters
    ----------
    destination : str or _IImageDestination
        Path to a folder. The saved images will follow a filename pattern
        of ``batch_<batch_id>.png``. The latest image will additionally be
        saved to ``latest.png``.

    interval : int
        Interval in batches. If set to ``N``, every ``N`` th batch an
        image will be generated and saved, starting with the first observed
        batch.
        Note that the augmenter only counts batches that it sees. If it is
        executed conditionally or re-instantiated, it may not see all batches
        or the counter may be wrong in other ways.

    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
    >>> import tempfile
    >>> folder_path = tempfile.mkdtemp()
    >>> seq = iaa.Sequential([
    >>>     iaa.Sequential([
    >>>         iaa.Fliplr(0.5),
    >>>         iaa.Crop(px=(0, 16))
    >>>     ], random_order=True),
    >>>     iaa.SaveDebugImageEveryNBatches(folder_path, 100)
    >>> ])

    Nr]  c                    sd   t |}t|ts"tj|sJ d|f tt|t|ddg}tt	| j
||||||d d S )NzSExpected 'destination' to be a string path to an existing directory. Got path '%s'.zbatch_latest.png)rM  )rG  ra  r^  r   r_  r`  )rX  
isinstancer>  rR  rS  isdirrD  rI  rK  rg  r?   )r0   rG  rY  r^  r   r_  r`  ra  rP  r*   r+   r?     s$   


z$SaveDebugImageEveryNBatches.__init__c                 C   s2   | j j}|d j|d j|d j|d j| jjgS )Nr   r   )rG  rE  rL  rM  ra  rY  )r0   Zdestsr*   r*   r+   get_parameters  s   z*SaveDebugImageEveryNBatches.get_parametersrf  )r5   r6   r7   r8   r?   rj  rV  r*   r*   rP  r+   rg    s    9rg  )NNNNNN)<r8   
__future__r   r   r   abcr   r   r   rR  r  sixnumpyr   rU  Zimgaugr   r   r
   rp   r   r   r!   r   rs   Z_COLOR_PINKrq   r,   Zadd_metaclassobjectr-   r:   rI   r`   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>  rD  rI  rW  rX  Z	Augmenterr\  rg  r*   r*   r*   r+   <module>   sh    	2/! A&1$
v#<0F "?