+
    åûj©:  ã                   ó  € ^ RI Ht ^ RIt^ RIHu Ht ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHtHt ^ RIHtHtHt ]P$                  P&                  P)                  4       tR R	 ltR
 R ltR R ltRR R llt ! R R]P4                  4      tR# )é    )ÚListN)Únn)ÚKORNIA_CHECK)Úis_exporting)Úfilter2d_separableÚget_gaussian_kernel1d)Ú_VALID_PADDINGÚ_compute_paddingÚ_padc                óz   € V ^8„  d   QhR\         P                  R\        \        ,          R\         P                  /# )é   ÚimgÚcropping_shapeÚreturn)ÚtorchÚTensorr   Úint)Úformats   "ÚOC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\metrics\ssim.pyÚ__annotate__r       s-   € ÷ ñ Œu�|‰|ð ¬T´#­Yð ¼5¿<¹<ñ ó    c                óœ   € \         P                  P                  P                  W^,          ) V^,          ) V^ ,          ) V^,          ) 34      # )z.Crop out the part of "valid" convolution area.)r   r   Ú
functionalÚpad)r   r   s   &&r   Ú_cropr       sL   € ä�8‰8×Ñ×"Ñ"Ø˜aÕ Ð  >°!Õ#4Ð"4°~ÀaÕ7HÐ6HÈ>ÐZ[ÕK\ÐJ\Ð]óð r   c                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# ©r   Úimg1Úimg2r   )r   r   Úbool)r   s   "r   r   r   '   s)   € ÷ ñ œUŸ\™\ð ´·±ð Ä$ñ r   c                óÆ  € V P                   P                  R8H  ;'       EdA    V P                  \        P                  8H  ;'       Ed    \
        ;'       Ed    \        P                  P                  P                  ;'       dà    \        4       '       * ;'       dÉ    \        P                  P                  4       '       * ;'       dž    \        P                  P                  4       '       * ;'       ds    \        P                  ! 4       ;'       d!    V P                  ;'       g    VP                  '       * ;'       d)    V P!                  4       ;'       d    VP!                  4       # )zgSelect contiguous forward-only CPU float32 images, whose convolutions oneDNN runs faster channels-last.Úcpu)ÚdeviceÚtypeÚdtyper   Úfloat32Ú_HAS_MKLDNNÚbackendsÚmkldnnÚenabledr   ÚjitÚ
