o
    oi                     @  s`   d dl mZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ G dd de	Zd	S )
    )annotations)AnyOptional)random_generator)IntensityAugmentationBase2D)Tensor)equalize_clahec                      s>   e Zd ZdZ						dd  fddZ	d!d"ddZ  ZS )#RandomClahea  Apply CLAHE equalization on the input tensor randomly.

    .. image:: _static/img/equalize_clahe.png

    Args:
        clip_limit: threshold value for contrast limiting. If 0 clipping is disabled.
        grid_size: number of tiles to be cropped in each direction (GH, GW).
        slow_and_differentiable: flag to select implementation
        same_on_batch: apply the same transformation across the batch.
        p: probability of applying the transformation.
        keepdim: whether to keep the output shape the same as input (True) or broadcast it
                 to the batch form (False).
    .. note::
        This function internally uses :func:`kornia.enhance.equalize_clahe`.

    Examples:
        >>> img = torch.rand(1, 10, 20)
        >>> aug = RandomClahe()
        >>> res = aug(img)
        >>> res.shape
        torch.Size([1, 1, 10, 20])

        >>> img = torch.rand(2, 3, 10, 20)
        >>> aug = RandomClahe()
        >>> res = aug(img)
        >>> res.shape
        torch.Size([2, 3, 10, 20])

    To apply the exact augmenation again, you may take the advantage of the previous parameter state:
        >>> input = torch.rand(1, 3, 32, 32)
        >>> aug = RandomClahe(p=1.)
        >>> (aug(input) == aug(input, params=aug._params)).all()
        tensor(True)

          D@r      r   F      ?
clip_limittuple[float, float]	grid_sizetuple[int, int]slow_and_differentiableboolsame_on_batchpfloatkeepdimreturnNonec                   s@   t  j||d|d || _t| jdd d f| _||d| _d S )Ng      ?)r   r   p_batchr   clip_limit_factor)r   r   )super__init__r   rgPlainUniformGenerator_param_generatorflags)selfr   r   r   r   r   r   	__class__ [/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/_2d/intensity/clahe.pyr   A   s   	zRandomClahe.__init__Ninputr   paramsdict[str, Tensor]r"   dict[str, Any]	transformOptional[Tensor]c                 C  s&   t |d d }t|||d |d S )Nr   r   r   r   )r   r   )r#   r(   r)   r"   r,   r   r&   r&   r'   apply_transformO   s   zRandomClahe.apply_transform)r
   r   FFr   F)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )N)
r(   r   r)   r*   r"   r+   r,   r-   r   r   )__name__
__module____qualname____doc__r   r.   __classcell__r&   r&   r$   r'   r	      s    &r	   N)
__future__r   typingr   r   kornia.augmentationr   r   &kornia.augmentation._2d.intensity.baser   kornia.corer   kornia.enhancer   r	   r&   r&   r&   r'   <module>   s   