Code covered by the BSD License  

Highlights from
Hausdorff Distance

4.25

4.2 | 4 ratings Rate this file 91 Downloads (last 30 days) File Size: 4.22 KB File ID: #26738
image thumbnail

Hausdorff Distance

by Zachary Danziger

 

19 Feb 2010 (Updated 03 Apr 2013)

Calculates the Hausdorff Distance between two sets of points in a Euclidean metric space.

| Watch this File

File Information
Description

The Hausdorff Distance is a mathematical construct to measure the "closeness" of two sets of points that are subsets of a metric space.

Such a measure may be used to assign a scalar score to the similarity between two trajectories, data clouds or any sets of points.

This function will return the Hausdorff Distance between two sets of points.

For more information on the Hausdorff Distance: http://en.wikipedia.org/wiki/Hausdorff_distance

Acknowledgements

Hausdorff Distance inspired this file.

This file inspired Modified Hausdorff Distance and *Mex* Modified Hausdorff Distance For 2 D Point Sets.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
distance(3), mathematics(2), metric, trajectory similarity
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
03 Oct 2012 Zachary Danziger

Roel H,
Agreed on both counts. The code has been updated and re-posted. Doing some quick testing, the updates you recommended significantly improve speed for very large matrices, thank you.

25 Sep 2012 Roel H

Nice code, thanks for writing this function!

Though I have a few remarks. For the largeMat case, it is better to use bsxfun instead of repmat, as it is more efficient(faster) for large matrices which obviously is the case. Also it may be an idea to postpone the "sqrt" call untill a maximum is found. This won't change the outcome, but should require less computations

%existing code:
minP = min(sqrt(sum((repmat(P(p,:),[sQ(1) 1]) - Q).^2,2)));
%sugestion:
minP = min(sum((bsxfun(@minus,P(p,:),Q)).^2,2));

30 Apr 2012 Zachary Danziger

It was brought to my attention by Roey Baror of Tel-Aviv University that creating/outputting a matrix of distances between all points could quickly tax the system's memory for large matrices, such as high resolution images. The update provides a secondary algorithm to calculate the Hausdorff Distance without storing the large matrix in memory, and detects automatically when this secondary algorithm is necessary.

24 Mar 2012 s_ppu  
12 Jul 2011 longan  
07 Jan 2011 SasiKanth

Nice code and well commented to!

Updates
28 May 2010

Edits Added the matrix of distances as an output option. Fixed a bug that would cause an error if one of the sets was a single point. Removed excess calls to "size" and "length". - May 2010

15 Jun 2010

Generalizes the code to allow N-dimensional point sets. This update is inspired by file 27905, which has a good implementation of HD beyond 2-D sets of points.

30 Apr 2012

The code now automatically switches to a secondary algorithm when there is insufficient memory to compute and store a matrix containing distances between all constituent points. It also allows the user to manually choose the desired algorithm.

04 Oct 2012

Based on user comments, the algorithm for large data sets was updated for performance.

03 Apr 2013

An option for data visualization is now included.

Contact us