+
     åûjhP ã                  óú  € ^ RI Ht ^ RIt^ RIHt ^ RIHtHtHt ^ RI	t	^ RI
Hu Ht ^ RI	Ht ^ RIHtHtHt ^ RIHtHtHtHtHt ^ RIHt ^ R	IHt ^ R
IHtHtHtH t H!t!H"t" ^ RI#H$t$H%t% R R lt&R R lt'RTR R llt(R R lt)R R lt*R R lt+R R lt,R R lt-R R lt.RUR R llt/RVR  R! llt0R" R# lt1RVR$ R% llt2RVR& R' llt3RWR( R) llt4RXR* R+ llt5RYR, R- llt6RZR. R/ llt7R0 R1 lt8R2 R3 lt9R4 R5 lt:R6 R7 lt;R8 R9 lt<R: R; lt=R[R< R= llt> ! R> R?]P~                  4      t@ ! R@ RA]P~                  4      tA ! RB RC]P~                  4      tB ! RD RE]P~                  4      tC ! RF RG]P~                  4      tD ! RH RI]P~                  4      tE ! RJ RK]P~                  4      tF ! RL RM]P~                  4      tG ! RN RO]P~                  4      tH ! RP RQ]P~                  4      tI ! RR RS]P~                  4      tJR# )\é    )ÚannotationsN)Úpi)ÚClassVarÚOptionalÚUnion)Únn)Ú
hsv_to_rgbÚrgb_to_grayscaleÚ
rgb_to_hsv)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_COLOR_OR_GRAYÚKORNIA_CHECK_IS_TENSORÚ_check_asyncÚare_checks_enabled)ÚTypeCheckError)Ú_device_literal)Ú_clamp_unit_rangeÚ_is_tracing_or_exportingÚ_needs_derivativesÚ _normalize_to_float32_or_float64Ú_to_device_nonblockingÚis_compiling)Ú	_to_bcdhwÚ_to_bchwc               ó    € V ^8„  d   QhRRRR/# ©é   Úimageútorch.TensorÚreturn© )Úformats   "ÚQC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\enhance\adjust.pyÚ__annotate__r$   1   s   € ÷ $ñ $˜Lð $¨\ñ $ó    c                ó<  € \         P                  P                  4       '       go   V P                  4       '       dY   \	        4       '       gI   \        V 4      '       g8   \         P                  P                  4       '       g   V P                  RRR7      # \        V 4      # )ad  Clamp a tensor this module just allocated into ``[0, 1]``, in place when no derivative can be asked for.

The values equal ``image.clamp(0, 1)``. Without a recorded gradient or a forward-mode tangent the clamp reuses the
fresh buffer instead of allocating another image-sized one: at batch 32 that third 25 MB temporary per call made
glibc trim and re-fault the heap on every call. With one it is ``_clamp_unit_range``, whose derivative at a bound
does not depend on the torch version. A captured graph takes the same path whatever the grad mode, so that
``torch.jit.trace``'s check under ``no_grad`` records the same clamp. Only call it on a tensor no caller can see.

An integer tensor, which reaches here only with checks disabled, keeps the out-of-place clamp: the float bounds
promote its result to the default float dtype, which an in-place clamp cannot do. So does a tensor under a function
transform: vmap has a batching rule for ``clamp`` but not for ``clamp_``, whose fallback loops over the batch and
rejects an empty one. TorchScript cannot compile the function-transform query, so a scripted call keeps it too.
ç        ç      ð?©ÚminÚmax)
ÚtorchÚjitÚis_scriptingÚis_floating_pointr   r   Ú_CÚ _are_functorch_transforms_activeÚclamp_r   )r   s   &r#   Ú_clip_unit_freshr3   1   sk   € ô �9‰9×!Ñ!×#Ò#à×#Ñ#×%Ò%Ü,×.Ò.Ü& u×-Ò-Ü—H‘H×=Ñ=×?Ò?à—<‘< C¨S�<Ó1Ð1Ü˜UÓ#Ð#r%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   ÚopÚstrr    ÚNoner!   )r"   s   "r#   r$   r$   J   s!   € ÷ ñ  ð °3ð ¸4ñ r%   c                ó  € \        V \        P                  4      '       d   V P                  4       '       d   R# \        P                  P                  4       '       g   \        4       '       g   R# \        P                  P                  4       '       d   \        VR,           4      h\        V RV P                   R2V P                  \        P                  \        P                  \        P                  \        P                  3R7      h)aÖ  Reject an integer image in an op that expects floating-point values in ``[0, 1]``.

These ops clamp to ``[0, 1]``, scale by 255 or index a 256-entry table, so an 8-bit image would
otherwise come back saturated, wrapped or negative without an error (#5981). The equalize family's
``[0, 1]`` range check let an integer 0/1 mask through, which ``equalize_clahe`` then mapped to wrong
values. The check reads only the dtype, so it stays ``torch.compile(fullgraph=True)``-safe, and
``disable_checks()`` skips it like every kornia check. A non-tensor is left to the op's own type check.
As in the core checks, TorchScript compiles neither the checks flag nor the exception metadata, so a
scripted op raises a plain message instead.
NzV expects a floating-point image in [0, 1]; convert it first, e.g. image.float() / 255.z/ expects a floating-point image in [0, 1], got zC. Convert it first, for example image.float() / 255 for 8-bit data.)Úactual_typeÚexpected_type)Ú
isinstancer,   ÚTensorr/   r-   r.   r   r   ÚdtypeÚfloat16Úbfloat16Úfloat32Úfloat64)r   r5   s   &&r#   Ú_check_floating_imagerB   J   s½   € ô �eœUŸ\™\×*Ò*¨e×.EÑ.E×.GÒ.GÙÜ�9‰9×!Ñ!×#Ò#Ü!×#Ò#ÙÜ‡y�y×Ñ×ÒÜØÐiÕió
ð 	
ô Øˆ$Ð=¸e¿k¹k¸]ð KLð 	Là—K‘KÜ—}‘}¤e§n¡n´e·m±mÄUÇ]Á]ÐSô	ð r%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r=   ztorch.dtypeÚtopÚfloatr    r!   )r"   s   "r#   r$   r$   f   s!   € ÷ ñ ˜ð ¨%ð ¸Eñ r%   c                ób   € V \         P                  \         P                  39   d
   VR,          # V# )aå  Return the factor that turns a value in ``[0, 1]`` into the level in ``0 .. top`` its truncation reads.

``(x * _level_scale(x.dtype)).long()`` is the 8-bit level ``(x * 255).long()``, except that ``k / 255`` reads
level ``k`` even when it was rounded a few units in the last place below ``k / 255``. CUDA divides by a Python
number by multiplying with its rounded reciprocal, as ``x * (1 / 255)`` does on any device, which leaves 24 of the
256 float64 levels one unit below ``k / 255``; truncating ``x * 255`` read those as ``k - 1``. For float32 and
float64 the factor is ``top`` raised by four float32 epsilons, relative (``2**-21``, eight units in the last place
of 255 in float32), so the margin grows with the level as that roundoff does, and a continuous value moves up a
level only within that margin below a level boundary, about 7 in 100000 values of a uniform image. float64 takes
the float32 margin rather than its own, so the same values read the same levels in both dtypes, and float32
roundoff carried into a float64 image is covered too. Half precision gets ``top`` itself, so the levels it reads
are unchanged: ``x * 255`` is rounded to the half-precision grid, which already gives ``k`` back for ``k / 255``
rounded to half precision.
g   €  ð?)r,   r@   rA   )r=   rD   s   &&r#   Ú_level_scalerG   f   s)   € ð ”—‘¤§¡Ð.Ô.Ø�nÕ%Ð%Ø€Jr%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úfactorr   r   r    r!   )r"   s   "r#   r$   r$   z   s!   € ÷ ñ  |ð ¸Lð È\ñ r%   c                óv  € V P                  4       VP                  4       8”  dh   \        P                  P                  4       '       d   \	        R4      h\	        R\        V P                  4       R\        VP                  4       R24      hV P                  4       VP                  4       8w  d   V R,          p K.  V # )ai  Right-pad ``factor`` with singleton dimensions so it broadcasts against ``image``.

A ``factor`` with more dimensions than ``image`` can never reach the image rank by appending
dimensions, so padding it would loop forever. Reject it here instead of hanging. The padding
only lines the ranks up: shapes that still do not broadcast are reported by the op itself.
zBFactor has more dimensions than the image and cannot be broadcast.zTFactor has more dimensions than the image and cannot be broadcast: got factor shape z for image shape Ú.).N)Údimr,   r-   r.   Ú
ValueErrorÚtupleÚshape)rI   r   s   &&r#   Ú_make_factor_broadcastablerP   z   s”   € ð ‡z�zƒ|�e—i‘i“kÔ!Ü�9‰9×!Ñ!×#Ò#ÜÐaÓbÐbÜØbÜ�V—\‘\Ó"Ð#Ð#4´U¸5¿;¹;Ó5GÐ4HÈðKó
ð 	
ð
 �*‰*‹,˜%Ÿ)™)›+Ô
%Ø˜	Õ"Šà€Mr%   c               ó$   € V ^8„  d   QhRRRRRR/# ©r   r   r   rI   úUnion[float, torch.Tensor]r    r!   )r"   s   "r#   r$   r$   �   s#   € ÷ )ñ ) ð )Ð7Qð )ÐVbñ )r%   c                ór  € \        V R4       \        \        V\        \        P
                  34      R4       \        V\        4      '       d.   \        P                  ! WP                  V P                  R7      pM@\        V\        P
                  4      '       d!   \        WP                  V P                  4      p\        W4      p\        P                  ! V ^RR7      w  r#pW1,          pVP                  4       '       d   \        V4      MVP                  ^ ^R7      p\        P                  ! W%V.RR7      pV# )a¤  Scale the saturation channel of an HSV image by a factor and clamp it to [0, 1].

``out = adjust_saturation_raw(image, factor)`` multiplies channel 1 (saturation) of a ``(*, 3, H, W)`` HSV image by
``factor``, clamps it to :math:`[0, 1]` and leaves hue and value as they are. For an RGB image, use
:func:`adjust_saturation`.

Args:
    image: HSV image with shape ``(*, 3, H, W)``.
    factor: saturation multiplier, a float or a tensor with shape ``(B,)`` for one value per image.

Returns:
    HSV image with shape ``(*, 3, H, W)``.

See Also:
    - :func:`adjust_saturation`: the same scaling on an RGB image.
    - :func:`adjust_hue_raw`: shifts the hue of an HSV image.

úExpected shape (*, H, W)ú'Factor should be float or torch.Tensor.©Údevicer=   ©ÚchunksrL   r)   ©rL   éýÿÿÿ)r   r   r;   rE   r,   r<   Ú	as_tensorrX   r=   r   rP   Úchunkr/   r   ÚclampÚcat)r   rI   ÚhÚsÚvÚs_outÚouts   &&     r#   Úadjust_saturation_rawrf   �   sä   € ô& ˜5Ð"<Ô=Ü”˜F¤U¬E¯L©LÐ$9Ó:Ð<eÔfä�&œ%× Ò ä—’ ·±ÀEÇKÁKÔP‰Ü	�FœEŸL™L×	)Ò	)Ü'¨·±¸e¿k¹kÓJˆä'¨Ó6€Fô �kŠk˜%¨¨rÔ2�G€Aˆ!ð �*€Eà(-×(?Ñ(?×(AÒ(AÔ˜eÔ$ÀuÇ{Á{ÐWXÐ^_À{ÓG`€Eô Ÿ	š	 1¨Q -°RÔ8€Cà€Jr%   c               ó$   € V ^8„  d   QhRRRRRR/# rR   r!   )r"   s   "r#   r$   r$   »   s#   € ÷ 5ñ 5°<ð 5ÐIcð 5Ðhtñ 5r%   c                óX  € \        V R4       \        V R4       \        \        V\        \
        P                  34      R4       \        V R4       V P                  R,          ^8X  d   V # \        V\        4      '       d.   \
        P                  ! WP                  V P                  R7      pM@\        V\
        P                  4      '       d!   \        WP                  V P                  4      p\        W4      p\        V 4      p^V,
          V,          W,          ,           p\        V4      pV# )ae  Adjust the saturation of an RGB image by blending it with its grayscale version, as PIL does.

``out = adjust_saturation_with_gray_subtraction(image, factor)`` returns ``factor * image + (1 - factor) * gray``
for a ``(*, 3, H, W)`` RGB image in :math:`[0, 1]`, clamped to :math:`[0, 1]`: ``0`` gives the gray image and ``1``
the input. A single-channel image is returned unchanged.

Args:
    image: RGB image with shape ``(*, 3, H, W)``, or gray image with shape ``(*, 1, H, W)``.
    factor: weight of the image, a float or a tensor with shape ``(B,)`` for one value per image.

Returns:
    Adjusted image with the shape of ``image``.

See Also:
    - :func:`adjust_saturation`: scales HSV saturation, so ``0`` gives max(R, G, B) instead of the gray level.
    - :class:`AdjustSaturationWithGraySubtraction`: the module form.

Example:
    >>> x = torch.ones(1, 3, 3, 3)
    >>> adjust_saturation_with_gray_subtraction(x, 2.).shape
    torch.Size([1, 3, 3, 3])

    >>> x = torch.ones(2, 3, 3, 3)
    >>> y = torch.tensor([1., 2.])
    >>> adjust_saturation_with_gray_subtraction(x, y).shape
    torch.Size([2, 3, 3, 3])

Ú'adjust_saturation_with_gray_subtractionrU   rV   z$Image should be an RGB or gray imagerW   r\   )rB   r   r   r;   rE   r,   r<   r   rO   r]   rX   r=   r   rP   r
   r   )r   rI   Úx_otherÚ
