§
    )Áôg«  ã                   óH   — d dl Z d dlZd dlmZ ddlmZmZ d„ Zd„ Z		 d
d	„Z
dS )é    N)Úfftconvolveé   )Úcheck_nDÚ_supported_float_typec                 ó  — t          j        | d¬¦  «        }||d         d…         |d |d          dz
  …         z
  }t          j        |d¬¦  «        }|d d …|d         d…f         |d d …d |d          dz
  …f         z
  }|S )Nr   ©Úaxiséÿÿÿÿé   )ÚnpÚcumsum©ÚimageÚwindow_shapeÚ
window_sums      úa/var/www/html/bac/bac_backend/python/env/lib/python3.11/site-packages/skimage/feature/template.pyÚ_window_sum_2dr   	   s§   € Ý”˜5 qÐ)Ñ)Ô)€JØ˜L¨œO¨bÐ0Ô1°JÐ?UÀ,ÈqÄ/ÐAQÐTUÑAUÐ?UÔ4VÑV€Jå”˜:¨AÐ.Ñ.Ô.€Jà�1�1�1�l 1”o¨Ð*Ð*Ô+¨j¸¸¸Ð<R¸|ÈA¼Ð>NÐQRÑ>RÐ<RÐ9RÔ.SÑSð ð Ðó    c                 ó¸   — t          | |¦  «        }t          j        |d¬¦  «        }|d d …d d …|d         d…f         |d d …d d …d |d          dz
  …f         z
  }|S )Nr   r   r
   r   )r   r   r   r   s      r   Ú_window_sum_3dr      s€   € Ý  |Ñ4Ô4€Jå”˜:¨AÐ.Ñ.Ô.€Jà�1�1�1�a�a�a˜ aœ¨2Ð-Ð-Ô.Ø
�Q�Q�Q˜˜˜Ð1˜l¨1œoÐ-°Ñ1Ð1Ð1Ô
2ñ	3ð ð
 Ðr   FÚconstantc           	      óð  — t          | d¦  «         | j        |j        k     rt          d¦  «        ‚t          j        t          j        | j        |j        ¦  «        ¦  «        rt          d¦  «        ‚| j        }t          | j        ¦  «        }|  	                    |d¬¦  «        } t          d„ |j        D ¦   «         ¦  «        }|dk    rt          j        | |||¬¦  «        } nt          j        | ||¬	¦  «        } | j        d
k    r.t          | |j        ¦  «        }t          | d
z  |j        ¦  «        }	n8| j        dk    r-t          | |j        ¦  «        }t          | d
z  |j        ¦  «        }	|                     ¦   «         }
t          j        |j        ¦  «        }t          j        ||
z
  d
z  ¦  «        }| j        d
k    r-t%          | |ddd…ddd…f         d¬¦  «        dd…dd…f         }n>| j        dk    r3t%          | |ddd…ddd…ddd…f         d¬¦  «        dd…dd…dd…f         }|||
z  z
  }|	}t          j        |||¬¦  «         t          j        |||¬¦  «         ||z  }||z  }t          j        |d|¬¦  «         t          j        ||¬¦  «         t          j        ||¬¦  «        }|t          j        |¦  «        j        k    }||         ||         z  ||<   g }t5          |j        ¦  «        D ]r}|r|j        |         dz
  d
z  }|||         z   }n,|j        |         dz
  }|||         z   |j        |         z
  dz   }|                     t9          ||¦  «        ¦  «         Œs|t          |¦  «                 S )aK  Match a template to a 2-D or 3-D image using normalized correlation.

    The output is an array with values between -1.0 and 1.0. The value at a
    given position corresponds to the correlation coefficient between the image
    and the template.

    For `pad_input=True` matches correspond to the center and otherwise to the
    top-left corner of the template. To find the best match you must search for
    peaks in the response (output) image.

    Parameters
    ----------
    image : (M, N[, P]) array
        2-D or 3-D input image.
    template : (m, n[, p]) array
        Template to locate. It must be `(m <= M, n <= N[, p <= P])`.
    pad_input : bool
        If True, pad `image` so that output is the same size as the image, and
        output values correspond to the template center. Otherwise, the output
        is an array with shape `(M - m + 1, N - n + 1)` for an `(M, N)` image
        and an `(m, n)` template, and matches correspond to origin
        (top-left corner) of the template.
    mode : see `numpy.pad`, optional
        Padding mode.
    constant_values : see `numpy.pad`, optional
        Constant values used in conjunction with ``mode='constant'``.

    Returns
    -------
    output : array
        Response image with correlation coefficients.

    Notes
    -----
    Details on the cross-correlation are presented in [1]_. This implementation
    uses FFT convolutions of the image and the template. Reference [2]_
    presents similar derivations but the approximation presented in this
    reference is not used in our implementation.

    References
    ----------
    .. [1] J. P. Lewis, "Fast Normalized Cross-Correlation", Industrial Light
           and Magic.
    .. [2] Briechle and Hanebeck, "Template Matching using Fast Normalized
           Cross Correlation", Proceedings of the SPIE (2001).
           :DOI:`10.1117/12.421129`

    Examples
    --------
    >>> template = np.zeros((3, 3))
    >>> template[1, 1] = 1
    >>> template
    array([[0., 0., 0.],
           [0., 1., 0.],
           [0., 0., 0.]])
    >>> image = np.zeros((6, 6))
    >>> image[1, 1] = 1
    >>> image[4, 4] = -1
    >>> image
    array([[ 0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  1.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0., -1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.]])
    >>> result = match_template(image, template)
    >>> np.round(result, 3)
    array([[ 1.   , -0.125,  0.   ,  0.   ],
           [-0.125, -0.125,  0.   ,  0.   ],
           [ 0.   ,  0.   ,  0.125,  0.125],
           [ 0.   ,  0.   ,  0.125, -1.   ]])
    >>> result = match_template(image, template, pad_input=True)
    >>> np.round(result, 3)
    array([[-0.125, -0.125, -0.125,  0.   ,  0.   ,  0.   ],
           [-0.125,  1.   , -0.125,  0.   ,  0.   ,  0.   ],
           [-0.125, -0.125, -0.125,  0.   ,  0.   ,  0.   ],
           [ 0.   ,  0.   ,  0.   ,  0.125,  0.125,  0.125],
           [ 0.   ,  0.   ,  0.   ,  0.125, -1.   ,  0.125],
           [ 0.   ,  0.   ,  0.   ,  0.125,  0.125,  0.125]])
    )r   é   zUDimensionality of template must be less than or equal to the dimensionality of image.z#Image must be larger than template.F)Úcopyc              3   ó   K  — | ]}||fV — Œ	d S )N© )Ú.0Úwidths     r   ú	<genexpr>z!match_template.<locals>.<genexpr>ƒ   s&   è è € ÐAÐA¨�u˜e�nÐAÐAÐAÐAÐAÐAr   r   )Ú	pad_widthÚmodeÚconstant_values)r    r!   r   r   Nr
   Úvalid)r!   r   )Úoutr   )Údtype)r   ÚndimÚ
