+
    ùäûj  ã                  óp   € ^ RI Ht ^ RIHtHt ^ RIt^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt  ! R R	]
4      tR# )
é    )Úannotations)ÚAnyÚOptionalN)Úrandom_generator)ÚIntensityAugmentationBase2D)Ú_clamp_unit_range)Ú_equalize_clahec                  óJ   a € ] tR t^tRtRtRR V 3R llltR	R R lltRtV ;t	# )
ÚRandomClaheaÀ  Equalize local contrast with CLAHE, applied per sample with probability ``p`` (default 0.5).

``output = RandomClahe(clip_limit, grid_size, ...)(input)`` equalizes each selected image through local tiles.
It accepts ``(B, C, H, W)`` images and clamps the selected inputs and outputs to ``[0, 1]``. Use
:class:`RandomEqualize` for one global histogram per channel.

.. image:: _static/img/equalize_clahe.png

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

Args:
    clip_limit: the ``(low, high)`` range the per-sample contrast-limiting threshold is drawn from.
        A value is drawn for each image, or once and shared across the batch when ``same_on_batch=True``.
        Unlike :func:`kornia.enhance.equalize_clahe`'s scalar argument of the same name this must be a
        two-element tuple -- a scalar raises a ``ValueError`` at construction -- and ``(0.0, 0.0)`` disables
        clipping. A negative bound is not rejected and behaves like ``0.0``.
    grid_size: number of tiles to be cropped in each direction (GH, GW).
    slow_and_differentiable: selects the implementation. At the default ``False`` the fast path breaks the
        autograd graph -- the output has ``requires_grad=False`` and no ``grad_fn``, which no other 2D
        intensity augmentation does -- so set it to ``True`` to keep the class differentiable.
    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:
    - input values are clamped into ``[0, 1]`` before the operation, and the result is clamped
      into the same range. This applies only to samples selected by the probability gate.
    - the wrapper clamps before calling :func:`kornia.enhance.equalize_clahe`; the functional
      API retains its strict range check.
    - ``grid_size`` tiles the two axes independently, and a grid that does not divide the image pads it, so
      ``grid_size=(3, 3)`` works on a ``10 x 10`` image. Each axis must be larger than its grid size, so a
      grid as large as the image, or larger, raises a ``ValueError`` naming the smallest image it admits.

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

See Also:
    - :class:`RandomEqualize`: equalizes each whole channel rather than local tiles.

Examples:
    >>> img = torch.rand(1, 10, 20)
    >>> aug = RandomClahe()
    >>> res = aug(img)
    >>> res.shape
    torch.Size([1, 1, 10, 20])

    >>> img = torch.rand(2, 3, 10, 20)
    >>> aug = RandomClahe()
    >>> res = aug(img)
    >>> res.shape
    torch.Size([2, 3, 10, 20])

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

Tc               ó4   € V ^8„  d   QhRRRRRRRRRR	R
RRR/# )é   Ú
clip_limitztuple[float, float]Ú	grid_sizeztuple[int, int]Úslow_and_differentiableÚboolÚsame_on_batchÚpÚfloatÚkeepdimÚreturnÚNone© )Úformats   "ÚcC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\intensity\clahe.pyÚ__annotate__ÚRandomClahe.__annotate__^   sY   € ÷ bñ bà'ðbð #ðbð "&ð	bð
 ðbð ðbð ðbð 
ñbó    c                	ó    <€ \         SV `  WTR VR7       Wn        \        P                  ! V P                  RRR34      V n        RVRV/V n        R# )g      ð?)r   r   Úp_batchr   Úclip_limit_factorNr   r   )ÚsuperÚ__init__r   ÚrgÚPlainUniformGeneratorÚ_param_generatorÚflags)Úselfr   r   r   r   r   r   Ú	__class__s   &&&&&&&€r   r"   ÚRandomClahe.__init__^   sT   ø€ ô 	‰Ñ˜1À3ÐPWÐÔXØ$ŒÜ "× 8Ò 8¸$¿/¹/ÐK^Ð`dÐfjÐ9kÓ lˆÔØ! 9Ð.GÐI`ÐaˆŽ
r   c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R/# )
r   Úinputztorch.TensorÚparamszdict[str, torch.Tensor]r&   zdict[str, Any]Ú	transformzOptional[torch.Tensor]r   r   )r   s   "r   r   r   l   sC   € ÷ yñ yàðyð (ðyð ð	yð
 *ðyð 
ñyr   c                	ó\   € \        V4      p\        WR ,          VR,          VR,          4      # )r    r   r   )r   r	   )r'   r+   r,   r&   r-   s   &&&&&r   Úapply_transformÚRandomClahe.apply_transforml   s/   € ô " %Ó(ˆÜ˜uÐ-@Õ&AÀ5ÈÕCUÐW\Ð]vÕWwÓxÐxr   )r%   r   r&   ))ç      D@r1   )é   r2   FFg      à?F)N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚSUBSTITUTE_SKIPPED_SAMPLESr"   r/   Ú__static_attributes__Ú__classcell__)r(   s   @r   r   r      s)   ø† ñ;ðz "&Ð÷bò b÷yõ yr   r   )Ú
__future__r   Útypingr   r   ÚtorchÚkornia.augmentationr   r#   Ú&kornia.augmentation._2d.intensity.baser   Úkornia.core.utilsr   Úkornia.enhance.equalizationr	   r   r   r   r   Ú<module>rB      s-   ðõ$ #ç  ã å 6Ý NÝ /Ý 7ôVyÐ-ö Vyr   