o
    eޫ                     @   s   d Z ddlmZmZm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	Zg d
Zedg dZdd Zdd 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dS )z@Classes representing batches of normalized or unnormalized data.    )print_functiondivisionabsolute_importN   )imgaug   )normalization)utilsDEFAULTimagesheatmapssegmentation_maps	keypointsbounding_boxespolygonsline_strings_AugmentableColumn)namevalue	attr_namec                 C   s   dd t | |D S )Nc                 S      g | ]}|j qS  )r   ).0columnr   r   KD:\Projects\ConvertPro\env\Lib\site-packages\imgaug/augmentables/batches.py
<listcomp>   s    
z%_get_column_names.<locals>.<listcomp>_get_columns)batchpostfixr   r   r   _get_column_names   s   r!   c                 C   sN   g }t D ] }|| }t| || }|d ur$t|dkr$|t||| q|S )Nr   )_AUGMENTABLE_NAMESgetattrlenappendr   )r   r    resultr   r   r   r   r   r   r      s   r   c                   @   s@   e Zd ZdZ			dddZdd Zdd Zd	d
 Zdd ZdS )UnnormalizedBatcha  
    Class for batches of unnormalized data before and after augmentation.

    Parameters
    ----------
    images : None or (N,H,W,C) ndarray or (N,H,W) ndarray or iterable of (H,W,C) ndarray or iterable of (H,W) ndarray
        The images to augment.

    heatmaps : None or (N,H,W,C) ndarray or imgaug.augmentables.heatmaps.HeatmapsOnImage or iterable of (H,W,C) ndarray or iterable of imgaug.augmentables.heatmaps.HeatmapsOnImage
        The heatmaps to augment.
        If anything else than ``HeatmapsOnImage``, then the number of heatmaps
        must match the number of images provided via parameter `images`.
        The number is contained either in ``N`` or the first iterable's size.

    segmentation_maps : None or (N,H,W) ndarray or imgaug.augmentables.segmaps.SegmentationMapsOnImage or iterable of (H,W) ndarray or iterable of imgaug.augmentables.segmaps.SegmentationMapsOnImage
        The segmentation maps to augment.
        If anything else than ``SegmentationMapsOnImage``, then the number of
        segmaps must match the number of images provided via parameter
        `images`. The number is contained either in ``N`` or the first
        iterable's size.

    keypoints : None or list of (N,K,2) ndarray or tuple of number or imgaug.augmentables.kps.Keypoint or iterable of (K,2) ndarray or iterable of tuple of number or iterable of imgaug.augmentables.kps.Keypoint or iterable of imgaug.augmentables.kps.KeypointOnImage or iterable of iterable of tuple of number or iterable of iterable of imgaug.augmentables.kps.Keypoint
        The keypoints to augment.
        If a tuple (or iterable(s) of tuple), then iterpreted as (x,y)
        coordinates and must hence contain two numbers.
        A single tuple represents a single coordinate on one image, an
        iterable of tuples the coordinates on one image and an iterable of
        iterable of tuples the coordinates on several images. Analogous if
        ``Keypoint`` objects are used instead of tuples.
        If an ndarray, then ``N`` denotes the number of images and ``K`` the
        number of keypoints on each image.
        If anything else than ``KeypointsOnImage`` is provided, then the
        number of keypoint groups must match the number of images provided
        via parameter `images`. The number is contained e.g. in ``N`` or
        in case of "iterable of iterable of tuples" in the first iterable's
        size.

    bounding_boxes : None or (N,B,4) ndarray or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage or iterable of (B,4) ndarray or iterable of tuple of number or iterable of imgaug.augmentables.bbs.BoundingBox or iterable of imgaug.augmentables.bbs.BoundingBoxesOnImage or iterable of iterable of tuple of number or iterable of iterable imgaug.augmentables.bbs.BoundingBox
        The bounding boxes to augment.
        This is analogous to the `keypoints` parameter. However, each
        tuple -- and also the last index in case of arrays -- has size 4,
        denoting the bounding box coordinates ``x1``, ``y1``, ``x2`` and ``y2``.

    polygons : None  or (N,#polys,#points,2) ndarray or imgaug.augmentables.polys.Polygon or imgaug.augmentables.polys.PolygonsOnImage or iterable of (#polys,#points,2) ndarray or iterable of tuple of number or iterable of imgaug.augmentables.kps.Keypoint or iterable of imgaug.augmentables.polys.Polygon or iterable of imgaug.augmentables.polys.PolygonsOnImage or iterable of iterable of (#points,2) ndarray or iterable of iterable of tuple of number or iterable of iterable of imgaug.augmentables.kps.Keypoint or iterable of iterable of imgaug.augmentables.polys.Polygon or iterable of iterable of iterable of tuple of number or iterable of iterable of iterable of tuple of imgaug.augmentables.kps.Keypoint
        The polygons to augment.
        This is similar to the `keypoints` parameter. However, each polygon
        may be made up of several ``(x,y)`` coordinates (three or more are
        required for valid polygons).
        The following datatypes will be interpreted as a single polygon on a
        single image:

          * ``imgaug.augmentables.polys.Polygon``
          * ``iterable of tuple of number``
          * ``iterable of imgaug.augmentables.kps.Keypoint``

        The following datatypes will be interpreted as multiple polygons on a
        single image:

          * ``imgaug.augmentables.polys.PolygonsOnImage``
          * ``iterable of imgaug.augmentables.polys.Polygon``
          * ``iterable of iterable of tuple of number``
          * ``iterable of iterable of imgaug.augmentables.kps.Keypoint``
          * ``iterable of iterable of imgaug.augmentables.polys.Polygon``

        The following datatypes will be interpreted as multiple polygons on
        multiple images:

          * ``(N,#polys,#points,2) ndarray``
          * ``iterable of (#polys,#points,2) ndarray``
          * ``iterable of iterable of (#points,2) ndarray``
          * ``iterable of iterable of iterable of tuple of number``
          * ``iterable of iterable of iterable of tuple of imgaug.augmentables.kps.Keypoint``

    line_strings : None or (N,#lines,#points,2) ndarray or imgaug.augmentables.lines.LineString or imgaug.augmentables.lines.LineStringOnImage or iterable of (#lines,#points,2) ndarray or iterable of tuple of number or iterable of imgaug.augmentables.kps.Keypoint or iterable of imgaug.augmentables.lines.LineString or iterable of imgaug.augmentables.lines.LineStringOnImage or iterable of iterable of (#points,2) ndarray or iterable of iterable of tuple of number or iterable of iterable of imgaug.augmentables.kps.Keypoint or iterable of iterable of imgaug.augmentables.polys.LineString or iterable of iterable of iterable of tuple of number or iterable of iterable of iterable of tuple of imgaug.augmentables.kps.Keypoint
        The line strings to augment.
        See `polygons` for more details as polygons follow a similar
        structure to line strings.

    data
        Additional data that is saved in the batch and may be read out
        after augmentation. This could e.g. contain filepaths to each image
        in `images`. As this object is usually used for background
        augmentation with multiple processes, the augmented Batch objects might
        not be returned in the original order, making this information useful.

    Nc	           	      C   ^   || _ d| _|| _d| _|| _d| _|| _d| _|| _d| _	|| _
d| _|| _d| _|| _dS )z4Construct a new :class:`UnnormalizedBatch` instance.Nimages_unaug
images_augheatmaps_unaugheatmaps_augsegmentation_maps_unaugsegmentation_maps_augkeypoints_unaugkeypoints_augbounding_boxes_unaugbounding_boxes_augpolygons_unaugpolygons_augline_strings_unaugline_strings_augdata	selfr   r   r   r   r   r   r   r8   r   r   r   __init__      
zUnnormalizedBatch.__init__c                 C   
   t | dS   Get the names of types of augmentables that contain data.

        This method is intended for situations where one wants to know which
        data is contained in the batch that has to be augmented, visualized
        or something similar.

        Added in 0.4.0.

        Returns
        -------
        list of str
            Names of types of augmentables. E.g. ``["images", "polygons"]``.

        Z_unaugr!   r:   r   r   r   get_column_names      
z"UnnormalizedBatch.get_column_namesc                 C   s   t dd | j D }|sJ dt| j}d}|dur%dd |D }t|t| j|t	| j
|t| j|t| j|t| j|t| j|| jdS )a  Convert this unnormalized batch to an instance of Batch.

        As this method is intended to be called before augmentation, it
        assumes that none of the ``*_aug`` attributes is yet set.
        It will produce an AssertionError otherwise.

        The newly created Batch's ``*_unaug`` attributes will match the ones
        in this batch, just in normalized form.

        Returns
        -------
        imgaug.augmentables.batches.Batch
            The batch, with ``*_unaug`` attributes being normalized.

        c                 S   s"   g | ]\}}| d r|du qS )Z_augN)endswith)r   r   attrr   r   r   r      s    z9UnnormalizedBatch.to_normalized_batch.<locals>.<listcomp>zExpected UnnormalizedBatch to not contain any augmented data before normalization, but at least one '*_aug' attribute was already set.Nc                 S   r   r   shaper   imager   r   r   r          r   r   r   r   r   r   r   r8   )all__dict__itemsnlibZnormalize_imagesr*   BatchZnormalize_heatmapsr,   Znormalize_segmentation_mapsr.   Znormalize_keypointsr0   Znormalize_bounding_boxesr2   Znormalize_polygonsr4   Znormalize_line_stringsr6   r8   )r:   Zcontains_no_augmented_data_yetr*   shapesr   r   r   to_normalized_batch   s@   z%UnnormalizedBatch.to_normalized_batchc                 C   s   t |j| j| _t |j| j| _t |j| j	| _t 
|j| j| _t |j| j| _t |j| j| _t |j| j| _| S )aF  
        Fill this batch with (normalized) augmentation results in-place.

        This method receives a (normalized) Batch instance, takes all
        ``*_aug`` attributes out if it and assigns them to this
        batch *in unnormalized form*. Hence, the datatypes of all ``*_aug``
        attributes will match the datatypes of the ``*_unaug`` attributes.

        Added in 0.4.0.

        Parameters
        ----------
        batch_aug_norm: imgaug.augmentables.batches.Batch
            Batch after normalization and augmentation.

        Returns
        -------
        imgaug.augmentables.batches.UnnormalizedBatch
            This instance itself.
            All ``*_unaug`` attributes are unchanged.
            All ``*_aug`` attributes are taken from `batch_normalized`,
            converted to unnormalized form.

        )rO   invert_normalize_imagesr+   r*   invert_normalize_heatmapsr-   r,   "invert_normalize_segmentation_mapsr/   r.   invert_normalize_keypointsr1   r0   invert_normalize_bounding_boxesr3   r2   invert_normalize_polygonsr5   r4   invert_normalize_line_stringsr7   r6   )r:   batch_aug_normr   r   r   %fill_from_augmented_normalized_batch_   s,   z7UnnormalizedBatch.fill_from_augmented_normalized_batch_c              
   C   s   t | j| j| j| j| j| j| j|jd}t	
