matlab练习程序(Hausdorff距离)


Hausdorff距离是根据Hausdorff(1868-1942)命名的,Hausdorff距离是指某一集合中离另一集合最近点的所有距离的最大值 。

通常用如下公式表示:

需要注意的是h(A,B)和h(B,A)通常不相等,所以可以定义更一般的Hausdorff距离:

matlab代码如下:

clear all;
close all;
clc;

p1 = rand(100,2);
p2 = rand(50,2)+1;

plot(p1(:,1),p1(:,2),'.');
hold on;
plot(p2(:,1),p2(:,2),'r.');

d = zeros(length(p1),1);
for i=1:length(p1)
    t = p2-p1(i,:);
    d(i) = min(sqrt(t(:,1).^2+t(:,2).^2));    
end
hab=max(d)

for i=1:length(p2)
    t = p1-p2(i,:);
    d(i) = min(sqrt(t(:,1).^2+t(:,2).^2));    
end
hba=max(d)

h=max([hab hba])

参考:http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/98/normand/main.html#algorithm


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM