rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
find_corresp.m
1 function [i,j] = find_corresp(V1,V2)
2 %function [i,j] = find_corresp(V1,V2)
3 %
4 % find identical columns in V1 and V2, i.e.
5 % V1(:,i(1)) = V2(:,j(1)) and all other indices in i,j
6 % double occurences can happen
7 
8 % Bernard Haasdonk 22.5.2007
9 
10 i = []; j = [];
11 n1 = size(V1,2);
12 n2 = size(V2,2);
13 
14 if n1>0 && n2> 0
15  cutsize = ceil(30000/n2);
16  ncuts = ceil(n1/cutsize);
17  for c = 1:ncuts
18  ind1 = (1+(c-1)*cutsize):min(n1, c*cutsize);
19  ind1 = ind1';
20  mask = ones(length(ind1),n2);
21  for dim = 1:size(V1,1);
22  VV1 = repmat(V1(dim,ind1)',1,n2);
23  VV2 = repmat(V2(dim,:),length(ind1),1);
24  mask = mask & (VV1 == VV2);
25  end;
26  [ipart,jpart] = find(mask);
27  j = [j; jpart(:)];
28  i = [i; ipart(:)+(c-1)*cutsize];
29  end;
30 end;
31 
32 %% for each column vector in the first matrix, the nearest neighbour
33 %% column in the second matrix is determined. such that
34 %% V(1) and V2(j(1)) are closest among all other V2 columns with
35 %% respect to l2-norm. The minimum distances are returned in dist
36 %%
37 %% The routine is required for large vector sets, such that the
38 %% simply tensor-product approach by setting up complete distance
39 %% matrices is avoided.
40 %%
41 %% Therefore, currently a stupid search is performed over all
42 %% columns of V1...
43 %
44 %% Bernard Haasdonk 22.5.2007
45 %
46 %n1 = size(V1,2);
47 %n2 = size(V2,2);
48 %j = zeros(n1,1);
49 %dmins = zeros(n1,1);
50 %for i=1:n1
51 % dist = sum((repmat(V1(:,i),1,n2)-V2).^2);
52 % [dmin, jmin] = min(dist);
53 % dmins(i) = sqrt(dmin(1));
54 % j(i) = jmin(1);
55 %end;
56 
57 % TO BE ADJUSTED TO NEW SYNTAX
58 %| \docupdate