+
    åûjÂ ã            
       óH  a € R0 t?0 t ^ RIt^ RIHt ^ RIHtHtHt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Ht ^ RIHt ^ RIHtHtHtHtHt ^ RIHtHtH t  ^R	I!H"t"H#t# ^R
I$H%t% ^RI&H't'H(t(H)t)H*t* R R lt+R R lt,R R lt-R1R R llt.R R lt/R R lt0R R lt1]]]3t2R R lt3](]']*])3t4R R lt5R R lt6R  R! lt7 ! R" R#]Pp                  4      t9 ! R$ R%]	4      t:R& R' lt; ! R( R)]Pp                  4      t<R*^R+^R,^R-]Pz                  ! ^4      R.R//t>] ^ k R# )2é    N)Únullcontext)ÚContextManagerÚListÚOptionalÚTupleÚ	TypedDictÚUnion)Únn)ÚKORNIA_CHECKÚKORNIA_CHECK_SAME_SIZEÚKORNIA_CHECK_SHAPEÚKORNIA_CHECK_SIZES)Ú_autocast_disabled)ÚAdaptiveQuadInterp3dÚConvQuadInterp3dÚIterativeQuadInterp3dÚNonMaximaSuppression2dÚnms3d_minmax)ÚScalePyramidÚpyrdownÚresize)Úlaf_from_center_scale_oriÚlaf_is_filled)ÚPassLAF)ÚBlobDoGÚBlobHessianÚ
CornerGFTTÚCornerHarrisc                ó„   € V ^8„  d   QhR\         P                  R\         P                  R\        R\         P                  /# )é   Ú
max_coordsÚsigmasÚ
num_levelsÚreturn©ÚtorchÚTensorÚint)Úformats   "Ú_C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\scale_space_detector.pyÚ__annotate__r+   *   s8   € ÷ ñ ¤e§l¡lð ¼E¿L¹Lð ÔVYð Ô^c×^jÑ^jñ ó    c                óÐ   € V P                   ^ ,          pVR,          P                  V^^4      pV\        P                  ! RV R,          \	        V4      ,          4      ,          V R&   V # )aP  Auxiliary function for ScaleSpaceDetector.

Converts scale level index from the subpix module to the actual
scale, using the sigmas from the ScalePyramid output.

Args:
    max_coords: torch.Tensor [BxNx3].
    sigmas: torch.Tensor [BxD], D >= 1
    num_levels: number of levels in the scale index.

Returns:
    torch.Tensor [BxNx3].

ç       @©ºNNNr   )r0   r0   :r   é   N)ÚshapeÚviewr&   ÚpowÚfloat)r!   r"   r#   ÚBÚ
base_sigmas   &&&  r*   Ú_scale_index_to_scaler8   *   s]   € ð 	×Ñ˜Õ€AØ˜•×"Ñ" 1 a¨Ó+€JØ&¬¯ª°3¸
À9Õ8MÔPUÐV`ÓPaÕ8aÓ)bÕb€JˆyÑØÐr,   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r    ÚmaskÚrefr$   ©r&   r'   )r)   s   "r*   r+   r+   ?   s-   € ÷ ñ ”u—|‘|ð ¬%¯,©,ð ¼5¿<¹<ñ r,   c                óú  € V P                  4       '       d_   T P                  V P                  \        P                  8X  d   \        P                  M\        P
                  4      P                  R4      pM.V P                  ^ 4      P                  \        P
                  4      pVP                  R,          VP                  R,          rC\        W#RR7      p\        W$RR7      pVP                  VP                  4      # )aÓ  Resample a full-resolution mask onto ``ref``'s spatial size and dtype, conservatively.

A mask says where a detection may be. A boolean or integer mask is binary -- any non-zero
value keeps a position, so a 0/1 and an OpenCV-style 0/255 mask mean the same thing -- and a
floating-point mask is used as weights (see :func:`_weight_scores`). The resample is a
min-pool: a level pixel takes the smallest mask value among the source pixels it covers, so a
zero region suppresses every level pixel it touches and a thin one cannot fall between the
samples of an interpolation. The result is cast to ``ref``'s dtype, so the weighting that
follows cannot promote the response map to the mask's dtype; a weight the image dtype cannot
hold (below ~6e-8 for a float16 image) rounds to zero and suppresses. Weights above one are
clamped to one -- a weight never promotes -- so a float 0/255 mask, an OpenCV mask that went
through ``.astype(np.float32)``, means the same as the integer one.
ç      ð?©Údiméþÿÿÿéÿÿÿÿ)
Úis_floating_pointÚtoÚdtyper&   Úfloat64Úfloat32Ú	clamp_maxÚner2   Ú_adaptive_min_pool_1d)r:   r;   ÚmÚhÚws   &&   r*   Ú_resize_maskrN   ?   s¡   € ð ×Ñ×ÒØ�G‰G T§Z¡Z´5·=±=Ô%@”E—M’MÄeÇmÁmÓT×^Ñ^Ð_bÓc‰à�G‰G�A‹J�M‰Mœ%Ÿ-™-Ó(ˆØ�9‰9�R�=˜#Ÿ)™) B�-€qÜ˜a¨Ô+€AÜ˜a¨Ô+€AØ�4‰4�—	‘	‹?Ðr,   c                óp   € V ^8„  d   QhR\         P                  R\        R\        R\         P                  /# )r    rK   Úout_sizer@   r$   r%   )r)   s   "r*   r+   r+   W   s0   € ÷ 5ñ 5œUŸ\™\ð 5´Sð 5¼sð 5ÄuÇ|Á|ñ 5r,   c                óh  € W P                  4       ,          pV P                  V,          pW18X  d   V # \        V4       Uu. uF  qDV,          V,          NK  	  pp\        V4       Uu. uF  qD^,           ) V,          V,          ) NK  	  pp\        R \	        WV4       4       4      p\	        WV4       UU	U
u. uF7  w  r‰\        V4       U
u. uF  p
\        WŠ,           V	^,
          4      NK  	  up
NK9  	  pp	pp
\        P                  ! W°P                  \        P                  R7      P                  R4      pV P                  W,4      p\        V P                  4      pWV&   VP                  V^,           V4       VP                  V4      P                  V^,           R7      # u upi u upi u up
i u up
p	pi )aŠ  Min-pool ``m`` along ``dim`` onto ``out_size`` samples with :func:`adaptive_max_pool2d`'s windows.

Output sample ``i`` covers the source samples ``floor(i * n / out_size) .. ceil((i + 1) * n / out_size) - 1``,
exactly the window of ``torch.nn.functional.adaptive_max_pool2d``, so the result equals
``-adaptive_max_pool2d(-m)`` on CPU. It is spelled as a gather so that every device pools the same windows:
on MPS, ``adaptive_max_pool2d`` returns the wrong shape when the output is larger than the input and pools
other windows than CPU when the ratio is not an integer, so the resampled mask, and with it the detections,
would depend on the device.
c              3   ó6   "  € T F  w  rW!,
          x € K  	  R # 5i©N© )Ú.0ÚsÚes   &  r*   Ú	<genexpr>Ú(_adaptive_min_pool_1d.<locals>.<genexpr>h   s   é € Ð4Ñ"3™$˜!�—’Ó"3ùs   ‚©ÚdevicerE   r?   rB   )r@   r2   ÚrangeÚmaxÚzipÚminr&   Útensorr[   ÚlongÚreshapeÚindex_selectÚlistÚinsertÚamin)rK   rP   r@   ÚnÚiÚstartsÚendsÚwidthrV   rW   ÚjÚidxÚindexÚgatheredr2   s   &&&            r*   rJ   rJ   W   sR  € ð —‘“�-€CØ	�‰��€AØ„}Øˆä+0°¬?Ó;©? a�1�u˜×!Ð!©?€FÐ;Ü38¸´?ÓC±?¨a�Q•ˆx˜!�| Õ(Ó)±?€DÐCÜÑ4¤# fÔ"3Ó4Ó4€Eô BEÀVÔARÕ
SÑAR¹¸¤u¨U¤|Ó4¡| !ŒC�•�q˜1•uÖ¡|Ô4ÑAR€CÒ
SÜ�LŠL˜§X¡X´U·Z±ZÔ@×HÑHÈÓL€EØ�~‰~˜cÓ)€HÜ�—‘‹M€EØˆ#�JØ	‡L�L��q•˜%Ô Ø×Ñ˜EÓ"×'Ñ'¨C°!­GÐ'Ó4Ð4ùò <ùÚCùò 5ùÔ
Ss#   ¿FÁ&!F#Â3F-Ã"F(Ã)F-Æ(F-c                ó®   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\         P                  /# )r    ÚscoresÚweightsÚbound_dtyper$   )r&   r'   r   rE   )r)   s   "r*   r+   r+   t   sG   € ÷ cñ cÜ�L‰LðcÜ#(§<¡<ðcÜ>FÄuÇ{Á{Õ>Sðcä
‡\�\ñcr,   c                óþ  € V P                   pV\        P                  \        P                  39   d   \        P                  MTpV P                  V4      VP                  V4      re\        P                  ! V^ 8„  V\        P                  ! V4      4      p\        P                  ! V^ 8¬  WV,          WW,          4      pTP                  \        P                  ! Vf   TMT4      P                  4      P                  V4      # )a   Scale detection ``scores`` by ``weights`` toward the worst score, so a weight never promotes.

A weight in ``(0, 1]`` multiplies a non-negative score and *divides* a negative one: the score
moves away from the best in both cases, and a down-weighted candidate can never outrank a
full-weight candidate whose unweighted score was at least as good. A plain multiply pulls a
negative score toward zero, i.e. up the ranking, which inverted the order of a signed
response. Positions with a zero or negative weight are excluded from the candidates before
this runs; their divisor is replaced by one so no ``inf`` is produced there.

The quotient of a negative score and a small weight can leave the dtype's range, and ``-inf``
is the sentinel an unfilled slot carries into the ranking, so the arithmetic runs in float32
for half-precision input and the result is bounded at ``finfo.min`` of the score dtype before
the cast back: a weighted detection is finite and so always stays ahead of the padding. Wider
dtypes are unchanged wherever the quotient is representable. ``bound_dtype`` names the dtype the
score is reported in when that is narrower than ``scores``, as for the float32 copy of a
half-precision response that :class:`ScaleSpaceDetector` ranks, so the bound still fits it.
)rE   r&   Úfloat16Úbfloat16rG   rD   ÚwhereÚ	ones_likeÚ	clamp_minÚfinfor_   )	rq   rr   rs   rE   ÚwiderV   rM   ÚdivisorÚouts	   &&&      r*   Ú_weight_scoresr~   t   s®   € ð( �L‰L€EØ!¤e§m¡m´U·^±^Ð%DÔDŒ5�=Š=È%€DØ�9‰9�T‹?˜GŸJ™J tÓ,€qÜ�kŠk˜!˜a™% ¤E§O¢O°AÓ$6Ó7€GÜ
�+Š+�a˜1‘f˜a�e Q¥[Ó
1€CØ�=‰=œŸš¨kÒ.A¡UÀ{ÓS×WÑWÓX×[Ñ[Ð\aÓbÐbr,   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r    r:   Úoctave_respr$   r<   )r)   s   "r*   r+   r+   �   s-   € ÷ 8ñ 8œeŸl™lð 8¼¿¹ð 8Ì%Ï,É,ñ 8r,   c                ó6   € \        W4      P                  ^4      # )zKResample a mask onto the given octave response map, as ``(B, 1, 1, H, W)``.)rN   Ú	unsqueeze)r:   r€   s   &&r*   Ú_create_octave_maskrƒ   �   s   € ä˜Ó*×4Ñ4°QÓ7Ð7r,   c                ó\   € V ^8„  d   QhR\         P                  R\         P                  RR/# )r    r:   Úimgr$   Nr<   )r)   s   "r*   r+   r+   •   s)   € ÷ ñ ”e—l‘lð ¬¯©ð ¸$ñ r,   c                óô  € \        V P                  4       ^8H  ;'       d    V P                  ^,          ^8H  R\        V P                  4       24       \        V P                  VP                  8H  RV P                   RVP                   24       \        WRRR7       \        V P                  R
R VP                  R
R 8H  R\        V P                  R
R 4       R	\        VP                  R
R 4       24       R# )aý  Check that ``mask`` is ``(1 or B, 1, H, W)`` for an image ``(B, C, H, W)``.

The mask is resampled onto every level, so a mask of another spatial size would be stretched
silently onto the wrong geometry -- a stale mask from before a resize, or a transposed one.
It must be single-channel: it multiplies a single-channel response per level in
:class:`MultiResolutionDetector`, and in :class:`ScaleSpaceDetector` it is broadcast over the
scale levels, where a channel axis would land on the level axis instead.
z$mask must be (1 or B, 1, H, W). Got zmask device z must match the image device Tz2The mask batch must be 1 or match the image batch.)Ú	allow_oneÚmsgNzmask spatial size z must match the image rA   )r   r@   r2   Útupler[   r   )r:   r…   s   &&r*   Ú_check_maskrŠ   •   sÜ   € ô �—‘“˜q‘×7Ð7 T§Z¡Z°¥]°aÑ%7Ð;_Ô`eÐfj×fpÑfpÓ`qÐ_rÐ9sÔtÜ�—‘ §
¡
Ñ*¨l¸4¿;¹;¸-ÐGdÐeh×eoÑeoÐdpÐ,qÔrÜ˜4°Ð:nÕoÜØ�
‰
�2�3ˆ˜3Ÿ9™9 R S˜>Ñ)Ø
œU 4§:¡:¨b¨c ?Ó3Ð4Ð4JÌ5ÐQT×QZÑQZÐ[]Ð[^ÐQ_ÓK`ÐJaÐbör,   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r    ÚlafsÚfilledr$   r<   )r)   s   "r*   r+   r+   §   s2   € ÷ Nñ NœŸ™ð N¬u¯|©|ð NÄÇÁñ Nr,   c                óh   € \         P                  ! VR,          V \         P                  ! V 4      4      # )aâ  Replace unused detection slots with zero LAFs.

