U
    h                     @  s   d dl mZ d dlmZmZmZ d dlZd dlm	Z	m
Z
mZ d dlmZmZmZ d dlmZ d dlmZmZ d dlmZmZ G d	d
 d
eZdS )    )annotations)AnyLiteralcastN)cutoutfilter_bboxes_by_holesfilter_keypoints_in_holes)BboxProcessordenormalize_bboxesnormalize_bboxes)KeypointsProcessor)BaseTransformInitSchemaDualTransform)	ColorTypeTargetsc                      s   e Zd ZdZejejejejfZ	G dd de
Zd"ddddd	 fd
dZdddddddZdddddddZdddddddZdddddddZddddddZddd d!Z  ZS )#BaseDropouta  Base class for dropout-style transformations.

    This class provides common functionality for various dropout techniques,
    including applying cutouts to images and masks.

    Args:
        fill_value (Union[int, float, list[int], list[float], str]): Value to fill dropped regions.
            If "random", fills with random values.
        mask_fill_value (Optional[Union[int, float, list[int], list[float]]]): Value to fill
            dropped regions in the mask. If None, the mask is not modified.
        p (float): Probability of applying the transform.

    Targets:
        image, mask, bboxes, keypoints

    Image types:
        uint8, float32
    c                   @  s   e Zd ZU ded< ded< dS )zBaseDropout.InitSchemaColorType | Literal['random']
fill_valueColorType | Nonemask_fill_valueN)__name__
__module____qualname____annotations__ r   r   S/tmp/pip-unpacked-wheel-e8onvpoz/albumentations/augmentations/dropout/transforms.py
InitSchema$   s   
r   Nr   r   floatzbool | None)r   r   palways_applyc                   s    t  j||d || _|| _d S )N)r   r   )super__init__r   r   )selfr   r   r   r   	__class__r   r   r!   (   s    zBaseDropout.__init__z
np.ndarrayr   )imgholesparamsreturnc                 K  s   t ||| jS N)r   r   )r"   r%   r&   r'   r   r   r   apply3   s    zBaseDropout.apply)maskr&   r'   r(   c                 K  s   | j d kr|S t||| j S r)   )r   r   )r"   r+   r&   r'   r   r   r   apply_to_mask6   s    
zBaseDropout.apply_to_mask)bboxesr&   r'   r(   c                 K  sV   t t| d}|d kr|S |d d d }t||}tt||||jj|jjd|S )Nr-   shape   )min_areamin_visibility)	r   r	   get_processorr
   r   r   r'   r0   r1   )r"   r-   r&   r'   	processorZimage_shapeZdenormalized_bboxesr   r   r   apply_to_bboxes;   s    
zBaseDropout.apply_to_bboxes)	keypointsr&   r'   r(   c                 K  s.   t t| d}|d ks |jjs$|S t||S )Nr5   )r   r   r2   r'   Zremove_invisibler   )r"   r5   r&   r'   r3   r   r   r   apply_to_keypointsT   s    zBaseDropout.apply_to_keypointszdict[str, Any])r'   datar(   c                 C  s   t ddS )a&  Get parameters of the transform conditioned on the input image.

        Args:
            params (dict): Parameters given to the transform.
            data (dict): Additional data given to the transform.

        Returns:
            dict: Parameters required to apply the transform.
        z&Subclasses must implement this method.N)NotImplementedError)r"   r'   r7   r   r   r   get_params_dependent_on_dataa   s    
z(BaseDropout.get_params_dependent_on_dataztuple[str, ...])r(   c                 C  s   dS )zvGet the names of the arguments used in __init__.

        Returns:
            tuple: Names of the arguments.
        )r   r   r   )r"   r   r   r   get_transform_init_args_namesm   s    z)BaseDropout.get_transform_init_args_names)N)r   r   r   __doc__r   ZIMAGEMASKZBBOXESZ	KEYPOINTSZ_targetsr   r   r!   r*   r,   r4   r6   r9   r:   __classcell__r   r   r#   r   r      s   	 r   )
__future__r   typingr   r   r   ZnumpynpZ/albumentations.augmentations.dropout.functionalr   r   r   Zalbumentations.core.bbox_utilsr	   r
   r   Z#albumentations.core.keypoints_utilsr   Z(albumentations.core.transforms_interfacer   r   Zalbumentations.core.typesr   r   r   r   r   r   r   <module>   s   