+
    åûj&  ã                  óØ   € ^ RI Ht ^ RIHt ^ RIHt ^ RIt^ RIHt ^ RIH	t	 ^ RI
HtHt  ! R R	]4      t]! R
 ] 4       4      tR R ltR]P"                  3R R llt ! R R]	4      tR# )é    )Úannotations)ÚIntEnum)ÚUnionN)ÚTensor)ÚModule)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_TENSORc                  ó2   € ] tR t^tRt^ t^t^t^t^t	^t
RtR# )ÚThresholdTypeaó  Select how :func:`threshold` maps each element, with OpenCV's values for the fixed modes.

Pass a member, or its integer value, as ``type``. Writing ``x`` for an element, ``t`` for ``thresh`` and ``m`` for
``maxval``:

- ``THRESH_BINARY`` (0): ``m`` where ``x > t``, else ``0``.
- ``THRESH_BINARY_INV`` (1): ``0`` where ``x > t``, else ``m``.
- ``THRESH_TRUNC`` (2): ``t`` where ``x > t``, else ``x``.
- ``THRESH_TOZERO`` (3): ``x`` where ``x > t``, else ``0``.
- ``THRESH_TOZERO_INV`` (4): ``0`` where ``x > t``, else ``x``.
- ``THRESH_OTSU`` (8): reserved; :func:`threshold` raises ``NotImplementedError`` for it, also when it is OR-ed into
  another mode.

See Also:
    - :func:`threshold`: applies a mode.
    - :class:`Threshold`: the module form.

© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚTHRESH_BINARYÚTHRESH_BINARY_INVÚTHRESH_TRUNCÚTHRESH_TOZEROÚTHRESH_TOZERO_INVÚTHRESH_OTSUÚ__static_attributes__r   ó    ÚTC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\enhance\threshold.pyr   r      s+   † ñð& €MØÐØ€LØ€MØÐð „Kr   r   c              #  ód   "  € T F&  q\         P                  8w  g   K  \        V4      x € K(  	  R # 5i©N)r   r   Úint)Ú.0Úxs   & r   Ú	<genexpr>r    >   s#   é € ÐY© A¼}×?XÑ?XÑ:Xœœ˜QŸ˜«ùs   ‚0�0c               ó$   € V ^8„  d   QhRRRRRR/# )é   Úinputr   ÚthreshúUnion[float, Tensor]Úreturnztuple[Tensor, Tensor]r   )Úformats   "r   Ú__annotate__r(   A   s(   € ÷ Fñ F˜fð FÐ.Bð FÐG\ñ Fr   c                óž  € V P                   \        P                  8X  d   RMS\        P                  ! V P                   4      P                  \        P                  ! V P                   4      P
                  3w  r#\        V\        4      '       gM   \        P                  ! T\        V\        4      '       d   \        P                  M\        P                  R7      pVP                  4       '       d   VP                  4       pW8  pW8¬  W8  ,          p\        P                  ! WQ^ 4      P                  V P                   4      P                  V P                   4      pVP                  V P                   4      VP                  V P                   4      rTW8„  V,          V,          pV\        P                  ! V\        P"                  ! Wb4      V4      3# )a  Return ``input > thresh`` and the value THRESH_TRUNC writes, for an integer ``input``.