``filled`` is a ``(B, N)`` boolean mask of the slots a detection actually filled. The
affine-shape and orientation modules may normalise or propagate invalid padding frames
differently by dtype, so the mask is re-applied after them. ``where`` rather than a multiply,
so a module that returns NaN for a zero frame cannot leak it into the padding.

Both detectors' ``forward`` read the mask off the LAFs that ``detect`` returns: a zero LAF is
the padding contract, and it is the one signal a subclass overriding ``detect`` also honours.
The response cannot serve: :class:`ScaleSpaceDetector`'s response function is pluggable and
may be signed, so an exact zero there is a legitimate maximum.
©.NN)r&   rw   Ú
zeros_like)rŒ   r�   s   &&r*   Ú_zero_unfilledr‘   §   s'   € ô �;Š;�v˜oÕ.°´e×6FÒ6FÀtÓ6LÓMÐMr,   c                óf   € V ^8„  d   QhR\         P                  R\        \        \        3,          /# ©r    Úmoduler$   )r
   ÚModuler   Úbool)r)   s   "r*   r+   r+   º   s'   € ÷ #ñ #œRŸY™Yð #¬5´´t°Õ+<ñ #r,   c                ó”   € \        V RV 4      p\        V\        4      p\        V4      \        9   ;'       d    \        VRR4      RJ pW#3# )aä  Classify the sub-pixel refiner the detector currently holds.

Returns ``(is_iterative, batchable)``. ``is_iterative`` means the module is one of the built-in
refiners or a subclass, so it accepts ``precomputed_nms_mask``. ``batchable`` means both response
signs can be refined in one stacked call: only the exact built-in classes qualify (a subclass may
change the per-image semantics), and only without a candidate cap, which
:func:`~kornia.geometry.subpix.iterative_quad_interp3d` applies across the whole batch rather
than per image. Both flags read through a :func:`torch.compile` wrapper, whether the detector
compiled the module itself or the caller passed a compiled one, so the same module is dispatched
the same way on every path.
Ú	_orig_modÚmax_candidatesN)ÚgetattrÚ
isinstanceÚ_BUILTIN_SUBPIXÚtype)r”   ÚsubpixÚis_iterativeÚ	batchables   &   r*   Ú_subpix_dispatchr¡   º   sN   € ô �V˜[¨&Ó1€FÜ˜f¤oÓ6€LÜ�V“¤Ñ/×cÐc´G¸FÐDTÐVZÓ4[Ð_cÐ4c€IØÐ"Ð"r,   c                óD   € V ^8„  d   QhR\         P                  R\        /# r“   ©r
   r•   r–   )r)   s   "r*   r+   r+   Ï   s"   € ÷ Pñ P¤§	¡	ð P¬dñ Pr,   c                óê   € \         ;QJ d<    R . V P                  4       OV P                  4       O 4       F  '       d   K   R# 	  R# ! R . V P                  4       OV P                  4       O 4       4      # )zlReturn whether every parameter and buffer of ``module`` is zero-dimensional, so none rejects an input dtype.c              3   óF   "  € T F  qP                  4       ^ 8H  x € K  	  R# 5i)r   Nr?   )rU   Úts   & r*   rX   Ú&_holds_only_scalars.<locals>.<genexpr>Ñ   s   é € ÐOÑ%N �u‰u‹w˜!Ž|Ó%Nùs   ‚!FT)ÚallÚ
parametersÚbuffers)r”   s   &r*   Ú_holds_only_scalarsr«   Ï   sa   € ç‹3ÑOÐ%N v×'8Ñ'8Ó':Ð%N¸V¿^¹^Ó=MÑ%NÓO�3Œ3ÐOŠ3ÐOˆ3ÑOÐ%N v×'8Ñ'8Ó':Ð%N¸V¿^¹^Ó=MÑ%NÓOÓOÐOr,   c                ó„   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        /# )r    ÚpyramidÚresponserž   r$   r£   )r)   s   "r*   r+   r+   Ô   s8   € ÷ ñ ¬¯©ð ¼b¿i¹ið ÔQS×QZÑQZð Ô_cñ r,   c                óÐ   € \        \        V RV 4      4      \        J ;'       dD    \        \        VRV4      4      \        9   ;'       d    \	        V4      ;'       d    \	        V4      # )aÂ  Return whether a float16 image can run through these modules in float32, with autocast off.

The pyramid and the response function get the image, so only their exact built-in classes qualify, read through a
:func:`torch.compile` wrapper. These follow their input's dtype, whatever dtype the module was converted to, so a
float32 input comes back as float32, which `_detect` can round to float16. A custom module or a subclass may hold
float16 weights that reject float32 input, or return a wider response on purpose, and from the outside neither can
be told from a module that follows its input, so it gets the float16 image. So does a :class:`CornerHarris` with a
non-scalar ``k``, which promotes a float16 response. The refiner gets the response in at least float32 on every
path, so its class does not matter; only autocast changes for it, and turning that off would make float16 weights
reject the input they now get cast for.

Measured on a float16 image, CPU and CUDA: with ``isinstance``, a subclass with a float16 weight raises and a
subclass returning a wider response has its float32 score of 1.0001 rounded to 1.0; the exact check costs an
unmodified subclass the fix (5120 of 5120 non-finite, as on main).
r˜   )r�   rš   r   Ú_FLOAT16_IN_FLOAT32_RESPONSESr«   )r­   r®   rž   s   &&&r*   Ú_detects_float16_in_float32r±   Ô   sf   € ô" 	ŒW�W˜k¨7Ó3Ó4¼ÐD÷ 	(ð 	(Ü”˜ ;°Ó9Ó:Ô>[Ñ[÷	(ð 	(ä Ó)÷	(ð 	(ô   Ó'ð	r,   c                óš   € V ^8„  d   QhR\         P                  R\        R\        \         P                  \         P                  3,          /# )r    r®   Úfloat16_scoresr$   ©r&   r'   r–   r   )r)   s   "r*   r+   r+   ì   s:   € ÷ ñ œeŸl™lð ¼Dð ÄUÌ5Ï<É<ÔY^×YeÑYeÐKeÕEfñ r,   c                ó–   € \        V 4      w  r#V'       d3   V P                  \        P                  4      ^ 8g  pW$,          W4,          3# W#3# )a•  Return the masks of the strict maxima and minima of ``response``, an octave's response in at least float32.