|j| j|_t	|j| j|_t	|j| j|_t	|j| j|_t	|j| j|_t	|j| j|_t	|j| j|_|S )ag  
        Fill this batch with (normalized) augmentation results.

        This method receives a (normalized) Batch instance, takes all
        ``*_aug`` attributes out if it and assigns them to this
        batch *in unnormalized form*. Hence, the datatypes of all ``*_aug``
        attributes will match the datatypes of the ``*_unaug`` attributes.

        Parameters
        ----------
        batch_aug_norm: imgaug.augmentables.batches.Batch
            Batch after normalization and augmentation.

        Returns
        -------
        imgaug.augmentables.batches.UnnormalizedBatch
            New UnnormalizedBatch instance. All ``*_unaug`` attributes are
            taken from the old UnnormalizedBatch (without deepcopying them)
            and all ``*_aug`` attributes are taken from `batch_normalized`,
            converted to unnormalized form.

        rK   )r'   r*   r,   r.   r0   r2   r4   r6   r8   rO   rS   r+   rT   r-   rU   r/   rV   r1   rW   r3   rX   r5   rY   r7   )r:   rZ   r   r   r   r   $fill_from_augmented_normalized_batch  s@   z6UnnormalizedBatch.fill_from_augmented_normalized_batchNNNNNNNN)	__name__
