
    9i8              	           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	            T/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/feature/peak.py_get_high_intensity_peaksr   
   s    
 JJtE,K**k\9KLL,E	{{9i.a
 5zIjy!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     ~~ejjAo  ""5INI

C '+lrvvc{sy8IA..s/A/A$/GHK#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:<=uT{nq E$$6#889=>uT{nq E5&$$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 	599;#>?	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 
NC	(	(AJKK&(5::5, + 
NE	*	*~%**,/  &Ggs++ $  { !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[        X5      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XX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0lQ6FF		
 .e>RLu]CI<!#GGTGejj0=	JJy)	~e	:t2 0&
f ] "&--V-"DlS==bkk22XXekk*..FXXekk*..F '(8(8(ABNIs{  	A5Js*J5;Jr~~j12!*iJOD3D|K
 $C.QAsF#qww.# ) $$[1+ C. ))$56K((65K{i'--T2C(,Ckmm$%3sIV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
                  " XSSSS9n
XZ:H  nX[-  nXS:  n[        R                  " U5      n[        R                  " X5      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   )keyrI   )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JD"&&+%	}$q(L}$q(L""QZaG ""!G >DKCOEe$I	3E 5782>EXXU;Urxx

+U;3GFIMM  "xx	**]N]Q=N,NN K %+ [[019${2J${2J 
Q
T8IJJ#J/J#J/J
 %q.K&*Z-D&DJ{#{#t+#%-L'+j.F'FJ|$|$,$ /0GJ
*+ U#  -  -9 %+< #IHH]+MHH]+M3y>!jj+DbD1*9=k*	%k2%k2m]22g <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 ff66CN !trvvh3r   