x_adjustedre   s   &&   r#   ri   ri   »   sÛ   € ô: ˜%Ð!JÔKÜ˜5Ð"<Ô=Ü”˜F¤U¬E¯L©LÐ$9Ó:Ð<eÔfÜ! %Ð)OÔPà‡{�{�2…˜!ÔØˆä�&œ%× Ò ä—’ ·±ÀEÇKÁKÔP‰Ü	�FœEŸL™L×	)Ò	)Ü'¨·±¸e¿k¹kÓJˆä'¨Ó6€Fä,¨UÓ3€Gð !" F¥
¨gÕ5¸½ÕF€Jô *¨*Ó5€Cà€Jr%   c               ó$   € V ^8„  d   QhRRRRRR/# rR   r!   )r"   s   "r#   r$   r$   ó   s-   € ÷ Jmñ Jm˜\ð JmÐ3Mð JmÐR^ñ Jmr%   c                óò  € \        V R4       \        \        V\        \        P
                  34      R4       \        V P                  4      ^8  g   V P                  R	,          ^8w  d   \        RV P                   24      hV P                  4       '       g   \        \        \        V 4      V4      4      # V P                  pV\        P                  \        P                  39   d   V P                  4       p \        V\        4      '       d.   \        P                   ! WP"                  V P                  R7      pM \%        WP"                  V P                  4      p\'        W4      pVP                  R	,          ^8w  d   \        RVP                   24      hV P)                  R	RR7      pV P+                  R	RR7      pW4,
          p\        P,                  ! V^ 8H  \        P.                  ! V4      VR,           4      pWV,          p\1        Wq,          4      pW7,          p\        P,                  ! V^ 8H  \        P.                  ! V4      V4      p	W,
          W‰,          ,          W8,
          ,           P3                  V4      # )
a  Adjust the saturation of an RGB image by scaling its HSV saturation channel.

``out = adjust_saturation(image, factor)`` multiplies the HSV saturation of a ``(*, 3, H, W)`` RGB image in
:math:`[0, 1]` by ``factor``, clamps it to :math:`[0, 1]` and returns RGB. ``0`` gives gray pixels equal to
max(R, G, B), not the gray level; for PIL's blend with the gray level, use
:func:`adjust_saturation_with_gray_subtraction`.

.. image:: _static/img/adjust_saturation.png

Args:
    image: RGB image with shape ``(*, 3, H, W)``.
    factor: saturation multiplier, a float or a tensor with shape ``(B,)`` for one value per image.

Returns:
    Adjusted image with shape ``(*, 3, H, W)``.

.. note::
   See a working example `here <https://www.kornia.org/tutorials/nbs/image_enhancement.html>`__.

See Also:
    - :func:`adjust_saturation_with_gray_subtraction`: blends with the gray image instead of scaling the HSV
      saturation.
    - :func:`adjust_saturation_raw`: the same scaling on an HSV image.
    - :class:`AdjustSaturation`: the module form.

Example:
    >>> x = torch.ones(1, 3, 3, 3)
    >>> adjust_saturation(x, 2.).shape
    torch.Size([1, 3, 3, 3])

    >>> x = torch.ones(2, 3, 3, 3)
    >>> y = torch.tensor([1., 2.])
    >>> adjust_saturation(x, y).shape
    torch.Size([2, 3, 3, 3])

rU   rV   z2Input size must have a shape of (*, 3, H, W). Got rW   zAFactor must hold one value per image, not per channel. Got shape T)rL   Úkeepdimg:Œ0âŽyE>r\   )r   r   r;   rE   r,   r<   ÚlenrO   rM   r/   r	   rf   r   r=   r>   r?   r]   rX   r   rP   ÚamaxÚaminÚwhereÚ	ones_liker   Úto)
r   rI   Ú	out_dtypeÚmax_rgbÚmin_rgbÚdeltaÚvalue_divisorÚ
saturationÚadjusted_deltaÚdelta_divisors
   &&        r#   Úadjust_saturationr}   ó   sÕ  € ôJ ˜5Ð"<Ô=Ü”˜F¤U¬E¯L©LÐ$9Ó:Ð<eÔfÜ
ˆ5�;‰;Ó˜!Ô˜uŸ{™{¨2�°!Ô3ÜÐMÈeÏkÉkÈ]Ð[Ó\Ð\à×"Ñ"×$Ò$ÜÔ/´
¸5Ó0AÀ6ÓJÓKÐKð —‘€IØ”U—]‘]¤E§N¡NÐ3Ô3Ø—‘“ˆä�&œ%× Ò Ü—’ ·±ÀEÇKÁKÔP‰ä'¨·±¸e¿k¹kÓJˆä'¨Ó6€FØ‡|�|�BÕ˜1ÔÜÐ\Ð]c×]iÑ]iÐ\jÐkÓlÐlð �j‰j˜R¨ˆjÓ.€GØ�j‰j˜R¨ˆjÓ.€GØÕ€EÜ—K’K ¨1¡¬e¯oªo¸gÓ.FÈÐRVÍÓW€MØÕ&€JÜ" :Õ#6Ó7€JàÕ)€NÜ—K’K ¨¡
¬E¯OªO¸EÓ,BÀEÓJ€MØ�_ Õ!?Õ@ÀGÕD\Õ]×aÑaÐbkÓlÐlr%   c               ó$   € V ^8„  d   QhRRRRRR/# rR   r!   )r"   s   "r#   r$   r$   @  s"   € ÷ -ñ -˜,ð -Ð0Jð -È|ñ -r%   c                óœ  € \        V R4       \        \        V\        \        \
        P                  34      ;'       d    \        V\        4      '       * R\        V4       24       \        V\        \        34      '       d-   \
        P                  ! WP                  V P                  R7      p\        WP                  V P                  4      p\        W4      p\
        P                  ! V ^RR7      w  r#p^\        ,          p\
        P                   ! W!,           V4      pVP#                  We8¬  R4      p\
        P$                  ! WcV.RR7      pV# )u  Shift the hue channel of an HSV image by an angle in radians, wrapping it into [0, 2Ï€).

``out = adjust_hue_raw(image, factor)`` adds ``factor`` radians to channel 0 (hue) of a ``(*, 3, H, W)`` HSV image
and wraps the sum into :math:`[0, 2\pi)`, leaving saturation and value as they are. For an RGB image, use
:func:`adjust_hue`.

Args:
    image: HSV image with shape ``(*, 3, H, W)``, hue in radians.
    factor: angle in radians, a number or a tensor with shape ``(B,)`` for one value per image.

Returns:
    HSV image with shape ``(*, 3, H, W)``.

See Also:
    - :func:`adjust_hue`: the same shift on an RGB image.
    - :func:`adjust_saturation_raw`: scales the saturation of an HSV image.
    - :func:`~kornia.color.rgb_to_hsv`: makes the HSV image this takes, with hue in radians.

rU   z<The factor should be an int, a float or a torch.Tensor. Got rW   rY   r'   r[   r\   )r   r   r;   ÚintrE   r,   r<   ÚboolÚtyper]   rX   r=   r   rP   r^   r   Ú	remainderÚmasked_fillr`   )r   rI   ra   rb   rc   ÚdivisorÚh_outre   s   &&      r#   Úadjust_hue_rawr‡   @  sû   € ô( ˜5Ð"<Ô=ÜÜ�6œC¤¬¯©Ð5Ó6×WÐW¼zÈ&ÔRVÓ?WÔ;WØ
FÄtÈFÃ|ÀnÐUôô
 �&œ3¤˜,×'Ò'Ü—’ ·±ÀEÇKÁKÔPˆä# F¯L©L¸%¿+¹+ÓF€Fä'¨Ó6€Fô �kŠk˜%¨¨rÔ2�G€Aˆ!ð œ•V€GÜŸ/š/¨!­*°gÓ>€Eà×Ñ˜eÑ.°Ó4€Eô Ÿ	š	 5¨Q -°RÔ8€Cà€Jr%   c               ó$   € V ^8„  d   QhRRRRRR/# rR   r!   )r"   s   "r#   r$   r$   p  s"   € ÷ 7=ñ 7=�lð 7=Ð,Fð 7=È<ñ 7=r%   c                óL  € Rp\        V \        P                  4      '       dL   V P                  \        P                  \        P
                  39   d   V P                  pV P                  4       p \        V 4      p\        W14      p\        V4      pVf   V# VP                  V4      # )u  Shift the hue of an RGB image by an angle in radians.

``out = adjust_hue(image, factor)`` rotates the hue of a ``(*, 3, H, W)`` RGB image in :math:`[0, 1]` by ``factor``
radians and returns RGB.

.. image:: _static/img/adjust_hue.png

Convention:
    - ``factor`` is any angle in radians, taken modulo :math:`2\pi`: ``factor`` and ``factor + 2Ï€`` agree, ``Â±Ï€``
      gives the complementary colors, and a positive angle turns red towards green.
    - torchvision's ``adjust_hue`` takes a fraction of a turn in :math:`[-0.5, 0.5]`: its ``hue_factor`` is
      ``factor / (2 * pi)`` for ``factor`` in :math:`[-\pi, \pi]`.

Args:
    image: RGB image with shape ``(*, 3, H, W)``.
    factor: hue shift in radians, a number or a tensor with shape ``(B,)`` for one value per image.

Returns:
    Adjusted image with shape ``(*, 3, H, W)``.

.. note::
   See a working example `here <https://www.kornia.org/tutorials/nbs/image_enhancement.html>`__.

See Also:
    - :func:`adjust_hue_raw`: the same shift on an HSV image.
    - :class:`AdjustHue`: the module form.

Example:
    >>> x = torch.ones(1, 3, 2, 2)
    >>> adjust_hue(x, 3.141516).shape
    torch.Size([1, 3, 2, 2])

    >>> x = torch.ones(2, 3, 3, 3)
    >>> y = torch.ones(2) * 3.141516
    >>> adjust_hue(x, y).shape
    torch.Size([2, 3, 3, 3])

