o
    oi                     @   s|   d dl mZmZ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G dd	 d	e	ZG d
d de	ZdS )    )AnyDictOptionalTuple)random_generator)IntensityAugmentationBase2D)diamond_square)Tensorc                       s   e Zd ZdZ					ddeeef deeef ded	ed
eddf fddZ	ddede	e
ef de	e
ef dee def
ddZ  ZS )RandomPlasmaBrightnessa  Adds brightness to the image based on a fractal map generated by the diamond square algorithm.

    .. image:: _static/img/RandomPlasmaBrightness.png

    This is based on the original paper: TorMentor: Deterministic dynamic-path, data augmentations with fractals.
    See: :cite:`tormentor` for more details.

    .. note::
        This function internally uses :func:`kornia.contrib.diamond_square`.

    Args:
        roughness: value to scale during the recursion in the generation of the fractal map.
        intensity: value that scales the intensity values of the generated maps.
        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).

    Examples:
        >>> rng = torch.manual_seed(0)
        >>> img = torch.ones(1, 1, 3, 4)
        >>> RandomPlasmaBrightness(roughness=(0.1, 0.7), p=1.)(img)
        tensor([[[[0.6415, 1.0000, 0.3142, 0.6836],
                  [1.0000, 0.5593, 0.5556, 0.4566],
                  [0.5809, 1.0000, 0.7005, 1.0000]]]])

    g?gffffff?              ?F      ?	roughness	intensitysame_on_batchpkeepdimreturnNc                    s6   t  j||d|d t|dd d f|dd d f| _d S )Nr   r   r   p_batchr   r   r   super__init__rgPlainUniformGenerator_param_generator)selfr   r   r   r   r   	__class__ \/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/_2d/intensity/plasma.pyr   7   s   
zRandomPlasmaBrightness.__init__imageparamsflags	transformc                 C   sr   |j \}}}}|d |}	|d |dddd}
dt||||f|	|j|jd d }||
 }|| ddS )Nr   r         devicedtyper   shapetoviewr   r+   r,   clamp_)r   r#   r$   r%   r&   BCHWr   r   brightness_mapr!   r!   r"   apply_transformD   s   $z&RandomPlasmaBrightness.apply_transform)r   r   Fr   FN__name__
__module____qualname____doc__r   floatboolr   r	   r   strr   r   r7   __classcell__r!   r!   r   r"   r
      s@    



r
   c                       s~   e Zd ZdZ				ddeeef dededed	d
f
 fddZ	
ddede	e
ef de	e
ef dee d	ef
ddZ  ZS )RandomPlasmaContrasta@  Adds contrast to the image based on a fractal map generated by the diamond square algorithm.

    .. image:: _static/img/RandomPlasmaContrast.png

    This is based on the original paper: TorMentor: Deterministic dynamic-path, data augmentations with fractals.
    See: :cite:`tormentor` for more details.

    .. note::
        This function internally uses :func:`kornia.contrib.diamond_square`.

    Args:
        roughness: value to scale during the recursion in the generation of the fractal map.
        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).

    Examples:
        >>> rng = torch.manual_seed(0)
        >>> img = torch.ones(1, 1, 3, 4)
        >>> RandomPlasmaContrast(roughness=(0.1, 0.7), p=1.)(img)
        tensor([[[[0.9651, 1.0000, 1.0000, 1.0000],
                  [1.0000, 0.9103, 0.8038, 0.9263],
                  [0.6882, 1.0000, 0.9544, 1.0000]]]])

    r   Fr   r   r   r   r   r   Nc                    s,   t  j||d|d t|dd d f| _d S )Nr   r   r   r   )r   r   r   r   r   r   r!   r"   r   k   s   zRandomPlasmaContrast.__init__r#   r$   r%   r&   c                 C   sT   |j \}}}}|d |}	dt||||f|	|j|jd }
|d |
 d ddS )Nr      r*   r   r   r(   )r.   r/   r   r+   r,   r1   )r   r#   r$   r%   r&   r2   r3   r4   r5   r   contrast_mapr!   r!   r"   r7   u   s    z$RandomPlasmaContrast.apply_transform)r   Fr   Fr8   r9   r!   r!   r   r"   rB   O   s:    


rB   c                       s   e Zd ZdZ						ddeeef deeef d	eeef d
edededdf fddZ	ddede	e
ef de	e
ef dee def
ddZ  ZS )RandomPlasmaShadowa  Add gaussian noise to a batch of multi-dimensional images.

    .. image:: _static/img/RandomPlasmaShadow.png

    This is based on the original paper: TorMentor: Deterministic dynamic-path, data augmentations with fractals.
    See: :cite:`tormentor` for more details.

    .. note::
        This function internally uses :func:`kornia.contrib.diamond_square`.

    Args:
        roughness: value to scale during the recursion in the generation of the fractal map.
        shade_intensity: value that scales the intensity values of the generated maps.
        shade_quantity: value to select the pixels to mask.
        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).

    Examples:
        >>> rng = torch.manual_seed(0)
        >>> img = torch.ones(1, 1, 3, 4)
        >>> RandomPlasmaShadow(roughness=(0.1, 0.7), p=1.)(img)
        tensor([[[[0.7682, 1.0000, 1.0000, 1.0000],
                  [1.0000, 1.0000, 1.0000, 1.0000],
                  [1.0000, 1.0000, 1.0000, 1.0000]]]])

    r   g      r   r   Fr   r   shade_intensityshade_quantityr   r   r   r   Nc                    s@   t  j||d|d t|dd d f|dd d f|dd d f| _d S )Nr   r   r   rG   rH   r   )r   r   rG   rH   r   r   r   r   r!   r"   r      s   	



zRandomPlasmaShadow.__init__r#   r$   r%   r&   c                 C   s   |j \}}}}|d |}	|d |dddd}
|d |dddd}t|d||f|	|j|jd}||k |j|
 }|| ddS )Nr   rG   r'   r(   rH   r*   r   r-   )r   r#   r$   r%   r&   r2   _r4   r5   r   rG   rH   	shade_mapr!   r!   r"   r7      s   z"RandomPlasmaShadow.apply_transform)r   rF   r   Fr   Fr8   r9   r!   r!   r   r"   rE   ~   sF    




rE   N)typingr   r   r   r   kornia.augmentationr   r   &kornia.augmentation._2d.intensity.baser   kornia.contribr   kornia.corer	   r
   rB   rE   r!   r!   r!   r"   <module>   s   5/