Casting ``thresh`` to an integer dtype truncates a fraction toward zero and wraps or rejects a value outside the
dtype's range, so the comparison would use another threshold. An integer is greater than ``thresh`` exactly when
it is greater than ``floor(thresh)``, which OpenCV also compares with. A threshold below the dtype's range passes
every element, one at or above its maximum passes none, and ``nan`` passes none, as for a floating-point input.
)Údtype)r   é   )r*   ÚtorchÚboolÚiinfoÚminÚmaxÚ
isinstancer   Útensorr   Úint64Úfloat64Úis_floating_pointÚfloorÚwhereÚtoÚdeviceÚ	full_like)r#   r$   ÚlowÚhighÚbelowÚinsideÚsafeÚmasks   &&      r   Ú_integer_thresholdrA   A   s5  € ð  Ÿ+™+¬¯©Ô3‘¼%¿+º+ÀeÇkÁkÓ:R×:VÑ:VÔX]×XcÒXcÐdi×doÑdoÓXp×XtÑXtÐ9u�I€CÜ�fœf×%Ò%ô —’˜f¼:ÀfÌc×;RÒ;R¬E¯KªKÔX]×XeÑXeÔfˆØ×Ñ×!Ò!Ø—‘“ˆØ‰L€EØ‰m ¡Õ.€FÜ�;Š;�v qÓ)×,Ñ,¨U¯[©[Ó9×<Ñ<¸U¿\¹\ÓJ€DØ—H‘H˜UŸ\™\Ó*¨F¯I©I°e·l±lÓ,Cˆ6Ø‰\˜VÕ# uÕ,€Dà”—’˜U¤E§O¢O°DÓ$>ÀÓEÐEÐEr   ç     ào@c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r"   r#   r   r$   r%   ÚmaxvalÚtypeúUnion[int, ThresholdType]r&   r   )r'   s   "r   r(   r(   Y   sA   € ÷ a<ñ a<Øða<à ða<ð !ða<ð $ð	a<ð
 ña<r   c                óÊ  a€ \        V 4       \        S4      pV\        \        P                  4      ,          '       d   \	        R4      h\        V\        9   V3R l4       V P                  4       '       g   V P                  4       '       dr   Tp\        V\        4      '       g.   \        P                  ! WPP                  V P                  R7      pM'VP                  V P                  V P                  R7      pW8„  pM\!        W4      w  reTp\        V\        4      '       g.   \        P                  ! WpP                  V P                  R7      pM'VP                  V P                  V P                  R7      p\        P"                  ! V 4      pV\        \        P$                  4      8X  d   \        P&                  ! WgV4      # V\        \        P(                  4      8X  d   \        P&                  ! WhV4      # V\        \        P*                  4      8X  dZ   V P                  4       '       g   V P                  4       '       d   \        P,                  ! W4      # \        P&                  ! WeV 4      # V\        \        P.                  4      8X  d   \        P&                  ! W`V4      # V\        \        P0                  4      8X  d   \        P&                  ! WhV 4      # \3        RS 24      h)a  Threshold every element at a fixed level, as ``cv2.threshold`` does.

``out = threshold(input, thresh, maxval, type)`` compares each element with ``thresh`` and maps it to ``maxval``,
``0``, ``thresh`` or itself, as the :class:`ThresholdType` ``type`` says. It takes tensors for ``thresh`` and
``maxval``.

Convention:
    - The comparison is strict: an element passes when ``input > thresh``.
    - ``thresh`` and ``maxval`` broadcast over ``input`` and move to its device. ``maxval`` is converted to the
      dtype of ``input``, and so is ``thresh`` for a floating-point input.
    - On an integer input ``thresh`` is not cast: as in OpenCV, an element passes when it is greater than
      ``floor(thresh)``. A ``thresh`` below the dtype's range passes every element and one at or above its maximum
      passes none. ``THRESH_TRUNC`` then writes ``floor(thresh)``, or the dtype's minimum for a ``thresh`` below its
      range.

Args:
    input: tensor with shape ``(*, H, W)``.
    thresh: level, a number or a tensor that broadcasts to ``input``.
    maxval: value written by the binary modes, a number or a tensor. The default ``255.0`` turns a :math:`[0, 1]`
        image into 0 and 255; pass ``1.0`` to keep its range.
    type: a :class:`ThresholdType` member or its value.

Returns:
    Thresholded tensor with the shape, dtype and device of ``input``.

Raises:
    NotImplementedError: if ``THRESH_OTSU`` is passed.
    BaseError: if ``type`` is not a supported mode.

See Also:
    - :class:`Threshold`: the module form.
    - :func:`~kornia.filters.otsu_threshold`: finds the level itself with Otsu's method.

Example:
    >>> x = torch.tensor([[0.2, 0.8]])
    >>> threshold(x, 0.5, 1.0)
    tensor([[0., 1.]])
    >>> threshold(x, 0.5, 1.0, ThresholdType.THRESH_TRUNC)
    tensor([[0.2000, 0.5000]])

