+
    ùäûj¤#  ã                   ót   € ^ RI Ht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Ht  ! R R]4      tR# )	é    )ÚAnyÚDictÚOptionalÚTupleÚUnionN)Úrandom_generator)ÚIntensityAugmentationBase2D)Ú_to_device_nonblocking)Úbbox_generatorÚbbox_to_maskc                   ór   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
V3R lR lltRtVt	V ;t
# )ÚRandomErasingaS  Erase a random rectangle of the image, applied per sample with probability ``p`` (default 0.5).

``output = RandomErasing(scale, ratio, value, ...)(input)`` replaces one sampled rectangle in each selected
image ``(B, C, H, W)``.

.. image:: _static/img/RandomErasing.png

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

The operator removes image parts and fills them with ``value`` at a selected rectangle
for each of the images in the batch.

The rectangle *targets* an area equal to the original image area multiplied by a value sampled from
``scale``, with an aspect ratio sampled from ``ratio``.

Args:
    scale: range of proportion of erased area against input image.
    ratio: range of aspect ratio of erased area.
    value: the value to fill the erased area.
    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).

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

Convention:
    - this operation is range-independent: it does not clamp the input into ``[0, 1]``.
    - ``scale`` is the fraction of the image *area* the rectangle targets and ``ratio`` is its height over
      its width, so a ratio above ``1`` targets a tall box and below ``1`` a wide one. The box is rounded
      to whole pixels and then clamped to ``[1, H] x [1, W]``, so it is never empty and never larger than the
      image, and the erased area can miss the target in either direction: ``scale=(0.25, 0.25)`` with
      ``ratio=(3.0, 3.0)`` on a ``10 x 20`` image erases ``10 x 4 = 40`` pixels of the 50 asked for, while
      ``scale=(0.0, 0.0)`` still erases one pixel.
    - when ``ratio`` straddles ``1`` the draw is not uniform over the interval: a fair coin picks between
      ``[ratio[0], 1]`` and ``[1, ratio[1]]``, so at the default ``ratio=(0.3, 3.3)`` half the draws are above
      ``1``.
    - the erased region is the half-open rectangle ``[ys, ys + h) x [xs, xs + w)`` in pixels, recorded as
      ``_params["ys"]``, ``["xs"]``, ``["heights"]`` and ``["widths"]``.
    - the erased pixels carry the literal ``value``, which has to lie in ``[0, 1]`` -- the parameter
      generator rejects anything else at construction. Every other pixel is carried through unclamped, so
      every pixel outside the box keeps the input's range.
    - inside :class:`~kornia.augmentation.container.AugmentationSequential` a ``mask`` data key is erased
      in the same rectangle, but the mask is filled with ``0`` whatever ``value`` is.

Note:
    This function accepts another transformation torch.Tensor (``(B, 3, 3)``), then the
    applied transformation will be merged int to the input transformation torch.Tensor and returned.

See Also:
    - :class:`RandomChannelDropout`: fills selected complete channels instead of one rectangle.
    - :class:`RandomDissolving`: creates semantic image-to-image occlusion with a diffusion model.

Examples:
    >>> rng = torch.manual_seed(0)
    >>> inputs = torch.ones(1, 1, 3, 3)
    >>> aug = RandomErasing((.4, .8), (.3, 1/.3), p=0.5)
    >>> aug(inputs)
    tensor([[[[1., 0., 0.],
              [1., 0., 0.],
              [1., 0., 0.]]]])

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