N)r;   r,   r<   r=   r>   r?   rE   r   r‡   r	   rt   )r   rI   Ú
half_dtypeÚx_hsvrk   re   s   &&    r#   Ú
adjust_huerŒ   p  s„   € ðR )-€JÜ�%œŸ™×&Ò&¨5¯;©;¼5¿=¹=Ì%Ï.É.Ð:YÔ+YØ—[‘[ˆ
Ø—‘“ˆô % UÓ+€Eô  .¨eÓ<€Jô # :Ó.€CàÒ$ˆ3Ð<¨#¯&©&°Ó*<Ð<r%   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úinputr   ÚgammarS   Úgainr    r!   )r"   s   "r#   r$   r$   ª  s2   € ÷ @*ñ @*Øð@*Ø :ð@*ØB\ð@*àñ@*r%   c                ó&
  € \        V R4       \        V \        P                  4      '       g   \	        R\        V 4       24      h\        V\        \        P                  34      '       g   \	        R\        V4       24      h\        V\        \        P                  34      '       g   \	        R\        V4       24      h\        P                  P                  4       '       Eg8   \        P                  P                  4       '       Eg   \        4       '       Eg   \        V\        4      '       Edë   \        V\        4      '       EdÔ   V P                  \        P                  \        P                  39   Ed¤   V P                  ^ 8”  Ed’   \        P                  ! V P                  4      pRTu;8:  d   VP                   8:  EdX   M EMSRTu;8:  d   VP                   8:  Ed:   M EM5V P                  \        P                  8X  dg   \"        P$                  ! R\"        P&                  ! RV4      4      ^ ,          p\"        P$                  ! R\"        P&                  ! RV4      4      ^ ,          pRTu;8  d   R8  d€   M M|\)        V 4      '       dl   V ^ 8H  p\        P*                  ! V\        P,                  ! V 4      \        P*                  ! V\        P.                  ! V 4      V 4      P1                  V4      4      pMV P1                  V4      p\3        WR,          4      # \        V\        4      '       d/   \        P4                  ! V.V P6                  V P                  R7      p\        V\        4      '       d/   \        P4                  ! V.V P6                  V P                  R7      p\9        WP6                  V P                  4      p\9        W P6                  V P                  4      p\;        VR8¬  P=                  4       R	4       \;        VR8¬  P=                  4       R
4       \?        W4      p\?        W 4      p\)        V 4      '       dª   \        P                  P                  4       '       g†   V ^ 8H  V^ 8„  ,          V^8  ,          p\        P*                  ! V\        P,                  ! V 4      \        P0                  ! \        P*                  ! V\        P.                  ! V 4      V 4      V4      4      pM\        P0                  ! W4      p\3        W%,          4      # )aø  Apply gamma correction ``gain * input ** gamma`` to an image.

``out = adjust_gamma(input, gamma, gain)`` takes an image in :math:`[0, 1]` and clamps the result to
:math:`[0, 1]`; ``gamma > 1`` darkens the shadows and ``gamma < 1`` lightens them.

.. image:: _static/img/adjust_gamma.png

Convention:
    For ``0 < gamma < 1`` the derivative of ``input ** gamma`` at a black pixel (``input == 0``) is infinite; the
    gradient there is 0 instead. A graph captured by ``torch.jit.trace`` keeps the plain power, whose gradient
    there is not finite.

Args:
    input: image with shape ``(*, H, W)``.
    gamma: non-negative exponent, a float or a tensor with shape ``(B,)`` for one value per image.
    gain: non-negative multiplier, a float or a tensor with shape ``(B,)``.

Returns:
    Adjusted image with the shape of ``input``.

.. note::
   See a working example `here <https://www.kornia.org/tutorials/nbs/image_enhancement.html>`__.

.. note::
   The non-negativity check on ``gamma``/``gain`` reads a CPU value during the call and raises
   :exc:`~kornia.core.exceptions.AsyncCheckError`, a :exc:`RuntimeError`. A tensor on CUDA, or on MPS
   from torch 2.13, is checked with ``torch._assert_async`` instead and raises ``RuntimeError`` by the
   next synchronization; on CUDA that is a device-side assert.

See Also:
    - :class:`AdjustGamma`: the module form.
    - :func:`adjust_sigmoid`: an S-shaped curve around a cutoff.
    - :func:`adjust_log`: a logarithmic curve.

Example:
    >>> x = torch.ones(1, 1, 2, 2)
    >>> adjust_gamma(x, 1.0, 2.0)
    tensor([[[[1., 1.],
              [1., 1.]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y1 = torch.ones(2) * 1.0
    >>> y2 = torch.ones(2) * 2.0
    >>> adjust_gamma(x, y1, y2).shape
    torch.Size([2, 5, 3, 3])

Úadjust_gammaú&Input type is not a torch.Tensor. Got z:The gamma should be a positive float or torch.Tensor. Got z9The gain should be a positive float or torch.Tensor. Got r'   Úfr(   rW   ziGamma must be non-negative. Clamp it first: max(gamma, 0.0) for floats, gamma.clamp_min(0.0) for tensors.zfGain must be non-negative. Clamp it first: max(gain, 0.0) for floats, gain.clamp_min(0.0) for tensors.) rB   r;   r,   r<   Ú	TypeErrorr‚   rE   r-   r.   Ú
is_tracingr   r=   r@   rA   ÚndimÚfinfor+   ÚstructÚunpackÚpackr   rr   Ú
zeros_likers   Úpowr3   ÚtensorrX   r   r   ÚallrP   )rŽ   r�   r�   ÚlimitsÚblackÚpowers   &&&   r#   r’   r’   ª  sx  € ôd ˜% Ô0Ü�eœUŸ\™\×*Ò*ÜÐ@ÄÀeÃÀÐNÓOÐOä�eœe¤U§\¡\Ð2×3Ò3ÜÐTÔUYÐZ_ÓU`ÐTaÐbÓcÐcä�dœU¤E§L¡LÐ1×2Ò2ÜÐSÔTXÐY]ÓT^ÐS_Ð`ÓaÐaô
 �9‰9×!Ñ!×#Ó#ä—	‘	×$Ñ$×&Ó&Ü —N“NÜ˜5¤%×(Ó(Ü˜4¤×'Ó'Ø—‘¤§¡¬u¯}©}Ð=Õ=Ø—
‘
˜Q•ä—[’[ §¡Ó-ˆFØ�eÖ)˜vŸz™z×)Ñ)¨c°TÖ.G¸V¿Z¹Z×.GÑ.Gð
 —;‘;¤%§-¡-Ô/Ü"ŸMšM¨#¬v¯{ª{¸3ÀÓ/FÓGÈÕJ�EÜ!Ÿ=š=¨¬f¯kªk¸#¸tÓ.DÓEÀaÕH�DØ˜Ö$ ×$Ô);¸E×)BÒ)Bà! Q™J�EÜ!ŸKšKØœu×/Ò/°Ó6¼¿ºÀEÌ5Ï?Ê?Ð[`ÓKaÐchÓ8i×8mÑ8mÐnsÓ8tó‘Eð "ŸI™I eÓ,�EÜ'¨­Ó5Ð5ä�%œ×ÒÜ—’˜e˜W¨U¯\©\ÀÇÁÔMˆä�$œ×ÒÜ�|Š|˜T˜F¨5¯<©<¸u¿{¹{ÔKˆä" 5¯,©,¸¿¹ÓD€EÜ! $¯©°e·k±kÓB€DäØ	�#‰×ÑÓØsôô Ø	�‰×ÑÓØpôô
 ' uÓ4€EÜ% dÓ2€Dô ˜%× Ò ¬¯©×)=Ñ)=×)?Ò)?Ø˜!‘ ¨¡	Õ*¨e°a©iÕ8ˆÜ—’Ø”5×#Ò# EÓ*¬E¯IªI´e·k²kÀ%ÌÏÊÐY^ÓI_ÐafÓ6gÐinÓ,oó
‰ô —	’	˜%Ó'ˆô ˜D�LÓ)Ð)r%   c               ó(   € V ^8„  d   QhRRRRRRRR/# ©r   r   r   rI   rS   Úclip_outputr�   r    r!   )r"   s   "r#   r$   r$   -  s1   € ÷ Iñ I˜<ð IÐ1Kð IÐZ^ð IÐjvñ Ir%   c                ó  € \        V R4       \        V R4       \        \        V\        \
        P                  34      R4       \        V\        4      '       d.   \
        P                  ! WP                  V P                  R7      pM@\        V\
        P                  4      '       d!   \        WP                  V P                  4      p\        W4      p\        V^ 8¬  P                  4       R4       W,          pV'       d   \        V4      pV# )aM  Adjust the contrast of an image by multiplying its values by a factor.

``out = adjust_contrast(image, factor)`` multiplies an image in :math:`[0, 1]` by ``factor``: ``0`` gives black and
``1`` leaves it unchanged. To blend with the mean gray level instead, as PIL does, use
:func:`adjust_contrast_with_mean_subtraction`.

.. image:: _static/img/adjust_contrast.png

Convention:
    Multiplicative, as in Szeliski's book and OpenCV's ``convertScaleAbs(alpha=factor)``.

Args:
    image: image with shape ``(*, H, W)``.
    factor: non-negative multiplier, a float or a tensor with shape ``(B,)`` for one value per image.
    clip_output: clamp the result to :math:`[0, 1]`.

Returns:
    Adjusted image with the shape of ``image``.

.. note::
   See a working example `here <https://www.kornia.org/tutorials/nbs/image_enhancement.html>`__.

.. note::
   The non-negativity check on ``factor`` reads a CPU value during the call and raises
   :exc:`~kornia.core.exceptions.AsyncCheckError`, a :exc:`RuntimeError`. A tensor on CUDA, or on MPS
   from torch 2.13, is checked with ``torch._assert_async`` instead and raises ``RuntimeError`` by the
   next synchronization; on CUDA that is a device-side assert.

See Also:
    - :func:`adjust_contrast_with_mean_subtraction`: blends with the mean gray level instead of scaling.
    - :func:`adjust_brightness_accumulative`: the same product, with a negative factor accepted.
    - :func:`adjust_gamma`: a power curve, which maps :math:`[0, 1]` onto itself at ``gain=1``.
    - :class:`AdjustContrast`: the module form.

Example:
    >>> import torch
    >>> x = torch.ones(1, 1, 2, 2)
    >>> adjust_contrast(x, 0.5)
    tensor([[[[0.5000, 0.5000],
              [0.5000, 0.5000]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y = torch.tensor([0.65, 0.50])
    >>> adjust_contrast(x, y).shape
    torch.Size([2, 5, 3, 3])

Úadjust_contrastrU   rV   rW   zuContrast factor must be non-negative. Clamp it first: max(factor, 0.0) for floats, factor.clamp_min(0.0) for tensors.)rB   r   r   r;   rE   r,   r<   r]   rX   r=   r   rP   r   rŸ   r3   ©r   rI   r¥   Ú
img_adjusts   &&& r#   r§   r§   -  sÅ   € ô` ˜%Ð!2Ô3Ü˜5Ð"<Ô=Ü”˜F¤U¬E¯L©LÐ$9Ó:Ð<eÔfä�&œ%× Ò ä—’ ·±ÀEÇKÁKÔP‰Ü	�FœEŸL™L×	)Ò	)Ü'¨·±¸e¿k¹kÓJˆä'¨Ó6€FäØ	�1‰×ÑÓð	-ôð  %�~€J÷ Ü% jÓ1ˆ
àÐr%   c               ó$   € V ^8„  d   QhRRRRRR/# rR   r!   )r"   s   "r#   r$   r$   y  s#   € ÷ 9)ñ 9)°ð 9)ÐGað 9)Ðfrñ 9)r%   c                óÆ  € \        V R4       \        V R4       \        \        V\        \
        P                  34      R4       \        V\        4      '       d.   \
        P                  ! WP                  V P                  R7      pM@\        V\
        P                  4      '       d!   \        WP                  V P                  4      p\        W4      pV P                  ^8  d   V P                  RR4      pMFV P                  R,          ^8X  d   \        V 4      P                  RR4      pMV P                  RR4      pW,          V^V,
          ,          ,           p\!        V4      # )	a²  Adjust the contrast of an image by blending it with its mean gray level, as PIL does.

``out = adjust_contrast_with_mean_subtraction(image, factor)`` returns ``factor * image + (1 - factor) * mean``,
clamped to :math:`[0, 1]`, for an image in :math:`[0, 1]`. ``mean`` is the mean of the image's grayscale for 3
channels and of all its values otherwise; ``0`` gives a uniform image and ``1`` the input.

Args:
    image: image with shape ``(*, C, H, W)``.
    factor: weight of the image, a float or a tensor with shape ``(B,)`` for one value per image.

Returns:
    Adjusted image with the shape of ``image``.

See Also:
    - :func:`adjust_contrast`: multiplies the values, so the mean moves with them.
    - :func:`adjust_gamma`: a power curve, which maps :math:`[0, 1]` onto itself at ``gain=1``.
    - :class:`AdjustContrastWithMeanSubtraction`: the module form.

Example:
    >>> import torch
    >>> x = torch.ones(1, 1, 2, 2)
    >>> adjust_contrast_with_mean_subtraction(x, 0.5)
    tensor([[[[1., 1.],
              [1., 1.]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y = torch.tensor([0.65, 0.50])
    >>> adjust_contrast_with_mean_subtraction(x, y).shape
    torch.Size([2, 5, 3, 3])

Ú%adjust_contrast_with_mean_subtractionrU   rV   rW   T)éþÿÿÿéÿÿÿÿr\   )r\   r­   r®   )rB   r   r   r;   rE   r,   r<   r]   rX   r=   r   rP   r—   ÚmeanrO   r
   r   )r   rI   Úimg_meanr©   s   &&  r#   r¬   r¬   y  s   € ô@ ˜%Ð!HÔIÜ˜5Ð"<Ô=Ü”˜F¤U¬E¯L©LÐ$9Ó:Ð<eÔfä�&œ%× Ò ä—’ ·±ÀEÇKÁKÔP‰Ü	�FœEŸL™L×	)Ò	)Ü'¨·±¸e¿k¹kÓJˆä'¨Ó6€Fð
 ‡z�z�A„~Ø—:‘:˜h¨Ó-‰Ø	�‰�R�˜AÔ	Ü# EÓ*×/Ñ/°¸$Ó?‰à—:‘:˜l¨DÓ1ˆð  %�~°¸AÀ½JÕ0GÕG€Jä˜ZÓ(Ð(r%   c               ó(   € V ^8„  d   QhRRRRRRRR/# r¤   r!   )r"   s   "r#   r$   r$   µ  s,   € ÷ ;ñ ;Øð;Ø!;ð;ØJNð;àñ;r%   c                óÜ  € \        V R4       \        V R4       \        \        V\        \
        P                  34      R4       \        V\        4      '       d.   \
        P                  ! WP                  V P                  R7      pM@\        V\
        P                  4      '       d!   \        WP                  V P                  4      p\        W4      pW,           pV'       d   \        V4      pV# )aè  Adjust the brightness of an image by adding a factor to its values.

``out = adjust_brightness(image, factor)`` adds ``factor`` to every value of an image in :math:`[0, 1]`; ``0``
leaves it unchanged. PIL multiplies instead, which is :func:`adjust_brightness_accumulative`.

.. image:: _static/img/adjust_brightness.png

Args:
    image: image with shape ``(*, H, W)``.
    factor: value to add, a float or a tensor with shape ``(B,)`` for one value per image.
    clip_output: clamp the result to :math:`[0, 1]`.

Returns:
    Adjusted image with the shape of ``image``.

.. note::
   See a working example `here <https://www.kornia.org/tutorials/nbs/image_enhancement.html>`__.

See Also:
    - :func:`adjust_brightness_accumulative`: multiplies instead of adding.
    - :func:`adjust_gamma`: a power curve, which maps :math:`[0, 1]` onto itself at ``gain=1``.
    - :func:`shift_rgb`: adds a different shift to each color channel.
    - :class:`AdjustBrightness`: the module form.

Example:
    >>> x = torch.ones(1, 1, 2, 2)
    >>> adjust_brightness(x, 1.)
    tensor([[[[1., 1.],
              [1., 1.]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y = torch.tensor([0.25, 0.50])
    >>> adjust_brightness(x, y).shape
    torch.Size([2, 5, 3, 3])

Úadjust_brightnessrU   rV   rW   )rB   r   r   r;   rE   r,   r<   r]   rX   r=   r   rP   r3   r¨   s   &&& r#   r³   r³   µ  sª   € ôN ˜%Ð!4Ô5Ü˜5Ð"<Ô=Ü”˜F¤U¬E¯L©LÐ$9Ó:Ð<eÔfô �&œ%× Ò ä—’ ·±ÀEÇKÁKÔP‰Ü	�FœEŸL™L×	)Ò	)Ü'¨·±¸e¿k¹kÓJˆä'¨Ó6€Fð  %�~€J÷ Ü% jÓ1ˆ
àÐr%   c               ó(   € V ^8„  d   QhRRRRRRRR/# r¤   r!   )r"   s   "r#   r$   r$   ó  s,   € ÷ 5ñ 5Øð5Ø!;ð5ØJNð5àñ5r%   c                óÜ  € \        V R4       \        V R4       \        \        V\        \
        P                  34      R4       \        V\        4      '       d.   \
        P                  ! WP                  V P                  R7      pM@\        V\
        P                  4      '       d!   \        WP                  V P                  4      p\        W4      pW,          pV'       d   \        V4      pV# )a  Multiply an image by a factor to brighten or darken it, as PIL's ``ImageEnhance.Brightness`` does.

``out = adjust_brightness_accumulative(image, factor)`` multiplies an image in :math:`[0, 1]` by ``factor``: ``0``
gives black, ``1`` leaves it unchanged and a larger factor brightens it.

Args:
    image: image with shape ``(*, H, W)``.
    factor: multiplier, a float or a tensor with shape ``(B,)`` for one value per image.
    clip_output: clamp the result to :math:`[0, 1]`.

Returns:
    Adjusted image with the shape of ``image``.

See Also:
    - :func:`adjust_brightness`: adds the factor.
    - :func:`adjust_contrast`: the same product, but a negative factor raises.
    - :class:`AdjustBrightnessAccumulative`: the module form.

Example:
    >>> x = torch.ones(1, 1, 2, 2)
    >>> adjust_brightness_accumulative(x, 1.)
    tensor([[[[1., 1.],
              [1., 1.]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y = torch.tensor([0.25, 0.50])
    >>> adjust_brightness_accumulative(x, y).shape
    torch.Size([2, 5, 3, 3])

Úadjust_brightness_accumulativerU   rV   rW   )rB   r   r   r;   rE   r,   r<   r]   rX   r=   r   rP   r   r¨   s   &&& r#   r¶   r¶   ó  sª   € ôB ˜%Ð!AÔBÜ˜5Ð"<Ô=Ü”˜F¤U¬E¯L©LÐ$9Ó:Ð<eÔfô �&œ%× Ò ä—’ ·±ÀEÇKÁKÔP‰Ü	�FœEŸL™L×	)Ò	)Ü'¨·±¸e¿k¹kÓJˆä'¨Ó6€Fð  %�~€J÷ Ü& zÓ2ˆ
àÐr%   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r   r   ÚcutoffrE   r�   Úinvr�   r    r!   )r"   s   "r#   r$   r$   +  s1   € ÷ 10ñ 10˜,ð 10°ð 10À5ð 10ÐTXð 10Ðeqñ 10r%   c                ó¨  € \        V R4       \        V R4       V P                  \        P                  8H  ;'       d5    \        V\        \        34      ;'       d    \        V\        \        34      pV'       dÜ   V P                  4       p \        V4      \        \        V4      \        RV,
          4      4      ,          pVR8”  d�   W V,
          ,          pV^ 8¬  p\        P                  ! Wv) V4      P                  4       pV'       d   \        P                  ! Wx^V,
          4      M\        P                  ! V^V,
          V4      p	V	P                  4       # V'       d3   ^^^W!V ,
          ,          P                  4       ,           ,          ,
          M*^^W!V ,
          ,          P                  4       ,           ,          p	V'       d   V	P                  4       # T	# )aÛ  Apply sigmoid correction around a cutoff to an image.

``out = adjust_sigmoid(image, cutoff, gain, inv)`` maps an image in :math:`[0, 1]` through the curve :math:`1 / (1 +
e^{\text{gain}\,(\text{cutoff} - x)})`, which equals 0.5 at ``cutoff``. With ``inv=True`` it returns one minus that
curve.

Reference:
    [1]: Gustav J. Braun, "Image Lightness Rescaling Using Sigmoidal Contrast Enhancement Functions",
         http://markfairchild.org/PDFs/PAP07.pdf

Args:
    image: image with shape ``(*, H, W)``.
    cutoff: input value at which the curve equals 0.5.
    gain: steepness of the curve.
    inv: return one minus the curve.

Returns:
    Adjusted image with the shape of ``image``.

See Also:
    - :class:`AdjustSigmoid`: the module form.
    - :func:`adjust_gamma`: a power curve.
    - :func:`adjust_log`: a logarithmic curve.

Example:
    >>> x = torch.ones(1, 1, 2, 2)
    >>> adjust_sigmoid(x, gain=0)
    tensor([[[[0.5000, 0.5000],
              [0.5000, 0.5000]]]])

Úadjust_sigmoidrU   r(   g      0@)rB   r   r=   r,   r>   r;   r€   rE   Úabsr+   rr   ÚsigmoidÚhalfÚexp)
r   r¸   r�   r¹   ÚpromoteÚboundÚlogitsÚpositiveÚtailÚresults
   &&&&      r#   r»   r»   +  sU  € ô@ ˜%Ð!1Ô2Ü˜5Ð"<Ô=ð �k‰kœUŸ]™]Ñ*×rÐr¬z¸$ÄÄeÀÓ/M×rÐrÔR\Ð]cÔfiÔkpÐeqÓRr€GßØ—‘“ˆÜ�D“	œC¤ F£¬S°°vµÓ->Ó?Õ?ˆð �4Œ<Ø V�^Õ,ˆFØ ‘{ˆHÜ—;’;˜x¨°&Ó9×AÑAÓCˆDß>A”U—[’[ °°TµÔ:ÄuÇ{Â{ÐS[Ð]^ÐaeÕ]eÐgkÓGlˆFØ—;‘;“=Ð ß>AˆQ��a˜4¨E¥>Õ2×7Ñ7Ó9Õ9Õ:Ö:ÀqÈAÐQUÐbgÕYgÕQh×PmÑPmÓPoÕLoÕGp€Fß#ˆ6�;‰;‹=Ð/¨Ð/r%   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r   r   r�   rE   r¹   r�   r¥   r    r!   )r"   s   "r#   r$   r$   _  s1   € ÷ 'ñ '�lð '¨%ð '¸$ð 'ÐUYð 'Ðeqñ 'r%   c                óÖ   € \        V R4       \        V R4       V'       d   ^V ,          ^,
          V,          M^V ,           P                  4       V,          pV'       d   \        V4      pV# )aj  Apply logarithmic correction to an image, or exponential correction with ``inv``.

``out = adjust_log(image, gain, inv, clip_output)`` returns ``gain * log2(1 + image)`` for an image in
:math:`[0, 1]`, or ``gain * (2 ** image - 1)`` with ``inv=True``.

Reference:
    [1]: http://www.ece.ucsb.edu/Faculty/Manjunath/courses/ece178W03/EnhancePart1.pdf

Args:
    image: image with shape ``(*, H, W)``.
    gain: multiplier of the curve.
    inv: use the exponential curve.
    clip_output: clamp the result to :math:`[0, 1]`.

Returns:
    Adjusted image with the shape of ``image``.

See Also:
    - :class:`AdjustLog`: the module form.
    - :func:`adjust_gamma`: a power curve.
    - :func:`adjust_sigmoid`: an S-shaped curve around a cutoff.

Example:
    >>> x = torch.zeros(1, 1, 2, 2)
    >>> adjust_log(x, inv=True)
    tensor([[[[0., 0.],
              [0., 0.]]]])

Ú
adjust_logrU   )rB   r   Úlog2r   )r   r�   r¹   r¥   r©   s   &&&& r#   rÈ   rÈ   _  sV   € ô< ˜% Ô.Ü˜5Ð"<Ô=ç*-�!�U•(˜Q•, $Ö&°A¸µI×3CÑ3CÓ3EÈÕ3L€J÷ Ü& zÓ2ˆ
àÐr%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rŽ   r   Ú
thresholdsrS   r    r!   )r"   s   "r#   r$   r$   ‰  s#   € ÷ #?ñ #?�\ð #?Ð/Ið #?ÐT`ñ #?r%   c                óö  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V\
        \        P                  34      '       g   \        R\	        V4       24      h\        V\        P                  4      '       da   VP                  4       ^8X  dL   \        VP                  4      ^ 8w  d!   \        WP                  V P                  4      pVP                  R4      p\        V\        P                  4      '       dÆ   \        VP                  4      ^ 8w  d¬   V P                  ^ 4      \        V4      8X  d   \        VP                  4      ^8X  g!   \        RV P                  ^ 4       RV 24      h\        WP                  V P                  4      pVP                  R.^.V P                   ^,
          ,          ,           4      p\        P"                  ! W8  V RV ,
          4      # )aÃ  For each pixel in the image, select the pixel if the value is less than the threshold.

Otherwise, replace it with ``1.0 - value``.

Args:
    input: image or batched images to solarize.
    thresholds: solarize thresholds.
        If a float or one-element torch.Tensor, input will be solarized across the whole batch.
        If 1-d torch.Tensor, input will be solarized element-wise, len(thresholds) == len(input).

Returns:
    Solarized images.

r“   ú9The factor should be either a float or torch.Tensor. Got z*thresholds must be a 1-d vector of shape (ú,). Got r(   r!   r®   )r;   r,   r<   r•   r‚   rE   Únumelro   rO   r   rX   r=   ÚreshapeÚsizeÚAssertionErrorÚviewr—   rr   )rŽ   rË   s   &&r#   Ú	_solarizerÔ   ‰  sy  € ô �eœUŸ\™\×*Ò*ÜÐ@ÄÀeÃÀÐNÓOÐOä�j¤5¬%¯,©,Ð"7×8Ò8ÜÐSÔTXÐYcÓTdÐSeÐfÓgÐgä�*œeŸl™l×+Ò+°
×0@Ñ0@Ó0BÀaÔ0Gô ˆz×ÑÓ  AÔ%Ü/°
¿L¹LÈ%Ï+É+ÓVˆJØ×'Ñ'¨Ó+ˆ
Ü�*œeŸl™l×+Ò+´°J×4DÑ4DÓ0EÈÔ0JØ—
‘
˜1“¤ Z£Ô0´S¸×9IÑ9IÓ5JÈaÔ5OÜ Ð#MÈeÏjÉjÐYZËmÈ_Ð\dÐeoÐdpÐ!qÓrÐrô ,¨J¿¹ÀeÇkÁkÓRˆ
Ø—_‘_ b T¨Q¨C°5·:±:Àµ>Õ,BÕ%BÓCˆ
ä�;Š;�uÑ)¨5°#¸µ+Ó>Ð>r%   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rŽ   r   rË   rS   Ú	additionsz$Optional[Union[float, torch.Tensor]]r    r!   )r"   s   "r#   r$   r$   ¯  s6   € ÷ ^(ñ ^(Øð^(à*ð^(ð 4ð^(ð ñ	^(r%   c                ó<  € \        V R4       \        V \        P                  4      '       g   \	        R\        V 4       24      h\        V\        \        P                  34      '       g   \	        R\        V4       24      h\        V\        4      '       d-   \        P                  ! WP                  V P                  R7      pVEeL   \        V\        \        P                  34      '       g   \	        R\        V4       24      h\        V\        4      '       dZ   \        P                  ! RTu;8*  ;'       d    R8*  Mu RR7      p\        P                  ! W P                  V P                  R7      pMVR8*  VR8¬  ,          P                  4       p\        VR4       \        V\        P                  4      '       da   VP                  4       ^8X  dL   \        VP                  4      ^ 8w  d!   \!        W P                  V P                  4      pVP#                  R4      p\        V\        P                  4      '       dÆ   \        VP                  4      ^ 8w  d¬   V P%                  ^ 4      \        V4      8X  d   \        VP                  4      ^8X  g!   \'        R	V P%                  ^ 4       R
V 24      h\!        W P                  V P                  4      pVP)                  R.^.V P*                  ^,
          ,          ,           4      p\-        W,           4      p \/        W4      # )a%  Invert the pixels at or above a threshold, optionally after adding an amount to every pixel.

