source: distools/distools/hausdm.m @ 10

Last change on this file since 10 was 1, checked in by dtax, 15 years ago

Dissimilarity toolbox, start!

File size: 2.2 KB
Line 
1%HAUSDM Hausdorff and modified Hausdorff distance between datasets of image blobs
2%
3%  [DH,DM] = HAUSDM(A,B,FID)
4%
5% INPUT
6%   A     XAxYAxNA matrix of NA binary images of the size XA x YA
7%   B     XBxYBxNB matrix of NB binary images of the size XB x YB
8%   FID   0/1 Report progress on the screen (default: 0)
9%
10% OUTPUT
11%   DH    NAxNB Hausdorff distance matrix
12%   DM    NAxNB Modified Hausdorff distance matrix
13%
14% DESCRIPTION
15% Computes a Hausdorff distance matrix DH and a modified Hausdorff distance
16% matrix DM between the sets of binary images A and B, or datasets containing
17% them as features. 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,fid)
30
31if nargin < 3, fid = 0; end
32if isdataset(A) & isdataset(B)
33        [dh,dm] = hausdm(data2im(A),data2im(B),fid);
34        dh = setdata(A,dh);
35        dm = setdata(A,dm);
36        return
37end
38
39[ma1,ma2,na] = size(A);
40[mb1,mb2,nb] = size(B);
41dh = zeros(na,nb);
42dm = zeros(na,nb);
43for i=1:na
44        a = A(:,:,i);
45        J = find(any(a));
46        J = [min(J):max(J)];
47        K = find(any(a'));
48        K = [min(K):max(K)];
49        a = double(a(K,J));
50        if length(a(:)) > 0
51                a = bord(a,0);
52        end
53        ca = contourc(a,[0.5,0.5]);
54        J = find(ca(1,:) == 0.5);
55        ca(:,[J J+1]) =[];
56        ca = ca - repmat([1.5;1.5],1,size(ca,2));
57        ca = ca/max(ca(:));
58        ca = ca - repmat(max(ca,[],2)/2,1,size(ca,2));
59        for j = 1:nb
60                b = B(:,:,j);
61                J = find(any(b));
62                J = [min(J):max(J)];
63                K = find(any(b'));
64                K = [min(K):max(K)];
65                b = double(b(K,J));
66                if length(b(:)) > 0
67                        b = bord(b,0);
68                end
69                cb = contourc(b,[0.5,0.5]);
70                J = find(cb(1,:) == 0.5);
71                cb(:,[J J+1]) =[];
72                cb = cb - repmat([1.5;1.5],1,size(cb,2));
73                cb = cb/max(cb(:));
74                cb = cb - repmat(max(cb,[],2)/2,1,size(cb,2));
75                dab = sqrt(distm(ca',cb'));
76                dh(i,j) = max(max(min(dab)),max(min(dab')));
77                dm(i,j) = max(mean(min(dab)),mean(min(dab')));
78                if fid, disp([i,j,dh(i,j),dm(i,j)]); end
79%               fprintf(fid,'%5d %5d %10.3f %8.3f \n',i,j,dh(i,j),dm(i,j));
80        end
81end
82       
Note: See TracBrowser for help on using the repository browser.