__module____qualname____doc__r;   rB   rR   r[   r\   r   r   r   r   r'   -   s    W
0)r'   c                   @   s   e Zd ZdZ			dddZeeddd Zeedd	d
 Z	eeddd Z
eeddd Zeeddd Zdd Zdd Zdd Zdd ZeeeeeeeeeeeeeefddZdS )rP   a  
    Class encapsulating a batch before and after augmentation.

    Parameters
    ----------
    images : None or (N,H,W,C) ndarray or list of (H,W,C) ndarray
        The images to augment.

    heatmaps : None or list of imgaug.augmentables.heatmaps.HeatmapsOnImage
        The heatmaps to augment.

    segmentation_maps : None or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage
        The segmentation maps to augment.

    keypoints : None or list of imgaug.augmentables.kps.KeypointOnImage
        The keypoints to augment.

    bounding_boxes : None or list of imgaug.augmentables.bbs.BoundingBoxesOnImage
        The bounding boxes to augment.

    polygons : None or list of imgaug.augmentables.polys.PolygonsOnImage
        The polygons to augment.

    line_strings : None or list of imgaug.augmentables.lines.LineStringsOnImage
        The line strings to augment.

    data
        Additional data that is saved in the batch and may be read out
        after augmentation. This could e.g. contain filepaths to each image
        in `images`. As this object is usually used for background
        augmentation with multiple processes, the augmented Batch objects might
        not be returned in the original order, making this information useful.

    Nc	           	      C   r(   )z(Construct a new :class:`Batch` instance.Nr)   r9   r   r   r   r;   ^  r<   zBatch.__init__zBatch.images_unaugc                 C      | j S )zGet unaugmented images.)r*   rA   r   r   r   r   r     zBatch.imageszBatch.heatmaps_unaugc                 C   rb   )zGet unaugmented heatmaps.)r,   rA   r   r   r   r   x  rc   zBatch.heatmapszBatch.segmentation_maps_unaugc                 C   rb   )z"Get unaugmented segmentation maps.)r.   rA   r   r   r   r   ~  rc   zBatch.segmentation_mapszBatch.keypoints_unaugc                 C   rb   )zGet unaugmented keypoints.)r0   rA   r   r   r   r     rc   zBatch.keypointszBatch.bounding_boxes_unaugc                 C   rb   )zGet unaugmented bounding boxes.)r2   rA   r   r   r   r     rc   zBatch.bounding_boxesc                 C   r=   r>   r@   rA   r   r   r   rB     rC   zBatch.get_column_namesc                 C      | S )a6  Return this batch.

        This method does nothing and only exists to simplify interfaces
        that accept both :class:`UnnormalizedBatch` and :class:`Batch`.

        Added in 0.4.0.

        Returns
        -------
        imgaug.augmentables.batches.Batch
            This batch (not copied).

        r   rA   r   r   r   rR        zBatch.to_normalized_batchc              	   C   sH   dd }t || j|| j|| j|| j|| j|| j|| jdS )zConvert this batch to a :class:`_BatchInAugmentation` instance.

        Added in 0.4.0.

        Returns
        -------
        imgaug.augmentables.batches._BatchInAugmentation
            The converted batch.

        c                 S   s   | d ur	t | S | S N)r	   copy_augmentables)varr   r   r   _copy  s   
