§
    ’©ºj}  ã                   ó²  — d dl mZ d dlmZ d dlZd dlmZ d dlmZ de	de
dej        d	eej        ef         d
ef
d„Zde	dee	         dee
         dej        d	eej        ef         d
efd„Zdede	d
eeef         fd„Zddede	de	de	d
ef
d„Zddede	de	d
efd„Zdede	d
efd„Zde	dee	         dee
         dej        d	ej        d
efd„Zdede	de	de	d
ef
d„ZdS )é    )ÚSequence)ÚUnionN)ÚTensor)Ú
functionalÚkernel_sizeÚsigmaÚdtypeÚdeviceÚreturnc                 óþ   — t          j        d| z
  dz  d| z   dz  d||¬¦  «        }t          j        t          j        ||z  d¦  «         dz  ¦  «        }||                     ¦   «         z                       d¬¦  «        S )aY  Compute 1D gaussian kernel.

    Args:
        kernel_size: size of the gaussian kernel
        sigma: Standard deviation of the gaussian kernel
        dtype: data type of the output tensor
        device: device of the output tensor

    Example:
        >>> _gaussian(3, 1, torch.float, 'cpu')
        tensor([[0.2741, 0.4519, 0.2741]])

    é   é   )ÚstartÚendÚstepr	   r
   r   ©Údim)ÚtorchÚarangeÚexpÚpowÚsumÚ	unsqueeze)r   r   r	   r
   ÚdistÚgausss         ús/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/image/utils.pyÚ	_gaussianr   	   s~   € õ Œ<˜q ;™°!Ñ3¸!¸k¹/ÈQÑ9NÐUVÐ^cÐlrÐsÑsÔs€DÝŒI•u”y ¨¡¨qÑ1Ô1Ð1°AÑ5Ñ6Ô6€EØ�E—I’I‘K”KÑ×*Ò*¨qÐ*Ñ1Ô1Ð1ó    Úchannelc                 ó  — t          |d         |d         ||¦  «        }t          |d         |d         ||¦  «        }t          j        |                     ¦   «         |¦  «        }|                     | d|d         |d         ¦  «        S )aµ  Compute 2D gaussian kernel.

    Args:
        channel: number of channels in the image
        kernel_size: size of the gaussian kernel as a tuple (h, w)
        sigma: Standard deviation of the gaussian kernel
        dtype: data type of the output tensor
        device: device of the output tensor

    Example:
        >>> _gaussian_kernel_2d(1, (5,5), (1,1), torch.float, "cpu")
        tensor([[[[0.0030, 0.0133, 0.0219, 0.0133, 0.0030],
                  [0.0133, 0.0596, 0.0983, 0.0596, 0.0133],
                  [0.0219, 0.0983, 0.1621, 0.0983, 0.0219],
                  [0.0133, 0.0596, 0.0983, 0.0596, 0.0133],
                  [0.0030, 0.0133, 0.0219, 0.0133, 0.0030]]]])

    r   r   )r   r   ÚmatmulÚtÚexpand)r   r   r   r	   r
   Úgaussian_kernel_xÚgaussian_kernel_yÚkernels           r   Ú_gaussian_kernel_2dr'      s{   € õ2 " +¨a¤.°%¸´(¸EÀ6ÑJÔJÐÝ! +¨a¤.°%¸´(¸EÀ6ÑJÔJÐÝŒ\Ð+×-Ò-Ñ/Ô/Ð1BÑCÔC€Fà�=Š=˜ ! [°¤^°[À´^ÑDÔDÐDr   ÚinputsÚwindow_sizec                 ó¤   — t          j        dd||| j        | j        ¬¦  «        }||dz  z  }t          j        d| j        | j        ¬¦  «        }||fS )zÒConstruct uniform weight and bias for a 2d convolution.

    Args:
        inputs: Input image
        window_size: size of convolutional kernel

    Return:
        The weight and bias for 2d convolution

    r   )r	   r
   r   )r   Úonesr	   r
   Úzeros)r(   r)   Úkernel_weightÚkernel_biass       r   Ú_uniform_weight_bias_conv2dr/   <   sY   € õ ”J˜q ! [°+ÀVÄ\ÐZ`ÔZgÐhÑhÔh€MØ�[ !‘^Ñ#€MÝ”+˜a v¤|¸F¼MÐJÑJÔJ€KØ˜+Ð%Ð%r   r   ÚpadÚ	outer_padc           	      ól  — | j         |         }t          j        | |t          j        |dz
  dd¦  «                             | j        ¦  «        ¦  «        }t          j        | |t          j        |dz
  ||z
  |z
  d¦  «                             | j        ¦  «        ¦  «        }t          j        || |f|¦  «        S )a,  Apply single-dimension reflection padding to match scipy implementation.

    Args:
        inputs: Input image
        dim: A dimension the image should be padded over
        pad: Number of pads
        outer_pad: Number of outer pads

    Return:
        Image padded over a single dimension

    r   éÿÿÿÿ)Úshaper   Úindex_selectr   Útor
   Úcat)r(   r   r0   r1   Ú_maxÚxÚys          r   Ú_single_dimension_padr;   M   s    € ð Œ<˜Ô€DÝÔ˜6 3­¬°S¸1±W¸bÀ"Ñ(EÔ(E×(HÒ(HÈÌÑ(WÔ(WÑXÔX€AÝÔ˜6 3­¬°T¸A±X¸tÀc¹zÈIÑ?UÐWYÑ(ZÔ(Z×(]Ò(]Ð^dÔ^kÑ(lÔ(lÑmÔm€AÝŒ9�a˜ �^ SÑ)Ô)Ð)r   c                 ó4   — dD ]}t          | |||¦  «        } Œ| S )z¿Apply reflection padding to the input image.

    Args:
        inputs: Input image
        pad: Number of pads
        outer_pad: Number of outer pads

    Return:
        Padded image

    )r   é   )r;   )r(   r0   r1   r   s       r   Ú_reflection_pad_2dr>   `   s/   € ð ð Dð DˆÝ& v¨s°C¸ÑCÔCˆˆØ€Mr   c                 óÔ   ‡ ‡‡— t          ‰ |dz  |dz  ¦  «        Š t          ‰ |¦  «        \  ŠŠt          j        ˆ ˆˆfd„t	          ‰ j        d         ¦  «        D ¦   «         d¬¦  «        S )zñApply uniform filter with a window of a given size over the input image.

    Args:
        inputs: Input image
        window_size: Sliding window used for rmse calculation

    Return:
        Image transformed with the uniform input

    r   c                 óz   •— g | ]7}t          j        ‰d d …|f                              d¦  «        ‰‰d¬¦  «        ‘Œ8S )Nr   r   )Úpadding)ÚFÚconv2dr   )Ú.0r   r(   r.   r-   s     €€€r   ú
<listcomp>z#_uniform_filter.<locals>.<listcomp>€   sX   ø€ ð 	
ð 	
ð 	
àõ ŒH�V˜A˜A˜A˜w˜JÔ'×1Ò1°!Ñ4Ô4°mÀ[ÐZ[Ð\Ñ\Ô\ð	
ð 	
ð 	
r   r   r   )r>   r/   r   r7   Úranger4   )r(   r)   r.   r-   s   ` @@r   Ú_uniform_filterrG   q   s‘   øøø€ õ   ¨°qÑ(8¸+È¹/ÑJÔJ€FÝ!<¸VÀ[Ñ!QÔ!QÑ€M�;åŒ9ð	
ð 	
ð 	
ð 	
ð 	
ð 	
å  ¤¨a¤Ñ1Ô1ð	
ñ 	
ô 	
ð ðñ ô ð r   c           	      ó.  — t          |d         |d         ||¦  «        }t          |d         |d         ||¦  «        }t          |d         |d         ||¦  «        }t          j        |                     ¦   «         |¦  «        }t          j        |                     d¦  «                             dd|d         ¦  «        |                     |d         |d         |d         ¦  «        ¦  «        }	|	                     | d|d         |d         |d         ¦  «        S )a6  Compute 3D gaussian kernel.

    Args:
        channel: number of channels in the image
        kernel_size: size of the gaussian kernel as a tuple (h, w, d)
        sigma: Standard deviation of the gaussian kernel
        dtype: data type of the output tensor
        device: device of the output tensor

    r   r   r   r3   )r   r   r!   r"   Úmulr   Úrepeatr#   )
r   r   r   r	   r
   r$   r%   Úgaussian_kernel_zÚ	kernel_xyr&   s
             r   Ú_gaussian_kernel_3drM   ˆ   sù   € õ " +¨a¤.°%¸´(¸EÀ6ÑJÔJÐÝ! +¨a¤.°%¸´(¸EÀ6ÑJÔJÐÝ! +¨a¤.°%¸´(¸EÀ6ÑJÔJÐÝ”Ð.×0Ò0Ñ2Ô2Ð4EÑFÔF€IÝŒYØ×Ò˜BÑÔ×&Ò& q¨!¨[¸¬^Ñ<Ô<Ø× Ò  ¨Q¤°¸Q´ÀÈQÄÑPÔPñô €Fð �=Š=˜ ! [°¤^°[À´^À[ÐQRÄ^ÑTÔTÐTr   Úpad_hÚpad_wÚpad_dc           	      ó<   — t          j        | ||||||fd¬¦  «        S )aU  Reflective padding of 3d input.

    Args:
        inputs: tensor to pad, should be a 3D tensor of shape ``[N, C, H, W, D]``
        pad_w: amount of padding in the height dimension
        pad_h: amount of padding in the width dimension
        pad_d: amount of padding in the depth dimension

    Returns:
        padded input tensor

    Úreflect)Úmode)rB   r0   )r(   rN   rO   rP   s       r   Ú_reflection_pad_3drT       s(   € õ Œ5�˜% ¨¨u°e¸UÐCÈ)ÐTÑTÔTÐTr   )r   )Úcollections.abcr   Útypingr   r   r   Útorch.nnr   rB   ÚintÚfloatr	   r
   Ústrr   r'   Útupler/   r;   r>   rG   rM   rT   © r   r   ú<module>r]      s�  ðØ $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð à €€€Ø Ð Ð Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $ð2˜3ð 2 uð 2°U´[ð 2È%ÐPUÔP\Ð^aÐPaÔJbð 2Ðgmð 2ð 2ð 2ð 2ð&EØðEà˜#”ðEð �EŒ?ðEð Œ;ð	Eð
 �%”, Ð#Ô$ðEð ðEð Eð Eð Eð@&¨ð &¸Sð &ÀUÈ6ÐSYÈ>ÔEZð &ð &ð &ð &ð"*ð * &ð *¨sð *¸ð *Èð *ÐU[ð *ð *ð *ð *ð&ð ˜vð ¨Cð ¸Cð Èð ð ð ð ð"˜Fð °ð ¸ð ð ð ð ð.UØðUØ'¨œ}ðUØ5=¸e´_ðUØMRÌ[ðUØbgÔbnðUàðUð Uð Uð Uð0U˜vð U¨cð U¸#ð UÀcð UÈfð Uð Uð Uð Uð Uð Ur   