mavillan/py-hausdorff

Fast computation of Hausdorff distance in Python/Cython
Switch branches/tags
Nothing to show
Latest commit e8ddf24 Jun 10, 2018
 Failed to load latest commit information. .gitignore Mar 23, 2017 LICENSE Nov 14, 2017 README.md Jun 11, 2018 hausdorff.c Jun 11, 2018 hausdorff.pyx Jun 11, 2018 setup.py Dec 17, 2016

py-hausdorff

Fast computation of Hausdorff distance in Python/Cython.

This code implements the algorithm presented in An Efficient Algorithm for Calculating the Exact Hausdorff Distance (DOI: 10.1109/TPAMI.2015.2408351) by Aziz and Hanbury.

To install the package I provide you a `setup.py` file. You must run:

`python setup.py install`

The main functions is:

`hausdorff(np.ndarray[:,:] X, np.ndarray[:,:] Y)`

Which computes the Hausdorff distance between the rows of `X` and `Y` using the Euclidean distance as metric. It receives the optional argument `distance` (string), which is the distance function used to compute the distance between the rows of `X` and `Y`. It could be any of the following: `manhattan`, `euclidean` (default), `chebyshev` and `cosine`.

Note: I will add more distances in the near future. If you need any distance in particular, open an issue.

```import numpy as np
from hausdorff import hausdorff

# two random 2D arrays (second dimension must match)
np.random.seed(0)
X = np.random.random((1000,100))
Y = np.random.random((5000,100))

# Test computation of Hausdorff distance with different base distances
print("Hausdorff distance test: {0}".format( hausdorff(X, Y, distance="manhattan") ))
print("Hausdorff distance test: {0}".format( hausdorff(X, Y, distance="euclidean") ))
print("Hausdorff distance test: {0}".format( hausdorff(X, Y, distance="chebyshev") ))
print("Hausdorff distance test: {0}".format( hausdorff(X, Y, distance="cosine") ))
```