1 | % FindInl find inliers in joint image matrix |
---|
2 | % by pairwise epipolar geometry |
---|
3 | % |
---|
4 | % function IdMatIn = findinl(Ws,IdMat,tol) |
---|
5 | % Ws ... 3MxN joint image matrix |
---|
6 | % IdMat ... MxN ... 0 -> no point detected |
---|
7 | % 1 -> point detected |
---|
8 | % tol ... [pixels] tolerance for the epipolar geometry |
---|
9 | % the point are accpted as outliers only if they |
---|
10 | % are closer to the epipolar line than tol |
---|
11 | |
---|
12 | % $Author: svoboda $ |
---|
13 | % $Revision: 2.1 $ |
---|
14 | % $Id: findinl.m,v 2.1 2003/07/30 10:28:29 svoboda Exp $ |
---|
15 | % $State: Exp $ |
---|
16 | |
---|
17 | function IdMatIn = findinl(Ws,IdMat,tol) |
---|
18 | |
---|
19 | NoCams = size(IdMat,1); |
---|
20 | |
---|
21 | % fill the array of structures not_used denoted as 0 |
---|
22 | % allocate the array of structures for used |
---|
23 | for i=1:NoCams, |
---|
24 | not_used(i).pts = sum(IdMat(i,:)); |
---|
25 | used(i).pts = -1; |
---|
26 | end |
---|
27 | |
---|
28 | % allocate IdMat for outliers |
---|
29 | IdMatIn = zeros(size(IdMat)); |
---|
30 | |
---|
31 | while (sum([not_used.pts])>1-NoCams), |
---|
32 | [buff, id.cam_max] = max([not_used.pts]); |
---|
33 | used = add(used, id.cam_max, not_used(id.cam_max).pts); |
---|
34 | not_used = remove(not_used, id.cam_max); |
---|
35 | Mask = repmat(IdMat(id.cam_max,:),NoCams,1); |
---|
36 | Corresp = Mask & IdMat; |
---|
37 | Corresp(id.cam_max,:) = 0; |
---|
38 | [buff, id.cam_to_pair] = max(sum(Corresp')); % find the camera with most correspondences |
---|
39 | idx.corr_to_pair = find(sum(IdMat([id.cam_max,id.cam_to_pair],:))==2); |
---|
40 | % used = add(used, id.cam_to_pair, not_used(id.cam_to_pair).pts); |
---|
41 | % not_used = remove(not_used, id.cam_to_pair); |
---|
42 | if size(idx.corr_to_pair,2)<8, |
---|
43 | error('Not enough points to compute epipolar geometry in RANSAC validation') |
---|
44 | end |
---|
45 | Wspair = []; |
---|
46 | Wspair = Ws(id.cam_max*3-2:id.cam_max*3, idx.corr_to_pair); |
---|
47 | Wspair = [Wspair; Ws(id.cam_to_pair*3-2:id.cam_to_pair*3, idx.corr_to_pair)]; |
---|
48 | % id |
---|
49 | [F, inls] = rEG(Wspair,tol,tol,0.99); |
---|
50 | IdMatIn(id.cam_max, idx.corr_to_pair(inls)) = 1; |
---|
51 | IdMat(id.cam_max, :) = 0; |
---|
52 | IdMat(id.cam_max, idx.corr_to_pair(inls)) = 1; |
---|
53 | end |
---|
54 | |
---|
55 | function list = add(list, id, value) |
---|
56 | list(id).pts = value; |
---|
57 | return |
---|
58 | |
---|
59 | function list = remove(list, id) |
---|
60 | list(id).pts = -1; |
---|
61 | return |
---|