is_tracingÚ_CÚ _are_functorch_transforms_activeÚis_grad_enabledÚrequires_gradÚis_contiguous)r   r   s   &&r   Ú_ssim_cpu_eligibler2   '   s  € ð 	�‰×Ñ˜EÑ!÷ 	!ñ 	!Ø�J‰Jœ%Ÿ-™-Ñ'÷	!ñ 	!ä÷	!ñ 	!ô �N‰N×!Ñ!×)Ñ)÷		!ð 	!ô “Ô÷	!ð 	!ô —	‘	×$Ñ$Ó&Ô&÷	!ð 	!ô —‘×9Ñ9Ó;Ô;÷	!ð 	!ô ×&Ò&Ó(×WÐW¨d×.@Ñ.@×.VÐ.VÀD×DVÑDVÔX÷	!ð 	!ð ×ÑÓ ÷	!ð 	!ð ×ÑÓ ðr   c                óÞ   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\        R\        R\        \        ,          R\         P                  /# )	r   r   r   ÚkernelÚc1Úc2Úepsr   r   )r   r   Úfloatr   r   )r   s   "r   r   r   >   sl   € ÷ (#ñ (#Ü
�,‰,ð(#ä
�,‰,ð(#ô �L‰Lð(#ô 	ð	(#ô
 	ð(#ô 
ð(#ô œ•Ið(#ô ‡\�\ñ(#r   c                ó>  aaaaa€ V P                  \        P                  R7      p VP                  \        P                  R7      pV P                  ^,          VP                  R,          ^,          uooVP	                  ^^^R4      P                  S^^R4      oVP	                  ^^R^4      P                  S^R^4      oR VVVVV3R llpV! V 4      V! V4      r˜W‰,          p
VP                  ^4      V	P                  ^4      rË??	V! V ^,          4      P                  V4      pV! V^,          4      P                  V4      pVP                  V4      P                  V4      P                  VP                  V4      P                  V4      4      p????V! W,          4      P                  V
4      pV
P                  R4      P                  V4      P                  VP                  R4      P                  V4      4      p?VP                  VP                  V4      4      # )aÛ  SSIM map from channels-last copies of the images, with the arithmetic of the NCHW path.

Each moment is filtered with the reflect padding and the two depthwise convolutions of ``filter2d_separable``,
called directly: its reshape would give a single channels-last image ambiguous strides, which oneDNN reads as
NCHW. No gradient is recorded, so the moments are combined by the NCHW path's operations, each value in the same
order, in place on this function's own temporaries.
)Úmemory_formatc                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )r   r   r   ©r   r   )r   s   "r   r   Ú_ssim_cpu.<locals>.__annotate__T   s&   € ÷ Nñ N”%—,‘,ð N¤5§<¡<ñ Nr   c                 óX  <€ \         P                  ! R RR7      ;_uu_ 4        \        P                  ! \	        V SS^ ^ .R4      SSR7      p\        P                  ! \	        V^ ^ SS.R4      SSR7      pRRR4       \        S4      ^ 8”  d   \        XS4      # X#   + '       g   i     L.; i)r"   F©Údevice_typer*   Úreflect)ÚgroupsN)r   ÚautocastÚFÚconv2dr   Úlenr   )r   ÚoutÚchannelsr   ÚradiusÚweight_xÚweight_ys   & €€€€€r   ÚblurÚ_ssim_cpu.<locals>.blurT   sŒ   ø€ Ü�^Š^¨°u×=Ö=Ü—(’(œ4  f¨f°a¸Ð%;¸YÓGÈÐZbÔcˆCÜ—(’(œ4  a¨¨F°FÐ%;¸YÓGÈÐZbÔcˆC÷ >ô .1°Ó-@À1Ô-DŒu�S˜.Ó)ÐMÈ#ÐM÷ >×=ús   ¢ABÂB)	ç       @éÿÿÿÿ)Ú
contiguousr   Úchannels_lastÚshapeÚviewÚexpandÚpow_Úsub_Úadd_Úmul_Údiv_)r   r   r4   r5   r6   r7   r   rL   Úmu1Úmu2Úmu1_mu2Úmu1_sqÚmu2_sqÚ	sigma1_sqÚ	sigma2_sqÚdenÚsigma12ÚnumrH   rI   rJ   rK   s   &&&&&&f           @@@@r   Ú	_ssim_cpurd   >   s·  ü€ ð  �?‰?¬×)<Ñ)<ˆ?Ó=€DØ�?‰?¬×)<Ñ)<ˆ?Ó=€DØ—z‘z !•} f§l¡l°2Õ&6¸!Õ&;Ð€HˆfØ�{‰{˜1˜a  BÓ'×.Ñ.¨x¸¸A¸rÓB€HØ�{‰{˜1˜a  QÓ'×.Ñ.¨x¸¸BÀÓB€H÷Nô Nñ �D‹z™4 ›:ˆØ�i€GØ—X‘X˜a“[ #§(¡(¨1£+ˆFØˆSÙ�T˜1•W“×"Ñ" 6Ó*€IÙ�T˜1•W“×"Ñ" 6Ó*€IØ
�+‰+�fÓ
×
"Ñ
" 2Ó
&×
+Ñ
+¨I¯N©N¸9Ó,E×,JÑ,JÈ2Ó,NÓ
O€CØ�˜	 9Ù�4•;Ó×$Ñ$ WÓ-€GØ
�,‰,�sÓ
×
 Ñ
  Ó
$×
)Ñ
)¨'¯,©,°sÓ*;×*@Ñ*@ÀÓ*DÓ
E€CØØ�8‰8�C—H‘H˜S“MÓ"Ð"r   c                ó¨   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        R\        R\        R\         P                  /# )r   r   r   Úwindow_sizeÚmax_valr7   Úpaddingr   )r   r   r   r8   Ústr)r   s   "r   r   r   i   sc   € ÷ e0ñ e0Ü
�,‰,ðe0ä
�,‰,ðe0ô ðe0ô ð	e0ô
 
ðe0ô ðe0ô ‡\�\ñe0r   c           	     ó°  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V\        P                  4      '       g   \        R\	        V4       24      h\        V\
        4      '       g   \        R\	        V4       24      h\        V P                  4      ^8X  g   \        RV P                   24      h\        VP                  4      ^8X  g   \        RVP                   24      hV P                  VP                  8X  g&   \        RV P                   RVP                   24      h\        \        V4      P                  4       \        9   RV R	\         24       \        V4      P                  4       pV P                  4       '       g6   V P                  4       '       g    V P                  \        P                   4      p VP                  4       '       g6   VP                  4       '       g    VP                  \        P                   4      p\        P"                  ! V P$                  VP$                  4      pV P$                  \        P&                  \        P(                  39   d   V P                  4       p VP$                  \        P&                  \        P(                  39   d   VP                  4       p\        P"                  ! V P$                  VP$                  4      pV P                  V4      VP                  V4      r\+        VR
V P,                  VR7      pRV,          ^,          p	RV,          ^,          p
\/        W4      '       dh   VR8X  d0   \1        VP                  R,          VP                  R,          .4      M. p\3        WW‰W¤V4      pVP                  V\        P4                  R7      # \        P6                  ! V P,                  P                  RR7      ;_uu_ 4        \9        WV4      p\9        WV4      pRRR4       . pVR8X  d<   VP                  R,          ;pp\1        VV.4      p\;        XV4      p\;        XV4      pMVR8X  d    X^,          pX^,          pWÞ,          p\        P6                  ! V P,                  P                  RR7      ;_uu_ 4        \9        V ^,          Wˆ4      p\9        V^,          Wˆ4      p\9        W,          Wˆ4      pRRR4       VR8X  d&   \;        XV4      p\;        XV4      p\;        XV4      pMVR8X  d    XV,
          pXV,
          pXV,
          pRV,          V	,           RV,          V
,           ,          pVV,           V	,           VV,           V
,           ,          pVVV,           ,          P                  V4      #   + '       g   i     EL¤; i  + '       g   i     LÜ; i)a  Compute the per-pixel structural similarity (SSIM) map between two images.

``ssim_map = ssim(img1, img2, window_size)`` takes two ``(B, C, H, W)`` images and returns the SSIM index at
every pixel, channel and sample; average the map for a score.

.. math::

  \text{SSIM}(x, y) = \frac{(2\mu_x\mu_y+c_1)(2\sigma_{xy}+c_2)}
  {(\mu_x^2+\mu_y^2+c_1)(\sigma_x^2+\sigma_y^2+c_2)}

Convention:
    - The window is a sampled Gaussian with :math:`\sigma = 1.5` whatever ``window_size``, which sets only the
      number of taps and must be odd.
    - ``padding='same'`` pads with ``'reflect'``, the torch mode that :ref:`Filtering <filtering-conventions>` maps
      onto OpenCV and scipy, and keeps ``(H, W)``; ``'valid'`` drops ``window_size // 2`` pixels on every side
      and equals the ``'same'`` map cropped. Reflected borders extend across any positive spatial axis length,
      including a singleton axis.
    - ``max_val`` is the data range :math:`L`, a Python ``float``: :math:`c_1 = (0.01 L)^2` and
      :math:`c_2 = (0.03 L)^2`. Pixel values are not rescaled, so images in ``[0, 255]`` need ``max_val=255.0``.
      ``eps`` is added to the denominator: two identical flat images of value :math:`\mu` score
      :math:`1 - \text{eps} / ((2\mu^2 + c_1)\, c_2 + \text{eps})`. With the default ``eps=1e-12``, black
      images score about ``0.99998889`` at ``max_val=1.0``; the bias grows to ``0.1`` at ``max_val=0.1``.
      Use ``eps=0.0`` to omit this denominator term when matching reference implementations.
    - The map is symmetric in ``img1`` and ``img2``, in :math:`[-1, 1]` in exact arithmetic and negative for
      anti-correlated content. :ref:`Losses and metrics <losses-metrics-conventions>` maps its mean onto
      scikit-image, pytorch-msssim and torchmetrics.
    - ``padding`` accepts ``'same'`` and ``'valid'`` case-insensitively; unsupported values raise ``BaseError``.

Args:
    img1: the first image with shape ``(B, C, H, W)``.
    img2: the second image with the shape of ``img1``.
    window_size: size of the Gaussian window in pixels, a positive odd integer.
    max_val: data range :math:`L` of the images, as a Python float.
    eps: term added to the denominator.
    padding: ``'same'`` keeps the spatial size; ``'valid'`` keeps only the area where the window fits, as the
        MATLAB implementation of the SSIM paper does.

Returns:
    the SSIM map with shape ``(B, C, H, W)``, or ``(B, C, H - 2p, W - 2p)`` with ``p = window_size // 2``
    under ``padding='valid'``.

Note:
    Integer images are converted to float32 before computing the local moments.
    Half-precision inputs are evaluated in float32 for numerical stability.
    A float32/float64 pair is filtered in float64, with the Gaussian window built in that dtype.
    Filtering runs with autocast disabled; the result uses the promoted input dtype.
    On the CPU with oneDNN, when no gradient is recorded, two contiguous images computed in float32 are filtered
    in channels-last layout, which oneDNN convolves without first copying the image into blocks of 8 or 16
    channels. The map agrees with the NCHW convolutions to rounding and is returned contiguous. Builds without
    oneDNN, such as the macOS arm64 wheels, oneDNN switched off with ``torch.backends.mkldnn``, ``torch.func``
    transforms, and exported and traced graphs keep the NCHW convolutions.

See Also:
    - :class:`~kornia.metrics.SSIM`: the module form.
    - :func:`~kornia.metrics.ssim3d`: the same map for volumes.
    - :func:`~kornia.losses.ssim_loss`: the dissimilarity :math:`(1 - \text{SSIM}) / 2`, clamped to :math:`[0, 1]`.
    - :func:`~kornia.metrics.psnr`: a pixel-error measure of the same pair, as one score in dB.

Examples:
    >>> input1 = torch.rand(1, 4, 5, 5)
    >>> input2 = torch.rand(1, 4, 5, 5)
    >>> ssim_map = ssim(input1, input2, 5)  # 1x4x5x5

z+Input img1 type is not a torch.Tensor. Got z+Input img2 type is not a torch.Tensor. Got z'Input max_val type is not a float. Got z,Invalid img1 shape, we expect BxCxHxW. Got: z,Invalid img2 shape, we expect BxCxHxW. Got: z,img1 and img2 shapes must be the same. Got: z and zInvalid padding mode, z. Expected one of g      ø?)r#   r%   g{®Gáz„?g¸…ëQ¸ž?Úvalid)r%   r:   Fr?   NÚsamerN   rO   )Ú
isinstancer   r   Ú	TypeErrorr$   r8   rF   rR   Ú
ValueErrorr   ri   Úlowerr	   Úis_floating_pointÚ
is_complexÚtor&   Úpromote_typesr%   Úfloat16Úbfloat16r   r#   r2   r
   rd   Úcontiguous_formatrC   r   r   )r   r   rf   rg   r7   rh   Úoutput_dtypeÚcompute_dtyper4   ÚC1ÚC2ÚcropÚssim_maprZ   r[   r   ÚheightÚwidthr]   r^   r\   Ú