``out = solarize(input, thresholds, additions)`` replaces every value of an image in :math:`[0, 1]` that is at or
above ``thresholds`` by ``1 - value``. Without ``additions`` it equals PIL's ``ImageOps.solarize``.

.. image:: _static/img/solarize.png

Convention:
    ``additions`` is added to the whole image and the sum clamped to :math:`[0, 1]` before the comparison, so it can
    move a pixel across the threshold: with ``thresholds=0.5`` and ``additions=0.2``, ``[0.1, 0.4, 0.6, 0.9]`` comes
    back as ``[0.3, 0.4, 0.2, 0.0]``.

Args:
    input: image with shape ``(*, C, H, W)``.
    thresholds: threshold in :math:`[0, 1]`, a float or a tensor. One value, as a float or a one-element tensor,
        applies to the whole batch, and a tensor with shape ``(B,)`` gives one value per image.
    additions: amount in :math:`[-0.5, 0.5]`, endpoints included, with the shapes of ``thresholds``. ``None`` adds
        nothing.

Returns:
    The solarized image with shape ``(*, C, H, W)``.

.. note::
   The range check on ``additions`` reads a float or a CPU tensor during the call and raises
   :exc:`~kornia.core.exceptions.AsyncCheckError`, a :exc:`RuntimeError`, whatever the device of the image.
   A tensor on CUDA, or on MPS from torch 2.13, is checked with ``torch._assert_async`` instead and raises
   ``RuntimeError`` by the next synchronization; on CUDA that is a device-side assert.

See Also:
    - :class:`~kornia.augmentation.RandomSolarize`: draws ``thresholds`` and ``additions`` at random per image.
    - :func:`posterize`: reduces the bit depth instead of inverting.
    - :func:`invert`: inverts every pixel.

Example:
    >>> x = torch.rand(1, 4, 3, 3)
    >>> out = solarize(x, thresholds=0.5, additions=0.)
    >>> out.shape
    torch.Size([1, 4, 3, 3])

    >>> x = torch.rand(2, 4, 3, 3)
    >>> thresholds = torch.tensor([0.8, 0.5])
    >>> additions = torch.tensor([-0.25, 0.25])
    >>> solarize(x, thresholds, additions).shape
    torch.Size([2, 4, 3, 3])

