
    9i                      0    S SK r S SKrS SKJr  SS jrS rg)    N)cKDTreec                    US;  a  [        SU 35      e[        R                  " [        R                  " U 5      5      n[        R                  " [        R                  " U5      5      n[	        U5      S:X  a!  [	        U5      S:X  a  S$ [        R
                  $ [	        U5      S:X  a  [        R
                  $ [        U5      R                  USS9S   [        U5      R                  USS9S   peUS:X  a  [        [        U5      [        U5      5      $ US:X  a4  [        [        R                  " U5      [        R                  " U5      5      $ g)	at  Calculate the Hausdorff distance between nonzero elements of given images.

Parameters
----------
image0, image1 : ndarray
    Arrays where ``True`` represents a point that is included in a
    set of points. Both arrays must have the same shape.
method : {'standard', 'modified'}, optional, default = 'standard'
    The method to use for calculating the Hausdorff distance.
    ``standard`` is the standard Hausdorff distance, while ``modified``
    is the modified Hausdorff distance.

Returns
-------
distance : float
    The Hausdorff distance between coordinates of nonzero pixels in
    ``image0`` and ``image1``, using the Euclidean distance.

Notes
-----
The Hausdorff distance [1]_ is the maximum distance between any point on
``image0`` and its nearest point on ``image1``, and vice-versa.
The Modified Hausdorff Distance (MHD) has been shown to perform better
than the directed Hausdorff Distance (HD) in the following work by
Dubuisson et al. [2]_. The function calculates forward and backward
mean distances and returns the largest of the two.

References
----------
.. [1] http://en.wikipedia.org/wiki/Hausdorff_distance
.. [2] M. P. Dubuisson and A. K. Jain. A Modified Hausdorff distance for object
   matching. In ICPR94, pages A:566-568, Jerusalem, Israel, 1994.
   :DOI:`10.1109/ICPR.1994.576361`
   http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1.8155

Examples
--------
>>> points_a = (3, 0)
>>> points_b = (6, 0)
>>> shape = (7, 1)
>>> image_a = np.zeros(shape, dtype=bool)
>>> image_b = np.zeros(shape, dtype=bool)
>>> image_a[points_a] = True
>>> image_b[points_b] = True
>>> hausdorff_distance(image_a, image_b)
3.0

)standardmodifiedzunrecognized method r      )kr   r   N)

ValueErrornp	transposenonzeroleninfr   querymaxmean)image0image1methoda_pointsb_pointsfwdbwds          [/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/metrics/set_metrics.pyhausdorff_distancer      s   d --/x899||BJJv./H||BJJv./H
 8}MQ&q2BFF2	X!	vv 	A.q1A.q1 

 3s8SX&&	:	2773<.. 
    c                    [         R                  " [         R                  " U 5      5      n[         R                  " [         R                  " U5      5      n[        U5      S:X  d  [        U5      S:X  a  [        R
                  " SSS9  g[        U5      R                  U5      u  pE[        U5      R                  U5      u  pgUR                  5       nUR                  5       n	XH   n
Xi   nX:  a  X)   X7U	      4$ X%U      X8   4$ )av  Returns pair of points that are Hausdorff distance apart between nonzero
elements of given images.

The Hausdorff distance [1]_ is the maximum distance between any point on
``image0`` and its nearest point on ``image1``, and vice-versa.

Parameters
----------
image0, image1 : ndarray
    Arrays where ``True`` represents a point that is included in a
    set of points. Both arrays must have the same shape.

Returns
-------
point_a, point_b : array
    A pair of points that have Hausdorff distance between them.

References
----------
.. [1] http://en.wikipedia.org/wiki/Hausdorff_distance

Examples
--------
>>> points_a = (3, 0)
>>> points_b = (6, 0)
>>> shape = (7, 1)
>>> image_a = np.zeros(shape, dtype=bool)
>>> image_b = np.zeros(shape, dtype=bool)
>>> image_a[points_a] = True
>>> image_b[points_b] = True
>>> hausdorff_pair(image_a, image_b)
(array([3, 0]), array([6, 0]))

r   z#One or both of the images is empty.   )
stacklevel) r   )	r
   r   r   r   warningswarnr   r   argmax)r   r   r   r   nearest_dists_from_bnearest_a_point_indices_from_bnearest_dists_from_anearest_b_point_indices_from_amax_index_from_amax_index_from_bmax_dist_from_amax_dist_from_bs               r   hausdorff_pairr+   R   s	   F ||BJJv./H||BJJv./H 8}S]a/;J;B8;L;R;R<8 <C8;L;R;R<8 ,224+224*<O*<O(&4DEF
 	
 4DEF&
 	
r   )r   )r    numpyr
   scipy.spatialr   r   r+   r   r   r   <module>r.      s      !H/VA
r   