z-Batch.to_batch_in_augmentation.<locals>._copyr   )_BatchInAugmentationr*   r,   r.   r0   r2   r4   r6   )r:   ri   r   r   r   to_batch_in_augmentation  s   zBatch.to_batch_in_augmentationc                 C   s<   |j | _|j| _|j| _|j| _|j| _	|j
| _|j| _| S )a  Set the columns in this batch to the column values of another batch.

        This method works in-place.

        Added in 0.4.0.

        Parameters
        ----------
        batch_in_augmentation : _BatchInAugmentation
            Batch of which to use the column values.
            The values are *not* copied. Only their references are used.

        Returns
        -------
        Batch
            The updated batch. (Modified in-place.)

        )r   r+   r   r-   r   r/   r   r1   r   r3   r   r5   r   r7   r:   Zbatch_in_augmentationr   r   r    fill_from_batch_in_augmentation_  s   z&Batch.fill_from_batch_in_augmentation_c                 C   s   dd }t || j||| j||| j||| j||| j|	|| j||| j|t	| j
d}|| j||_|| j||_|| j||_|| j||_|| j|
|_|| j||_|| j||_|S )a  Copy this batch and all of its column values.

        Parameters
        ----------
        images_unaug : imgaug.augmentables.batches.DEFAULT or None or (N,H,W,C) ndarray or list of (H,W,C) ndarray
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        images_aug : imgaug.augmentables.batches.DEFAULT or None or (N,H,W,C) ndarray or list of (H,W,C) ndarray
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        heatmaps_unaug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.heatmaps.HeatmapsOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        heatmaps_aug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.heatmaps.HeatmapsOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        segmentation_maps_unaug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        segmentation_maps_aug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        keypoints_unaug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.kps.KeypointOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        keypoints_aug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.kps.KeypointOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        bounding_boxes_unaug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.bbs.BoundingBoxesOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        bounding_boxes_aug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.bbs.BoundingBoxesOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        polygons_unaug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.polys.PolygonsOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        polygons_aug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.polys.PolygonsOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        line_strings_unaug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.lines.LineStringsOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        line_strings_aug : imgaug.augmentables.batches.DEFAULT or None or list of imgaug.augmentables.lines.LineStringsOnImage
            Copies the current attribute value without changes if set to
            ``imgaug.augmentables.batches.DEFAULT``.
            Otherwise same as in :func:`Batch.__init__`.

        Returns
        -------
        Batch
            Deep copy of the batch, optionally with new attributes.

        c                 S   s   t |tur	|S | S rf   )r	   deepcopy_fastr
   )Z	self_attrargr   r   r   _copy_optionalG  s   z&Batch.deepcopy.<locals>._copy_optionalrK   )rP   r*   r,   r.   r0   r2   r4   r6   r	   rn   r8   r+   r-   r/   r1   r3   r5   r7   )r:   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   rp   r   r   r   r   deepcopy  s>   _




