
    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[        R                  " SU-
  S-  SSS9nUS:X  a  [        R                  " U5      nU$ US:X  a  [        R
                  " U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, H, W)`.
    img2: the second input image with shape :math:`(B, C, 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)
    >>> input2 = torch.rand(1, 4, 5, 5)
    >>> loss = ssim_loss(input1, input2, 5)

      ?   r      )minmaxmeansumnonezInvalid reduction option.)r   ssimtorchclampr   r   NotImplementedError)	img1img2window_sizemax_valeps	reductionpaddingssim_maplosss	            L/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/losses/ssim.py	ssim_lossr      s    T %\\$kCYH ;;h!+:DFzz$ K 
e	yy 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$ )	SSIMLossU   aa  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)
    >>> input2 = torch.rand(1, 4, 5, 5)
    >>> criterion = SSIMLoss(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%   SSIMLoss.__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SSIMLoss.forward   s0    T%5%5t||TXXt~~_c_k_kllr   )r   r   r   r   r   r   g-q=r   same)r   intr   floatr   r/   r   strr   r0   returnNone)r   torch.Tensorr   r3   r1   r3   )	__name__
__module____qualname____firstlineno____doc__r%   r*   __static_attributes____classcell__)r'   s   @r   r    r    U   sV    B sy$$).$;@$UX$lo$	$ $m mr   r    r,   )r   r3   r   r3   r   r.   r   r/   r   r/   r   r0   r   r0   r1   r3   )	
__future__r   r   r   korniar   r   Moduler     r   r   <module>r?      s   $ #    8
8
8 8 	8
 
8 8 8 8v,mryy ,mr   