ValueErrorr   ÚanyÚlessÚshaper   r%   ÚastypeÚtupleÚpadr   r   ÚmeanÚmathÚprodÚsumr   ÚmultiplyÚdivideÚmaximumÚsqrtÚ
zeros_likeÚfinfoÚepsÚrangeÚappendÚslice)r   ÚtemplateÚ	pad_inputr!   r"   Úimage_shapeÚfloat_dtyper    Úimage_window_sumÚimage_window_sum2Útemplate_meanÚtemplate_volumeÚtemplate_ssdÚxcorrÚ	numeratorÚdenominatorÚresponseÚmaskÚslicesÚiÚd0Úd1s                         r   Úmatch_templaterN   !   s¶  € õf ˆU�FÑÔÐà„z�H”MÒ!Ð!Ýð4ñ
ô 
ð 	
õ 
„v�bŒg�e”k 8¤>Ñ2Ô2Ñ3Ô3ð @ÝÐ>Ñ?Ô?Ð?à”+€Kå'¨¬Ñ4Ô4€KØ�LŠL˜¨5ˆLÑ1Ô1€EåÐAÐA°(´.ÐAÑAÔAÑAÔA€IØˆzÒÐÝ”Ø˜Y¨TÀ?ð
ñ 
ô 
ˆˆõ ”�u¨	¸Ð=Ñ=Ô=ˆð „z�Q‚€Ý)¨%°´Ñ@Ô@ÐÝ*¨5°!©8°X´^ÑDÔDÐÐØ	Œ�qŠˆÝ)¨%°´Ñ@Ô@ÐÝ*¨5°!©8°X´^ÑDÔDÐà—M’M‘O”O€MÝ”i ¤Ñ/Ô/€OÝ”6˜8 mÑ3¸Ñ9Ñ:Ô:€Là„z�Q‚€Ý˜E 8¨D¨D¨b¨D°$°$°B°$¨JÔ#7¸gÐFÑFÔFÀqÈÀtÈQÈrÈTÀzÔRˆˆØ	Œ�qŠˆÝ˜E 8¨D¨D¨b¨D°$°$°B°$¸¸¸"¸Ð,<Ô#=ÀGÐLÑLÔLØˆbˆD�!�B�$˜˜"˜Ðô
ˆð Ð(¨=Ñ8Ñ8€Ià#€KÝ„KÐ Ð"2Ð8HÐIÑIÔIÐIÝ„IÐ Ð5EÐFÑFÔFÐFØÐ#Ñ#€KØ�<Ñ€KÝ„Jˆ{˜A ;Ð/Ñ/Ô/Ð/Ý„GˆK˜[Ð)Ñ)Ô)Ð)åŒ}˜U¨+Ð6Ñ6Ô6€Hð �œ +Ñ.Ô.Ô2Ò2€Dà˜t”_ {°4Ô'8Ñ8€HˆT�Nà€FÝ�8”=Ñ!Ô!ð %ð %ˆØð 	=Ø”. Ô# aÑ'¨AÑ-ˆBØ�k !”nÑ$ˆBˆBà” Ô" QÑ&ˆBØ�k !”nÑ$ x¤~°aÔ'8Ñ8¸1Ñ<ˆBØ�Š•e˜B ‘m”mÑ$Ô$Ð$Ð$à•E˜&‘M”MÔ"Ð"r   )Fr   r   )r/   Únumpyr   Úscipy.signalr   Ú_shared.utilsr   r   r   r   rN   r   r   r   ú<module>rR      s�   ðØ €€€à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;ð	ð 	ð 	ð	ð 	ð 	ð HIðY#ð Y#ð Y#ð Y#ð Y#ð Y#r   