zBatch.deepcopyr]   )r^   r_   r`   ra   r;   propertyia
deprecatedr   r   r   r   r   rB   rR   rk   rm   r
   rq   r   r   r   r   rP   :  sP    #
rP   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )&_BatchInAugmentationPropagationContextc                 C   s"   || _ || _|| _|| _d | _d S rf   )r   	augmenterhooksparents
noned_info)r:   r   rv   rw   rx   r   r   r   r;   g  s
   
z/_BatchInAugmentationPropagationContext.__init__c                 C   s(   | j d ur| j| j| j | j| _| jS rf   )rw   r   apply_propagation_hooks_rv   rx   ry   rA   r   r   r   	__enter__n  s
   
z0_BatchInAugmentationPropagationContext.__enter__c                 C   s"   | j d ur| j| j | _d S d S rf   )ry   r   invert_apply_propagation_hooks_)r:   exc_typeexc_valexc_tbr   r   r   __exit__t  s   
z/_BatchInAugmentationPropagationContext.__exit__N)r^   r_   r`   r;   r{   r   r   r   r   r   ru   f  s    ru   c                   @   s   e Zd ZdZ			d!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dd Zdd Zdd Zdd Zdd  ZdS )"rj   aC  
    Class encapsulating a batch during the augmentation process.

    Data within the batch is already verified and normalized, similar to
    :class:`Batch`. Data within the batch may be changed in-place. No initial
    copy is needed.

    Added in 0.4.0.

    Parameters
    ----------
    images : None or (N,H,W,C) ndarray or list of (H,W,C) ndarray
        The images to augment.

    heatmaps : None or list of imgaug.augmentables.heatmaps.HeatmapsOnImage
        The heatmaps to augment.

    segmentation_maps : None or list of imgaug.augmentables.segmaps.SegmentationMapsOnImage
        The segmentation maps to augment.

    keypoints : None or list of imgaug.augmentables.kps.KeypointOnImage
        The keypoints to augment.

    bounding_boxes : None or list of imgaug.augmentables.bbs.BoundingBoxesOnImage
        The bounding boxes to augment.

    polygons : None or list of imgaug.augmentables.polys.PolygonsOnImage
        The polygons to augment.

    line_strings : None or list of imgaug.augmentables.lines.LineStringsOnImage
        The line strings to augment.

    Nc	           	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _dS )z4Create a new :class:`_BatchInAugmentation` instance.NrK   r9   r   r   r   r;     s   
