Code covered by the BSD License

### Highlights from Frechet Distance Calculator

5.0
5.0 | 4 ratings Rate this file 12 Downloads (last 30 days) File Size: 2.49 KB File ID: #41956 Version: 1.0

# Frechet Distance Calculator

### Tristan Ursell (view profile)

Estimate the similarity between curves in space using the scalar Frechet Distance.

File Information
Description

Tristan Ursell
Frechet Distance between two curves
May 2013

f = frechet(X1,Y1,X2,Y2)
f = frechet(X1,Y1,X2,Y2,res)

(X1,Y1) are the x and y coordinates of the first curve (column vector).
(X2,Y2) are the x and y coordinates of the second curve (column vector).

The lengths of the two curves do not have to be the same.

'res' is an optional parameter to set the resolution of 'f', the time to
compute scales linearly with 'res'. 'res' must be positive, and if 'res'
is larger than the largest distance between any two points on the curve
the function will throw a warning. If 'res' is unspecified, the function
will select a reasonable value, given the inputs.

This function estimates the Frechet Distance, which is a measure of the
dissimilarity between two curves in space (in this case in 2D). It is a
scalar value that is symmetric with respect to the two curves (i.e.
switching X1->X2 and Y1->Y2 does not change the value). Roughly
speaking, this distance metric is the minimum length of a line that
connects a point on each curve, and allows one to traverse both curves
from start to finish. (wiki: Frechet Distance)

The function requires column input vectors, and the function 'bwlabel'
from the image processing toolbox.

EXAMPLE: compare three curves to find out which two are most similar

%curve 1
t1=0:1:50;
X1=(2*cos(t1/5)+3-t1.^2/200)/2;
Y1=2*sin(t1/5)+3;

%curve 2
X2=(2*cos(t1/4)+2-t1.^2/200)/2;
Y2=2*sin(t1/5)+3;

%curve 3
X3=(2*cos(t1/4)+2-t1.^2/200)/2;
Y3=2*sin(t1/4+2)+3;

f12=frechet(X1',Y1',X2',Y2');
f13=frechet(X1',Y1',X3',Y3');
f23=frechet(X2',Y2',X3',Y3');
f11=frechet(X1',Y1',X1',Y1');
f22=frechet(X2',Y2',X2',Y2');
f33=frechet(X3',Y3',X3',Y3');

figure;
subplot(2,1,1)
hold on
plot(X1,Y1,'r','linewidth',2)
plot(X2,Y2,'g','linewidth',2)
plot(X3,Y3,'b','linewidth',2)
legend('curve 1','curve 2','curve 3','location','eastoutside')
xlabel('X')
ylabel('Y')
axis equal tight
box on
title(['three space curves to compare'])

subplot(2,1,2)
imagesc([[f11,f12,f13];[f12,f22,f23];[f13,f23,f33]])
xlabel('curve')
ylabel('curve')
cb1=colorbar('peer',gca);
set(get(cb1,'Ylabel'),'String','Frechet Distance')
axis equal tight

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.14 (R2012a)
05 Jul 2016 Lisa Wang

### Lisa Wang (view profile)

Just what i need! Thank you so much!

19 Apr 2016 yak1226

### yak1226 (view profile)

just what I want ，great！

30 Jan 2014 Venkat R

### Venkat R (view profile)

Nice submission. Has great potential application.

05 Aug 2013 you