source: distools/blurdistm.m @ 116

Last change on this file since 116 was 10, checked in by bduin, 14 years ago
File size: 2.1 KB
Line 
1%BLURDM Blurred Euclidean distance between blobs
2%
3%   D = BLURDISTM(A,B,RA,RB)
4%
5% INPUT
6%   A     MYA x MXA x NA matrix of NA binary images of the size MYA x MXA
7%   B     MYB x MXB x NB matrix of NA binary images of the size MYB x MXB
8%   RA,RB Blurring paramters (optional, default: 1, no blurring)
9%
10% OUTPUT
11%   D     NA x NB Blurred Euclidean distance matrix
12%
13% DESCRIPTION
14% Computes the blurred Euclidean distance matrix D between sets of blobs.
15% Images are first uniformly blurred with the sizes of RA x RA or RB x RB.
16% Next they are rescaled to square images with the sizes equal to
17% max([MYA,MXA,MYB,MXB]) vy using bilinear interpolation. Finally, the
18% Euclidean distance is computed.
19%
20% Preferably use NA <= NB, as it is faster.
21
22% Copyright: R.P.W. Duin, r.duin@ieee.org
23% Ela Pekalska, ela.pekalska@googlemail.com
24% Faculty EWI, Delft University of Technology and
25% School of Computer Science, University of Manchester
26
27
28function d = blurdistm(A,B,ra,rb,fid)
29if nargin < 3,
30  ra = 1;
31end
32if nargin < 4,
33  rb = ra;
34end
35if nargin < 5,
36  fid = 0;
37end
38
39[ma1,ma2,na] = size(A);
40[mb1,mb2,nb] = size(B);
41m = max([ma1,ma2,mb1,mb2]);
42d = zeros(na,nb);
43filta = exp(-[-ra:ra].^2/(0.5*ra*ra));
44filta = filta./sum(filta);
45filtb = exp(-[-rb:rb].^2/(0.5*rb*rb));
46filtb = filtb./sum(filtb);
47
48if fid > 0,
49  figure(1); clf;
50  figure(2); clf;
51end
52
53for i=1:na
54  a = A(:,:,i);
55  J = find(any(a));
56  J = [min(J):max(J)];
57  K = find(any(a'));
58  K = [min(K):max(K)];
59  a = double(a(K,J));
60
61% figure(1); imagesc(a); drawnow
62
63  a = bord(a,0,ra);
64  a = conv2(filta,filta,a,'same');
65  a = a(ra:end-ra,ra:end-ra);
66  a = imresize(a,[32 32],'bilnear');
67  if fid > 0,
68    figure(1); imagesc(a); drawnow
69  end
70  for j = 1:nb
71    b = B(:,:,j);
72    J = find(any(b));
73    J = [min(J):max(J)];
74    K = find(any(b'));
75    K = [min(K):max(K)];
76    b = double(b(K,J));
77    b = bord(b,0,rb);
78    b = conv2(filtb,filtb,b,'same');
79    b = b(rb:end-rb,rb:end-rb);
80    b = imresize(b,[32 32],'bilnear');
81    d(i,j) = sqrt(sum((a(:)-b(:)).^2));
82    if fid > 0
83      fprintf(fid,'%5d %5d %10.3f \n',i,j,d(i,j));
84      figure(2); imagesc(b); drawnow;
85    end
86  end
87end
Note: See TracBrowser for help on using the repository browser.