ó
    Å“,j2:  ã            	       óÜ   • S SK Jr  S SKrS SKJr  SSKJr  SSK	J
r
  S rSS jrS rS	 rS
 rSSSS\R                   SS\R                   \R                   4	S jrSSS\R                   4S jrg)é    )ÚwarnNé   )Úmeasure)Úensure_spacingc                 ó2  • [         R                  " U5      nX   n[         R                  " U* SS9n[         R                  " U5      U   n[         R                  " U5      (       a  [        U5      nOSnUS:”  a
  [        XSXHS9n[        U5      U:”  a  USU nU$ )z0
Return the highest intensity peak coordinates.
Ústable)ÚkindNé   )ÚspacingÚp_normÚmax_out)ÚnpÚnonzeroÚargsortÚ	transposeÚisfiniteÚintr   Úlen)	ÚimageÚmaskÚ	num_peaksÚmin_distancer   ÚcoordÚintensitiesÚidx_maxsortr   s	            Ú¢C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\skimage/feature/peak.pyÚ_get_high_intensity_peaksr   
   s‘   € ô
 �JŠJ�tÓ€EØ‘,€Kä—*’*˜k˜\°Ñ9€KÜ�LŠL˜Ó Ñ,€Eä	‡{‚{�9×ÑÜ�i“.‰àˆà�aÓÜØ°ñ
ˆô ˆ5ƒz�IÓØ�j�yÐ!ˆà€Ló    c                 ól  • UR                   S:X  d  U R                   S:X  a  X:„  $ [        R                  " XSS9nX:H  nUc  [        R                  " U5      O[        R                  " XS   5      nU(       a7  SUSS& Ub/  [        R
                  " U[        R                  " U5      5      nSXW'   XPU:„  -  nU$ )zB
Return the mask containing all peak candidates above thresholds.
r
   Únearest)Ú	footprintÚmodeNFT)ÚsizeÚndiÚmaximum_filterr   ÚallÚlogical_xorÚbinary_opening)r   r!   Ú	thresholdr   Ú	image_maxÚoutÚimage_is_trivialÚisolated_pxs           r   Ú_get_peak_maskr.   %   s¥   € ð ‡~�~˜Ó˜eŸj™j¨A›oØÑ Ð ä×"Ò" 5ÀIÑN€Ià
Ñ
€Cð '+¡l”r—v’v˜c”{¼¿º¸s¹yÓ8IÐÞØˆ‰AˆØÑäŸ.š.¨¬s×/AÒ/AÀ$Ó/GÓHˆKØ#ˆCÑà�9ÑÑ€CØ€Jr   c                 óÀ   • [        U5       HN  u  p#US:X  a  M  SU [        S5      4U-  [        SU5      4-   '   SU [        S5      4U-  [        U* S5      4-   '   MP     U $ )zSet label border values to 0.r   N)Ú	enumerateÚslice)ÚlabelÚborder_widthÚiÚwidths       r   Ú_exclude_borderr6   =   sp   € ô ˜lÖ+‰ˆØ�A‹:ÙØ<=ˆŒu�T‹{ˆn˜qÑ ¤E¨$°Ó$6Ð#8Ñ8Ñ9Ø=>ˆŒu�T‹{ˆn˜qÑ ¤E¨5¨&°$Ó$7Ð#9Ñ9Ó:ñ	 ,ð
 €Lr   c                 ón   • Ub  UOU R                  5       nUb  [        X2U R                  5       -  5      nU$ )zKReturn the threshold value according to an absolute and a relative
value.

)ÚminÚmax)r   Úthreshold_absÚthreshold_relr)   s       r   Ú_get_thresholdr<   H   s7   € ð
 "/Ñ!:‘ÀÇ	Á	Ã€IàÑ Ü˜	°5·9±9³;Ñ#>Ó?ˆ	àÐr   c                 óÖ  • [        U[        5      (       a  U(       a  UOS4U R                  -  nU$ [        U[        5      (       a#  US:  a  [	        S5      eU4U R                  -  nU$ [        U[
        5      (       ab  [        U5      U R                  :w  a  [	        S5      eU H4  n[        U[        5      (       d  [	        S5      eUS:  d  M+  [	        S5      e   UnU$ [        S5      e)zCReturn border_width values relative to a min_distance if requested.r   z+`exclude_border` cannot be a negative valuezP`exclude_border` should have the same length as the dimensionality of the image.zD`exclude_border`, when expressed as a tuple, must only contain ints.z,`exclude_border` can not be a negative valueze`exclude_border` must be bool, int, or tuple with the same length as the dimensionality of the image.)Ú
isinstanceÚboolÚndimr   Ú
ValueErrorÚtupler   Ú	TypeError)r   r   Úexclude_borderr3   Úexcludes        r   Ú_get_excluded_border_widthrF   U   sÿ   € ô �.¤$×'Ñ'Þ(6™¸AÐ?À%Ç*Á*ÑLˆð4 Ðô3 
�N¤C×	(Ñ	(Ø˜AÓÜÐJÓKÐKØ&Ð(¨5¯:©:Ñ5ˆð, Ðô+ 
�N¤E×	*Ñ	*Üˆ~Ó %§*¡*Ó,Üð/óð ó &ˆGÜ˜g¤s×+Ñ+Ü ð$óð ð ˜�{Ü Ð!OÓPÐPñ &ð &ˆð Ðô ð9ó
ð 	
r   r
   Tc
                 óF  • Ub  UR                   S:X  a  US:  a  [        S[        SS9  [        XU5      n
[	        XU5      nUc0  SU-  S-   n[
        R                  " U4U R                  -  [        S9nO[
        R                  " U5      nUc&  [        XU5      n[        XÚ5      n[        XXQU	5      nU$ [        UR                  [        SS9U
5      n[
        R                  " U R                   [
        R"                  5      (       a+  [
        R$                  " U R                   5      R&                  nO*[
        R(                  " U R                   5      R&                  n/ n[+        [,        R.                  " U5      5       H�  u  nnUc  M  UU   US-   :H  nU U   R1                  5       nUU[
        R2                  " U5      '   [        UXkU5      n[        UXØX5      n[+        U5       H!  u  nnUSS2U4==   UR4                  -  ss'   M#     UR7                  U5        MŸ     U(       a  [
        R8                  " U5      nO[
        R:                  " S	[        S9n[=        U5      U:”  a?  [
        R>                  " U [        S9nS
U[A        URB                  5      '   [        U UXQU	5      nU$ )aè  Find peaks in an image as coordinate list.

Peaks are the local maxima in a region of `2 * min_distance + 1`
(i.e. peaks are separated by at least `min_distance`).

If both `threshold_abs` and `threshold_rel` are provided, the maximum
of the two is chosen as the minimum intensity threshold of peaks.

.. versionchanged:: 0.18
    Prior to version 0.18, peaks of the same height within a radius of
    `min_distance` were all returned, but this could cause unexpected
    behaviour. From 0.18 onwards, an arbitrary peak within the region is
    returned. See issue gh-2592.

Parameters
----------
image : ndarray
    Input image.
min_distance : int, optional
    The minimal allowed distance separating peaks. To find the
    maximum number of peaks, use `min_distance=1`.
threshold_abs : float or None, optional
    Minimum intensity of peaks. By default, the absolute threshold is
    the minimum intensity of the image.
threshold_rel : float or None, optional
    Minimum intensity of peaks, calculated as
    ``max(image) * threshold_rel``.
exclude_border : int, tuple of ints, or bool, optional
    If positive integer, `exclude_border` excludes peaks from within
    `exclude_border`-pixels of the border of the image.
    If tuple of non-negative ints, the length of the tuple must match the
    input array's dimensionality.  Each element of the tuple will exclude
    peaks from within `exclude_border`-pixels of the border of the image
    along that dimension.
    If True, takes the `min_distance` parameter as value.
    If zero or False, peaks are identified regardless of their distance
    from the border.
num_peaks : int, optional
    Maximum number of peaks. When the number of peaks exceeds `num_peaks`,
    return `num_peaks` peaks based on highest peak intensity.
footprint : ndarray of bools, optional
    If provided, `footprint == 1` represents the local region within which
    to search for peaks at every point in `image`.
labels : ndarray of ints, optional
    If provided, each unique region `labels == value` represents a unique
    region to search for peaks. Zero is reserved for background.
num_peaks_per_label : int, optional
    Maximum number of peaks for each label.
p_norm : float
    Which Minkowski p-norm to use. Should be in the range [1, inf].
    A finite large p may cause a ValueError if overflow can occur.
    ``inf`` corresponds to the Chebyshev distance and 2 to the
    Euclidean distance.

Returns
-------
output : ndarray
    The coordinates of the peaks.

Notes
-----
The peak local maximum function returns the coordinates of local peaks
(maxima) in an image. Internally, a maximum filter is used for finding
local maxima. This operation dilates the original image. After comparison
of the dilated and original images, this function returns the coordinates
of the peaks where the dilated image equals the original image.

See also
--------
skimage.feature.corner_peaks

Examples
--------
>>> img1 = np.zeros((7, 7))
>>> img1[3, 4] = 1
>>> img1[3, 2] = 1.5
>>> img1
array([[0. , 0. , 0. , 0. , 0. , 0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. ],
       [0. , 0. , 1.5, 0. , 1. , 0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. ],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. ]])

>>> peak_local_max(img1, min_distance=1)
array([[3, 2],
       [3, 4]])

>>> peak_local_max(img1, min_distance=2)
array([[3, 2]])

>>> img2 = np.zeros((20, 20, 20))
>>> img2[10, 10, 10] = 1
>>> img2[15, 15, 15] = 1
>>> peak_idx = peak_local_max(img2, exclude_border=0)
>>> peak_idx
array([[10, 10, 10],
       [15, 15, 15]])

>>> peak_mask = np.zeros_like(img2, dtype=bool)
>>> peak_mask[tuple(peak_idx.T)] = True
>>> np.argwhere(peak_mask)
array([[10, 10, 10],
       [15, 15, 15]])

Nr
   zmWhen min_distance < 1, peak_local_max acts as finding image > max(threshold_abs, threshold_rel * max(image)).r   )Ú
stacklevel©ÚdtypeÚsafe)Úcasting)r   r   T)"r#   r   ÚRuntimeWarningrF   r<   r   Úonesr@   r?   Úasarrayr.   r6   r   Úastyper   Ú
issubdtyperJ   ÚfloatingÚfinfor8   Úiinfor0   r$   Úfind_objectsÚcopyÚlogical_notÚstartÚappendÚvstackÚemptyr   Ú
zeros_likerB   ÚT)r   r   r:   r;   rD   r   r!   ÚlabelsÚnum_peaks_per_labelr   r3   r)   r#   r   ÚcoordinatesÚ_labelsÚbg_valÚlabels_peak_coordÚ	label_idxÚroiÚ
label_maskÚ
img_objectÚidxÚsr+   s                            r   Úpeak_local_maxrj   v   sU  € ðn 	Ñ˜YŸ^™^¨qÓ0°lÀQÓ6FÜðFäØò		
ô .¨eÀ>ÓR€Lä˜u°]ÓC€IàÑØ�<Ñ !Ñ#ˆÜ—G’G˜T˜G e§j¡jÑ0¼Ñ=‰	ä—J’J˜yÓ)ˆ	à�~ä˜e°	Ó:ˆä˜tÓ2ˆô 0Ø˜°&ó
ˆðf Ðô] " &§-¡-´¸V -Ð"DÀlÓSˆä�=Š=˜Ÿ™¤b§k¡k×2Ñ2Ü—X’X˜eŸk™kÓ*×.Ñ.‰Fä—X’X˜eŸk™kÓ*×.Ñ.ˆFð Ðä'¬×(8Ò(8¸Ó(AÖB‰NˆI�sØ‰{Ùð   ™¨	°A©Ñ5ˆJà˜s™Ÿ™Ó*ˆJà5;ˆJ”r—~’~ jÓ1Ñ2ä! *¨iÀJÓOˆDä3Ø˜D°|óˆKô
 $ Cž.‘��QØšA˜s˜FÓ# q§w¡wÑ.Õ#ñ )ð ×$Ñ$ [Ö1ñ+ Cö. ÜŸ)š)Ð$5Ó6‰KäŸ(š( 6´Ñ5ˆKäˆ{Ó˜iÓ'Ü—-’- ¬TÑ2ˆCØ(,ˆC”�k—m‘mÓ$Ñ%Ü3Ø�s˜I°VóˆKð Ðr   c                 óú  • U R                  5       nUR                  u  pgUc  S[        R                  " U5      -  nSU-  S-   nSU-  S-   n	[        R
                  " XXSSSS9n
[        R
                  " X©SSSS9n
XZ:H  nX[-  nXS:„  n[        R                  " U5      n[        R                  " XÚ5      n[        US S	9SSS
2   n[        R                  " U Vs/ s H#  n[        R                  " UR                  5      PM%     sn[        S9n/ n/ n/ n[        R                  U* US-   2U* US-   24   u  nnU Hº  u  nnU
UU4   nUU:”  d  M  UU-   nUU-   n[        R                  " US:„  UU:  5      nUU   nUU   nUS:  nUUU   -
  UU'   UU==   U-  ss'   UU:¬  nUUU   -
  UU'   UU==   U-  ss'   SU
UU4'   UR!                  U5        UR!                  U5        UR!                  U5        M¼     [        R                  " U5      n[        R                  " U5      n[        R                  " U5      nU[#        U5      :  a.  [        R$                  " U5      SSS
2   SU nUU   nUU   nUU   nUUU4$ s  snf )a'  Return peaks with non-maximum suppression.

Identifies most prominent features separated by certain distances.
Non-maximum suppression with different sizes is applied separately
in the first and second dimension of the image to identify peaks.

Parameters
----------
image : (M, N) ndarray
    Input image.
min_xdistance : int
    Minimum distance separating features in the x dimension.
min_ydistance : int
    Minimum distance separating features in the y dimension.
threshold : float
    Minimum intensity of peaks. Default is `0.5 * max(image)`.
num_peaks : int
    Maximum number of peaks. When the number of peaks exceeds `num_peaks`,
    return `num_peaks` coordinates based on peak intensity.

Returns
-------
intensity, xcoords, ycoords : tuple of array
    Peak intensity values, x and y indices.
Ng      à?r   r
   r   Úconstant)r#   Úaxisr"   Úcvalc                 ó   • U R                   $ ©N)Úintensity_max)Úxs    r   Ú<lambda>Ú"_prominent_peaks.<locals>.<lambda>p  s   € ¨¯ªr   )ÚkeyéÿÿÿÿrI   )rV   Úshaper   r9   r$   Úmaximum_filter1dr   r2   ÚregionpropsÚsortedÚarrayÚroundÚcentroidr   ÚmgridÚlogical_andrY   r   r   )r   Úmin_xdistanceÚmin_ydistancer)   r   ÚimgÚrowsÚcolsÚycoords_sizeÚxcoords_sizeÚimg_maxr   Úimg_tÚ	label_imgÚpropsÚpÚcoordsÚ	img_peaksÚycoords_peaksÚxcoords_peaksÚycoords_extÚxcoords_extÚycoords_idxÚxcoords_idxÚaccumÚ
ycoords_nhÚ
xcoords_nhÚ
ycoords_inÚxcoords_lowÚxcoords_highr   s                                  r   Ú_prominent_peaksrš   <  sÍ  € ð: �*‰*‹,€CØ—‘�J€DàÑØœ"Ÿ&š& ›+Ñ%ˆ	à�}Ñ$ qÑ(€LØ�}Ñ$ qÑ(€LÜ×"Ò"Ø Q¨Z¸añ€Gô ×"Ò"Ø¨°À!ñ€Gð ‰>€DØ�K€CØ‰O€Eä—’˜eÓ$€IÜ×Ò 	Ó3€Eô �5Ñ7Ñ8¹¸2¸Ñ>€EÜ�XŠX±UÓ;²U°”r—x’x §
¡
Ö+±UÑ;Ä3ÑG€Fà€IØ€MØ€Mô  "Ÿx™xØ	ˆ˜¨Ñ*Ð*¨]¨N¸]ÈQÑ=NÐ,NÐNñ Ñ€K�ó %+Ñ ˆ�[Ø˜ [Ð0Ñ1ˆØ�9Õà$ {Ñ2ˆJØ$ {Ñ2ˆJô Ÿš¨
°Q©¸
ÀTÑ8IÓJˆJØ# JÑ/ˆJØ# JÑ/ˆJð
 % q™.ˆKØ&*¨Z¸Ñ-DÑ&DˆJ�{Ñ#Ø�{Ó# tÑ+Ó#Ø%¨Ñ-ˆLØ'+¨j¸Ñ.FÑ'FˆJ�|Ñ$Ø�|Ó$¨Ñ,Ó$ð /0ˆG�J 
Ð*Ñ+ð ×Ñ˜UÔ#Ø× Ñ  Ô-Ø× Ñ  Ö-ñ9 %+ô< —’˜Ó#€IÜ—H’H˜]Ó+€MÜ—H’H˜]Ó+€Mà”3�y“>Ó!Ü—j’j Ó+©D¨b¨DÑ1°*°9Ð=ˆØ˜kÑ*ˆ	Ø% kÑ2ˆØ% kÑ2ˆà�m ]Ð2Ð2ùòg <s   Ã*I8rp   )Úwarningsr   Únumpyr   Úscipy.ndimageÚndimager$   Ú r   Ú_shared.coordr   r   r.   r6   r<   rF   Úinfrj   rš   © r   r   Ú<module>r£      ss   ðÝ ã Ý å Ý *òô6ò0ò
òðF ØØØØ�f‰fØØØŸ™Ø�6‰6ôCðN ¨!°tÀrÇvÁvõh3r   