
    3j                        S SK Jr  S SKrS SKJr  S SKJr      S               S	S jjr " S S\R                  5      rg)
    )annotationsN)nn)metricsc                    [         R                  " XX#XF5      nSU-
  nUS:X  a  UR                  5       nU$ US:X  a  UR                  5       nU$ US:X  a   U$ [	        S5      e)a  Compute a loss based on the SSIM measurement.

The loss, or the Structural dissimilarity (DSSIM) is described as:

.. math::

  \text{loss}(x, y) = \frac{1 - \text{SSIM}(x, y)}{2}

See :meth:`~kornia.losses.ssim` for details about SSIM.

Args:
    img1: the first input image with shape :math:`(B, C, D, H, W)`.
    img2: the second input image with shape :math:`(B, C, D, H, W)`.
    window_size: the size of the gaussian kernel to smooth the images.
    max_val: the dynamic range of the images.
    eps: Small value for numerically stability when dividing.
    reduction : Specifies the reduction to apply to the
     output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction will be applied,
     ``'mean'``: the sum of the output will be divided by the number of elements
     in the output, ``'sum'``: the output will be summed.
    padding: ``'same'`` | ``'valid'``. Whether to only use the "valid" convolution
     area to compute SSIM to match the MATLAB implementation of original SSIM paper.

Returns:
    The loss based on the ssim index.

Examples:
    >>> input1 = torch.rand(1, 4, 5, 5, 5)
    >>> input2 = torch.rand(1, 4, 5, 5, 5)
    >>> loss = ssim3d_loss(input1, input2, 5)

      ?meansumnonezInvalid reduction option.)r   ssim3dr   r	   NotImplementedError)	img1img2window_sizemax_valeps	reductionpaddingssim_maplosss	            N/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/losses/ssim3d.pyssim3d_lossr      sz    T %^^Dc[H >DFyy{ K 
e	xxz K 
f	 K ""=>>    c                  V   ^  \ rS rSrSr S           SU 4S jjjrSS jrSrU =r$ )	
SSIM3DLossU   ai  Create a criterion that computes a loss based on the SSIM measurement.

The loss, or the Structural dissimilarity (DSSIM) is described as:

.. math::

  \text{loss}(x, y) = \frac{1 - \text{SSIM}(x, y)}{2}

See :meth:`~kornia.losses.ssim_loss` for details about SSIM.

Args:
    window_size: the size of the gaussian kernel to smooth the images.
    max_val: the dynamic range of the images.
    eps: Small value for numerically stability when dividing.
    reduction : Specifies the reduction to apply to the
     output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction will be applied,
     ``'mean'``: the sum of the output will be divided by the number of elements
     in the output, ``'sum'``: the output will be summed.
    padding: ``'same'`` | ``'valid'``. Whether to only use the "valid" convolution
     area to compute SSIM to match the MATLAB implementation of original SSIM paper.

Returns:
    The loss based on the ssim index.

Examples:
    >>> input1 = torch.rand(1, 4, 5, 5, 5)
    >>> input2 = torch.rand(1, 4, 5, 5, 5)
    >>> criterion = SSIM3DLoss(5)
    >>> loss = criterion(input1, input2)

c                ^   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        g N)super__init__r   r   r   r   r   )selfr   r   r   r   r   	__class__s         r   r   SSIM3DLoss.__init__v   s*     	 +%'#r   c           	         [        XU R                  U R                  U R                  U R                  U R
                  5      $ r   )r   r   r   r   r   r   )r    r   r   s      r   forwardSSIM3DLoss.forward   s3    4t'7'7txxQUQ_Q_aeamamnnr   )r   r   r   r   r   r   g-q=r   same)r   intr   floatr   r)   r   strr   r*   returnNone)r   torch.Tensorr   r-   r+   r-   )	__name__
__module____qualname____firstlineno____doc__r   r$   __static_attributes____classcell__)r!   s   @r   r   r   U   sV    B sy$$).$;@$UX$lo$	$ $o or   r   r&   )r   r-   r   r-   r   r(   r   r)   r   r)   r   r*   r   r*   r+   r-   )	
__future__r   torchr   korniar   r   Moduler    r   r   <module>r:      s   $ #    8
8
8 8 	8
 
8 8 8 8v,o ,or   