o
    oiM                     @   sd   d dl mZmZ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dS )	    )AnyDictListOptionalTupleUnion)random_generator)IntensityAugmentationBase2D)Tensorjpeg_codec_differentiablec                       s   e Zd ZdZ				ddeeeeeef 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 )
RandomJPEGa  Applies random (differentiable) JPEG coding to a tensor image.

    .. image:: _static/img/RandomJPEG.png

    Args:
        jpeg_quality: The range of compression rates to be applied.
        p: probability of applying the transformation.
        same_on_batch: apply the same transformation across the batch.
        keepdim: whether to keep the output shape the same as input (True) or broadcast it
                 to the batch form (False).

    Shape:
        - Input: :math:`(C, H, W)` or :math:`(B, C, H, W)`
        - Output: :math:`(B, C, H, W)`

    .. note::
        This function internally uses :func:`kornia.enhance.jpeg_codec_differentiable`.

    Examples:
        >>> import torch
        >>> rng = torch.manual_seed(0)
        >>> images = 0.1904 * torch.ones(2, 3, 32, 32)
        >>> aug = RandomJPEG(jpeg_quality=(1.0, 50.0), p=1.)
        >>> images_jpeg = aug(images)

    To apply the exact augmenation again, you may take the advantage of the previous parameter state:
        >>> images = 0.1904 * torch.ones(2, 3, 32, 32)
        >>> aug = RandomJPEG(jpeg_quality=20.0, p=1.)  # Samples a JPEG quality from the range [30.0, 70.0]
        >>> (aug(images) == aug(images, params=aug._params)).all()
        tensor(True)

          I@F      ?jpeg_qualitysame_on_batchpkeepdimreturnNc                    s(   t  j|||d || _t|| _d S )N)r   r   r   )super__init__r   rgJPEGGenerator_param_generator)selfr   r   r   r   	__class__ Z/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/_2d/intensity/jpeg.pyr   <   s   zRandomJPEG.__init__inputparamsflags	transformc                 C   s   t ||d }|S )Nr   r   )r   r   r    r!   r"   jpeg_outputr   r   r   apply_transformG   s   zRandomJPEG.apply_transform)r   Fr   F)N)__name__
__module____qualname____doc__r   r
   floatr   r   boolr   r   strr   r   r$   __classcell__r   r   r   r   r      s:    #

r   N)typingr   r   r   r   r   r   kornia.augmentationr   r   &kornia.augmentation._2d.intensity.baser	   kornia.corer
   kornia.enhancer   r   r   r   r   r   <module>   s    