zFTHRESH_OTSU is not implemented yet. Please use a fixed threshold type.c                 ó   <€ R S  R2# )úUnsupported threshold type: z;. Supported: BINARY, BINARY_INV, TRUNC, TOZERO, TOZERO_INV.r   )rE   s   €r   Ú<lambda>Úthreshold.<locals>.<lambda>’   s   ø€ Ð.¨t¨fÐ4oÑpr   )r9   r*   rI   )r	   r   r   r   ÚNotImplementedErrorr   Ú_FIXED_TYPESr5   Ú
is_complexr1   r   r,   r2   r9   r*   r8   rA   Ú
zeros_liker   r7   r   r   Úminimumr   r   Ú
ValueError)	r#   r$   rD   rE   ÚtÚthresh_tr@   Úmaxval_tÚzeross	   &&&f     r   Ú	thresholdrV   Y   s  ø€ ô^ ˜5Ô!äˆD‹	€Að 	Œ3Œ}×(Ñ(Ó)×)Ô)Ü!Ð"jÓkÐkäØ	Œ\ÑÜpôð ×Ñ× Ò  E×$4Ñ$4×$6Ò$6ØˆÜ˜(¤F×+Ò+Ü—|’| H·\±\ÈÏÉÔU‰Hà—{‘{¨%¯,©,¸e¿k¹k�{ÓJˆHØÑ‰ä+¨EÓ:‰ˆà€HÜ�h¤×'Ò'Ü—<’< ·±ÀUÇ[Á[ÔQ‰à—;‘; e§l¡l¸%¿+¹+�;ÓFˆä×Ò˜UÓ#€EàŒC”×+Ñ+Ó,Ô,Ü�{Š{˜4¨5Ó1Ð1àŒC”×/Ñ/Ó0Ô0Ü�{Š{˜4¨Ó1Ð1àŒC”×*Ñ*Ó+Ô+Ø×"Ñ"×$Ò$¨×(8Ñ(8×(:Ò(:Ü—=’= Ó1Ð1Ü�{Š{˜4¨5Ó1Ð1àŒC”×+Ñ+Ó,Ô,Ü�{Š{˜4¨Ó.Ð.àŒC”×/Ñ/Ó0Ô0Ü�{Š{˜4¨Ó.Ð.ô Ð3°D°6Ð:Ó
;Ð;r   c                  óZ   a € ] tR t^½tRtR]P                  3R V 3R llltR R ltRt	V ;t
# )Ú	ThresholdaÏ  Threshold every element at a fixed level (module form).

``op = Threshold(thresh, maxval, type)`` stores the three values as plain numbers and ``out = op(input)`` is
:func:`threshold` with them.

Convention:
    - See the convention block of :func:`threshold`; ``thresh`` and ``maxval`` are numbers here, not tensors.

Args:
    thresh: level, a number.
    maxval: value written by the binary modes, a number. The default ``255.0`` turns a :math:`[0, 1]` image into 0
        and 255; pass ``1.0`` to keep its range.
    type: a :class:`ThresholdType` member or its value.

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

Example:
    >>> Threshold(0.5, 1.0)(torch.tensor([[0.2, 0.8]]))
    tensor([[0., 1.]])

rB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r"   r$   ÚfloatrD   rE   rF   r&   ÚNoner   )r'   s   "r   r(   ÚThreshold.__annotate__Õ   s2   € ÷ 	ñ 	àð	ð ð	ð (ð		ð
 
ñ	r   c                	ó„   <€ \         SV `  4        \        V4      V n        \        V4      V n        \        V4      V n        R # r   )ÚsuperÚ__init__rZ   r$   rD   r   rE   )Úselfr$   rD   rE   Ú	__class__s   &&&&€r   r_   ÚThreshold.__init__Õ   s1   ø€ ô 	‰ÑÔÜ˜F“mˆŒÜ˜F“mˆŒÜ˜“IˆŽ	r   c               ó    € V ^8„  d   QhRRRR/# )r"   r#   r   r&   r   )r'   s   "r   r(   r\   à   s   € ÷ Eñ E˜Vð E¨ñ Er   c                óX   € \        WP                  V P                  V P                  4      # )a%  Apply thresholding with this module's configured parameters.

This method delegates to :func:`threshold` and reuses the threshold
value, maximum replacement value, and thresholding mode stored on the
module instance.

Args:
    input: Input tensor to threshold. Typical image inputs are shaped
        ``(*, C, H, W)``, but any tensor shape supported by
        :func:`threshold` is accepted.

Returns:
    A tensor with the same shape as ``input`` where values are remapped
    according to ``self.type`` using ``self.thresh`` and ``self.maxval``.
)rV   r$   rD   rE   )r`   r#   s   &&r   ÚforwardÚThreshold.forwardà   s   € ô  ˜§¡¨T¯[©[¸$¿)¹)ÓDÐDr   )rD   r$   rE   )r   r   r   r   r   r   r   r_   re   r   Ú__classcell__)ra   s   @r   rX   rX   ½   s,   ø† ñð4 Ø*7×*EÑ*E÷		ò 	÷Eó Er   rX   )Ú
__future__r   Úenumr   Útypingr   r,   r   Útorch.nnr   Úkornia.core.checkr   r	   r   Ú	frozensetrM   rA   r   rV   rX   r   r   r   Ú<module>rn      sd   ðõ$ #å Ý ã Ý Ý ç Bô�Gô ñ@ ÑY©ÓYÓY€õFð6 $)Ø&3×&AÑ&A÷	a<ôH3E�ö 3Er   