Úsolarizer“   rÍ   rW   ç      à?Úcpu©rX   z˜The addition must be in the closed range [-0.5, 0.5]. Clamp it first: min(max(additions, -0.5), 0.5) for floats, additions.clamp(-0.5, 0.5) for tensors.z)additions must be a 1-d vector of shape (rÎ   g      à¿r!   r®   )rB   r;   r,   r<   r•   r‚   rE   r]   rX   r=   rž   rŸ   r   rÏ   ro   rO   r   rÐ   rÑ   rÒ   rÓ   r—   r   rÔ   )rŽ   rË   rÖ   Úin_ranges   &&& r#   rØ   rØ   ¯  sP  € ôf ˜% Ô,Ü�eœUŸ\™\×*Ò*ÜÐ@ÄÀeÃÀÐNÓOÐOä�j¤5¬%¯,©,Ð"7×8Ò8ÜÐSÔTXÐYcÓTdÐSeÐfÓgÐgä�*œe×$Ò$Ü—_’_ Z¿¹ÈEÏKÉKÔXˆ
àÓÜ˜)¤e¬U¯\©\Ð%:×;Ò;ÜÐWÔX\Ð]fÓXgÐWhÐiÓjÐjä�i¤×'Ò'ô —|’| D¨I×$<Ô$<¸Ô$<ÀUÔKˆHÜŸš¨	¿,¹,ÈeÏkÉkÔZ‰Ià" cÑ)¨i¸4Ñ.?Õ@×EÑEÓGˆHäØðBô	
ô �i¤§¡×.Ò.°9·?±?Ó3DÈÔ3Iô �9—?‘?Ó# qÔ(Ü2°9¿l¹lÈEÏKÉKÓX�	Ø!×)Ñ)¨"Ó-ˆIÜ�i¤§¡×.Ò.´3°y·±Ó3GÈ1Ô3LØ—J‘J˜q“M¤S¨£^Ô3¼¸I¿O¹OÓ8LÐPQÔ8QÜ$Ð'PÐQV×Q[ÑQ[Ð\]ÓQ^ÐP_Ð_gÐhqÐgrÐ%sÓtÐtô /¨y¿,¹,ÈÏÉÓTˆIØ!Ÿ™¨ t¨q¨c°U·Z±ZÀ!µ^Õ.DÕ'DÓEˆIÜ! %Õ"3Ó4ˆä�UÓ'Ð'r%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rŽ   r   Úspatial_dimsr€   r    r!   )r"   s   "r#   r$   r$     s&   € ÷ Fñ F Lð FÀð FÈñ Fr%   c                ó  € \        V \        P                  4      '       g   \        R\	        V 4       24      h^ V P
                  V^,           ) R 9   d   \        RV P
                   R24      hV^8X  d   \        V 4      # \        V 4      # )zTBatch image or volume inputs without accepting empty channels or spatial dimensions.r“   Nz;Input channel and spatial dimensions must be non-zero. Got rK   )	r;   r,   r<   r•   r‚   rO   rM   r   r   )rŽ   rÞ   s   &&r#   Ú_prepare_intensity_inputrà     s   € ä�eœUŸ\™\×*Ò*ÜÐ@ÄÀeÃÀÐNÓOÐOØˆE�K‰K˜,¨Õ*Ð+Ð-Ð.Ô.ÜÐVÐW\×WbÑWbÐVcÐcdÐeÓfÐfØ+¨qÔ0Œ9�UÓÐE´h¸u³oÐEr%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rŽ   r   ÚbitszUnion[int, torch.Tensor]r    r!   )r"   s   "r#   r$   r$     s'   € ÷ p=ñ p=�\ð p=Ð)Að p=Àlñ p=r%   c           
     ó   aaa€ \        V R4       \        V \        P                  4      '       g   \	        R\        V 4       24      hV P                  p\        V ^4      p \        V\        \        P                  34      '       g   \	        R\        V4       24      h\        V\        4      '       dO   \        P                  ! ^ Tu;8*  ;'       d    ^8*  Mu RR7      p\        P                  ! WP                  R7      pMV^ 8¬  V^8*  ,          P                  4       p\        VR4       VP                  V P                  R7      p\        V P                   4      oR V3R lloR	 V3R
 lloR VV3R llp\#        VP                  4      ^ 8X  g+   \#        VP                  4      ^8X  d(   \#        V4      ^8X  d   V! W4      P%                  V4      # \#        VP                  4      ^8X  d    VP                  ^ ,          V P                  ^ ,          8w  d5   \'        RVP                  ^ ,           RV P                  ^ ,           R24      hV! WP(                  ! R.^.V P*                  ^,
          ,          O5!  4      P%                  V4      # VP                  V P                  R\#        VP                  4       8w  d=   \'        RVP                   RV P                  R\#        VP                  4        R24      hVP(                  ! . VP                  O^.V P*                  VP*                  ,
          ,          O5!  pV! W4      P%                  V4      # )aÿ  Keep only the highest ``bits`` of the 8 bits of each color level, as PIL's ``ImageOps.posterize`` does.

``out = posterize(input, bits)`` quantizes an image in :math:`[0, 1]` to its ``bits`` highest bits per value:
``bits=8`` returns the input and ``bits=0`` gives black.

.. image:: _static/img/posterize.png

Convention:
    - Each value is read at its 8-bit level ``(x * 255).long()``, with the 255 raised by four float32 epsilons,
      relative, in float32 and float64, so ``k / 255`` reads level ``k`` even when its division was rounded a unit
      low, as dividing by 255 on CUDA does.
    - The gradient is zero, except for ``bits=8``, which returns the input.
    - Empty leading dimensions are supported; channels and spatial dimensions must be non-empty.

Args:
    input: image with shape ``(*, C, H, W)``.
    bits: number of high bits to keep, in ``[0, 8]``. An integer or a one-element tensor applies to the whole batch.
        A tensor with shape ``(B,)`` gives one value per image, one with shape ``(B, C)`` one per channel, and a
        longer prefix of ``(B, C, H, W)`` element-wise values, where ``B`` is the product of the leading dimensions
        of ``input``.

Returns:
    Image with the shape of ``input``.

Raises:
    AssertionError: if a ``bits`` tensor does not match the leading dimensions of ``input``.
    AsyncCheckError: if ``bits`` is outside ``[0, 8]``; it is a :exc:`ValueError` and a :exc:`RuntimeError`. A
        ``bits`` tensor on CUDA, or on MPS from torch 2.13, is checked with ``torch._assert_async`` instead and
        raises ``RuntimeError`` by the next synchronization.

See Also:
    - :class:`~kornia.augmentation.RandomPosterize`: draws ``bits`` at random per image.
    - :func:`solarize`: inverts pixels above a threshold instead.

Example:
    >>> x = torch.rand(1, 6, 3, 3)
    >>> out = posterize(x, bits=8)
    >>> torch.testing.assert_close(x, out)

    >>> x = torch.rand(2, 6, 3, 3)
    >>> bits = torch.tensor([4, 2])
    >>> posterize(x, bits).shape
    torch.Size([2, 6, 3, 3])

Ú	posterizer“   z-bits type is not an int or torch.Tensor. Got rÚ   rÛ   z(bits must be in the closed range [0, 8].c               ó$   € V ^8„  d   QhRRRRRR/# ©r   rŽ   r   Úshiftr    r!   )r"   s   "r#   r$   Úposterize.<locals>.__annotate__f  s&   € ÷ Vñ V˜<ð V°ð VÀñ Vr%   c                ó¬   <€ V S,          P                  \        P                  4      ^V,          ,          P                  V P                  4      R,          # ©r   ç     ào@©rt   r,   Úuint8r=   ©rŽ   rç   Úscales   &&€r#   Ú_left_shiftÚposterize.<locals>._left_shiftf  s:   ø€ Ø˜•×"Ñ"¤5§;¡;Ó/°1°eµ8Õ<×@Ñ@ÀÇÁÓMÐPUÕUÐUr%   c               ó$   € V ^8„  d   QhRRRRRR/# ræ   r!   )r"   s   "r#   r$   rè   i  s&   € ÷ Tñ T˜Lð T°ð TÀ,ñ Tr%   c                ó¬   <€ V S,          P                  \        P                  4      ^V,          P                  V P                  4      ,          R,          # rê   rì   rî   s   &&€r#   Ú_right_shiftÚposterize.<locals>._right_shifti  s7   ø€ Ø˜•×!Ñ!¤%§+¡+Ó.°!°Uµ(·±¸u¿{¹{Ó1KÕKÈeÕSÐSr%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rŽ   r   râ   r    r!   )r"   s   "r#   r$   rè   l  s!   € ÷ 2ñ 2˜lð 2°,ð 2À<ñ 2r%   c                óÆ   <€ ^V,
          pS! S! W4      V4      p\         P                  ! V^ 8H  \         P                  ! V 4      V4      p\         P                  ! V^8H  W4      # )é   )r,   rr   rœ   )rŽ   râ   rç   Úshiftedre   rð   rô   s   &&   €€r#   Ú_posterize_oneÚ!posterize.<locals>._posterize_onel  sU   ø€ ð �D•ˆÙ™l¨5Ó8¸%Ó@ˆÜ�kŠk˜$ !™)¤U×%5Ò%5°eÓ%<¸gÓFˆÜ�{Š{˜4 1™9 eÓ1Ð1r%   z5Batch size must be equal between bits and input. Got z, rK   Nz<Batch and channel must be equal between bits and input. Got r®   )rB   r;   r,   r<   r•   r‚   rO   rà   r€   rž   r]   rX   rŸ   r   rt   rG   r=   ro   rÐ   rÒ   rÓ   r—   )	rŽ   râ   Úinput_shaperÜ   rú   Ú_bitsrð   rô   rï   s	   &&    @@@r#   rä   rä     sœ  ú€ ô\ ˜% Ô-Ü�eœUŸ\™\×*Ò*ÜÐ@ÄÀeÃÀÐNÓOÐOà—+‘+€KÜ$ U¨AÓ.€Eä�dœS¤%§,¡,Ð/×0Ò0ÜÐGÌÈTË
À|ÐTÓUÐUä�$œ×ÒÜ—<’<  T§¤¨Q¤°uÔ=ˆÜ�Š˜t¯L©LÔ9‰à˜Q‘Y 4¨1¡9Õ-×2Ñ2Ó4ˆÜ�ÐEÔFð
 �7‰7˜%Ÿ,™,ˆ7Ó'€Dô ˜Ÿ™Ó%€E÷Vð V÷Tð T÷2ñ 2ô ˆ4�:‰:ƒ˜!Ô¤ D§J¡J£°1Ô 4¼¸T»Àa¼Ù˜eÓ*×2Ñ2°;Ó?Ð?ä
ˆ4�:‰:ƒ˜!ÔØ�:‰:�a�=˜EŸK™K¨�NÔ*Ü ØGÈÏ
É
ÐSTÍÀÐVXÐY^×YdÑYdÐefÕYgÐXhÐhiÐjóð ñ ˜e§Y¢Y¨rÐ%M°a°S¸E¿J¹JÈ½NÕ5KÓ%MÓN×VÑVÐWbÓcÐcà‡z�z�U—[‘[Ð!2¤3 t§z¡z£?Ð3Ô3ÜðØ—:‘:�,˜b §¡Ð->¬s°4·:±:«Ð!?Ð @ÀðCó
ð 	
ð
 �IŠIÐE�t—z‘zÐE a S¨E¯J©J¸¿¹Õ,BÕ%CÓE€EÙ˜%Ó'×/Ñ/°Ó<Ð<r%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rŽ   r   rI   rS   r    r!   )r"   s   "r#   r$   r$   Œ  s,   € ÷ SVñ SV�\ð SVÐ+Eð SVÈ,ñ SVr%   c           	     ó   € \        V R4       \        V ^4      pV P                  pTp \        V\        \
        34      '       d#   \        WP                  V P                  R7      pMm\        V\        P                  4      '       g.   \        P                  ! WP                  V P                  R7      pM \        WP                  V P                  4      p\        VP                  4       4      ^ 8w  d†   VP                  \        P                  ! V P                  ^ 4      .4      8w  dQ   VP                  \        P                  ! ^.4      8w  d+   \!        RV P                  ^ 4       RVP                   24      h\        . RO. R	O. RO.V P                  V P                  R7      P#                  ^^^^4      P%                  V P                  ^4      ^^^4      ^,          p\        P&                  P(                  P+                  WR^V P                  ^4      R7      p\-        V4      p\        P.                  ! V4      p\0        P2                  ! V. R
O4      p\0        P2                  ! V. R
O4      p\        P4                  ! V^8H  W€4      p	\        VP                  4       4      ^ 8w  d2   VP"                  ! R.^.V	P7                  4       ^,
          ,          O5!  p\-        W�V	,
          V,          ,           4      P9                  V4      # )aÞ  Blend an image with a smoothed copy to sharpen or blur it, as PIL's ``ImageEnhance.Sharpness`` does.

``out = sharpness(input, factor)`` blends a ``(*, C, H, W)`` image in :math:`[0, 1]` with a copy smoothed by a 3x3
kernel: ``0`` returns the smoothed image, ``1`` the input, and a factor above ``1`` sharpens. The result is clamped
to :math:`[0, 1]`.

.. image:: _static/img/sharpness.png

Convention:
    - The smoothing kernel is :math:`\tfrac{1}{13}[[1, 1, 1], [1, 5, 1], [1, 1, 1]]`, and the one-pixel border keeps
      the input's values.
    - Empty leading dimensions are supported; channels must be non-empty and both spatial dimensions at least 3
      pixels.

Args:
    input: image with shape ``(*, C, H, W)``.
    factor: blend weight of the input against the smoothed copy. A float or a 0-d tensor applies to the whole batch,
        and a tensor with shape ``(B,)`` gives one value per image, where ``B`` is the product of the leading
        dimensions of ``input``. A ``(1,)`` tensor applies to every image. Negative factors are accepted and
        extrapolate past the smoothed image.

Returns:
    Sharpened image with the shape of ``input``.

See Also:
    - :func:`~kornia.filters.unsharp_mask`: adds back the detail a Gaussian blur removes, with a fixed gain and no
      clamp.
    - :class:`~kornia.augmentation.RandomSharpness`: draws ``factor`` at random per image.

Example:
    >>> x = torch.rand(1, 1, 5, 5)
    >>> sharpness(x, 0.5).shape
    torch.Size([1, 1, 5, 5])

Ú	sharpnessrW   zYInput batch size shall match with factor size if factor is not a 0-dim torch.Tensor. Got z and )r=   rX   N)ÚbiasÚstrideÚgroups)é   r  r  )r  é   r  )r  r  r  r  r®   )rB   rà   rO   r;   r€   rE   r   rX   r=   r,   r<   r]   r   ro   rÑ   ÚSizerÒ   rÓ   Úrepeatr   Ú
functionalÚconv2dr   rs   ÚFÚpadrr   rL   rÐ   )
rŽ   rI   Úbatched_inputrü   ÚkernelÚ
degenerateÚmaskÚpadded_maskÚpadded_degeneraterÅ   s
   &&        r#   r   r   Œ  s@  € ôH ˜% Ô-Ü,¨U°AÓ6€MØ—+‘+€KØ€Eä�&œ3¤˜,×'Ò'ô ! ·±ÀEÇKÁKÔP‰Ü˜¤§¡×-Ò-Ü—’ ·±ÀEÇKÁKÔP‰ô (¨·±¸e¿k¹kÓJˆä