z_BatchInAugmentation.__init__c                 C   s
   | j dkS )zEstimate whether this batch is empty, i.e. contains no data.

        Added in 0.4.0.

        Returns
        -------
        bool
            ``True`` if the batch contains no data to augment.
            ``False`` otherwise.

        r   )nb_rowsrA   r   r   r   empty  s   
z_BatchInAugmentation.emptyc                 C   s,   t D ]}t| |}|durt|  S qdS )a)  Get the number of rows (i.e. examples) in this batch.

        Note that this method assumes that all columns have the same number
        of rows.

        Added in 0.4.0.

        Returns
        -------
        int
            Number of rows or ``0`` if there is no data in the batch.

        Nr   )r"   r#   r$   )r:   	augm_namer   r   r   r   r     s   
z_BatchInAugmentation.nb_rowsc                 C   r=   )a*  Get the columns of data to augment.

        Each column represents one datatype and its corresponding data,
        e.g. images or polygons.

        Added in 0.4.0.

        Returns
        -------
        list of _AugmentableColumn
            The columns to augment within this batch.

         r   rA   r   r   r   columns  rC   z_BatchInAugmentation.columnsc                 C   r=   )r?   r   r@   rA   r   r   r   rB     rC   z%_BatchInAugmentation.get_column_namesc                 C   s   | j }| j}dg| }tj|ftd}|D ]9}|jdkr.t|jr.|jj	dd g| }nt
|jD ]\}}|durD|j	||< d||< q3t|rN|  S q|S )a  Get the shape of each row within this batch.

        Each row denotes the data of different types (e.g. image array,
        polygons) corresponding to a single example in the batch.

        This method assumes that all ``.shape`` attributes contain the same
        shape and that it is identical to the image's shape.
        It also assumes that there are no columns containing only ``None`` s.

        Added in 0.4.0.

        Returns
        -------
        list of tuple of int
            The shapes of each row.

        N)dtyper   r   T)r   r   npZzerosboolr   rs   is_np_arrayr   rG   	enumeraterL   )r:   r   r   rQ   foundr   iitemr   r   r   get_rowwise_shapes  s    


