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dS )	    )AnyDictOptionalTuple)random_generator)IntensityAugmentationBase2D)Tensor)StableDiffusionDissolvingc                       s   e Zd ZdZ				ddeeef de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 )RandomDissolvinga:  Perform dissolving transformation using StableDiffusion models.

    Based on :cite:`shi2024dissolving`, the dissolving transformation is essentially applying one-step
    reverse diffusion. Our implementation currently supports HuggingFace implementations of SD 1.4, 1.5
    and 2.1. SD 1.X tends to remove more details than SD2.1.

    .. list-table:: Title
        :widths: 32 32 32
        :header-rows: 1

        * - SD 1.4
          - SD 1.5
          - SD 2.1
        * - figure:: https://raw.githubusercontent.com/kornia/data/main/dslv-sd-1.4.png
          - figure:: https://raw.githubusercontent.com/kornia/data/main/dslv-sd-1.5.png
          - figure:: https://raw.githubusercontent.com/kornia/data/main/dslv-sd-2.1.png

    Args:
        p: probability of applying the transformation.
        version: the version of the stable diffusion model.
        step_range: the step range of the diffusion model steps. Higher the step, stronger
                    the dissolving effects.
        keepdim: whether to keep the output shape the same as input (True) or broadcast it
                 to the batch form (False).
        **kwargs: additional arguments for `.from_pretrained` for HF StableDiffusionPipeline.

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

    d   i  2.1      ?F
step_rangeversionpkeepdimkwargsreturnNc                    sD   t  j|d|d || _t|fi || _t| jdd d f| _d S )NT)r   same_on_batchr   step_range_factor)super__init__r   r	   _dslvrgPlainUniformGenerator_param_generator)selfr   r   r   r   r   	__class__ `/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/_2d/intensity/dissolving.pyr   ;   s   zRandomDissolving.__init__inputparamsflags	transformc                 C   s   |  ||d d   S )Nr   r   )r   longitem)r   r"   r#   r$   r%   r    r    r!   apply_transformH   s   z RandomDissolving.apply_transform)r   r   r   F)N)__name__
__module____qualname____doc__r   floatstrboolr   r   r   r   r   r(   __classcell__r    r    r   r!   r
      s>    "


r
   N)typingr   r   r   r   kornia.augmentationr   r   &kornia.augmentation._2d.intensity.baser   kornia.corer   kornia.filtersr	   r
   r    r    r    r!   <module>   s   