ˆ6�;‰;‹=Ó˜QÔ 6§<¡<´5·:²:¸u¿z¹zÈ!»}¸oÓ3NÔ#NÐSY×S_ÑS_Ôch×cmÒcmÐopÐnqÓcrÔSrÜðØ—:‘:˜a“=�/  v§|¡| nð6ó
ð 	
ô 	š¢IªyÐ9ÀÇÁÐUZ×UaÑUaÔbß	‰ˆa��A�qÓ	ß	‰�—
‘
˜1“˜q ! QÓ	'Ø
õ	ð ô —‘×$Ñ$×+Ñ+¨EÀÈQÐW\×WaÑWaÐbcÓWdÐ+Óe€JÜ" :Ó.€Jô �?Š?˜:Ó&€DÜ—%’%˜šlÓ+€KÜŸš˜jª,Ó7ÐÜ�[Š[˜¨Ñ)Ð+<ÓD€Fô ˆ6�;‰;‹=Ó˜QÔØ—’˜RÐ= A 3¨&¯*©*«,¸Õ*:Õ#;Ó=ˆÜ˜V¨v¥~¸Õ&?Õ?Ó@×HÑHÈÓUÐUr%   c               ó    € V ^8„  d   QhRRRR/# ©r   rŽ   r   r    r!   )r"   s   "r#   r$   r$   â  s"   € ÷ BCñ BC ,ð BC°<ñ BCr%   c           	     óî  € V P                   pV^ ,          V^,          ,          pV P                  ^ ^4      P                  ^4      pV\        VP                  4      ,          p\	        VR8„  VR8  ,          P                  4       RRR7       \        VP                  4      pVP                  4       p\        P                  ! VRV P                  VR7      pVP                  ^V\        P                  ! WER7      4       VP                  ^4      p\        P                  ! RV P                  R7      p	\        P                  ! V^ 8„  V	\        P                   ! V	4      4      P#                  ^4      p
VP%                  ^V
P'                  ^4      4      P)                  ^4      p\        P*                  ! W‹,
          ^ÿR	R
7      pVP'                  ^4      p\        P*                  ! V^R	R
7      P'                  ^4      p\        P*                  ! VP-                  ^4      V,           VP/                  ^R7      R	R
7      p\        P0                  ! \        P                  ! V^V P                  VP                  R7      VRRR13,          .^4      p\        P.                  ! V^ ^ÿ4      P3                  VP                  4      pVP%                  ^V4      R,          p\        P                  ! V^ 8H  VV4      P5                  V4      # )a½  Vectorized histogram equalization over the leading ``(B, C)`` planes.

Computes all per-plane histograms/LUTs in a single batched pass instead of a Python loop of
``B * C`` serial calls. Each pixel is counted in the LUT entry it reads, its 8-bit level
``(x * _level_scale(x.dtype)).long()`` computed in the input dtype, so a plane whose LUT step is not 0 comes
out as ``PIL.ImageOps.equalize`` of those levels while the counts and their running sums are exact (a plane
of up to ``2**24`` pixels in float32); a plane whose step is 0 is returned as it is.

Args:
    input: image tensor shaped ``(B, C, *spatial)`` with values in ``[0, 1]``.

Returns:
    The equalized tensor, same shape as ``input``.
g      p@zyequalize expects input values in [0, 1]. Scale the image into that range first, for example image / 255.0 for 8-bit data.T)Úguardé   rW   )r=   rÛ   Útrunc)Úrounding_mode)r*   :NNNNrë   g      ð¿r®   )rO   ÚflattenrG   r=   r   rŸ   r   Úlongr,   ÚzerosrX   Úscatter_add_rs   ÚsumÚarangerr   rœ   rp   ÚgatherÚ	unsqueezeÚsqueezeÚdivÚcumsumr_   r`   rt   rÐ   )rŽ   rO   ÚnÚflatÚlevelsÚcount_dtypeÚindexÚhistoÚtotalÚarÚlast_idxÚ
last_countÚstepÚstep_colÚ
step_truncÚlutrÅ   s   &                r#   Ú_scale_channel_batchedr2  â  sD  € ð �K‰K€EØˆa��5˜•8Õ€AØ�=‰=˜˜AÓ×&Ñ& qÓ)€Dð ”L §¡Ó,Õ,€Fô Ø
�4‰-˜F U™NÕ	+×0Ñ0Ó2ð	4àõ	ô 3°4·:±:Ó>€Kð �K‰K‹M€EÜ�KŠK˜˜3 u§|¡|¸;ÔG€EØ	×Ñ�q˜%¤§¢°Ô!KÔLð �I‰I�a‹L€EÜ	�Š�c %§,¡,Ô	/€BÜ�{Š{˜5 1™9 b¬%×*:Ò*:¸2Ó*>Ó?×DÑDÀQÓG€HØ—‘˜a ×!3Ñ!3°AÓ!6Ó7×?Ñ?ÀÓB€JÜ�9Š9�UÕ'¨¸GÔD€Dð �~‰~˜aÓ €HÜ—’˜4 °'Ô:×DÑDÀQÓG€JÜ
�)Š)�E—L‘L “O jÕ0°(·.±.ÀQ°.Ó2GÐW^Ô
_€CÜ
�)Š)”U—[’[  A¨e¯l©lÀ#Ç)Á)ÔLÈcÐRSÐUXÐVXÐUXÐRXÍkÐZÐ\]Ó
^€Cä
�+Š+�c˜1˜cÓ
"×
%Ñ
% d§j¡jÓ
1€Cð �Z‰Z˜˜5Ó! EÕ)€FÜ�;Š;�x 1‘} d¨FÓ3×;Ñ;¸EÓBÐBr%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   r$   '  s   € ÷ 0[ñ 0[�Lð 0[ \ñ 0[r%   c                óv   € \        V R4       \        \        V ^4      4      P                  V P                  4      # )a…	  Equalize the histogram of each channel of an image, as PIL's ``ImageOps.equalize`` does.

``out = equalize(input)`` equalizes each channel of each image in a ``(*, C, H, W)`` batch in :math:`[0, 1]` on its
own.

.. image:: _static/img/equalize.png

Convention:
    - Each pixel is counted in the lookup-table entry it reads, its 8-bit level ``(x * 255).long()`` in the input
      dtype, so a float32 or float64 image gives ``PIL.ImageOps.equalize`` of those levels. In float32 and float64
      the 255 is raised by four float32 epsilons, relative (``2**-21``), so ``k / 255`` reads level ``k`` even when
      its division was rounded a unit low. Dividing by 255 on CUDA leaves 24 of the 256 float64 levels a unit low.
      A continuous value moves up a level only within that margin below a level boundary.
    - The lookup step is the pixel count minus the count at the highest occupied level, integer-divided by 255. A
      channel whose step is 0, which includes every channel of up to 255 pixels, is returned unchanged.
    - A float32 image counts in float32, which is exact while a channel holds at most ``2**24`` pixels (a 4096 by
      4096 image).
    - Empty leading dimensions are supported; channels and spatial dimensions must be non-empty.

Args:
    input: image with shape ``(*, C, H, W)``.

Returns:
    Equalized image with shape ``(*, C, H, W)``.

.. note::
   An integer or boolean image raises :exc:`~kornia.core.exceptions.TypeCheckError` (a :exc:`TypeError`); convert
   8-bit data with ``image.float() / 255`` first. Values the 256-bin lookup cannot index, those whose level
   before truncation lies outside ``(-1, 256)``, raise a ``RuntimeError`` naming the range, during the call for a
   CPU image, even when checks are disabled, since the check keeps the lookup in bounds. On CUDA, and on MPS from
   torch ``2.13``, the check is ``torch._assert_async`` and raises by the next synchronization; on an older MPS
   release the condition is read on the host instead, one device sync per call, and is skipped there under
   ``torch.compile``.

See Also:
    - :func:`equalize3d`: the volume twin, with one histogram per channel volume.
    - :func:`equalize_clahe`: equalizes each tile of a grid with a clipped histogram.
    - :class:`~kornia.augmentation.RandomEqualize`: applies it at random per image.

Example:
    >>> x = torch.rand(1, 2, 3, 3)
    >>> equalize(x).shape
    torch.Size([1, 2, 3, 3])

Úequalize©rB   r2  rà   rÐ   rO   ©rŽ   s   &r#   r5  r5  '  s1   € ô\ ˜% Ô,ä!Ô":¸5À!Ó"DÓE×MÑMÈeÏkÉkÓZÐZr%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   r$   Z  s   € ÷ [ñ [�lð [ |ñ [r%   c                óv   € \        V R4       \        \        V ^4      4      P                  V P                  4      # )aõ  Equalize the histogram of each channel of a 3D volume.

``out = equalize3d(input)`` equalizes each channel of each volume in a ``(*, C, D, H, W)`` batch in :math:`[0, 1]`
from one histogram over its whole ``(D, H, W)`` volume.

Convention:
    - Each voxel is read at its 8-bit level as :func:`equalize` reads a pixel.
    - The lookup step and the unchanged-channel rule are those of :func:`equalize`, counted over the voxels of a
      channel volume.
    - Empty leading dimensions are supported; channels and spatial dimensions must be non-empty.

Args:
    input: volume with shape ``(*, C, D, H, W)``.

Returns:
    Equalized volume with the shape of ``input``.

.. note::
   An integer or boolean volume raises :exc:`~kornia.core.exceptions.TypeCheckError`, and a value whose level
   before truncation lies outside ``(-1, 256)`` raises a ``RuntimeError``, as for :func:`equalize`, with the same
   device behavior.

See Also:
    - :func:`equalize`: the image twin, with one histogram per channel plane.

Ú
equalize3dr6  r7  s   &r#   r:  r:  Z  s0   € ô6 ˜% Ô.ä!Ô":¸5À!Ó"DÓE×MÑMÈeÏkÉkÓZÐZr%   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   Úmax_valúOptional[torch.Tensor]r    r!   )r"   s   "r#   r$   r$   z  s"   € ÷ )&ñ )&�,ð )&Ð)?ð )&È<ñ )&r%   c                óF  € \        V \        P                  4      '       g   \        R\	        V 4       24      hVf   \        P
                  ! R4      MTp\        V\        P                  4      '       g   \        R\	        V4       24      hVP                  V 4      V ,
          # )aÌ  Invert an image by subtracting it from its maximum value.

``out = invert(image, max_val)`` returns ``max_val - image``.

.. image:: _static/img/invert.png

Args:
    image: tensor of any shape.
    max_val: tensor the image is subtracted from, broadcastable to ``image``. The default is ``1``, so for a
        ``uint8`` image pass ``torch.tensor(255)``.

Returns:
    Inverted tensor with the shape of ``image``.

See Also:
    - :class:`Invert`: the module form.
    - :func:`solarize`: inverts only the pixels at or above a threshold.
    - :class:`~kornia.augmentation.RandomInvert`: inverts at random per image.

Example:
    >>> img = torch.rand(1, 2, 4, 4)
    >>> invert(img).shape
    torch.Size([1, 2, 4, 4])

    >>> img = 255. * torch.rand(1, 2, 3, 4, 4)
    >>> invert(img, torch.as_tensor(255.)).shape
    torch.Size([1, 2, 3, 4, 4])

    >>> img = torch.rand(1, 3, 4, 4)
    >>> invert(img, torch.as_tensor([[[[1.]]]])).shape
    torch.Size([1, 3, 4, 4])

z"Input is not a torch.Tensor. Got: r(   z$max_val is not a torch.Tensor. Got: )r;   r,   r<   rÒ   r‚   rž   rt   )r   r<  Ú_max_vals   && r#   Úinvertr@  z  s~   € ôD �eœUŸ\™\×*Ò*ÜÐAÄ$ÀuÃ+ÀÐOÓPÐPà$+¢OŒu�|Š|˜CÔ ¸€HÜ�h¤§¡×-Ò-ÜÐCÄDÈÃNÐCSÐTÓUÐUà�;‰;�uÓ Õ%Ð%r%   c                  ód   a € ] tR tRt$ Rt. ROtR]R&   . ROtR]R&   R V 3R lltR R	 lt	R
t
V ;t# )ÚAdjustSaturationi¦  aF  Adjust the saturation of an RGB image by scaling its HSV saturation (module form).

``adjust = AdjustSaturation(saturation_factor)`` stores the factor, and ``out = adjust(image)`` is
:func:`adjust_saturation` with it.

Args:
    saturation_factor: saturation multiplier, a float or a tensor with shape ``(B,)``.

Shape:
    - Input: ``(*, 3, H, W)``
    - Output: ``(*, 3, H, W)``

See Also:
    - :func:`adjust_saturation`: the one-call form.
    - :class:`AdjustSaturationWithGraySubtraction`: blends with the gray image instead of scaling the HSV
      saturation.

Example:
    >>> x = torch.ones(1, 3, 3, 3)
    >>> AdjustSaturation(2.)(x)
    tensor([[[[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]],
    <BLANKLINE>
             [[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]],
    <BLANKLINE>
             [[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]]]])

    >>> x = torch.ones(2, 3, 3, 3)
    >>> y = torch.ones(2)
    >>> out = AdjustSaturation(y)(x)
    >>> torch.nn.functional.mse_loss(x, out)
    tensor(0.)

úClassVar[list[int]]ÚONNX_DEFAULT_INPUTSHAPEÚONNX_DEFAULT_OUTPUTSHAPEc               ó    € V ^8„  d   QhRRRR/# ©r   Úsaturation_factorrS   r    r7   r!   )r"   s   "r#   r$   ÚAdjustSaturation.__annotate__Ò  ó   € ÷ Oñ OÐ*Dð OÈñ Or%   c                	ó0   <€ \         SV `  4        Wn        R # ©N©ÚsuperÚ__init__rH  ©ÚselfrH  Ú	__class__s   &&€r#   rO  ÚAdjustSaturation.__init__Ò  ó   ø€ Ü‰ÑÔØ=NÖr%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   rI  Ö  ó   € ÷ 	@ñ 	@˜\ð 	@¨lñ 	@r%   c                ó,   € \        WP                  4      # )zÎAdjust RGB saturation using the module's configured factor.

