
    3j                        S SK Jr  S SKJr  S SKJr  S SKrS SKJr  S SKJ	r	  S SK
JrJr   " S S	\5      rS
\R                  4         SS jjr " S S\	5      rg)    )annotations)IntEnum)UnionN)Tensor)Module)KORNIA_CHECKKORNIA_CHECK_IS_TENSORc                  0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)ThresholdType   zThreshold types compatible with OpenCV fixed thresholding types.

Note: THRESH_OTSU is intentionally not supported in this PR.
r                   N)__name__
__module____qualname____firstlineno____doc__THRESH_BINARYTHRESH_BINARY_INVTHRESH_TRUNCTHRESH_TOZEROTHRESH_TOZERO_INVTHRESH_OTSU__static_attributes__r       R/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/enhance/threshold.pyr   r      s+    
 MLM Kr   r        o@c           	        [        U 5        [        U5      nU[        [        R                  5      -  (       a  [	        S5      e[        U[         Vs1 s H#  oU[        R                  :w  d  M  [        U5      iM%     sn;   SU S35        Un[        U[        5      (       d*  [        R                  " X`R                  U R                  S9nO$UR                  U R                  U R                  S9nUn[        U[        5      (       d*  [        R                  " XpR                  U R                  S9nO$UR                  U R                  U R                  S9nX:  n[        R                  " U 5      n	U[        [        R                  5      :X  a  [        R                  " XU	5      $ U[        [        R                   5      :X  a  [        R                  " XU5      $ U[        [        R"                  5      :X  a  [        R$                  " X5      $ U[        [        R&                  5      :X  a  [        R                  " XU	5      $ U[        [        R(                  5      :X  a  [        R                  " XU 5      $ [+        SU 35      es  snf )a  Apply a fixed-level threshold to each element in the input tensor.

Implements OpenCV-like behavior for the following threshold types:
- THRESH_BINARY
- THRESH_BINARY_INV
- THRESH_TRUNC
- THRESH_TOZERO
- THRESH_TOZERO_INV

Args:
    input: Image tensor of shape (..., H, W). Typically (B, C, H, W).
    thresh: Threshold value (scalar or tensor broadcastable to input).
    maxval: Maximum value used with binary thresholding types.
    type: Threshold type.

Returns:
    Thresholded tensor with same shape/dtype/device as `input`.

Raises:
    NotImplementedError: if THRESH_OTSU flag is passed.
    ValueError: if type is not supported.
zFTHRESH_OTSU is not implemented yet. Please use a fixed threshold type.zUnsupported threshold type: z;. Supported: BINARY, BINARY_INV, TRUNC, TOZERO, TOZERO_INV.)devicedtype)r	   intr   r   NotImplementedErrorr   
isinstancer   torchtensorr#   r$   to
zeros_liker   wherer   r   minimumr   r   
ValueError)
inputthreshmaxvaltypetxthresh_tmaxval_tmaskzeross
             r    	thresholdr9   .   s   8 5!D	A 	3}(())!"jkk	mNmM4M4M/Mfc!fmNN
&tf,gh Hh''<<U[[Q;;ell%++;FHh''<<U[[Q;;ell%++;FDU#EC++,,{{4511C//00{{411C**++}}U--C++,,{{4..C//00{{4.. 3D6:
;;I Os   I>
,I>
c                  d   ^  \ rS rSrSrS\R                  4       SU 4S jjjrSS jrSr	U =r
$ )		Thresholdz   z.Module wrapper for `kornia.enhance.threshold`.r!   c                   > [         TU ]  5         [        U5      U l        [        U5      U l        [        U5      U l        g N)super__init__floatr0   r1   r%   r2   )selfr0   r1   r2   	__class__s       r    r@   Threshold.__init__}   s1     	FmFmI	r   c                X    [        XR                  U R                  U R                  5      $ r>   )r9   r0   r1   r2   )rB   r/   s     r    forwardThreshold.forward   s    T[[$))DDr   )r1   r0   r2   )r0   rA   r1   rA   r2   Union[int, ThresholdType]returnNone)r/   r   rI   r   )r   r   r   r   r   r   r   r@   rF   r   __classcell__)rC   s   @r    r;   r;   z   sP    8
 *7*E*E			 	 (		
 
	 	E Er   r;   )
r/   r   r0   Union[float, Tensor]r1   rL   r2   rH   rI   r   )
__future__r   enumr   typingr   r(   r   torch.nnr   kornia.core.checkr   r	   r   r   r9   r;   r   r   r    <module>rR      s~   $ #      BG & $)&3&A&A	I<I< I< !I< $	I<
 I<XE Er   