source: distools/hausdma.m @ 89

Last change on this file since 89 was 28, 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% DH = MAX_B(MIN_A(D_AB)), DM = MEAN_B(MIN_A(D_AB))
17% Preferably, NA <= NB (faster computation).
18% Progress is reported in fid (fid = 1: on the sreeen).
19%
20% LITERATURE
21% M.-P. Dubuisson and A.K. Jain, "Modified Hausdorff distance for object matching",
22% International Conference on Pattern Recognition, vol. 1, 566-568, 1994.
23%
24
25% Copyright: R.P.W. Duin, r.duin@ieee.org
26% Faculty of EWI, Delft University of Technology
27
28
29function [dh,dm] = hausdm(A,B)
30
31
32na = size(A,1);
33nb = size(B,1);
34dh = zeros(na,nb);
35dm = zeros(na,nb);
36s1 = sprintf('Hausdorff distances from %i objects: ',na);
37prwaitbar(na,s1)
38A = data2im(A);
39B = data2im(B);
40for i=1:na
41  prwaitbar(na,i,[s1 int2str(i)]);
42  a = A{i};
43        if ~isempty(a)
44                a = bord(a,0);
45        end
46        ca = contourc(a,[0.5,0.5]);
47        J = find(ca(1,:) == 0.5);
48        ca(:,[J J+1]) =[];
49        ca = ca - repmat([1.5;1.5],1,size(ca,2));
50        ca = ca/max(ca(:));
51        ca = ca - repmat(max(ca,[],2)/2,1,size(ca,2));
52  %s2 = sprintf('Hausdorff distances to %i objects: ',nb);
53  %prwaitbar(nb,s2)
54        for j = 1:nb
55    %prwaitbar(na,j,[s2 int2str(j)]);
56                b = B{j};
57                if ~isempty(b)
58                        b = bord(b,0);
59                end
60                cb = contourc(b,[0.5,0.5]);
61                J = find(cb(1,:) == 0.5);
62                cb(:,[J J+1]) =[];
63                cb = cb - repmat([1.5;1.5],1,size(cb,2));
64                cb = cb/max(cb(:));
65                cb = cb - repmat(max(cb,[],2)/2,1,size(cb,2));
66                dab = sqrt(distm(ca',cb'));
67                dh(i,j) = max(min(dab));
68                dm(i,j) = mean(min(dab));
69  end
70  %prwaitbar(0);
71end
72prwaitbar(0);
73       
Note: See TracBrowser for help on using the repository browser.