Args:
    input: Input RGB tensor, typically shaped ``(*, 3, H, W)``.

Returns:
    Saturation-adjusted tensor with the same shape as ``input``.
)r}   rH  ©rQ  rŽ   s   &&r#   ÚforwardÚAdjustSaturation.forwardÖ  ó   € ô ! ×(>Ñ(>Ó?Ð?r%   ©rH  ©r®   é   r®   r®   ©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rD  Ú__annotations__rE  rO  rY  Ú__static_attributes__Ú__classcell__©rR  s   @r#   rB  rB  ¦  s<   ø‡ ñ&òP 4CÐÐ0ÓBÚ4CÐÐ1ÓC÷Oð O÷	@ó 	@r%   rB  c                  ód   a € ] tR tRt$ Rt. ROtR]R&   . ROtR]R&   R V 3R lltR R	 lt	R
t
V ;t# )Ú#AdjustSaturationWithGraySubtractioniâ  a’  Adjust the saturation of an RGB image by blending it with its grayscale version (module form).

``adjust = AdjustSaturationWithGraySubtraction(saturation_factor)`` stores the factor, and ``out = adjust(image)``
is :func:`adjust_saturation_with_gray_subtraction` with it.

Args:
    saturation_factor: weight of the image, a float or a tensor with shape ``(B,)``.

Shape:
    - Input: ``(*, 3, H, W)`` or ``(*, 1, H, W)``
    - Output: same as the input

See Also:
    - :func:`adjust_saturation_with_gray_subtraction`: the one-call form.
    - :class:`AdjustSaturation`: scales the HSV saturation instead.

Example:
    >>> x = torch.ones(1, 3, 3, 3)
    >>> AdjustSaturationWithGraySubtraction(2.)(x)
    tensor([[[[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]],
    <BLANKLINE>
             [[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]],
    <BLANKLINE>
             [[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]]]])

    >>> x = torch.ones(2, 3, 3, 3)
    >>> y = torch.ones(2)
    >>> out = AdjustSaturationWithGraySubtraction(y)(x)
    >>> torch.nn.functional.mse_loss(x, out)
    tensor(0.)

rC  rD  rE  c               ó    € V ^8„  d   QhRRRR/# rG  r!   )r"   s   "r#   r$   Ú0AdjustSaturationWithGraySubtraction.__annotate__  rJ  r%   c                	ó0   <€ \         SV `  4        Wn        R # rL  rM  rP  s   &&€r#   rO  Ú,AdjustSaturationWithGraySubtraction.__init__  rT  r%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   rl    s   € ÷ Vñ V˜\ð V¨lñ Vr%   c                ó,   € \        WP                  4      # )aD  Adjust saturation using gray-subtraction interpolation behavior.

This forwards to :func:`adjust_saturation_with_gray_subtraction`,
which follows PIL-like saturation behavior.

Args:
    input: Input image tensor, typically shaped ``(*, 3, H, W)``.

Returns:
    Saturation-adjusted tensor with the same shape as ``input``.
)ri   rH  rX  s   &&r#   rY  Ú+AdjustSaturationWithGraySubtraction.forward  s   € ô 7°u×>TÑ>TÓUÐUr%   r\  r]  r_  rh  s   @r#   rj  rj  â  s<   ø‡ ñ%òN 4CÐÐ0ÓBÚ4CÐÐ1ÓC÷Oð O÷Vó Vr%   rj  c                  ód   a € ] tR tRt$ Rt. ROtR]R&   . ROtR]R&   R V 3R lltR R	 lt	R
t
V ;t# )Ú	AdjustHuei   a¾  Shift the hue of an RGB image by an angle in radians (module form).

``adjust = AdjustHue(hue_factor)`` stores the angle, and ``out = adjust(image)`` is :func:`adjust_hue` with it.

Convention:
    - See the convention block of :func:`adjust_hue`.

Args:
    hue_factor: hue shift in radians, a number or a tensor with shape ``(B,)``.

Shape:
    - Input: ``(*, 3, H, W)``
    - Output: ``(*, 3, H, W)``

See Also:
    - :func:`adjust_hue`: the one-call form.

Example:
    >>> x = torch.ones(1, 3, 3, 3)
    >>> AdjustHue(3.141516)(x)
    tensor([[[[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]],
    <BLANKLINE>
             [[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]],
    <BLANKLINE>
             [[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]]]])

    >>> x = torch.ones(2, 3, 3, 3)
    >>> y = torch.ones(2) * 3.141516
    >>> AdjustHue(y)(x).shape
    torch.Size([2, 3, 3, 3])

rC  rD  rE  c               ó    € V ^8„  d   QhRRRR/# )r   Ú
hue_factorrS   r    r7   r!   )r"   s   "r#   r$   ÚAdjustHue.__annotate__K  s   € ÷ Añ AÐ#=ð AÀ$ñ Ar%   c                	ó0   <€ \         SV `  4        Wn        R # rL  )rN  rO  ru  )rQ  ru  rR  s   &&€r#   rO  ÚAdjustHue.__init__K  s   ø€ Ü‰ÑÔØ6@Žr%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   rv  O  s   € ÷ 
2ñ 
2˜\ð 
2¨lñ 
2r%   c                ó,   € \        WP                  4      # )zäShift image hue by the module's configured hue factor.

Args:
    input: Input RGB tensor in the expected image range, usually shaped
        ``(*, 3, H, W)``.

Returns:
    Hue-adjusted tensor with the same shape as ``input``.
)rŒ   ru  rX  s   &&r#   rY  ÚAdjustHue.forwardO  s   € ô ˜%§¡Ó1Ð1r%   )ru  r]  r_  rh  s   @r#   rs  rs     s:   ø‡ ñ%òN 4CÐÐ0ÓBÚ4CÐÐ1ÓC÷Að A÷
2ó 
2r%   rs  c                  óB   a € ] tR tRtRtRR V 3R llltR R ltRtV ;t# )	ÚAdjustGammai\  ac  Apply gamma correction with a stored exponent and gain (module form).

``adjust = AdjustGamma(gamma, gain)`` stores both, and ``out = adjust(image)`` is :func:`adjust_gamma` with them.

Convention:
    - See the convention block of :func:`adjust_gamma`.

Args:
    gamma: non-negative exponent, a float or a tensor with shape ``(B,)``.
    gain: non-negative multiplier, a float or a tensor with shape ``(B,)``.

Shape:
    - Input: ``(*, H, W)``
    - Output: ``(*, H, W)``

See Also:
    - :func:`adjust_gamma`: the one-call form.