z'_BatchInAugmentation.get_rowwise_shapesc                    sz   d| j i}tD ].}t| |  dur1|dkr t r  |  n	 fdd|D  t dkr1d  ||< qtdi |S )aH  Reduce this batch to a subset of rows based on their row indices.

        Added in 0.4.0.

        Parameters
        ----------
        indices : iterable of int
            Row indices to select.

        Returns
        -------
        _BatchInAugmentation
            Batch containing only a subselection of rows.

        r8   Nr   c                    s   g | ]} | qS r   r   )r   indexrowsr   r   r   *      zB_BatchInAugmentation.subselect_rows_by_indices.<locals>.<listcomp>r   r   )r8   r"   r#   rs   r   r$   rj   )r:   indiceskwargsr   r   r   r   subselect_rows_by_indices  s   



z._BatchInAugmentation.subselect_rows_by_indicesc           
      C   s(  t D ]}t| |}|durt||}|du rq|dkrt|rt|r<|jdd |jdd h}|jj|jjh}nt|jdd gdd |D  }t|jjgdd |D  }t|dkrlt|dkrl|||< qt	|| _
t|D ]\}}	|| | j
|	< quqt|D ]
\}}	|| ||	< qq| S )a?  Reverse the subselection of rows in-place.

        This is the inverse of
        :func:`_BatchInAugmentation.subselect_rows_by_indices`.

        This method has to be executed on the batch *before* subselection.

        Added in 0.4.0.

        Parameters
        ----------
        indices : iterable of int
            Row indices that were selected. (This is the input to

        batch_subselected : _BatchInAugmentation
            The batch after
            :func:`_BatchInAugmentation.subselect_rows_by_indices` was called.

        Returns
        -------
        _BatchInAugmentation
            The updated batch. (Modified in-place.)

        Examples
        --------
        >>> import numpy as np
        >>> from imgaug.augmentables.batches import _BatchInAugmentation
        >>> images = np.zeros((2, 10, 20, 3), dtype=np.uint8)
        >>> batch = _BatchInAugmentation(images=images)
        >>> batch_sub = batch.subselect_rows_by_indices([0])
        >>> batch_sub.images += 1
        >>> batch = batch.invert_subselect_rows_by_indices_([0], batch_sub)

        Nr   r   c                 S   r   r   rF   rH   r   r   r   r   i  rJ   zJ_BatchInAugmentation.invert_subselect_rows_by_indices_.<locals>.<listcomp>c                 S   s   g | ]}|j jqS r   )r   r   rH   r   r   r   r   l  r   )r"   r#   rs   r   rG   r   r   setr$   listr   r   )
r:   r   Zbatch_subselectedr   r   Z
column_subrQ   ZdtypesZ	ith_indexr   r   r   r   !invert_subselect_rows_by_indices_2  s<   #




z6_BatchInAugmentation.invert_subselect_rows_by_indices_c                 C   s   t | |||dS )a  Start a context in which propagation hooks are applied.

        Added in 0.4.0.

        Parameters
        ----------
        augmenter : imgaug.augmenters.meta.Augmenter
            Augmenter to provide to the propagation hook function.

        hooks : imgaug.imgaug.HooksImages or imgaug.imgaug.HooksKeypoints
            The hooks that might contain a propagation hook function.

        parents : list of imgaug.augmenters.meta.Augmenter
            The list of parents to provide to the propagation hook function.

        Returns
        -------
        _BatchInAugmentationPropagationContext
            The progagation hook context.

        )rv   rw   rx   )ru   )r:   rv   rw   rx   r   r   r   propagation_hooks_ctxz  s   z*_BatchInAugmentation.propagation_hooks_ctxc                 C   sX   |du rdS g }| j D ]}|j|j||dd}|s)t| |jd ||j|jf q|S )a  Set columns in this batch to ``None`` based on a propagation hook.

        This method works in-place.

        Added in 0.4.0.

        Parameters
        ----------
        augmenter : imgaug.augmenters.meta.Augmenter
            Augmenter to provide to the propagation hook function.

        hooks : imgaug.imgaug.HooksImages or imgaug.imgaug.HooksKeypoints
            The hooks that might contain a propagation hook function.

        parents : list of imgaug.augmenters.meta.Augmenter
            The list of parents to provide to the propagation hook function.

        Returns
        -------
        list of tuple of str
            Information about which columns were set to ``None``.
            Each tuple contains
            ``(column attribute name, column value before setting it to None)``.
            This information is required when calling
            :func:`_BatchInAugmentation.invert_apply_propagation_hooks_`.

        NT)rv   rx   default)r   Zis_propagatingr   setattrr   r%   )r:   rv   rw   rx   ry   r   Zis_propr   r   r   rz     s   
