source: distools/hausdma.m @ 24

Last change on this file since 24 was 22, checked in by bduin, 13 years ago
File size: 1.8 KB
Line 
1%HAUSDMA Asymmetric Hausdorff and modified Hausdorff distance between datafiles of image blobs
2%
3%  [DH,DM] = HAUSDMA(A,B)
4%
5% INPUT
6%   A     Datafile of NA binary images
7%   B     Datafileof of NB binary images
8%
9% OUTPUT
10%   DH    NAxNB Hausdorff distance matrix
11%   DM    NAxNB Modified Hausdorff distance matrix
12%
13% DESCRIPTION
14% Computes a Hausdorff distance matrix DH and a modified Hausdorff distance
15% matrix DM between the datafiles of binary images A and B.
16% Preferably, NA <= NB (faster computation).
17% Progress is reported in fid (fid = 1: on the sreeen).
18%
19% LITERATURE
20% M.-P. Dubuisson and A.K. Jain, "Modified Hausdorff distance for object matching",
21% International Conference on Pattern Recognition, vol. 1, 566-568, 1994.
22%
23
24% Copyright: R.P.W. Duin, r.duin@ieee.org
25% Faculty of EWI, Delft University of Technology
26
27
28function [dh,dm] = hausdm(A,B)
29
30
31na = size(A,1);
32nb = size(B,1);
33dh = zeros(na,nb);
34dm = zeros(na,nb);
35s1 = sprintf('Hausdorff distances from %i objects: ',na);
36prwaitbar(na,s1)
37A = data2im(A);
38B = data2im(B);
39for i=1:na
40  prwaitbar(na,i,[s1 int2str(i)]);
41  a = A{i};
42        if ~isempty(a)
43                a = bord(a,0);
44        end
45        ca = contourc(a,[0.5,0.5]);
46        J = find(ca(1,:) == 0.5);
47        ca(:,[J J+1]) =[];
48        ca = ca - repmat([1.5;1.5],1,size(ca,2));
49        ca = ca/max(ca(:));
50        ca = ca - repmat(max(ca,[],2)/2,1,size(ca,2));
51  %s2 = sprintf('Hausdorff distances to %i objects: ',nb);
52  %prwaitbar(nb,s2)
53        for j = 1:nb
54    %prwaitbar(na,j,[s2 int2str(j)]);
55                b = B{j};
56                if ~isempty(b)
57                        b = bord(b,0);
58                end
59                cb = contourc(b,[0.5,0.5]);
60                J = find(cb(1,:) == 0.5);
61                cb(:,[J J+1]) =[];
62                cb = cb - repmat([1.5;1.5],1,size(cb,2));
63                cb = cb/max(cb(:));
64                cb = cb - repmat(max(cb,[],2)/2,1,size(cb,2));
65                dab = sqrt(distm(ca',cb'));
66                dh(i,j) = max(min(dab));
67                dm(i,j) = mean(min(dab));
68  end
69  %prwaitbar(0);
70end
71prwaitbar(0);
72       
Note: See TracBrowser for help on using the repository browser.