Example:
    >>> x = torch.ones(1, 1, 3, 3)
    >>> AdjustGamma(1.0, 2.0)(x)
    tensor([[[[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y1 = torch.ones(2) * 1.0
    >>> y2 = torch.ones(2) * 2.0
    >>> AdjustGamma(y1, y2)(x).shape
    torch.Size([2, 5, 3, 3])

c               ó$   € V ^8„  d   QhRRRRRR/# )r   r�   rS   r�   r    r7   r!   )r"   s   "r#   r$   ÚAdjustGamma.__annotate__~  s$   € ÷ 5ñ 5Ð8ð 5Ð@Zð 5Ðeiñ 5r%   c                	ó<   <€ \         SV `  4        Wn        W n        R # rL  )rN  rO  r�   r�   )rQ  r�   r�   rR  s   &&&€r#   rO  ÚAdjustGamma.__init__~  s   ø€ Ü‰ÑÔØ16Œ
Ø04Ž	r%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   r  ƒ  s   € ÷ 
:ñ 
:˜\ð 
:¨lñ 
:r%   c                óB   € \        WP                  V P                  4      # )zåApply gamma correction using this module's ``gamma`` and ``gain``.

Args:
    input: Input tensor to correct, commonly image-shaped
        ``(*, C, H, W)``.

Returns:
    Gamma-corrected tensor with the same shape as ``input``.
)r’   r�   r�   rX  s   &&r#   rY  ÚAdjustGamma.forwardƒ  s   € ô ˜E§:¡:¨t¯y©yÓ9Ð9r%   )r�   r�   ©r(   ©	r`  ra  rb  rc  rd  rO  rY  rf  rg  rh  s   @r#   r}  r}  \  s   ø† ñ÷B5ò 5÷

:ó 
:r%   r}  c                  ó>   a € ] tR tRtRtR V 3R lltR R ltRtV ;t# )ÚAdjustContrasti�  aÚ  Adjust the contrast of an image by multiplying its values by a stored factor (module form).

``adjust = AdjustContrast(contrast_factor)`` stores the factor, and ``out = adjust(image)`` is
:func:`adjust_contrast` with it and ``clip_output=True``.

Convention:
    - See the convention block of :func:`adjust_contrast`.

Args:
    contrast_factor: non-negative multiplier, a float or a tensor with shape ``(B,)``.

Shape:
    - Input: ``(*, H, W)``
    - Output: ``(*, H, W)``

See Also:
    - :func:`adjust_contrast`: the one-call form, with ``clip_output``.
    - :class:`AdjustContrastWithMeanSubtraction`: blends with the mean gray level instead of scaling.

Example:
    >>> x = torch.ones(1, 1, 3, 3)
    >>> AdjustContrast(0.5)(x)
    tensor([[[[0.5000, 0.5000, 0.5000],
              [0.5000, 0.5000, 0.5000],
              [0.5000, 0.5000, 0.5000]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y = torch.ones(2)
    >>> AdjustContrast(y)(x).shape
    torch.Size([2, 5, 3, 3])

c               ó    € V ^8„  d   QhRRRR/# ©r   Úcontrast_factorrS   r    r7   r!   )r"   s   "r#   r$   ÚAdjustContrast.__annotate__²  ó   € ÷ Kñ KÐ(Bð KÀtñ Kr%   c                	ó0   <€ \         SV `  4        Wn        R # rL  ©rN  rO  r‹  ©rQ  r‹  rR  s   &&€r#   rO  ÚAdjustContrast.__init__²  ó   ø€ Ü‰ÑÔØ;JÖr%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   rŒ  ¶  s   € ÷ 	<ñ 	<˜\ð 	<¨lñ 	<r%   c                ó,   € \        WP                  4      # )zÌAdjust contrast using the configured contrast factor.

Args:
    input: Input tensor to adjust, typically shaped ``(*, C, H, W)``.

Returns:
    Contrast-adjusted tensor with the same shape as ``input``.
)r§   r‹  rX  s   &&r#   rY  ÚAdjustContrast.forward¶  s   € ô ˜u×&:Ñ&:Ó;Ð;r%   ©r‹  r†  rh  s   @r#   rˆ  rˆ  �  s   ø† ñ÷BKð K÷	<ó 	<r%   rˆ  c                  ó>   a € ] tR tRtRtR V 3R lltR R ltRtV ;t# )Ú!AdjustContrastWithMeanSubtractioniÂ  ay  Adjust the contrast of an image by blending it with its mean gray level (module form).

``adjust = AdjustContrastWithMeanSubtraction(contrast_factor)`` stores the factor, and ``out = adjust(image)`` is
:func:`adjust_contrast_with_mean_subtraction` with it.

Args:
    contrast_factor: weight of the image, a float or a tensor with shape ``(B,)``.

Shape:
    - Input: ``(*, C, H, W)``
    - Output: ``(*, C, H, W)``

See Also:
    - :func:`adjust_contrast_with_mean_subtraction`: the one-call form.
    - :class:`AdjustContrast`: multiplies the values instead.

Example:
    >>> x = torch.ones(1, 1, 3, 3)
    >>> AdjustContrastWithMeanSubtraction(0.5)(x)
    tensor([[[[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y = torch.ones(2)
    >>> AdjustContrastWithMeanSubtraction(y)(x).shape
    torch.Size([2, 5, 3, 3])

c               ó    € V ^8„  d   QhRRRR/# rŠ  r!   )r"   s   "r#   r$   Ú.AdjustContrastWithMeanSubtraction.__annotate__á  r�  r%   c                	ó0   <€ \         SV `  4        Wn        R # rL  r�  r�  s   &&€r#   rO  Ú*AdjustContrastWithMeanSubtraction.__init__á  r’  r%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   rš  å  s   € ÷ Rñ R˜\ð R¨lñ Rr%   c                ó,   € \        WP                  4      # )a<  Adjust contrast with mean-subtraction based interpolation.

This forwards to :func:`adjust_contrast_with_mean_subtraction`, which
applies PIL-like contrast behavior.

Args:
    input: Input tensor to adjust, typically shaped ``(*, C, H, W)``.

Returns:
    Contrast-adjusted tensor with the same shape as ``input``.
)r¬   r‹  rX  s   &&r#   rY  Ú)AdjustContrastWithMeanSubtraction.forwardå  s   € ô 5°U×<PÑ<PÓQÐQr%   r–  r†  rh  s   @r#   r˜  r˜  Â  s    ø† ñ÷<Kð K÷Ró Rr%   r˜  c                  ó>   a € ] tR tRtRtR V 3R lltR R ltRtV ;t# )ÚAdjustBrightnessiô  aD  Adjust the brightness of an image by adding a stored factor (module form).

``adjust = AdjustBrightness(brightness_factor)`` stores the factor, and ``out = adjust(image)`` is
:func:`adjust_brightness` with it and ``clip_output=True``.

Args:
    brightness_factor: value to add, a float or a tensor with shape ``(B,)``.

Shape:
    - Input: ``(*, H, W)``
    - Output: ``(*, H, W)``

See Also:
    - :func:`adjust_brightness`: the one-call form, with ``clip_output``.
    - :class:`AdjustBrightnessAccumulative`: multiplies instead of adding.

Example:
    >>> x = torch.ones(1, 1, 3, 3)
    >>> AdjustBrightness(1.)(x)
    tensor([[[[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y = torch.ones(2)
    >>> AdjustBrightness(y)(x).shape
    torch.Size([2, 5, 3, 3])

c               ó    € V ^8„  d   QhRRRR/# ©r   Úbrightness_factorrS   r    r7   r!   )r"   s   "r#   r$   ÚAdjustBrightness.__annotate__  rJ  r%   c                	ó0   <€ \         SV `  4        Wn        R # rL  ©rN  rO  r¤  ©rQ  r¤  rR  s   &&€r#   rO  ÚAdjustBrightness.__init__  rT  r%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   r¥    rV  r%   c                ó,   € \        WP                  4      # )z×Adjust image brightness using the configured brightness factor.

Args:
    input: Input tensor to adjust, commonly shaped ``(*, C, H, W)``.

Returns:
    Brightness-adjusted tensor with the same shape as ``input``.
)r³   r¤  rX  s   &&r#   rY  ÚAdjustBrightness.forward  r[  r%   ©r¤  r†  rh  s   @r#   r¡  r¡  ô  s    ø† ñ÷<Oð O÷	@ó 	@r%   r¡  c                  óB   a € ] tR tRtRtRR V 3R llltR R ltRtV ;t# )	ÚAdjustSigmoidi#  a  Apply sigmoid correction with a stored cutoff and gain (module form).

``adjust = AdjustSigmoid(cutoff, gain, inv)`` stores its arguments, and ``out = adjust(image)`` is
:func:`adjust_sigmoid` with them.

Reference:
    [1]: Gustav J. Braun, "Image Lightness Rescaling Using Sigmoidal Contrast Enhancement Functions",
         http://markfairchild.org/PDFs/PAP07.pdf

Args:
    cutoff: input value at which the curve equals 0.5.
    gain: steepness of the curve.
    inv: return one minus the curve.

Shape:
    - Input: ``(*, H, W)``
    - Output: ``(*, H, W)``

See Also:
    - :func:`adjust_sigmoid`: the one-call form.

Example:
    >>> x = torch.ones(1, 1, 2, 2)
    >>> AdjustSigmoid(gain=0)(x)
    tensor([[[[0.5000, 0.5000],
              [0.5000, 0.5000]]]])

c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r¸   rE   r�   r¹   r�   r    r7   r!   )r"   s   "r#   r$   ÚAdjustSigmoid.__annotate__A  s)   € ÷ ñ ˜uð °%ð À4ð ÐTXñ r%   c                	óH   <€ \         SV `  4        Wn        W n        W0n        R # rL  )rN  rO  r¸   r�   r¹   )rQ  r¸   r�   r¹   rR  s   &&&&€r#   rO  ÚAdjustSigmoid.__init__A  s   ø€ Ü‰ÑÔØ#ŒØŒ	ØŽr%   c               ó    € V ^8„  d   QhRRRR/# r   r!   )r"   s   "r#   r$   r±  G  s   € ÷ 
Wñ 
W˜\ð 
W¨lñ 
Wr%   c                óZ   € \        WP                  V P                  V P                  R7      # )zõApply sigmoid-based intensity remapping to the input image.

Args:
    image: Input image tensor to remap, typically shaped
        ``(*, C, H, W)`` or ``(*, H, W)``.

Returns:
    Tensor with sigmoid correction applied, preserving input shape.
©r¸   r�   r¹   )r»   r¸   r�   r¹   ©rQ  r   s   &&r#   rY  ÚAdjustSigmoid.forwardG  s   € ô ˜e¯K©K¸d¿i¹iÈTÏXÉXÔVÐVr%   r¶  ©rÙ   é
   Fr†  rh  s   @r#   r¯  r¯  #  s   ø† ñ÷:ò ÷
Wó 
Wr%   r¯  c                  óB   a € ] tR tRtRtRR V 3R llltR R ltRtV ;t# )	Ú	AdjustLogiT  aŸ  Apply logarithmic correction with a stored gain (module form).

``adjust = AdjustLog(gain, inv, clip_output)`` stores its arguments, and ``out = adjust(image)`` is
:func:`adjust_log` with them.

Reference:
    [1]: http://www.ece.ucsb.edu/Faculty/Manjunath/courses/ece178W03/EnhancePart1.pdf

Args:
    gain: multiplier of the curve.
    inv: use the exponential curve.
    clip_output: clamp the result to :math:`[0, 1]`.

Shape:
    - Input: ``(*, H, W)``
    - Output: ``(*, H, W)``

See Also:
    - :func:`adjust_log`: the one-call form.

Example:
    >>> x = torch.zeros(1, 1, 2, 2)
    >>> AdjustLog(inv=True)(x)
    tensor([[[[0., 0.],
              [0., 0.]]]])

c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r�   rE   r¹   r�   r¥   r    r7   r!   )r"   s   "r#   r$   ÚAdjustLog.__annotate__q  s)   € ÷ -ñ -˜Uð -¨Tð -Èð -ÐX\ñ -r%   c                	óH   <€ \         SV `  4        Wn        W n        W0n        R # rL  )rN  rO  r�   r¹   r¥   )rQ  r�   r¹   r¥   rR  s   &&&&€r#   rO  ÚAdjustLog.__init__q  s   ø€ Ü‰ÑÔØŒ	ØŒØ!,Ör%   c               ó    € V ^8„  d   QhRRRR/# r   r!   )r"   s   "r#   r$   r¾  w  s   € ÷ 
]ñ 
]˜\ð 
]¨lñ 
]r%   c                óZ   € \        WP                  V P                  V P                  R7      # )zóApply logarithmic or inverse-logarithmic intensity correction.

Args:
    image: Input image tensor to transform, typically shaped
        ``(*, C, H, W)`` or ``(*, H, W)``.

Returns:
    Log-corrected tensor with the same shape as ``image``.
)r�   r¹   r¥   )rÈ   r�   r¹   r¥   r·  s   &&r#   rY  ÚAdjustLog.forwardw  s!   € ô ˜%§i¡i°T·X±XÈ4×K[ÑK[Ô\Ð\r%   )r¥   r�   r¹   ©r  FTr†  rh  s   @r#   r¼  r¼  T  s   ø† ñ÷8-ò -÷
]ó 
]r%   r¼  c                  ó>   a € ] tR tRtRtR V 3R lltR R ltRtV ;t# )ÚAdjustBrightnessAccumulativei„  aq  Multiply an image by a stored factor to brighten or darken it (module form).

``adjust = AdjustBrightnessAccumulative(brightness_factor)`` stores the factor, and ``out = adjust(image)`` is
:func:`adjust_brightness_accumulative` with it and ``clip_output=True``.

Args:
    brightness_factor: multiplier, a float or a tensor with shape ``(B,)``.

Shape:
    - Input: ``(*, H, W)``
    - Output: ``(*, H, W)``

See Also:
    - :func:`adjust_brightness_accumulative`: the one-call form, with ``clip_output``.
    - :class:`AdjustBrightness`: adds the factor instead.

Example:
    >>> x = torch.ones(1, 1, 3, 3)
    >>> AdjustBrightnessAccumulative(1.)(x)
    tensor([[[[1., 1., 1.],
              [1., 1., 1.],
              [1., 1., 1.]]]])

    >>> x = torch.ones(2, 5, 3, 3)
    >>> y = torch.ones(2)
    >>> AdjustBrightnessAccumulative(y)(x).shape
    torch.Size([2, 5, 3, 3])

c               ó    € V ^8„  d   QhRRRR/# r£  r!   )r"   s   "r#   r$   Ú)AdjustBrightnessAccumulative.__annotate__£  rJ  r%   c                	ó0   <€ \         SV `  4        Wn        R # rL  r§  r¨  s   &&€r#   rO  Ú%AdjustBrightnessAccumulative.__init__£  rT  r%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   rÈ  §  s   € ÷ 	Mñ 	M˜\ð 	M¨lñ 	Mr%   c                ó,   € \        WP                  4      # )zÐAdjust brightness with accumulative (PIL-like) behavior.

Args:
    input: Input tensor to adjust, commonly shaped ``(*, C, H, W)``.

Returns:
    Brightness-adjusted tensor with the same shape as ``input``.
)r¶   r¤  rX  s   &&r#   rY  Ú$AdjustBrightnessAccumulative.forward§  s   € ô .¨e×5KÑ5KÓLÐLr%   r­  r†  rh  s   @r#   rÆ  rÆ  „  s    ø† ñ÷<Oð O÷	Mó 	Mr%   rÆ  c                  óB   a € ] tR tRtRtRR V 3R llltR R ltRtV ;t# )	ÚInverti³  ai  Invert an image by subtracting it from a stored maximum value (module form).

``op = Invert(max_val)`` stores ``max_val`` as a buffer, or as a parameter if it is an ``nn.Parameter``, and
``out = op(image)`` is :func:`invert` with it.

Args:
    max_val: tensor the image is subtracted from, broadcastable to the input. The default is ``1``, so for a
        ``uint8`` image pass ``torch.tensor(255)``.

Shape:
    - Input: any shape
    - Output: same as the input

See Also:
    - :func:`invert`: the one-call form.

Example:
    >>> img = torch.rand(1, 2, 4, 4)
    >>> Invert()(img).shape
    torch.Size([1, 2, 4, 4])

    >>> img = 255. * torch.rand(1, 2, 3, 4, 4)
    >>> Invert(torch.as_tensor(255.))(img).shape
    torch.Size([1, 2, 3, 4, 4])

    >>> img = torch.rand(1, 3, 4, 4)
    >>> Invert(torch.as_tensor([[[[1.]]]]))(img).shape
    torch.Size([1, 3, 4, 4])

c               ó    € V ^8„  d   QhRRRR/# )r   r<  r=  r    r7   r!   )r"   s   "r#   r$   ÚInvert.__annotate__Ó  s   € ÷ #ñ #Ð 6ð #À$ñ #r%   c                	óÌ   <€ \         SV `  4        Vf   \        P                  ! R4      p\	        V\
        P                  4      '       g   V P                  RV4       R # Wn        R # )Nr(   r<  )	rN  rO  r,   rž   r;   r   Ú	ParameterÚregister_bufferr<  )rQ  r<  rR  s   &&€r#   rO  ÚInvert.__init__Ó  sG   ø€ Ü‰ÑÔØŠ?Ü—l’l 3Ó'ˆGÜ˜'¤2§<¡<×0Ò0Ø× Ñ  ¨GÖ4à"ŽLr%   c               ó    € V ^8„  d   QhRRRR/# r  r!   )r"   s   "r#   r$   rÑ  Ü  s   € ÷ 
+ñ 
+˜\ð 
+¨lñ 
+r%   c                ó,   € \        WP                  4      # )zþInvert values using the module's configured maximum reference.

Args:
    input: Tensor to invert. Any shape is accepted as long as it is
        broadcast-compatible with ``self.max_val``.

Returns:
    Inverted tensor with the same shape as ``input``.
)r@  r<  rX  s   &&r#   rY  ÚInvert.forwardÜ  s   € ô �eŸ\™\Ó*Ð*r%   )r<  rL  r†  rh  s   @r#   rÏ  rÏ  ³  s   ø† ñ÷>#ò #÷
+ó 
+r%   rÏ  )rë   r…  )Tr¹  rÄ  )rÙ   )rÙ   NrL  )KÚ
__future__r   r™   Úmathr   Útypingr   r   r   r,   Útorch.nn.functionalr   r  r
  Úkornia.colorr	   r
   r   Úkornia.core.checkr   r   r   r   r   Úkornia.core.exceptionsr   Úkornia.core.opsr   Úkornia.core.utilsr   r   r   r   r   r   Úkornia.image.utilsr   r   r3   rB   rG   rP   rf   ri   r}   r‡   rŒ   r’   r§   r¬   r³   r¶   r»   rÈ   rÔ   rØ   rà   rä   r   r2  r5  r:  r@  ÚModulerB  rj  rs  r}  rˆ  r˜  r¡  r¯  r¼  rÆ  rÏ  r!   r%   r#   Ú<module>rä     s¯  ðõ$ #ã Ý ß ,Ñ ,ã ß Ð Ý ç AÑ A÷õ õ 2Ý +÷÷ ÷ 3õ$õ2÷8õ(õ*)õX5õpJmõZ-õ`7=÷t@*÷FIõX9)÷x;÷|5÷p10÷h'÷T#?÷L^(õBFõp=õfSVõlBCõJ0[õf[÷@)&ôX9@�r—y‘yô 9@ôx;V¨"¯)©)ô ;Vô|92�—	‘	ô 92ôx1:�"—)‘)ô 1:ôh/<�R—Y‘Yô /<ôd/R¨¯	©	ô /Rôd,@�r—y‘yô ,@ô^.W�B—I‘Iô .Wôb-]�—	‘	ô -]ô`,M 2§9¡9ô ,Mô^3+ˆR�Y‰Yö 3+r%   