z-_BatchInAugmentation.apply_propagation_hooks_c                 C   s   |D ]
\}}t | || q| S )ac  Set columns from ``None`` back to their original values.

        This is the inverse of
        :func:`_BatchInAugmentation.apply_propagation_hooks_`.

        This method works in-place.

        Added in 0.4.0.

        Parameters
        ----------
        noned_info : list of tuple of str
            Information about which columns were set to ``None`` and their
            original values. This is the output of
            :func:`_BatchInAugmentation.apply_propagation_hooks_`.

        Returns
        -------
        _BatchInAugmentation
            The updated batch. (Modified in-place.)

        )r   )r:   ry   r   r   r   r   r   r|     s   z4_BatchInAugmentation.invert_apply_propagation_hooks_c                 C   rd   )a^  Convert this batch to a :class:`_BatchInAugmentation` instance.

        This method simply returns the batch itself. It exists for consistency
        with the other batch classes.

        Added in 0.4.0.

        Returns
        -------
        imgaug.augmentables.batches._BatchInAugmentation
            The batch itself. (Not copied.)

        r   rA   r   r   r   rk     re   z-_BatchInAugmentation.to_batch_in_augmentationc                 C   sH   || u r| S |j | _ |j| _|j| _|j| _|j| _|j| _|j| _| S )a  Set the columns in this batch to the column values of another batch.

        This method works in-place.

        Added in 0.4.0.

        Parameters
        ----------
        batch_in_augmentation : _BatchInAugmentation
            Batch of which to use the column values.
            The values are *not* copied. Only their references are used.

        Returns
        -------
        _BatchInAugmentation
            The updated batch. (Modified in-place.)

        r   rl   r   r   r   rm     s   z5_BatchInAugmentation.fill_from_batch_in_augmentation_c              
   C   sd   t |j|j|j|j|j|j|j|jd}| j	|_
| j|_| j|_| j|_| j|_| j|_| j|_|S )a[  Convert this batch into a :class:`Batch` instance.

        Added in 0.4.0.

        Parameters
        ----------
        batch_before_aug : imgaug.augmentables.batches.Batch
            The batch before augmentation. It is required to set the input
            data of the :class:`Batch` instance, e.g. ``images_unaug``
            or ``data``.

        Returns
        -------
        imgaug.augmentables.batches.Batch
            Batch, with original unaugmented inputs from `batch_before_aug`
            and augmented outputs from this :class:`_BatchInAugmentation`
            instance.

        rK   )rP   r*   r,   r.   r0   r2   r4   r6   r8   r   r+   r   r-   r   r/   r   r1   r   r3   r   r5   r   r7   )r:   Zbatch_before_augr   r   r   r   to_batch  s$   
z_BatchInAugmentation.to_batchc                 C   sD   t t| jd}tD ]}t| |}|durt||t| q|S )zCopy this batch and all of its column values.

        Added in 0.4.0.

        Returns
        -------
        _BatchInAugmentation
            Deep copy of this batch.

        )r8   N)rj   r	   rn   r8   r"   r#   r   rg   )r:   r   r   r   r   r   r   rq   .  s   
z_BatchInAugmentation.deepcopyr]   )r^   r_   r`   ra   r;   rr   r   r   r   rB   r   r   r   r   rz   r|   rk   rm   r   rq   r   r   r   r   rj   z  s.    #



"H) 'rj   )ra   
__future__r   r   r   collectionsnumpyr   r   r   rs   r   rO   r	   r
   r"   
namedtupler   r!   r   objectr'   rP   ru   rj   r   r   r   r   <module>   s.        .