c                óÂ   <€ V ^8„  d   QhRS[ S[P                  S[S[S[3,          3,          RS[ S[P                  S[S[S[3,          3,          RS[RS[RS[RS[RR/# )	é   ÚscaleÚratioÚvalueÚsame_on_batchÚpÚkeepdimÚreturnN)r   ÚtorchÚTensorr   ÚfloatÚbool)ÚformatÚ__classdict__s   "€ÚeC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\intensity\erasing.pyÚ__annotate__ÚRandomErasing.__annotate__e   sˆ   ø€ ÷ Pñ Pá‘U—\‘\¡5©±¨Õ#6Ð6Õ7ðPñ ‘U—\‘\¡5©±¨Õ#6Ð6Õ7ðPñ ð	Pñ
 ðPñ ðPñ ðPð 
ñPó    c                ó†   <€ \         SV `  WTVR 7       Wn        W n        W0n        \
        P                  ! WV4      V n        R# ))r   r   r   N)ÚsuperÚ__init__r   r   r   ÚrgÚRectangleEraseGeneratorÚ_param_generator)Úselfr   r   r   r   r   r   Ú	__class__s   &&&&&&&€r   r$   ÚRandomErasing.__init__e   s;   ø€ ô 	‰Ñ˜1À7ÐÔKØŒ
ØŒ
ØŒ
Ü "× :Ò :¸5ÈÓ OˆÖr!   c          
      óÄ   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[S[ P                  ,          RS[ P                  /# ©r   ÚinputÚparamsÚflagsÚ	transformr   ©r   r   r   Ústrr   r   )r   r   s   "€r   r   r    t   sd   ø€ ÷ $7ñ $7á�|‰|ð$7ñ ‘S™%Ÿ,™,Ð&Õ'ð$7ñ ‘C™�H�~ð	$7ñ
 ™EŸL™LÕ)ð$7ñ 
�‰ñ$7r!   c                ór  € VP                  4       w   rVp\        VR ,          P                  R^^^4      VP                  VP                  4      pV P
                  '       dœ   \        P                  ! VR,          ^ ,          VR,          ^ ,          VR,          ^ ,          VR,          ^ ,          .4      P                  4       P                  4       w  ršr¼VP                  4       pW�RRWªV,           1W™V,           13&   V# \        VR,          VR,          VR,          VR,          4      p\        WáP                  \        P                  ! VP                  \        P                  4      4      p\        WæV3R7      P                  ^4      P!                  VP                  4      p\        P"                  ! VR8H  W�4      # )	ÚvaluesÚxsÚysÚwidthsÚheights:NNN©Úsizeç      ð?éÿÿÿÿ)r:   r
   ÚviewÚdeviceÚdtyper   r   ÚstackÚlongÚtolistÚcloner   Úpromote_typesÚfloat32r   Ú	unsqueezeÚtoÚwhere)r(   r-   r.   r/   r0   Ú_ÚhÚwr4   r5   r6   Úbox_wÚbox_hÚtransformedÚbboxesÚmasks   &&&&&           r   Úapply_transformÚRandomErasing.apply_transformt   se  € ð —Z‘Z“\‰
ˆˆ1�Ü'¨¨xÕ(8×(=Ñ(=¸bÀ!ÀQÈÓ(JÈEÏLÉLÐZ_×ZeÑZeÓfˆà××Ðô —’˜V D�\¨!�_¨f°T­l¸1­o¸vÀhÕ?OÐPQÕ?RÐTZÐ[dÕTeÐfgÕThÐiÓjß‘“ß‘“ñ !ˆB�Eð
  Ÿ+™+›-ˆKØBH˜˜1˜b¨¥:˜o¨r¸µJ¨Ð>Ñ?ØÐô    t¥¨f°T­l¸FÀ8Õ<LÈfÐU^ÕN_Ó`ˆô (¨·±¼e×>QÒ>QÐRW×R]ÑR]Ô_d×_lÑ_lÓ>mÓnˆÜ˜F¨Q¨Ô0×:Ñ:¸1Ó=×@Ñ@ÀÇÁÓMˆÜ�{Š{˜4 3™;¨Ó6Ð6r!   c          
      óÄ   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[S[ P                  ,          RS[ P                  /# r,   r1   )r   r   s   "€r   r   r    š   sd   ø€ ÷ 7ñ 7á�|‰|ð7ñ ‘S™%Ÿ,™,Ð&Õ'ð7ñ ‘C™�H�~ð	7ñ
 ™EŸL™LÕ)ð7ñ 
�‰ñ7r!   c                óþ  € VP                  4       w   rVp\        P                  ! RVP                  VP                  R 7      p\        VR,          VR,          VR,          VR,          4      p	\        W‘P                  \        P                  ! VP                  \        P                  4      4      p	\        W–V3R7      P                  ^4      P                  VP                  4      p
\        P                  ! V
R8H  W�4      # ))r?   r>   r5   r6   r7   r8   r9   r;   © )r:   r   Úzerosr?   r>   r   r
   rD   rE   r   rF   rG   rH   )r(   r-   r.   r/   r0   rI   rJ   rK   r4   rO   rP   s   &&&&&      r   Úapply_transform_maskÚ"RandomErasing.apply_transform_maskš   s¾   € ð —Z‘Z“\‰
ˆˆ1�ô
 —’˜R u§{¡{¸5¿<¹<ÔHˆä  t¥¨f°T­l¸FÀ8Õ<LÈfÐU^ÕN_Ó`ˆô (¨·±¼e×>QÒ>QÐRW×R]ÑR]Ô_d×_lÑ_lÓ>mÓnˆÜ˜F¨Q¨Ô0×:Ñ:¸1Ó=×@Ñ@ÀÇÁÓMˆÜ�{Š{˜4 3™;¨Ó6Ð6r!   )r'   r   r   r   ))g{®Gáz”?g…ëQ¸Õ?)g333333Ó?gffffff
@g        Fg      à?F)N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r$   rQ   rW   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r)   r   s   @@r   r   r      s2   ù‡ € ñF÷PPõ P÷$7ò $7÷L7÷ 7ò 7r!   r   )Útypingr   r   r   r   r   r   Úkornia.augmentationr   r%   Ú&kornia.augmentation._2d.intensity.baser	   Úkornia.core.utilsr
   Úkornia.geometry.bboxr   r   r   rU   r!   r   Ú<module>rf      s+   ð÷$ 5Õ 4ã å 6Ý NÝ 4ß =ôR7Ð/ö R7r!   