+
    åûj&  ã                   ó²   € ^ RI Ht ^ RIt^ RIHu Ht ^ RIHt ^ RIHtH	t	H
t
 ^ RIHtHt ^ RIHtHt R R ltRR	 R
 llt ! R R]P&                  4      tR# )é    )ÚListN)Únn)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_TENSORÚKORNIA_CHECK_SHAPE)Úfilter3dÚget_gaussian_kernel3d)Ú_VALID_PADDINGÚ_compute_paddingc                óz   € V ^8„  d   QhR\         P                  R\        \        ,          R\         P                  /# )é   ÚimgÚcropping_shapeÚreturn)ÚtorchÚTensorr   Úint)Úformats   "ÚQC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\metrics\ssim3d.pyÚ__annotate__r      s-   € ÷ ñ Œu�|‰|ð ¬T´#­Yð ¼5¿<¹<ñ ó    c           
     óœ   € \         P                  ! V V^,          ) V^,          ) V^,          ) V^,          ) V^ ,          ) V^,          ) 34      # )z.Crop out the part of "valid" convolution area.)ÚFÚpad)r   r   s   &&r   Ú_cropr      s]   € ä�5Š5Øà˜AÕÐØ˜AÕÐØ˜AÕÐØ˜AÕÐØ˜AÕÐØ˜AÕÐð	
ó
ð 
r   c                ó¨   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        R\        R\        R\         P                  /# )r   Úimg1Úimg2Úwindow_sizeÚmax_valÚepsÚpaddingr   )r   r   r   ÚfloatÚstr)r   s   "r   r   r   ,   sc   € ÷ G0ñ G0Ü
�,‰,ðG0ä
�,‰,ðG0ô ðG0ô ð	G0ô
 
ðG0ô ðG0ô ‡\�\ñG0r   c                óˆ	  € \        V 4       \        V4       \        V . RO4       \        V. RO4       \        V P                  VP                  8H  RV P                   RVP                   24       \	        V\
        4      '       g   \        R\        V4       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\)        W"V3RV P*                  VR7      pRV,          ^,          p	RV,          ^,          p
\        P,                  ! V P*                  P                  R	R
7      ;_uu_ 4        \/        WRR7      p\/        WRR7      pRRR4       . pVR8X  d9   VP                  RR w  rïp\1        WïV.4      p\3        XV4      p\3        XV4      pMVR8X  d    X^,          pX^,          pW¼,          p\        P,                  ! V P*                  P                  R	R
7      ;_uu_ 4        \/        V ^,          VRR7      p\/        V^,          VRR7      p\/        W,          VRR7      pRRR4       VR8X  d&   \3        XV4      p\3        XV4      p\3        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-voxel structural similarity (SSIM) map between two volumes.

``ssim_map = ssim3d(img1, img2, window_size)`` takes two ``(B, C, D, H, W)`` volumes and returns the SSIM index at
every voxel, channel and sample; average the map for a score. The formula is that of
:func:`~kornia.metrics.ssim`, with an isotropic Gaussian window over ``(D, H, W)``.

Convention:
    See the Convention block of :func:`~kornia.metrics.ssim` for the window, reflected border, ``padding`` and
    ``max_val``; ``'valid'`` crops every axis. A volume of identical slices reproduces the 2-D map up to
    floating-point roundoff.

Args:
    img1: the first volume with shape ``(B, C, D, H, W)``.
    img2: the second volume with the shape of ``img1``.
    window_size: size of the Gaussian window in voxels, a positive odd integer.
    max_val: data range :math:`L` of the volumes, 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.

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

Note:
    The volume is reflected at its faces for ``padding='same'``, as :func:`kornia.metrics.ssim` does for
    images, across any positive spatial size, including ``D = 1``. The Gaussian window is built on the device
    of the inputs, in the dtype they are filtered in.
    Integer images are converted to float32 before computing the local moments.
    Half-precision inputs are evaluated in float32 for numerical stability.
    Filtering runs with autocast disabled; the result uses the promoted input dtype.
    On CUDA the float32 filtering follows ``torch.backends.cudnn.allow_tf32``, which PyTorch enables by default.
    cuDNN can then filter a single-channel volume with a TF32 kernel, which rounds the inputs of the local
    moments to 10 mantissa bits. The variances are differences of those moments, so in flat regions the map can
    be off by more than ``1e-2``. Set ``torch.backends.cudnn.allow_tf32 = False`` when float32 accuracy matters.

See Also:
    - :class:`~kornia.metrics.SSIM3D`: the module form.
    - :func:`~kornia.metrics.ssim`: the same map for images.
    - :func:`~kornia.losses.ssim3d_loss`: the dissimilarity :math:`(1 - \text{SSIM}) / 2`, clamped to
      :math:`[0, 1]`.

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

z,img1 and img2 shapes must be the same. Got: z and z'Input max_val type is not a float. Got zInvalid padding mode, z. Expected one of )ÚdeviceÚdtypeg{®Gáz„?g¸…ëQ¸ž?F)Údevice_typeÚenabledÚreflect)Úborder_typeNÚvalidÚsameg       @)ÚBÚCÚDÚHÚW)ç      ø?r3   r3   éýÿÿÿ)r   r   r   ÚshapeÚ
isinstancer#   Ú	TypeErrorÚtyper$   Úlowerr
   Úis_floating_pointÚ
