o
    oif                     @  sP   d dl mZ d dlmZ d dlmZmZ 				ddddZG dd deZdS )    )annotations)metrics)ModuleTensor      ?-q=meansameimg1r   img2window_sizeintmax_valfloateps	reductionstrpaddingreturnc           	      C  sZ   t | |||||}d| }|dkr| }|S |dkr"| }|S |dkr)	 |S td)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)

    r   r   sumnonezInvalid reduction option.)r   ssim3dr   r   NotImplementedError)	r
   r   r   r   r   r   r   ssim_maploss r   H/home/ubuntu/.local/lib/python3.10/site-packages/kornia/losses/ssim3d.pyssim3d_loss   s   *r   c                      s0   e Zd ZdZ	dd fddZdddZ  ZS )
SSIM3DLossa  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)

    r   r   r   r	   r   r   r   r   r   r   r   r   r   Nonec                   s,   t    || _|| _|| _|| _|| _d S N)super__init__r   r   r   r   r   )selfr   r   r   r   r   	__class__r   r   r"   t   s   

zSSIM3DLoss.__init__r
   r   r   c                 C  s   t ||| j| j| j| j| jS r    )r   r   r   r   r   r   )r#   r
   r   r   r   r   forward~   s   zSSIM3DLoss.forwardr   r   r   r	   )r   r   r   r   r   r   r   r   r   r   r   r   )r
   r   r   r   r   r   )__name__
__module____qualname____doc__r"   r&   __classcell__r   r   r$   r   r   S   s
    !
r   Nr'   )r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )	
__future__r   korniar   kornia.corer   r   r   r   r   r   r   r   <module>   s   ;