+
    ùäûjÜ  ã                   óx   € ^ RI HtHtHtHt ^ RIt^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt  ! R R	]4      tR# )
é    )ÚAnyÚDictÚOptionalÚUnionN)ÚTensor)ÚIntensityAugmentationBase2D)Ú_device_literal)Ú_to_device_nonblocking)Úinvertc                   ó\   a a€ ] tR t^t oRtRV3R lV 3R llltRV3R lR lltRtVtV ;t	# )	ÚRandomInverta›  Invert image values as ``max_val - x``, applied per sample with probability ``p`` (default 0.5).

``output = RandomInvert(max_val, ...)(input)`` subtracts selected image values from a chosen maximum.

.. image:: _static/img/RandomInvert.png

See the Convention block on :class:`~kornia.augmentation.IntensityAugmentationBase2D`.

Args:
    max_val: The expected maximum value in the input tensor. The shape has to
      according to the input tensor shape, or at least has to work with broadcasting.
    same_on_batch: apply the same transformation across the batch.
    p: probability of applying the transformation to each sample.
    keepdim: whether to keep the output shape the same as input (True) or broadcast it
             to the batch form (False).

Convention:
    - this operation is range-independent: it does not clamp the input into ``[0, 1]``.
    - the output is ``max_val - input``, with no clamp, so an input outside ``[0, max_val]`` comes
      back outside it rather than clipped. ``max_val`` describes the input's maximum, so it has to be
      set to match an input that is not in ``[0, 1]``.

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

See Also:
    - :class:`RandomSolarize`: inverts only values above a sampled threshold.

Examples:
    >>> rng = torch.manual_seed(0)
    >>> img = torch.rand(1, 1, 5, 5)
    >>> inv = RandomInvert()
    >>> inv(img)
    tensor([[[[0.4963, 0.7682, 0.0885, 0.1320, 0.3074],
              [0.6341, 0.4901, 0.8964, 0.4556, 0.6323],
              [0.3489, 0.4017, 0.0223, 0.1689, 0.2939],
              [0.5185, 0.6977, 0.8000, 0.1610, 0.2823],
              [0.6816, 0.9152, 0.3971, 0.8742, 0.4194]]]])

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

c          
      óL   <€ V ^8„  d   QhRS[ S[S[3,          RS[RS[RS[RR/# )é   Úmax_valÚsame_on_batchÚpÚkeepdimÚreturnN)r   Úfloatr   Úbool)ÚformatÚ__classdict__s   "€ÚdC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\intensity\invert.pyÚ__annotate__ÚRandomInvert.__annotate__M   sF   ø€ ÷ *ñ *á‘u™f�}Õ%ð*ñ ð*ñ ð	*ñ
 ð*ð 
ñ*ó    c                ó>   <€ \         SV `  W2R VR7       RV/V n        R# )ç      ð?)r   r   Úp_batchr   r   N)ÚsuperÚ__init__Úflags)Úselfr   r   r   r   Ú	__class__s   &&&&&€r   r!   ÚRandomInvert.__init__M   s&   ø€ ô 	‰Ñ˜1À3ÐPWÐÔXØ Ð)ˆŽ
r   c          
      ót   <€ V ^8„  d   QhRS[ RS[S[S[ 3,          RS[S[S[3,          RS[S[ ,          RS[ /# )r   ÚinputÚparamsr"   Ú	transformr   )r   r   Ústrr   r   )r   r   s   "€r   r   r   W   sS   ø€ ÷ 	_ñ 	_Ùð	_Ù%)©#©v¨+Õ%6ð	_Ù?CÁCÉÀH½~ð	_ÙZbÑciÕZjð	_á	ñ	_r   c           	     óŽ  € VR ,          p\        V\        4      '       d+   \        V\        WQP                  VP
                  4      4      # \        V\        \        34      '       d,   \        V\        WQP                  VP
                  R7      4      # \        V\        P                  ! WQP                  VP
                  R7      4      # )r   )ÚdeviceÚdtype)Ú
isinstancer   r   r
   r,   r-   Úintr   r	   ÚtorchÚ	as_tensor)r#   r'   r(   r"   r)   r   s   &&&&& r   Úapply_transformÚRandomInvert.apply_transformW   s‹   € ð ˜	Õ"ˆÜ�gœv×&Ò&Ü˜%Ô!7¸ÇÁÈuÏ{É{Ó![Ó\Ð\Ü�g¤¤U˜|×,Ò,ä˜%¤°ÇÁÐUZ×U`ÑU`Ô!aÓbÐbÜ�eœUŸ_š_¨W¿\¹\ÐQV×Q\ÑQ\Ô]Ó^Ð^r   )r"   )r   Fg      à?F)N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r!   r2   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r$   r   s   @@r   r   r      s'   ù‡ € ñ-÷^*õ *÷	_÷ 	_ò 	_r   r   )Útypingr   r   r   r   r0   r   Ú&kornia.augmentation._2d.intensity.baser   Úkornia.core.opsr	   Úkornia.core.utilsr
   Úkornia.enhancer   r   © r   r   Ú<module>rB      s0   ð÷$ .Ó -ã Ý å NÝ +Ý 4Ý !ôC_Ð.ö C_r   