Ë
    ÿ[;j³  ã                   ó.   — d dl Z d dlZd dlmZ dd„Zd„ Zy)é    N)ÚcKDTreec                 ó�  — |dvrt        d|› �«      ‚t        j                  t        j                  | «      «      }t        j                  t        j                  |«      «      }t	        |«      dk(  r t	        |«      dk(  rdS t        j
                  S t	        |«      dk(  rt        j
                  S t        |«      j                  |d¬«      d   t        |«      j                  |d¬«      d   }}|dk(  rt        t        |«      t        |«      «      S |dk(  r2t        t        j                  |«      t        j                  |«      «      S y)	a  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          údG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\skimage/metrics/set_metrics.pyÚhausdorff_distancer      s  € ðd Ð-Ñ-ÜÐ/°¨xÐ8Ó9Ð9ä�|‰|œBŸJ™J vÓ.Ó/€HÜ�|‰|œBŸJ™J vÓ.Ó/€Hô
 ˆ8ƒ}˜ÒÜ˜“M QÒ&ˆqÐ2¬B¯F©FÐ2Ü	ˆX‹˜!Ò	Ü�v‰vˆô 	�Ó×Ñ ¨AÐÓ.¨qÑ1Ü�Ó×Ñ ¨AÐÓ.¨qÑ1ð 
€Cð
 �ÒÜ”3�s“8œS ›XÓ&Ð&Ø	�:Ò	Ü”2—7‘7˜3“<¤§¡¨£Ó.Ð.ð 
ó    c                 ó  — t        j                  t        j                  | «      «      }t        j                  t        j                  |«      «      }t        |«      dk(  st        |«      dk(  rt	        j
                  dd¬«       yt        |«      j                  |«      \  }}t        |«      j                  |«      \  }}|j                  «       }|j                  «       }	||   }
||	   }||
kD  r||	   |||	      fS |||      ||   fS )aâ  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 �|‰|œBŸJ™J vÓ.Ó/€HÜ�|‰|œBŸJ™J vÓ.Ó/€Hô ˆ8ƒ}˜ÒœS ›]¨aÒ/Ü�‰Ð;ÈÕJØä;BÀ8Ó;L×;RÑ;RØó<Ñ8ÐÐ8ô <CÀ8Ó;L×;RÑ;RØó<Ñ8ÐÐ8ð ,×2Ñ2Ó4ÐØ+×2Ñ2Ó4Ðà*Ð+;Ñ<€OØ*Ð+;Ñ<€Oà˜Ò(àÐ%Ñ&ØÐ3Ð4DÑEÑFð
ð 	
ð Ð3Ð4DÑEÑFØÐ%Ñ&ð
ð 	
r   )r   )r    Únumpyr
   Úscipy.spatialr   r   r+   r   r   r   Ú<module>r.      s   ðÛ ã Ý !óH/óVA
r   