is_complexÚtor   Úfloat32Úpromote_typesr'   Úfloat16Úbfloat16r	   r&   Úautocastr   r   r   )r   r   r   r    r!   r"   Úoutput_dtypeÚcompute_dtypeÚkernelÚC1ÚC2Úmu1Úmu2r   ÚdepthÚheightÚwidthÚmu1_sqÚmu2_sqÚmu1_mu2Ú
mu_img1_sqÚ
mu_img2_sqÚmu_img1_img2Ú	sigma1_sqÚ	sigma2_sqÚsigma12ÚnumÚdens   &&&&&&                      r   Ússim3drW   ,   s»  € ôn ˜4Ô Ü˜4Ô Ü�tÒ6Ô7Ü�tÒ6Ô7Ü�—‘˜tŸz™zÑ)Ð-YÐZ^×ZdÑZdÐYeÐejÐko×kuÑkuÐjvÐ+wÔxä�gœu×%Ò%ÜÐAÄ$ÀwÃ-ÀÐQÓRÐRäÜˆ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Ø	 ;Ð/°ÈÏÉÐ\iô€Fð
 ˜• AÕ%€BØ˜• AÕ%€Bô 
�Š D§K¡K×$4Ñ$4¸e×	DÖ	DÜ$ T¸yÔIˆÜ$ T¸yÔIˆ÷ 
Eð !#€NØ�'ÔØ%Ÿ|™|¨B¨CÐ0Ñˆ�uÜ)¨5¸%Ð*@ÓAˆÜ�C˜Ó(ˆÜ�C˜Ó(‰Ø	�FÔ	Øà�!�V€FØ�!�V€FØ�i€Gä	�Š D§K¡K×$4Ñ$4¸e×	DÖ	DÜ˜d A�g v¸9ÔEˆ
Ü˜d A�g v¸9ÔEˆ
Ü ¥¨VÀÔKˆ÷ 
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   Ë$RÎ?R1ÒR.	Ò1S	c                   óX   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RtVtV ;t	# )ÚSSIM3DaÀ  Compute the per-voxel structural similarity (SSIM) map between two volumes (module form).

``criterion = SSIM3D(window_size, ...)`` stores its arguments, and ``ssim_map = criterion(img1, img2)`` is
:func:`~kornia.metrics.ssim3d` on two ``(B, C, D, H, W)`` volumes.

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

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

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

See Also:
    - :func:`~kornia.metrics.ssim3d`: the one-call form.
    - :class:`~kornia.metrics.SSIM`: the same map for images.
    - :class:`~kornia.losses.SSIM3DLoss`: the dissimilarity loss built on this map.

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

c          
      ó6   <€ V ^8„  d   QhRS[ RS[RS[RS[RR/# )r   r   r    r!   r"   r   N)r   r#   r$   )r   Ú__classdict__s   "€r   r   ÚSSIM3D.__annotate__Ø   s2   ø€ ÷ ñ ¡Cð ±%ð ÁEð Ñ\_ð Ðmqñ r   c                óT   <€ \         SV `  4        Wn        W n        W0n        W@n        R # )N)ÚsuperÚ__init__r   r    r!   r"   )Úselfr   r    r!   r"   Ú	__class__s   &&&&&€r   r_   ÚSSIM3D.__init__Ø   s#   ø€ Ü‰ÑÔØ +ÔØ%ŒØŒØŽr   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# )r   r   r   r   )r   r   )r   r[   s   "€r   r   r\   ß   s3   ø€ ÷ Zñ Z™EŸL™Lð Z±·±ð ZÁÇÁñ Zr   c                óp   € \        WV P                  V P                  V P                  V P                  4      # )ab  Compute a 3D SSIM map between two volume batches.

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

Returns:
    Tensor with shape ``(B, C, D, H, W)``, cropped under ``padding='valid'``, containing local
    structural similarity values across depth, height, and width.
)rW   r   r    r!   r"   )r`   r   r   s   &&&r   ÚforwardÚSSIM3D.forwardß   s)   € ô �d $×"2Ñ"2°D·L±LÀ$Ç(Á(ÈDÏLÉLÓYÐYr   )r!   r    r"   r   ©g      ð?gê-�™—q=r-   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r_   re   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)ra   r[   s   @@r   rY   rY   ¶   s'   ù‡ € ñ÷Bõ ÷Z÷ Zð Zr   rY   rg   )Útypingr   r   Útorch.nn.functionalr   Ú
functionalr   Úkornia.core.checkr   r   r   Úkornia.filtersr   r	   Úkornia.filters.filterr
   r   r   rW   ÚModulerY   © r   r   Ú<module>rx      s@   ðõ$ ã ß Ð Ý ç VÑ Vß :ß Bõ÷G0ôT4ZˆR�Y‰Yö 4Zr   