With ``float16_scores`` it comes from a float16 image, whose quantisation noise makes weak maxima with scores below
float16's resolution, so only those are dropped. Rounding the response before NMS would also merge real maxima:
Harris fills 252 slots against float32's 825 on HPatches, this 545.
)r   rD   r&   ru   )r®   r³   Úmax_maskÚmin_maskÚscoreds   &&   r*   Ú_nms_candidatesr¹   ì   sE   € ô & hÓ/Ñ€HßØ—‘œUŸ]™]Ó+¨qÑ0ˆØÕ  (Õ"3Ð3Ð3ØÐÐr,   c                   óæ   a a€ ] tR t^út oRtRV3R lV 3R llltV3R lR ltV3R lR ltV3R lR	 ltRV3R
 lR llt	RV3R lR llt
V3R lR ltRV3R lR lltRV3R lR lltRtVtV ;t# )ÚScaleSpaceDetectora±  Detect LAFs at the sub-pixel scale-space maxima of a pluggable response, for a batch of images.

``detector = ScaleSpaceDetector(num_features)`` builds a detector with a Hessian response by default.
``lafs, responses = detector(img)`` takes grayscale images ``(B, 1, H, W)`` and returns LAFs
``(B, num_features, 2, 3)`` in input pixels and responses ``(B, num_features)``, strongest first.
Use :func:`laf_is_filled` to keep detected features and discard padded slots in both outputs.
For per-level 2D maxima, use :class:`MultiResolutionDetector`; for SIFT detection and description,
use :class:`SIFTFeatureScaleSpace`.

Convention:
    - The modules run in this order: ``scale_pyr_module``, ``resp_module``, ``subpix_module``, ``aff_module``,
      then ``ori_module``. The last two default to :class:`PassLAF`, which leaves frames unchanged.
      ``detector.detect(img, num_feats)`` returns ``(responses, lafs)`` before shape and orientation estimation;
      note the reversed output order compared with ``detector(img)``.
    - The candidates are the strict :math:`3 \times 3 \times 3` maxima of the response over level, row and column
      (:func:`~kornia.geometry.subpix.nms3d_minmax`) on the levels given under ``scale_pyr_module``, whatever their
      sign. With ``minima_are_also_good`` a strict minimum is a candidate too when its negated response after
      sub-pixel refinement exceeds the response the maxima pass reports at that voxel, which the built-in refiners
      leave at its sampled value: in effect every minimum below zero, and a minimum above zero only when the
      refinement extrapolates it below minus its sampled value. There is no response threshold. The
      ``num_features`` strongest candidates of all octaves are kept; a minimum is ranked and returned with its
      refined response negated.
    - The default Hessian response is a maximum at bright and dark blobs alike. It keeps the channels, so a
      multi-channel image needs a ``resp_module`` that returns one map. A DoG response
      (:class:`~kornia.feature.BlobDoG`) is a maximum at a dark blob and a minimum at a bright one, which only
      ``minima_are_also_good=True`` detects.
    - A LAF centre is the refined sub-pixel position, mapped to input pixels as given under
      ``scale_pyr_module``, using the pixel convention of :func:`~kornia.feature.laf_from_center_scale_ori`
      (see :ref:`Local features <local-features-conventions>`). Before ``aff_module`` and ``ori_module`` run, the
      frame is diagonal: ``mr_size`` times the detection scale, mapped to input pixels along each axis like the
      centre.
    - A candidate is kept when half its frame lies at least 5 octave pixels inside the octave's outer pixel
      centres; the whole frame can reach outside the image.
    - The output has ``num_features`` slots: the detections by decreasing response, then the unfilled slots, which
      hold a zero response and a zero LAF.
    - The LAFs are float32 for a float16 or bfloat16 image and float64 for a float64 one; the responses keep the
      response function's dtype. Non-maximum suppression and sub-pixel refinement run on the response promoted to
      at least float32. With :class:`~kornia.geometry.transform.ScalePyramid`, a :class:`BlobHessian`,
      :class:`BlobDoG`, :class:`CornerHarris` or :class:`CornerGFTT` response, and a response and refiner holding
      only scalar parameters and buffers, a float16 image is detected in float32 with autocast off and its scores
      are returned in float16, because the gradient overflows float16 on the way through the scale space. A
      candidate whose score is zero in float16 is dropped. With any other pyramid or response function, a subclass
      or a :class:`CornerHarris` with a non-scalar ``k`` included, or a refiner with non-scalar state, the detector
      passes the float16 image on, in the caller's autocast region.
    - With the default modules the responses, centres and scales carry gradients to the image.
    - A batch of zero images returns empty outputs of the documented shapes, after the checks a non-empty batch
      runs.
    - Border and refined-centre mask checks run before the per-octave feature budget, so a rejected
      candidate cannot displace a weaker valid candidate.

Args:
    num_features: Number of features to detect. In order to keep everything batchable,
      output would always have num_features output, even for completely homogeneous images.
    mr_size: multiplier from the detection scale to the LAF scale. The default 6.0 gives a frame of about six
      times the :math:`\sigma` of a detected Gaussian blob.
    scale_pyr_module: generates scale pyramid. See :class:`~kornia.geometry.transform.ScalePyramid` for details.
      Default: ``ScalePyramid(3, 1.6, 16, extra_levels=3)`` with a scale-space response,
      ``extra_levels=2`` without. A detection at octave pixel :math:`(u, v)` is reported at
      :math:`(u (W - 1) / (W_o - 1), v (H - 1) / (H_o - 1))` in the input, the map of
      :class:`~kornia.geometry.transform.ScalePyramid`'s ``align_corners=True`` resizes; a custom pyramid has to
      resize the same way. Each octave searches ``n_levels`` response levels, levels
      ``1..n_levels``; the levels below and above them are NMS neighbours only, and any further
      level is ignored. A per-level response therefore needs ``extra_levels >= 2``, and DoG,
      which has one level fewer than its pyramid, ``extra_levels >= 3``.
    resp_module: calculates ``'cornerness'`` of the pixel. Default: :class:`~kornia.feature.BlobHessian`.
    subpix_module: refines the position and scale of each candidate to sub-pixel / sub-scale accuracy. The
      candidates are those of the Convention block, whatever the module. Default:
      :class:`~kornia.geometry.subpix.AdaptiveQuadInterp3d` with ``allow_scale_steps=True``.
    ori_module: for local feature orientation estimation. Default: :class:`~kornia.feature.PassLAF`,
       which does nothing. See :class:`~kornia.feature.LAFOrienter` for details.
    aff_module: for local feature affine shape estimation. Default: :class:`~kornia.feature.PassLAF`,
        which does nothing. See :class:`~kornia.feature.LAFAffineShapeEstimator` for details.
    minima_are_also_good: if True, then both response function minima and maxima are detected.
        A DoG response needs it to detect bright blobs. Default is False.
        Refining both signs can use roughly twice the peak memory of refining maxima alone.
    scale_space_response: if True, ``resp_module`` gets each whole octave ``(B, C, L, H, W)`` with its
        sigmas ``(B * L,)`` and returns a ``(B, 1, L', H, W)`` scale-space response, as
        :class:`~kornia.feature.BlobDoG` does. If False (the default), it gets the octave's levels
        ``0 .. n_levels + 1`` as ``(B * L, C, H, W)`` images, ``L = n_levels + 2``, with their sigmas
        and returns ``(B * L, 1, H, W)``.
    compile_modules: selects which sub-modules to wrap with :func:`torch.compile`.
        Pass ``True`` to compile every sub-module, ``False`` (default) for none, or a list
        containing any subset of ``["scale_pyr", "resp", "subpix", "ori", "aff"]``.
        The first call compiles, and a new input shape, such as another batch size, can compile again.

See Also:
    - :class:`MultiResolutionDetector`: one image per call, the 2D maxima of a response on each level of an image
      pyramid, at integer level pixels and without scale selection.
    - :class:`KeyNetDetector`: that detector on the learned KeyNet response.
    - :class:`SIFTFeatureScaleSpace`: SIFT, whose ``"patch"`` backend is this detector on a DoG response.
    - :class:`DoGHardNet`: this detector on a DoG response, with HardNet descriptors.
    - :class:`~kornia.geometry.subpix.ConvSoftArgmax3d`: a ``subpix_module`` that takes the soft-argmax of a
      window instead of a quadratic fit.

Example:
    >>> lafs, responses = ScaleSpaceDetector(num_features=100)(torch.rand(2, 1, 64, 64))
    >>> lafs.shape, responses.shape
    (torch.Size([2, 100, 2, 3]), torch.Size([2, 100]))

c                ó4  <€ V ^8„  d   QhRS[ RS[RS[S[P                  ,          RS[S[P                  ,          RS[S[P                  ,          RS[S[P                  ,          RS[S[P                  ,          RS[R	S[R
S[S[S[S[,          3,          RR/# )r    Únum_featuresÚmr_sizeÚscale_pyr_moduleÚresp_moduleÚsubpix_moduleÚ
ori_moduleÚ
aff_moduleÚminima_are_also_goodÚscale_space_responseÚcompile_modulesr$   N)	r(   r5   r   r
   r•   r–   r	   r   Ústr)r)   Ú__classdict__s   "€r*   r+   ÚScaleSpaceDetector.__annotate__`  s³   ø€ ÷ 49ñ 49áð49ñ ð49ñ #¡2§9¡9Õ-ð	49ñ
 ™bŸi™iÕ(ð49ñ  ¡§	¡	Õ*ð49ñ ™RŸY™YÕ'ð49ñ ™RŸY™YÕ'ð49ñ #ð49ñ #ð49ñ ™t¡T©#¥Y˜Õ/ð49ð 
ñ49r,   c                ób  <a € \         SS `  4        VS n        VS n        0 RmpV
RJ d   TpM=V
RJ d   \	        4       pM,\	        V
4      pWË,
          pV'       d   \        RV RV 24      h\        V4      S n        R	 V 3R
 llpVf   V	'       d   ^M^p\        ^R^VR7      pV! VR 4      S n	        Vf   \        4       pV! VR4      S n        Vf   \        RR7      pV! VR4      S n        Vf   \        4       pV! VR4      S n        Vf   \        4       pV! VR4      S n        VS n        V	S n        R# )Ú	scale_pyrÚresprž   ÚoriÚaffTFz)Unknown module names in compile_modules: z	. Valid: c                ód   € V ^8„  d   QhR\         P                  R\        R\         P                  /# )r    ÚmodÚnamer$   )r
   r•   rÇ   )r)   s   "r*   r+   Ú1ScaleSpaceDetector.__init__.<locals>.__annotate__~  s.   € ÷ 	Zñ 	Z¤§	¡	ð 	Z´ð 	Z¼¿¹ñ 	Zr,   c                 óZ   <€ VSP                   9   d   \        P                  ! V R R7      # T # )T©Údynamic)Ú_compile_setr&   Úcompile)rÐ   rÑ   Úselfs   &&€r*   Ú_maybe_compileÚ3ScaleSpaceDetector.__init__.<locals>._maybe_compile~  s'   ø€ Ø7;¸t×?PÑ?PÔ7P”5—=’= ¨dÔ3ÐYÐVYÐYr,   Ngš™™™™™ù?)Úextra_levels)Úallow_scale_steps>   rÎ   rÍ   rÌ   rž   rË   )ÚsuperÚ__init__r¾   r½   ÚsetÚ
ValueErrorÚ	frozensetrÖ   r   rË   r   rÌ   r   rž   r   rÍ   rÎ   rÄ   rÅ   )rØ   r½   r¾   r¿   rÀ   rÁ   rÂ   rÃ   rÄ   rÅ   rÆ   Ú
_all_namesrÖ   ÚunknownrÙ   rÛ   Ú	__class__s   f&&&&&&&&&&     €r*   rÞ   ÚScaleSpaceDetector.__init__`  s<  ù€ ô 	‰ÑÔØˆŒØ(ˆÔâBˆ
Ø˜dÓ"Ø%‰LØ Ó%Ü›5‰Lä˜Ó/ˆLØ"Õ/ˆGßÜ Ð#LÈWÈIÐU^Ð_iÐ^jÐ!kÓlÐlä,5°lÓ,CˆÔ÷	Zð 	Zð Ò#ß 4™1¸!ˆLÜ+¨A¨s°BÀ\ÔRÐÙ'Ð(8¸+ÓFˆŒØÒÜ%›-ˆKÙ" ;°Ó7ˆŒ	ØÒ Ü0À4ÔHˆMÙ$ ]°HÓ=ˆŒØÒÜ ›ˆJÙ! *¨eÓ4ˆŒØÒÜ ›ˆJÙ! *¨eÓ4ˆŒØ$8ˆÔ!ð %9ˆÖ!r,   c                óH   <€ V ^8„  d   QhRS[ S[R3,          RS[R,          /# )r    Úmodules.r$   N)r   rÇ   r   )r)   rÈ   s   "€r*   r+   rÉ   –  s(   ø€ ÷ ñ ©E±#°s°(­Oð ÁÈtÕ@Tñ r,   c                ó¬   € V P                   P                  V4      '       d+   \        P                  P                  P                  R R7      # \        4       # )T)Ú capture_dynamic_output_shape_ops)rÖ   Úintersectionr&   Ú_dynamoÚconfigÚpatchr   )rØ   rç   s   &&r*   Ú_dynamo_config_patchÚ'ScaleSpaceDetector._dynamo_config_patch–  sA   € Ø×Ñ×)Ñ)¨'×2Ò2ô
 —=‘=×'Ñ'×-Ñ-ÈtÐ-ÓTÐTÜ‹}Ðr,   c                ó    <€ V ^8„  d   QhRS[ /# ©r    r$   )rÇ   )r)   rÈ   s   "€r*   r+   rÉ   Ÿ  s   ø€ ÷ 

ñ 

™#ñ 

r,   c                óv  € V P                   P                   R V P                   RV P                   RV P                  P                  4        RV P                  P                  4        RV P                  P                  4        RV P                  P                  4        RV P                  P                  4        R2# )z(num_features=z
, mr_size=z, scale_pyr=z, resp=z	, subpix=z, ori=z, aff=Ú))
rä   Ú__name__r½   r¾   rË   Ú__repr__rÌ   rž   rÍ   rÎ   )rØ   s   &r*   rõ   ÚScaleSpaceDetector.__repr__Ÿ  sµ   € à�~‰~×&Ñ&Ð'ð (Ø ×-Ñ-Ð.ð /Ø—|‘|�nð %ØŸ™×0Ñ0Ó2Ð3ð 4Ø—I‘I×&Ñ&Ó(Ð)ð *Ø—k‘k×*Ñ*Ó,Ð-ð .Ø—8‘8×$Ñ$Ó&Ð'ð (Ø—8‘8×$Ñ$Ó&Ð' qð*ð		
r,   c                óè   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[RS[RS[S[ P                  S[ P                  S[ P                  S[ P                  3,          /# )r    r®   r¶   r·   Úis_iterative_subpixÚbatchable_subpixr$   r´   )r)   rÈ   s   "€r*   r+   rÉ   «  sy   ø€ ÷ @ñ @á—,‘,ð@ñ —,‘,ð@ñ —,‘,ð	@ñ
 "ð@ñ ð@ñ 
‰u�|‰|™UŸ\™\©5¯<©<¹¿¹ÐEÕ	Fñ@r,   c                óœ  € V'       dh   VP                   ^ ,          pV P                  \        P                  ! W) 3^ R7      \        P                  ! W#3^ R7      R7      w  rxVRV VRV WvR W†R 3# V'       d,   V P                  WR7      w  ršV P                  V) VR7      w  r¼M'V P                  V4      w  ršV P                  V) 4      w  r¼WšW¼3# )zHRefine both response signs, batching only independent built-in refiners.r?   ©Úprecomputed_nms_maskN)r2   rž   r&   Úcat)rØ   r®   r¶   r·   rø   rù   ÚbatchÚcoordsÚvaluesÚ	coord_maxÚresponse_maxÚ	coord_minÚresponse_mins   &&&&&&       r*   Ú_refine_minmaxÚ!ScaleSpaceDetector._refine_minmax«  sÔ   € ÷ ð —N‘N 1Õ%ˆEØ!Ÿ[™[Ü—	’	˜8 YÐ/°QÔ7Ü%*§Y¢Y°Ð/CÈÔ%Kð )ó ‰NˆFð ˜&˜5�> 6¨&¨5 >°6¸&°>À6È&À>ÐQÐQßØ&*§k¡k°( kÓ&ZÑ#ˆIØ&*§k¡k°8°)ÐRZ kÓ&[Ñ#ˆI�|à&*§k¡k°(Ó&;Ñ#ˆIØ&*§k¡k°8°)Ó&<Ñ#ˆIØ¨	Ð?Ð?r,   c                ó@  <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[RS[S[ P                  ,          RS[ P                  RS[RS[RS[R	S[S[S[3,          R
S[RS[S[ P                  S[ P                  S[ P                  S[ P                  3,          /# )r    ÚoctaveÚ
sigmas_octÚ	num_featsr:   Úrotmatr#   rø   rù   Úoctave_to_imager³   r$   )r&   r'   r(   r   r–   r   r5   rE   )r)   rÈ   s   "€r*   r+   rÉ   Æ  sÏ   ø€ ÷ ^@ñ ^@á—‘ð^@ñ —L‘Lð^@ñ ð	^@ñ
 ‘u—|‘|Õ$ð^@ñ —‘ð^@ñ ð^@ñ "ð^@ñ ð^@ñ ™u¡e˜|Õ,ð^@ñ ð^@ñ 
‰u�|‰|™UŸ\™\©5¯<©<¹¿¹ÐDÕ	Eñ^@r,   c                ó|  € VP                   pV^,           pV P                  '       g   VRRRV13,          pVRRV13,          pVP                  4       w  rÞpppV P                  '       dD   V P                  R4      ;_uu_ 4        V P	                  WP                  R4      4      pRRR4       M®V P                  R4      ;_uu_ 4        V P	                  VP                  ^ ^^^^4      P                  Wß,          VVV4      VP                  R4      4      pRRR4       \        XWß,          ^VV.R4       VP                  Wß^VV4      pVP                  ^ ^^^^4      p\        XV^RVV.R4       VRRRV13,          P                  4       pVf   RM\        VV4      pV
'       d   \        P                  MVP                  pVP                  \        P                  ! VP                  \        P                   4      4      pVRRVP"                  ^,          13,          P                  VP                  4      p\%        VV
4      w  ppRpRpVe4   Ve0   V^ 8„  pVV,          pVV,          pVP'                  4       '       d   TpV P                  R4      ;_uu_ 4        V P(                  '       d   V P+                  VVVWx4      w  ppppM3V'       d   V P-                  VVR7      w  ppMV P-                  V4      w  ppRRR4       RXR&   RVR&   Ve   \/        VVV4      pV P(                  '       dJ   RXR&   RVR&   Ve   \/        VVV4      pVV8„  V,          p\        P0                  ! VVV4      pVV,          p MTp V P3                  ^4      p!VP3                  ^4      p"XP5                  ^R4      P3                  ^R4      p#V!P7                  RR7      w  p$p%V#V$V%3,          p&V P(                  '       d]   XP5                  ^R4      P3                  ^R4      p'\        P0                  ! XP3                  ^4      V$V%R3,          V'V$V%3,          V&4      p&VV$^ 3,          \        P8                  ! R	V&R,          \;        V4      ,          4      ,          p(\        P                  ! V(P                  VP                  4      p)V P<                  V(,          P                  V)4      R
,          p*V&R,          V&R,          p,p+V+V*,
          ^8¬  V+V*,           V^,
          ^,
          8*  ,          p-V-V,V*,
          ^8¬  ,          V,V*,           V^,
          ^,
          8*  ,          p-VEe,   VP3                  ^4      P?                  VR4      p.V+PA                  4       PC                  4       PE                  ^ V^,
          4      p/V+PG                  4       PC                  4       PE                  ^ V^,
          4      p0V,PA                  4       PC                  4       PE                  ^ V^,
          4      p1V,PG                  4       PC                  4       PE                  ^ V^,
          4      p2V1V23 F.  p3V/V03 F#  p4V-V.V$V3V,          V4,           3,          ,          p-K%  	  K0  	  V^8X  dÇ   V%V-,          p5V"^ ,          V5,          p6\I        VV5P"                  ^ ,          4      p7\        PJ                  ! ^V7\        PL                  VR7      p8V7^ 8”  dF   \        PN                  ! V6V7R7      w  p9p:V5V:,          PQ                  ^ 4      p;V9PQ                  ^ 4      p9MžV"R,          p9V5PS                  ^^ 4      p;M‚V!PU                  4       p!V-V!V$V%3&   V"PW                  V!( \;        R4      4      p<\I        VV<P                  ^4      4      p7\        PN                  ! V<V7^R7      w  p9p;\        PX                  ! V!^V;4      p8V;PQ                  R4      P?                  RR^4      p=\        PX                  ! V#^V=4      p>V P(                  '       d‰   XP5                  ^R4      P3                  ^R4      p'\        PX                  ! V'^V=4      p?\        PX                  ! XP3                  ^4      ^V;4      p@\        P0                  ! V@PQ                  R4      V?V>4      p>V9P                  4       w  ppA\[        V>VV4      p>\        P\                  ! V P<                  V>R,          P                  VVA^^4      ,          V,          V>R,          P                  VVA^^4      .^4      pBT8pCV9PW                  VC( \;        R4      4      p9VBR,          P_                  V	^ ,          4       VBR,          P_                  V	^,          4       V9VBVCV3#   + '       g   i     EL8; i  + '       g   i     ELŒ; i  + '       g   i     EL¼; i)u0  Process one scale-space octave: response â†’ NMS/subpix â†’ validity â†’ top-K â†’ LAF.

Returns the top-K responses, their LAFs, a boolean mask of the slots a detection
actually filled, and the dtype of the response function's output. The batched top-K below
ranks over the whole volume and returns its ``fill`` sentinel once the octave runs out of
valid candidates; the mask tells those slots apart from a detection, since the response alone
cannot. The responses and LAFs are in at least float32; ``_detect`` casts the responses back to
the returned dtype.
r0   NzEresp_module must return one response map per image, (B * L, 1, H, W).zÀresp_module must return one scale-space response channel, (B, 1, L, H, W). For a multi-channel image, convert it to grayscale first or use a response function that reduces the channels to one.rû   ç        T)Úas_tupler.   ç      à?©rE   r[   ©Úkú-inf©r  r@   )rÌ   rB   )rž   )r0   r0   r   )r0   r0   rB   rA   r/   )r0   r1   )r0   r    )r0   :Nr   N)r0   r0   :r1   é   N)r0   r0   r   r0   )r0   r0   r1   r0   )0r[   rÅ   Úsizerî   rÌ   r3   Úpermuterb   r   Ú
contiguousrƒ   r&   ru   rE   rD   Úpromote_typesrG   r2   r¹   rC   rÄ   r  rž   r~   rw   ÚflattenÚmovedimÚnonzeror4   r5   r¾   ÚexpandÚfloorra   Úclamp_Úceilr_   Úonesr–   Útopkr‚   Ú	new_emptyÚcloneÚmasked_fillÚgatherr8   rý   Úmul_)DrØ   r  r	  r
  r:   r  r#   rø   rù   r  r³   ÚdevÚn_resp_levelsr6   ÚCHÚLÚHÚWÚoct_respÚ
level_respÚ	resampledÚ
resp_dtypeÚscale_sigmasÚmax_nms_maskÚmin_nms_maskÚoct_maskÚoct_keepr  r  r  r  Útake_min_maskÚ	cand_maskÚ	mask_flatÚ	resp_flatÚ
coord_flatÚ	batch_idxÚcandidate_idxÚcandidate_coordsÚcoord_min_flatÚcandidate_scaleÚframe_dtypeÚhalf_sÚcxÚcyÚ	good_maskÚ	keep_flatÚx0Úx1Úy0Úy1ÚyyÚxxÚnms_idxÚ
resp_candsÚk_effÚis_candÚresp_flat_bestÚ	local_idxÚidxsÚresp_maskedÚ
coord_idxsÚmax_coords_bestÚmin_coords_bestÚtake_min_bestÚNÚcurrent_lafsr�   sD   &&&&&&&&&&&                                                         r*   Ú_process_octaveÚ"ScaleSpaceDetector._process_octaveÆ  s«  € ð, �m‰mˆð # Q�ˆØ×(×(Ð(Ø˜A˜q . = .Ð0Õ1ˆFØ# A ~¨ ~Ð$5Õ6ˆJØŸ™›‰ˆˆq�!�Qð ×$×$Ð$Ø×*Ñ*¨9×5Õ5ØŸ9™9 V¯_©_¸RÓ-@ÓA�÷ 6Ð5ð ×*Ñ*¨9×5Õ5Ø!ŸY™Y v§~¡~°a¸¸A¸qÀ!Ó'D×'LÑ'LÈQÍUÐTVÐXYÐ[\Ó']Ð_i×_qÑ_qÐrtÓ_uÓv�
÷ 6äØ˜Q�U A q¨!Ð,Ð.uôð "—‘ q¨Q°°1Ó5ˆHà×'Ñ'¨¨1¨a°°AÓ6ˆHÜØØ��4˜˜AÐðiô	
ð ˜A˜q . = .Ð0Õ1×<Ñ<Ó>ˆà šL‘DÔ.AÀ$ÈÓ.Qˆ	÷ '5”U—]’]¸(¿.¹.ˆ
Ø—;‘;œu×2Ò2°8·>±>Ä5Ç=Á=ÓQÓRˆØ! !Ð%8 x§~¡~°aÕ'8Ð%8Ð"8Õ9×<Ñ<¸X¿^¹^ÓLˆô &5°X¸~Ó%NÑ"ˆ�lð ,0ˆØ+/ˆØÒ 	Ò 5Ø  1‘}ˆHØ'¨(Õ2ˆLØ'¨(Õ2ˆLð ×%Ñ%×'Ò'Ø$�à×&Ñ& {×3Õ3Ø×(×(Ð(ØCG×CVÑCVØ˜l¨LÐ:MóDÑ@�	˜<¨±L÷ %Ø*.¯+©+°hÐUa¨+Ó*bÑ'�	™<à*.¯+©+°hÓ*?Ñ'�	˜<÷ 4ð !$ˆ�WÑØ!$ˆ�XÑØÒÜ)¨,¸À*ÓMˆLà×$×$Ð$Ø$'ˆL˜Ñ!Ø%(ˆL˜Ñ"ØÒ#Ü-¨l¸HÀjÓQ�Ø)¨LÑ8¸LÕHˆMÜ Ÿ;š; }°lÀLÓQˆLà$ }Õ4‰Ià$ˆIð ×%Ñ% aÓ(ˆ	Ø ×(Ñ(¨Ó+ˆ	Ø×&Ñ& q¨"Ó-×5Ñ5°a¸Ó<ˆ
ð $-×#4Ñ#4¸dÐ#4Ó#CÑ ˆ	�=Ø% i°Ð&>Õ?ÐØ×$×$Ð$Ø&×.Ñ.¨q°"Ó5×=Ñ=¸aÀÓDˆNÜ$Ÿ{š{Ø×%Ñ% aÓ(¨°MÀ4Ð)GÕHØ˜y¨-Ð7Õ8Ø ó Ðð
 ' y°! |Õ4´u·y²yÀÐFVÐW[ÕF\Ô_dÐeoÓ_pÕFpÓ7qÕqˆô ×)Ò)¨/×*?Ñ*?ÀÇÁÓNˆØ—,‘, Õ0×4Ñ4°[ÓAÀCÕGˆØ! $Õ'Ð)9¸$Õ)?ˆBˆð ˜&•[ AÑ%¨"¨v­+¸¸Q½À½Ñ*BÕCˆ	Ø  f¥°Ñ!1Õ2°b¸6µkÀQÈÅUÈQÅYÑ6NÕOˆ	ØÓð !×(Ñ(¨Ó+×2Ñ2°1°bÓ9ˆIØ—‘“—‘Ó"×)Ñ)¨!¨Q°­UÓ3ˆBØ—‘“—‘Ó!×(Ñ(¨¨A°­EÓ2ˆBØ—‘“—‘Ó"×)Ñ)¨!¨Q°­UÓ3ˆBØ—‘“—‘Ó!×(Ñ(¨¨A°­EÓ2ˆBØ˜2“h�Ø˜r›(�BØ )¨I°iÀÀaÅÈ"ÅÐ6LÕ,MÕ M’Ió #ñ ð �Œ6Ø# IÕ.ˆGØ" 1� gÕ.ˆJÜ˜	 7§=¡=°Õ#3Ó4ˆEä—j’j  E´·±ÀCÔHˆGØ�qŒyÜ,1¯JªJ°zÀUÔ,KÑ)� 	Ø˜yÕ)×3Ñ3°AÓ6�Ø!/×!9Ñ!9¸!Ó!<‘ð "+¨5Õ!1�Ø×(Ñ(¨¨AÓ.‘ð
 "Ÿ™Ó)ˆIØ2;ˆI�i Ð.Ñ/Ø#×/Ñ/°°
¼EÀ&»MÓJˆKÜ˜	 ;×#3Ñ#3°AÓ#6Ó7ˆEÜ#(§:¢:¨k¸UÈÔ#JÑ ˆN˜Dô —l’l 9¨a°Ó6ˆGà—^‘^ BÓ'×.Ñ.¨r°2°qÓ9ˆ
ÜŸ,š, z°1°jÓAˆØ×$×$Ð$ð '×.Ñ.¨q°"Ó5×=Ñ=¸aÀÓDˆNÜ#Ÿlšl¨>¸1¸jÓIˆOÜ!ŸLšL¨×)>Ñ)>¸qÓ)AÀ1ÀdÓKˆMÜ#Ÿkšk¨-×*AÑ*AÀ"Ó*EÀÐXgÓhˆOà×"Ñ"Ó$‰ˆˆ1ä/°ÀÈzÓZˆä—y’yà—‘˜¨wÕ7×<Ñ<¸QÀÀ1ÀaÓHÕHÈ6ÕQØ 	Õ*×/Ñ/°°1°a¸Ó;ðð ó
ˆð ˆØ'×3Ñ3°V°G¼UÀ6»]ÓKˆà�ZÕ ×%Ñ% o°aÕ&8Ô9Ø�ZÕ ×%Ñ% o°aÕ&8Ô9Ø˜|¨V°ZÐ?Ð?÷u 6×5Ð5ú÷ 6×5Ð5ú÷f 4×3Ð3ús+   Â!fÃAfÊ4f*Ë+f*æf	æf'	æ*f;	c                óÀ   <€ V ^8„  d   QhRS[ P                  RS[RS[S[ P                  ,          RS[S[ P                  S[ P                  S[ P                  3,          /# ©r    r…   r
  r:   r$   ©r&   r'   r(   r   r   )r)   rÈ   s   "€r*   r+   rÉ   ¦  sX   ø€ ÷ Hñ HÙ—<‘<ðHÙ,/ðHÙ7?ÁÇÁÕ7MðHá	‰u�|‰|™UŸ\™\©5¯<©<Ð7Õ	8ñHr,   c                ó$  € Ve   \        W14       VP                  \        P                  8X  d¾   \	        V P
                  V P                  V P                  4      '       d�   Ve6   VP                  4       '       d    VP                  \        P                  4      p\        VP                  P                  4      ;_uu_ 4        V P                  VP                  4       W#R4      uuRRR4       # V P                  WVR4      #   + '       g   i     L#; i)zòRun the detection and also return the boolean mask of the slots a detection filled.

``forward`` needs the mask after ``aff`` and ``ori`` have run, and it cannot be recovered
from the responses, so :meth:`detect` is a two-value view of this.
NTF)rŠ   rE   r&   ru   r±   rË   rÌ   rž   rC   rD   r   r[   r�   Ú_detect_in_image_dtyper5   )rØ   r…   r
  r:   s   &&&&r*   Ú_detectÚScaleSpaceDetector._detect¦  s½   € ð ÒÜ˜Ô"ð �9‰9œŸ™Ô%Ô*EÀdÇnÁnÐVZ×V_ÑV_Ðae×alÑal×*mÒ*mØÒ D×$:Ñ$:×$<Ò$<Ø—w‘wœuŸ}™}Ó-�Ü# C§J¡J§O¡O×4Õ4Ø×2Ñ2°3·9±9³;À	ÐQUÓV÷ 5Ò4à×*Ñ*¨3¸4ÀÓGÐG÷ 5×4ús   Ã !C?Ã?D	c                óÆ   <€ V ^8„  d   QhRS[ P                  RS[RS[S[ P                  ,          RS[RS[S[ P                  S[ P                  S[ P                  3,          /# )r    r…   r
  r:   r³   r$   )r&   r'   r(   r   r–   r   )r)   rÈ   s   "€r*   r+   rÉ   ¼  sa   ø€ ÷ N?ñ N?Ù—<‘<ðN?Ù,/ðN?Ù7?ÁÇÁÕ7MðN?Ù_cðN?á	‰u�|‰|™UŸ\™\©5¯<©<Ð7Õ	8ñN?r,   c                ó¼  € VP                   pVP                  pV P                  R4      ;_uu_ 4        V P                  V4      w  rxp	RRR4       \	        V P                  P
                  \        P                  4      '       d/   \        V P                  P
                  P                  4       4      p
Ml\	        V P                  P
                  \        4      '       d   V P                  P
                  p
M+\        R\        V P                  P
                  4       24      h\        P                  ! ^\        P                  ! V\        P                  4      VR7      P                  ^^^^4      p\!        V P"                  4      w  rÍVP$                  RR w  rïX Uu. uFg  pV^,
          \'        VP$                  R	,          ^,
          ^4      ,          V^,
          \'        VP$                  R,          ^,
          ^4      ,          3NKi  	  pp\)        V4      p\+        V4       Uu. uF2  pV P-                  VV,          XV,          VVVV
VVVV,          V4
      NK4  	  pp\        P.                  ! V Uu. uF  pV^ ,          NK  	  up^4      p\        P.                  ! V Uu. uF  pV^,          NK  	  up^4      p\        P.                  ! V Uu. uF  pV^,          NK  	  up^4      pVP1                  ^4      pVV8  dd   VV,
          p\2        P4                  ! V^ V3\7        R4      R7      p\2        P4                  ! V^ ^ ^ ^ ^ V34      p\2        P4                  ! V^ V34      p\        P8                  ! VV^R7      w  pp\        P:                  ! V^VP=                  R	4      P=                  R	4      P?                  R	R	^^4      4      p\        P:                  ! V^V4      p\        P@                  ! VV\        PB                  ! V4      4      PE                  V^ ,          ^,          4      pV\G        VV4      V3#   + '       g   i     ELó; iu upi u upi u upi u upi u upi )
zÁRun the scale space, the octaves and the cross-octave ranking on ``img`` in the dtype it has.

``float16_scores`` says that ``img`` is the float32 copy of a float16 image: see :meth:`_detect`.
NzRExpected the scale pyramid module to have `n_levels` as a torch.Tensor or int.Got r  r  )Úvaluer  )rË   rA   rB   )$r[   rE   rî   rË   r›   Ún_levelsr&   r'   r(   ÚitemÚ	TypeErrorr�   Úeyer  rG   r3   r¡   rž   r2   r]   Úlenr\   r\  rý   r  ÚFÚpadr5   r#  r'  r‚   r  rw   r�   rD   r‘   )rØ   r…   r
  r:   r³   r)  rE   Úspr"   Ú_r#   r  rø   rù   r-  r.  r  r  Ún_octrh   ÚresultsÚrÚ	responsesrŒ   r�   Ún_candidatesrn  rT  s   &&&&&                       r*   rb  Ú)ScaleSpaceDetector._detect_in_image_dtype¼  s¥  € ð �j‰jˆØ ŸY™YˆØ×&Ñ& ~×6Õ6Ø ŸN™N¨3Ó/‰MˆB˜÷ 7ô �d—n‘n×-Ñ-¬u¯|©|×<Ò<Ü˜TŸ^™^×4Ñ4×9Ñ9Ó;Ó<‰JÜ˜Ÿ™×/Ñ/´×5Ò5ØŸ™×0Ñ0‰JäðÜ˜DŸN™N×3Ñ3Ó4Ð5ð7óð ô
 —’˜1¤E×$7Ò$7¸¼u¿}¹}Ó$MÐVYÔZ×_Ñ_Ð`aÐcdÐfgÐijÓkˆô 1AÀÇÁÓ0MÑ-Ðð �y‰y˜˜ˆ~‰ˆákmó
ÙkmÐagˆa�!�e”s˜6Ÿ<™<¨Õ+¨aÕ/°Ó3Õ3°a¸!µe¼sÀ6Ç<Á<ÐPRÕCSÐVWÕCWÐYZÓ?[Õ5[Ó\Ñkmð 	ð 
ô �B“ˆô ˜5”\óW
ñ "�ð × Ñ Ø�1•Ø�q•	ØØØØØ#Ø Ø Õ"Øöñ "ð 	ð W
ô, —I’I©WÓ5©W¨˜q Ÿt˜t©WÑ5°qÓ9ˆ	Ü�yŠy©Ó0© 1˜!˜AŸ$˜$©Ñ0°!Ó4ˆÜ—’©'Ó2©' Q˜A˜aŸD˜D©'Ñ2°AÓ6ˆØ —~‘~ aÓ(ˆØ˜)Ô#Ø˜lÕ*ˆCÜŸš˜i¨!¨S¨¼¸v»ÔGˆIÜ—5’5˜  1 a¨¨A¨sÐ3Ó4ˆDÜ—U’U˜6 A s 8Ó,ˆFÜŸ*š* Y°)ÀÔC‰ˆ	�4Ü�|Š|˜D ! T§^¡^°BÓ%7×%AÑ%AÀ"Ó%E×%LÑ%LÈRÐQSÐUVÐXYÓ%ZÓ[ˆÜ—’˜f a¨Ó.ˆä—K’K ¨	´5×3CÒ3CÀIÓ3NÓO×RÑRÐSZÐ[\ÕS]Ð^_ÕS`Óaˆ	Øœ.¨¨vÓ6¸Ð>Ð>÷K 7×6Ð6üò.
ùòW
ùò, 6ùÚ0ùÚ2s*   ²P1ÆA-QÈ8Q
É,QÊQËQÐ1Q	c          
      ó¨   <€ V ^8„  d   QhRS[ P                  RS[RS[S[ P                  ,          RS[S[ P                  S[ P                  3,          /# r_  r`  )r)   rÈ   s   "€r*   r+   rÉ     sL   ø€ ÷ ñ Ù—<‘<ðÙ,/ðÙ7?ÁÇÁÕ7Mðá	‰u�|‰|™UŸ\™\Ð)Õ	*ñr,   c                ó2   € V P                  WV4      w  rEpWE3# )aè  Detect local features in an image batch.

Args:
    img: Input image tensor with shape ``(B, C, H, W)``.
    num_feats: Number of features requested from the detector.
    mask: Optional mask with shape ``(1 or B, 1, H, W)`` saying where a detection may be. A boolean or integer
        mask is binary (any non-zero value keeps a position), a floating-point mask is used as weights on the
        detection scores: a weight in ``(0, 1]`` scales a score toward the worst (a non-negative score is
        multiplied by it, a negative one divided), so a down-weighted candidate never outranks a full-weight
        one, and a zero or negative weight suppresses. Weights above one are clamped to one, so a float
        0/255 mask means what the integer one means. The weights are cast to the response's dtype. The mask is
        resampled onto every octave conservatively, so a zero region suppresses every candidate within one
        octave pixel of it.

Returns:
    Tuple containing detection scores and local affine frames, shaped ``(B, num_feats)`` and
    ``(B, num_feats, 2, 3)``, in that order, the reverse of ``forward``'s. A slot that no detection filled --
    there were fewer candidates inside the border and the mask than requested -- carries a
    zero response and a zero LAF, and sorts after every real detection. The converse does not hold: a signed
    response function can peak at exactly zero, and that slot keeps its frame. A batch of zero images returns
    empty outputs of these shapes.
)rc  )rØ   r…   r
  r:   rt  rŒ   rp  s   &&&&   r*   ÚdetectÚScaleSpaceDetector.detect  s!   € ð2 "Ÿ\™\¨#¸$Ó?Ñˆ	˜ØˆÐr,   c                ó¢   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[S[ P                  S[ P                  3,          /# ©r    r…   r:   r$   ©r&   r'   r   r   )r)   rÈ   s   "€r*   r+   rÉ   (  óH   ø€ ÷ 7ñ 7™5Ÿ<™<ð 7©x¹¿¹Õ/Eð 7ÑQVÑW\×WcÑWcÑej×eqÑeqÐWqÕQrñ 7r,   c                ó†  € V P                  WP                  V4      w  r4\        V4      pV P                  R4      ;_uu_ 4        V P	                  WA4      pRRR4       V P                  R4      ;_uu_ 4        V P                  WA4      pRRR4       \        WE4      V3#   + '       g   i     LP; i  + '       g   i     L0; i)aY  Three stage local feature detection.

First the location and scale of interest points are determined by detect function.
Then affine shape and orientation.

Args:
    img: image to extract features with shape ``(B, C, H, W)``.
    mask: a mask saying where a detection may be, shape ``(1, 1, H, W)`` or ``(B, 1, H, W)``. A boolean or
        integer mask is binary, a floating-point mask weights the detection scores; see :meth:`detect`.

Returns:
    Tuple of ``lafs`` with shape ``(B, N, 2, 3)``, the detected local affine frames, and ``responses`` with
    shape ``(B, N)``, the response function values for the corresponding lafs, with ``N = num_features``.
    When fewer detections than ``num_features`` survive for an image, the remaining slots hold a zero
    response and a zero LAF, whichever affine-shape and orientation modules are configured.

N)rÎ   )rÍ   )ry  r½   r   rî   rÎ   rÍ   r‘   ©rØ   r…   r:   rt  rŒ   r�   s   &&&   r*   ÚforwardÚScaleSpaceDetector.forward(  sŽ   € ð( Ÿ+™+ c×+<Ñ+<¸dÓC‰ˆ	Ü˜tÓ$ˆØ×&Ñ& x×0Õ0Ø—8‘8˜DÓ&ˆD÷ 1à×&Ñ& x×0Õ0Ø—8‘8˜DÓ&ˆD÷ 1ä˜dÓ+¨YÐ6Ð6÷	 1×0úç0×0ús   ÁBÁ6B0ÂB-	Â0C 	)
rÖ   rÎ   rÄ   r¾   r½   rÍ   rÌ   rË   rÅ   rž   )
iô  g      @NNNNNFFF)FrS   )rô   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rÞ   rî   rõ   r  r\  rc  rb  ry  r�  Ú__static_attributes__Ú__classdictcell__Ú__classcell__©rä   rÈ   s   @@r*   r»   r»   ú   sx   ù‡ € ñc÷J49õ 49÷lð ÷

ð 

÷@ð @÷6^@ò ^@÷@Hò H÷,N?ð N?÷`ò ÷87÷ 7ò 7r,   r»   c                   ó0   a € ] tR tRt o RtV 3R ltRtV tR# )ÚDetector_configiE  aÅ  Configuration for the multi-resolution detector, the ``config`` of :class:`MultiResolutionDetector`.

Attributes:
    nms_size: The size of the Non-Maximum Suppression window, in level pixels.
    pyramid_levels: The number of image-pyramid levels below the input.
    up_levels: The number of image-pyramid levels above the input, upscaled.
    scale_factor_levels: The scale factor between adjacent levels.
    s_mult: The LAF scale, in level pixels.
c                óV   <€ V ^8„  d   Qh/ S[ ;R&   S[ ;R&   S[ ;R&   S[;R&   S[;R&   # )r    Únms_sizeÚpyramid_levelsÚ	up_levelsÚscale_factor_levelsÚs_mult)r(   r5   )r)   rÈ   s   "€r*   r+   ÚDetector_config.__annotate__E  sC   ø‡ ‚ ñ �Mñ ñ Ññ ñ �Nñ ñ Ññ ñ �Mò r,   rT   N)rô   rƒ  r„  r…  r†  Ú__annotate_func__r‡  rˆ  )rÈ   s   @r*   rŒ  rŒ  E  s   ø‡ € ñ÷ ƒ r,   rŒ  c                ó$   € V ^8„  d   QhR\         /# rñ   )rŒ  )r)   s   "r*   r+   r+   W  s   € ÷ +ñ +¤_ñ +r,   c                 ó*   € \         P                  4       # )zReturn default config.)Ú_DEFAULT_DETECTOR_CONFIGÚcopyrT   r,   r*   Úget_default_detector_configr™  W  s   € ô $×(Ñ(Ó*Ð*r,   c                   ó´   a a€ ] tR tRt oRtRV3R lV 3R llltRV3R lR lltRR/V3R	 lR
 lltV3R lR ltRV3R lR llt	RV3R lR llt
RtVtV ;t# )ÚMultiResolutionDetectori]  aÂ  Detect LAFs at the 2D maxima of a response on each level of an image pyramid, one image per call.

``detector = MultiResolutionDetector(model, num_features)`` builds an image pyramid detector from a response
model. ``lafs, responses = detector(img)`` takes one image ``(1, C, H, W)`` and returns LAFs
``(1, num_features, 2, 3)`` in input pixels and responses ``(1, num_features)``, strongest first.
Use :func:`laf_is_filled` to keep detected features and discard padded slots in both outputs.
Detections lie at integer pixels of each pyramid level, without scale selection or subpixel refinement.
For a batch or refined centres and scales, use :class:`ScaleSpaceDetector`; for KeyNet responses,
use :class:`KeyNetDetector`.

This is based on the original code from the paper "Key.Net: Keypoint Detection by Handcrafted and Learned CNN
Filters". See :cite:`KeyNet2019` for more details.

The Key.Net reference code zeroes a 15 px strip along each side of a level before the non-maxima
suppression, which reports a "maximum" beside the strip wherever the response rises into it. This
detector suppresses on the whole response and removes the strip from the suppression output instead;
see :meth:`detect_features_on_single_level`.

Convention:
    - ``model`` maps each pyramid level ``(1, C, H_l, W_l)`` to a response ``(1, 1, H_l, W_l)``.
      Only responses carry gradients; the selected centres and scales do not.
      ``aff_module`` and then ``ori_module`` modify the upright frames; both default to :class:`PassLAF`.
      ``detector.detect(img)`` returns ``(responses, lafs)`` before those two modules run, reversing the output
      order of ``detector(img)``.
    - Detections are maxima of the response above ``score_threshold``. For a signed response whose minima are
      features as well, such as a difference of Gaussians, pass its magnitude, as
      :class:`~kornia.feature.SIFTFeature` does.
    - A detection is an integer pixel :math:`(u, v)` of a pyramid level of size ``(H_l, W_l)``, without a
      sub-pixel step. It is reported at the centre of that level pixel,
      :math:`((u + 0.5) W / W_l - 0.5, (v + 0.5) H / H_l - 0.5)` of the ``(H, W)`` input, in the frame of
      :func:`~kornia.feature.laf_from_center_scale_ori` (see :ref:`Local features <local-features-conventions>`).
      The Key.Net reference reports :math:`(u W / W_l, v H / H_l)` instead. For :math:`f = W / W_l > 1` (likewise
      along y) that is :math:`0.5 (f - 1)` px up and to the left of the centre, about 1.5 px on the default coarsest
      level; on the default up level, where :math:`f < 1`, it is about 0.15 px down and to the right.
    - Before ``aff_module`` and ``ori_module`` run, the frame is upright and isotropic, with the scale
      ``s_mult * (W / W_l + H / H_l) / 2`` whatever the response; ``s_mult`` of ``config`` is 22 by default.

Args:
    model: response function, such as KeyNet or BlobHessian
    num_features: Number of features to detect. Every pyramid level is searched for this many
        candidates and the whole set is ranked together, so the result is the ``num_features``
        highest responses in the image, and the sorted response vector for one value is a prefix
        of the vector for any larger one. Which detection carries a given response is not pinned
        when responses tie: ``topk`` breaks a tie by position, and the positions it ranks over
        depend on ``num_features``.
    config: Dict with initialization parameters. Do not pass it, unless you know what you are doing. The
        pyramid has ``up_levels`` levels (1 by default) upscaled by successive powers of ``scale_factor_levels``
        (``sqrt(2)``), the input, and ``pyramid_levels`` levels (4) below it, each the previous one downscaled by
        ``scale_factor_levels`` with :func:`~kornia.geometry.transform.pyrdown`; ``nms_size`` (15) is the side of
        the suppression window in level pixels, and ``s_mult`` (22) the frame scale, in level pixels.
    ori_module: for local feature orientation estimation. Default: :class:`~kornia.feature.PassLAF`,
       which does nothing. See :class:`~kornia.feature.LAFOrienter` for details.
    aff_module: for local feature affine shape estimation. Default: :class:`~kornia.feature.PassLAF`,
        which does nothing. See :class:`~kornia.feature.LAFAffineShapeEstimator` for details.
    compile_model: wrap the response function and the non-maxima suppression with :func:`torch.compile`.
    score_threshold: minimum response for a position to count as a detection. Must be non-negative:
        non-maxima suppression writes an exact zero at every suppressed position, so a negative
        threshold would admit all of them; it raises ``ValueError``.

See Also:
    - :class:`ScaleSpaceDetector`: a batch of images, the sub-pixel maxima of a response over a Gaussian scale
      space, with scale selection across levels.
    - :class:`KeyNetDetector`: this detector on the learned KeyNet response.
    - :class:`SIFTFeature`: this detector on the magnitude of a DoG response, with SIFT descriptors.

Example:
    >>> detector = MultiResolutionDetector(BlobHessian(), num_features=50)
    >>> lafs, responses = detector(torch.rand(1, 1, 64, 64))
    >>> lafs.shape, responses.shape
    (torch.Size([1, 50, 2, 3]), torch.Size([1, 50]))

Nc                ó´   <€ V ^8„  d   QhRS[ P                  RS[RS[S[,          RS[S[ P                  ,          RS[S[ P                  ,          RS[RS[RR	/# )
r    Úmodelr½   rì   rÂ   rÃ   Úcompile_modelÚscore_thresholdr$   N)r
   r•   r(   r   rŒ  r–   r5   )r)   rÈ   s   "€r*   r+   Ú$MultiResolutionDetector.__annotate__§  sv   ø€ ÷ +"ñ +"á�y‰yð+"ñ ð+"ñ ™Õ)ð	+"ñ
 ™RŸY™YÕ'ð+"ñ ™RŸY™YÕ'ð+"ñ ð+"ñ ð+"ð 
ñ+"r,   c                óX  <€ \         S	V `  4        Vf   \        4       pVR,          V n        VR,          V n        VR,          V n        VR,          V n        VR,          V n        V^ 8  d   \        RV 24      hWpn	        \        V P                  V P                  34      pW n        V'       d<   \        P                  ! VRR7      V n        \        P                  ! VRR7      V n        MWn        W€n        Vf   \!        4       V n        MW@n        Vf   \!        4       V n        R # WPn        R # )	Nr�  r�  r‘  r’  rŽ  z*score_threshold must be non-negative. Got TrÔ   )rÝ   rÞ   r™  Únum_pyramid_levelsÚnum_upscale_levelsr‘  r¾   rŽ  rà   rŸ  r   r½   r&   r×   r�  Únmsr   rÍ   rÎ   )
rØ   r�  r½   rì   rÂ   rÃ   rž  rŸ  r¤  rä   s
   &&&&&&&& €r*   rÞ   Ú MultiResolutionDetector.__init__§  sø   ø€ ô 	‰ÑÔØŠ>Ü0Ó2ˆFà"(Ð)9Õ":ˆÔØ"(¨Õ"5ˆÔØ#)Ð*?Õ#@ˆÔ Ø˜hÕ'ˆŒØ˜zÕ*ˆŒØ˜QÔô ÐIÈ/ÐIZÐ[Ó\Ð\Ø.ÔÜ$ d§m¡m°T·]±]Ð%CÓDˆØ(ÔçÜŸš u°dÔ;ˆDŒJÜ—}’} S°$Ô7ˆD�HàŒJØŒHàÒÜ")£)ˆD�Hà!ŒHàÒÜ")£)ˆDŽHà!ŽHr,   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# )r    Ú	score_mapÚbordersr$   r%   )r)   rÈ   s   "€r*   r+   r   Ô  s*   ø€ ÷ 3ñ 3©¯©ð 3¹sð 3ÉEÏLÉLñ 3r,   c                óH  € VP                   RR w  r4\        P                  ! W1P                  R7      p\        P                  ! WAP                  R7      pWR8¬  WSV,
          8  ,          P	                  V^4      Wb8¬  WdV,
          8  ,          ,          pVP                  V( R4      # )aV  Zero the strip of ``borders`` pixels along each side of a level, so that no detection is made there.

:meth:`detect_features_on_single_level` applies it to the non-maxima suppression output, not to the
response, so an override receives the suppressed map. The strip is set to an exact zero whatever the
score there, an infinite one included.
N)r[   r  rA   )r2   r&   Úaranger[   r3   r&  )rØ   r§  r¨  rL   rM   ÚrowsÚcolsÚinsides   &&&     r*   Úremove_bordersÚ&MultiResolutionDetector.remove_bordersÔ  s‰   € ð �‰˜r˜sÐ#‰ˆÜ�|Š|˜A×&6Ñ&6Ô7ˆÜ�|Š|˜A×&6Ñ&6Ô7ˆØ‘? t°'­kÑ'9Õ:×@Ñ@ÀÀAÓFÈ4É?Ð_cÐjqÕfqÑ_qÕJrÕsˆØ×$Ñ$ f W¨cÓ2Ð2r,   r:   c                óÄ   <€ V ^8„  d   QhRS[ P                  RS[RS[S[S[3,          RS[S[ P                  ,          RS[S[ P                  S[ P                  3,          /# ©r    Ú	level_imgÚnum_kpÚfactorr:   r$   ©r&   r'   r(   r   r5   r   )r)   rÈ   s   "€r*   r+   r   á  sl   ø€ ÷ _ ñ _ á—<‘<ð_ ñ ð_ ñ ‘e™U�lÕ#ð	_ ñ ‘u—|‘|Õ$ð_ ñ 
‰u�|‰|™UŸ\™\Ð)Õ	*ñ_ r,   c               óø  € V P                  V4      p\        VP                  4       ^8H  ;'       d5    VP                  ^ ,          ^8H  ;'       d    VP                  ^,          ^8H  R\	        VP                  4       R24       \        VP                  RR VP                  RR 8H  R\	        VP                  RR 4       R\	        VP                  RR 4       R24       V P                  V P                  V4      4      pVeJ   \        WF4      pVP                  4       '       d!   \        Wg4      P                  V^ 8„  ( R4      pMWg,          pVP                  R,          pVP                  R4      p	V	P                  W�P                  8*  \        R4      4      p
\        W)P                  4       4      p\         P"                  ! W«R	7      w  rÍWÀP                  8„  p\         P$                  ! Wì\         P&                  ! V4      4      p\         P(                  ! WØ,          WØ,          .^R
7      p\         P*                  ! VP,                  \         P.                  4      p\         P0                  ! V^ ,          V^,          .VP2                  VR7      pVP                  ^V^4      P5                  ^4      P7                  V4      R,           V,          R,
          pRV^ ,          V^,          ,           ,          V P8                  ,          p\         P:                  ! ^V^^3VVP2                  VR7      p\=        VVVP?                  ^V^4      4      pVVP                  ^V^^4      P7                  VP,                  4      ,          pVV3# )a  Detect keypoints on one image-pyramid level.

The response function may consume a multi-channel image -- for example, a learned color detector -- but must
return one response map. A LAF has no response-channel identity, so independent per-channel detections are
ambiguous and rejected. :class:`ScaleSpaceDetector` follows the same contract.

A detection is a strict maximum of the response over its ``nms_size`` window, above ``score_threshold``,
that lies outside the 15 px strip along the level's sides. The suppression reads the whole response, the
strip included, and :meth:`remove_borders` then zeroes the strip in its output: a position beside the strip
is reported only when no response at least as strong, inside the strip or not, lies within its window.

Args:
    level_img: Image tensor for a single pyramid level.
    num_kp: Number of keypoints requested from this pyramid level.
    factor: Per-axis factor ``(W / W_l, H / H_l)`` from the current pyramid level to the original image:
        level pixel :math:`(u, v)` is reported at its centre,
        ``((u + 0.5) * factor[0] - 0.5, (v + 0.5) * factor[1] - 0.5)``.
    mask: Optional mask with shape ``(1, 1, H, W)`` at the *original* image resolution, saying where a
        detection may be. It is resampled onto this level conservatively and applied to the non-maxima
        suppression output, so a zero region drops every maximum within one level pixel of it and a
        floating-point weight scales the score. Keyword-only.

Returns:
    Tuple containing scores and local affine frames detected at the requested pyramid level, with
    ``min(num_kp, H_l * W_l)`` slots for a level of size ``(H_l, W_l)``. When the level holds fewer
    above-threshold maxima than that, the remaining slots are padded with a zero response and a zero LAF.
z@model must return one response map with shape (1, 1, H, W). Got z{. For a multi-channel image, convert it to grayscale first or use a response function that reduces the channels to one map.Nz?model must return a response map with the level's spatial size z. Got zA; pad the response function so that its output matches its input.r  r  r  r?   rZ   r  rA   rB   ) r�  r   r@   r2   r‰   r®  r¤  rN   rC   r~   r&  r3   rŸ  r5   r_   Únumelr&   r#  rw   r�   Ústackr  rE   rG   r`   r[   ÚfliprD   r¾   Úfullr   Ú	new_zeros)rØ   r²  r³  r´  r:   Úresp_mapÚdet_maprr   rM   Údet_flatÚ
det_maskedr  Ú
top_scoresÚtop_flat_idxÚvalidÚyxr{   ÚfxÚxy_projectedÚ	scale_valÚscalerŒ   s   &&&&$                 r*   Údetect_features_on_single_levelÚ7MultiResolutionDetector.detect_features_on_single_levelá  sô  € ðF —:‘:˜iÓ(ˆÜØ�L‰L‹N˜aÑ×UÐU H§N¡N°1Õ$5¸Ñ$:×UÐU¸x¿~¹~ÈaÕ?PÐTUÑ?UØNÌuÐU]×UcÑUcÓOdÐNeð f/ð /ô	
ô 	Ø�N‰N˜2˜3Ð 9§?¡?°2°3Ð#7Ñ7ØMÌeÐT]×TcÑTcÐdfÐdgÐThÓNiÐMjð kÜ˜Ÿ™¨¨Ð,Ó-Ð.Ð.oðqô	
ð ×%Ñ% d§h¡h¨xÓ&8Ó9ˆØÒÜ" 4Ó1ˆGð ×%Ñ%×'Ò'Ü(¨Ó:×FÑFÈÐSTÉÀ~ÐWZÓ[‘à!Õ+�Ø�M‰M˜"ÕˆØ—<‘< Ó#ˆð
 ×)Ñ)¨(×6JÑ6JÑ*JÌEÐRXËMÓZˆ
Ü�Ÿ™Ó(Ó)ˆÜ#(§:¢:¨jÔ#>Ñ ˆ
ð ×1Ñ1Ñ1ˆÜ—[’[ ´E×4DÒ4DÀZÓ4PÓQˆ
ô �[Š[˜,Õ+¨\Õ-=Ð>ÀAÔFˆÜ×"Ò" 9§?¡?´E·M±MÓBˆÜ�\Š\˜6 !�9 f¨Q¥iÐ0¸×9IÑ9IÐQUÔVˆØŸ™  1 aÓ(×-Ñ-¨aÓ0×3Ñ3°DÓ9¸CÕ?À2ÕEÈÕKˆØ˜6 !�9 v¨a¥yÕ0Õ1°D·L±LÕ@ˆ	Ü—
’
˜A˜q ! Q˜<¨¸9×;KÑ;KÐSWÔXˆÜ(¨°u¸e¿o¹oÈaÐQRÐTUÓ>VÓWˆØ�e—j‘j  A q¨!Ó,×/Ñ/°·
±
Ó;Õ;ˆØ˜4ÐÐr,   c                óÄ   <€ V ^8„  d   QhRS[ P                  RS[RS[S[S[3,          RS[S[ P                  ,          RS[S[ P                  S[ P                  3,          /# r±  rµ  )r)   rÈ   s   "€r*   r+   r   B  sg   ø€ ÷ Zñ ZÙŸ™ðZÙ/2ðZÙ<AÁ%ÉÀ,Õ<OðZÙW_Ñ`e×`lÑ`lÕWmðZá	‰u�|‰|™UŸ\™\Ð)Õ	*ñZr,   c                óT   € Vf   V P                  WV4      # V P                  WW4R7      # )N)r:   )rÈ  )rØ   r²  r³  r´  r:   s   &&&&&r*   Ú_detect_levelÚ%MultiResolutionDetector._detect_levelB  s2   € ð
 Š<Ø×7Ñ7¸	È6ÓRÐRØ×3Ñ3°IÀvÐ3ÓYÐYr,   c                ó¢   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[S[ P                  S[ P                  3,          /# r|  r}  )r)   rÈ   s   "€r*   r+   r   K  sM   ø€ ÷ Rñ R™%Ÿ,™,ð R©h±u·|±|Õ.Dð RÑPUÑV[×VbÑVbÑdi×dpÑdpÐVpÕPqñ Rr,   c           
     ó  € \        V. RO4       Ve   \        W!4       VP                  w   r4pTpTp. p. p	\        V P                  4       FÕ  p
V P
                  ^V
,           ,          p\        WK,          4      \        W[,          4      rÜ\        V4      \        V4      ,          \        V4      \        V4      ,          3p\        WlV3RRR7      pV P                  W`P                  Wâ4      w  ppVP                  VP                  ^R4      4       V	P                  V4       K×  	  \        V P                  ^,           4       F»  p
V
^ 8”  d^   \        WpP
                  R7      pVP                  w   r<p\        V4      \        V4      ,          \        V4      \        V4      ,          3pMRpV P                  WpP                  VV4      w  ppVP                  VP                  ^R4      4       V	P                  V4       K½  	  \        P                   ! V^4      p\        P                   ! V	^4      pVP                  ^,          V P                  8  d[   V P                  VP                  ^,          ,
          p\"        P$                  ! V^ V34      p\"        P$                  ! V^ ^ ^ ^ ^ V34      p\        P&                  ! VV P                  ^R7      w  pp\        P(                  ! V^VR	,          P+                  RR^^4      4      pVV3# )
a•  Detect local features in one image, a batch of one.

Args:
    img: Input image tensor with shape ``(1, C, H, W)``.
    mask: Optional mask with shape ``(1, 1, H, W)`` saying where a detection may be. A boolean or integer
        mask is binary (any non-zero value keeps a position), a floating-point mask is used as weights on
        the detection scores: a weight in ``(0, 1]`` scales a score toward the worst, so a down-weighted
        maximum never outranks a full-weight one, and a zero or negative weight suppresses. Weights above
        one are clamped to one, so a float 0/255 mask means what the integer one means. The weights are
        cast to the response's dtype. The mask is resampled onto every pyramid level conservatively, so a
        zero region suppresses every maximum within one level pixel of it.

Returns:
    Tuple containing detection scores and local affine frames, shaped ``(1, num_features)`` and
    ``(1, num_features, 2, 3)``, in that order, the reverse of ``forward``'s, holding the ``num_features``
    highest responses in the image and sorted by response, descending. The shape holds even when the image
    yields fewer above-threshold maxima than requested: those slots carry a zero response and a zero LAF,
    and sort after every real detection. The LAFs are float32 for a float16 or bfloat16 image and float64
    for a float64 one; the responses keep the response function's dtype.
ÚbilinearF)ÚinterpolationÚalign_corners)r´  r  ©Ú1ÚCr-  r.  rB   )r>   r>   r�   )r   rŠ   r2   r\   r£  r‘  r(   r5   r   rÌ  r½   Úappendr3   r¢  r   r&   rý   rm  rn  r#  r'  r  )rØ   r…   r:   rp  rL   rM   Úimg_upÚcur_imgÚall_responsesÚall_lafsÚ	idx_levelÚ	up_factorÚnhÚnwÚup_factor_kptsÚ
cur_scoresÚcur_lafsr´  rt  rŒ   rn  rT  s   &&&                   r*   ry  ÚMultiResolutionDetector.detectK  s~  € ô* 	˜3Ò 4Ô5ØÒÜ˜Ô"ð —Y‘Y‰
ˆˆ1�ØˆØˆØ,.ˆØ')ˆä˜t×6Ñ6Ö7ˆIà×0Ñ0°Q¸µ]ÕCˆIÜ˜�Ó'¬¨Q­]Ó);�Ü# A›h¬¨r«Õ2´E¸!³H¼uÀR»yÕ4HÐIˆNÜ˜F¨ H¸JÐV[Ô\ˆFà#'×#5Ñ#5°f×>OÑ>OÐQ_Ó#fÑ ˆJ˜à× Ñ  §¡°°BÓ!7Ô8Ø�O‰O˜HÖ%ñ 8ô ˜t×6Ñ6¸Õ:Ö;ˆIØ˜1Œ}Ü! '×2JÑ2JÔK�Ø&Ÿ}™}‘��1˜"Ü ›(¤U¨2£YÕ.´°a³¼5À»9Õ0DÐE‘à#�à#'×#5Ñ#5°g×?PÑ?PÐRXÐZ^Ó#_Ñ ˆJ˜Ø× Ñ  §¡°°BÓ!7Ô8Ø�O‰O˜HÖ%ñ <ô —I’I˜m¨QÓ/ˆ	Ü�yŠy˜ 1Ó%ˆð �:‰:�a�=˜4×,Ñ,Ô,Ø×#Ñ# d§j¡j°¥mÕ3ˆCÜŸš˜i¨!¨S¨Ó2ˆIÜ—5’5˜  1 a¨¨A¨sÐ3Ó4ˆDô  Ÿ*š* Y°$×2CÑ2CÈÔK‰ˆ	�4Ü�|Š|˜D ! T¨/Õ%:×%AÑ%AÀ"ÀbÈ!ÈQÓ%OÓPˆØ˜$ˆÐr,   c                ó¢   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[S[ P                  S[ P                  3,          /# r|  r}  )r)   rÈ   s   "€r*   r+   r   Ÿ  r~  r,   c                ó¸   € \        V. RO4       V P                  W4      w  r4\        V4      pV P                  WA4      pV P	                  WA4      p\        WE4      V3# )a¤  Three stage local feature detection.

First the location and scale of interest points are determined by detect function.
Then affine shape and orientation.

Args:
    img: image to extract features with shape ``(1, C, H, W)``. Only a batch of one image is accepted.
    mask: a mask saying where a detection may be, shape ``(1, 1, H, W)``. A boolean or integer mask is
        binary, a floating-point mask weights the detection scores; see
        :meth:`~kornia.feature.MultiResolutionDetector.detect`.

Returns:
    Tuple of ``lafs`` with shape ``(1, N, 2, 3)``, the detected local affine frames, and ``responses`` with
    shape ``(1, N)``, the response function values for the corresponding lafs, with ``N = num_features``.
    When the image yields fewer above-threshold maxima than ``num_features``, the remaining slots hold a zero
    response and a zero LAF, whichever affine-shape and orientation modules are configured.

rÓ  )r   ry  r   rÎ   rÍ   r‘   r€  s   &&&   r*   r�  ÚMultiResolutionDetector.forwardŸ  sW   € ô& 	˜3Ò 4Ô5ØŸ+™+ cÓ0‰ˆ	ô ˜tÓ$ˆØ�x‰x˜Ó"ˆØ�x‰x˜Ó"ˆÜ˜dÓ+¨YÐ6Ð6r,   )rÎ   r�  r¾   r¤  rŽ  r½   r¢  r£  rÍ   r‘  rŸ  )i   NNNFr  )é   rS   )rô   rƒ  r„  r…  r†  rÞ   r®  rÈ  rÌ  ry  r�  r‡  rˆ  r‰  rŠ  s   @@r*   r›  r›  ]  sa   ù‡ € ñG÷R+"õ +"÷Z3ò 3ð_ ð (,÷_ ò _ ÷BZð Z÷Rò R÷h7÷ 7ò 7r,   r›  rŽ  r�  r�  r‘  r’  g      6@c                ó@   € V ^8„  d   Qh/ ^ \         9   d
   \        ;R&   # )r    r—  )Ú__conditional_annotations__rŒ  )r)   s   "r*   r+   r+      s   € ‡�÷T%ò œ/ñ òU% r,   rS   )@rè  ÚmathÚ
contextlibr   Útypingr   r   r   r   r   r	   r&   Útorch.nn.functionalr
   Ú
functionalrm  Úkornia.core.checkr   r   r   r   Úkornia.core.utilsr   Úkornia.geometry.subpixr   r   r   r   r   Úkornia.geometry.transformr   r   r   Úlafr   r   Úorientationr   rt  r   r   r   r   r8   rN   rJ   r~   rƒ   rŠ   r‘   rœ   r¡   r°   r«   r±   r¹   r•   r»   rŒ  r™  r›  Úsqrtr—  r+   )rè  s   @r*   Ú<module>rõ     s  øð÷$ €Ý "ß J× Jã ß Ð Ý ç jÓ jÝ 0÷õ ÷ DÑ Cç 9Ý  ß EÓ Eõõ*õ05÷:cõ88õ
õ$Nð  $Ð%9Ð;PÐQ€õ#ð$ "-¨g°|ÀZÐ PÐ õPõ
õ0ôH	7˜Ÿ™ô H	7ôV�iô õ$+ô\7˜bŸi™iô \7ðB �Ø�aØ�Ø˜4Ÿ9š9 Q›<Øˆdð-Ð õ r,   