mu_img1_sqÚ
mu_img2_sqÚmu_img1_img2r_   r`   rb   rc   ra   s   &&&&&&                       r   Ússimrƒ   i   sƒ  € ôP �dœEŸL™L×)Ò)ÜÐEÄdÈ4ÃjÀ\ÐRÓSÐSä�dœEŸL™L×)Ò)ÜÐEÄdÈ4ÃjÀ\ÐRÓSÐSä�gœu×%Ò%ÜÐAÄ$ÀwÃ-ÀÐQÓRÐRäˆt�z‰z‹?˜aÔÜÐGÈÏ
É
À|ÐTÓUÐUäˆt�z‰z‹?˜aÔÜÐGÈÏ
É
À|ÐTÓUÐUà�:‰:˜Ÿ™Ô#ÜÐGÈÏ
É
À|ÐSXÐY]×YcÑYcÐXdÐeÓfÐfäÜˆG‹×ÑÓ¤Ñ.Ø
   	Ð);¼NÐ;KÐLôô
 �'‹l× Ñ Ó"€Gð ×!Ñ!×#Ò#¨D¯O©O×,=Ò,=Ø�w‰w”u—}‘}Ó%ˆØ×!Ñ!×#Ò#¨D¯O©O×,=Ò,=Ø�w‰w”u—}‘}Ó%ˆä×&Ò& t§z¡z°4·:±:Ó>€Là‡z�z”e—m‘m¤U§^¡^Ð4Ô4Ø�z‰z‹|ˆØ‡z�z”e—m‘m¤U§^¡^Ð4Ô4Ø�z‰z‹|ˆä×'Ò'¨¯
©
°D·J±JÓ?€MØ—‘˜Ó'¨¯©°Ó)?ˆ$ô 1°¸cÈ$Ï+É+Ð]jÔk€Fð ˜• AÕ%€BØ˜• AÕ%€Bä˜$×%Ò%ØIPÐT[ÔI[Ô §¡¨bÕ!1°6·<±<ÀÕ3CÐ DÔEÐacˆÜ˜T¨°R¸dÓCˆà�{‰{ ¼U×=TÑ=Tˆ{ÓUÐUô 
�Š D§K¡K×$4Ñ$4¸e×	DÖ	DÜ.¨t¸VÓDˆÜ.¨t¸VÓDˆ÷ 
Eð !#€NØ�'ÔØŸ™ bÕ)Ð)ˆ�Ü)¨6°5¨/Ó:ˆÜ�C˜Ó(ˆÜ�C˜Ó(‰Ø	�FÔ	Øà�!�V€FØ�!�V€FØ�i€Gä	�Š D§K¡K×$4Ñ$4¸e×	DÖ	DÜ'¨¨a­°Ó@ˆ
Ü'¨¨a­°Ó@ˆ
Ü)¨$­+°vÓFˆ÷ 
Eð
 �'ÔÜ˜: ~Ó6ˆ
Ü˜: ~Ó6ˆ
Ü˜\¨>Ó:‰Ø	�FÔ	Øð ˜VÕ#€IØ˜VÕ#€IØ˜WÕ$€Gð ˜w�¨Õ+°°gµÀÕ0BÕC€CØ &�¨2Õ-°)¸iÕ2GÈ"Õ2LÕM€Cà�3˜•9Õ×!Ñ! ,Ó/Ð/÷M 
E×	DÐ	Dú÷" 
E×	Dús   Ï=V1Ò89WÖ1W	×W	c                   óX   a a€ ] tR tRt oRtRV3R lV 3R llltV3R lR ltRtVtV ;t	# )	ÚSSIMi  a–  Compute the per-pixel structural similarity (SSIM) map between two images (module form).

``criterion = SSIM(window_size, ...)`` stores its arguments, and ``ssim_map = criterion(img1, img2)`` is
:func:`~kornia.metrics.ssim` on two ``(B, C, H, W)`` images.

Convention:
    See the Convention block of :func:`~kornia.metrics.ssim`.

Args:
    window_size: size of the Gaussian window in pixels, a positive odd integer.
    max_val: data range :math:`L` of the images, as a Python float.
    eps: term added to the denominator.
    padding: ``'same'`` or ``'valid'``, as in :func:`~kornia.metrics.ssim`.

Shape:
    - img1: ``(B, C, H, W)``.
    - img2: ``(B, C, H, W)``.
    - Output: ``(B, C, H, W)``, or ``(B, C, H - 2p, W - 2p)`` with ``p = window_size // 2`` under
      ``padding='valid'``.

See Also:
    - :func:`~kornia.metrics.ssim`: the one-call form.
    - :class:`~kornia.metrics.SSIM3D`: the same map for volumes.
    - :class:`~kornia.losses.SSIMLoss`: the dissimilarity loss built on this map.

Examples:
    >>> input1 = torch.rand(1, 4, 5, 5)
    >>> input2 = torch.rand(1, 4, 5, 5)
    >>> ssim = SSIM(5)
    >>> ssim_map = ssim(input1, input2)  # 1x4x5x5

c          
      ó6   <€ V ^8„  d   QhRS[ RS[RS[RS[RR/# )r   rf   rg   r7   rh   r   N)r   r8   ri   )r   Ú__classdict__s   "€r   r   ÚSSIM.__annotate__3  s2   ø€ ÷ ñ ¡Cð ±%ð ÁEð Ñ\_ð Ðmqñ r   c                óT   <€ \         SV `  4        Wn        W n        W0n        W@n        R # )N)ÚsuperÚ__init__rf   rg   r7   rh   )Úselfrf   rg   r7   rh   Ú	__class__s   &&&&&€r   r‹   ÚSSIM.__init__3  s#   ø€ Ü‰ÑÔØ +ÔØ%ŒØŒØŽr   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# r   r<   )r   r‡   s   "€r   r   rˆ   :  s3   ø€ ÷ Xñ X™EŸL™Lð X±·±ð XÁÇÁñ Xr   c                óp   € \        WV P                  V P                  V P                  V P                  4      # )a_  Compute a 2D SSIM map between two image batches.

Args:
    img1: First image tensor with shape ``(B, C, H, W)``.
    img2: Second image tensor with the same shape as ``img1``.

Returns:
    Tensor with shape ``(B, C, H, W)``, cropped under ``padding='valid'``, containing local structural
    similarity values for each channel and spatial location.
)rƒ   rf   rg   r7   rh   )rŒ   r   r   s   &&&r   ÚforwardÚSSIM.forward:  s)   € ô �D × 0Ñ 0°$·,±,ÀÇÁÈ$Ï,É,ÓWÐWr   )r7   rg   rh   rf   ©g      ð?gê-�™—q=rl   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r‹   r‘   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r�   r‡   s   @@r   r…   r…     s'   ù‡ € ñ÷Bõ ÷X÷ Xð Xr   r…   r“   )Útypingr   r   Útorch.nn.functionalr   r   rD   Úkornia.core.checkr   Úkornia.core.utilsr   Úkornia.filtersr   r   Úkornia.filters.filterr	   r
   r   r(   r)   Úis_availabler'   r   r2   rd   rƒ   ÚModuler…   © r   r   Ú<module>r¥      sf   ðõ$ ã ß Ð Ý å *Ý *ß Dß HÑ Hà�n‰n×#Ñ#×0Ñ0Ó2€õõõ.(#÷Ve0ôP4Xˆ2�9‰9ö 4Xr   