1 | % By Philip Torr 2002
|
---|
2 | % copyright Microsoft Corp.
|
---|
3 | %
|
---|
4 | % %designed for the good of the world by Philip Torr
|
---|
5 | % copyright Philip Torr and Microsoft Corp 2002
|
---|
6 | % linear estimation of H
|
---|
7 | %
|
---|
8 | % @article{Torr99c,
|
---|
9 | % author = "Torr, P. H. S. and Zisserman, A",
|
---|
10 | % title ="MLESAC: A New Robust Estimator with Application to Estimating Image Geometry ",
|
---|
11 | % journal = "CVIU",
|
---|
12 | % Volume = {78},
|
---|
13 | % number = 1,
|
---|
14 | % pages = {138-156},
|
---|
15 | % year = 2000}
|
---|
16 | %
|
---|
17 | % %MAPSAC is the Bayesian version of MLESAC, and it is easier to pronounce!
|
---|
18 | % it is described in:
|
---|
19 | %
|
---|
20 | % @article{Torr02d,
|
---|
21 | % author = "Torr, P. H. S.",
|
---|
22 | % title ="Bayesian Model Estimation and Selection for Epipolar Geometry and
|
---|
23 | % Generic Manifold Fitting",
|
---|
24 | % journal = "IJCV",
|
---|
25 | % Volume = {?},
|
---|
26 | % number = ?,
|
---|
27 | % pages = {?},
|
---|
28 | % url = "http://research.microsoft.com/~philtorr/",
|
---|
29 | % year = 2002}
|
---|
30 | %
|
---|
31 |
|
---|
32 | function [h,h_sq_errors, n_inliers,inlier_index] = torr_napsac_H(x1,y1,x2,y2, no_matches,m3, no_samp, T)
|
---|
33 |
|
---|
34 | %disp('mapsac-ing H')
|
---|
35 | %bestsse = T * no_matches + 1;
|
---|
36 |
|
---|
37 | %%%%%%%%%%debug
|
---|
38 | %used for debugging:
|
---|
39 | no_trials = 1;
|
---|
40 | max_inliers = 0;
|
---|
41 | %%%%%%%%%%end debug
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 | for(i = 1:1)
|
---|
46 | %for(i = 1:no_samp)
|
---|
47 |
|
---|
48 | choice = randperm(no_matches);
|
---|
49 | %NAPSAC frenzyoid! first pick one point then take 6 nearest, described in thesis/china paper
|
---|
50 | distance_xyxy = (x1 - x1(choice(1))).^2 + (x2 - x2(choice(1))).^2 + (y1 - y1(choice(1))).^2 + (y2 - y2(choice(1))).^2;
|
---|
51 | [sorted_distance_xyxy, index_distance_xyxy] = sort(distance_xyxy);
|
---|
52 |
|
---|
53 | %next randomly permute the best 50 matches
|
---|
54 | choice2 = randperm(60);
|
---|
55 |
|
---|
56 | for (j = 1:8)
|
---|
57 | tx1(j) = x1( index_distance_xyxy(choice2(j)));
|
---|
58 | tx2(j) = x2( index_distance_xyxy(choice2(j)));
|
---|
59 | ty1(j) = y1( index_distance_xyxy(choice2(j)));
|
---|
60 | ty2(j) = y2( index_distance_xyxy(choice2(j)));
|
---|
61 | end % for (j = 1:7)
|
---|
62 |
|
---|
63 | % tx1 = x1( index_distance_xyxy(1:7));
|
---|
64 | % tx2 = x2( index_distance_xyxy(1:7));
|
---|
65 | % ty1 = y1( index_distance_xyxy(1:7));
|
---|
66 | % ty2 = y2( index_distance_xyxy(1:7));
|
---|
67 | %set up local design matrix
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 | figure
|
---|
81 | %take minimum of matches; minc provides match scores
|
---|
82 | title('First Image: plus matches')
|
---|
83 | hold on
|
---|
84 |
|
---|
85 | for j = 1:5
|
---|
86 | a = [x1( index_distance_xyxy(choice2(j))),x2( index_distance_xyxy(choice2(j)))]; %x1 x2
|
---|
87 | b = [y1( index_distance_xyxy(choice2(j))),y2( index_distance_xyxy(choice2(j)))]; %y1 y2
|
---|
88 | %x1 y1
|
---|
89 | %x2 y2
|
---|
90 | line(a,b);
|
---|
91 | end
|
---|
92 | hold off
|
---|
93 |
|
---|
94 | %matches = mat12;
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | for (j = 1:4)
|
---|
102 | tx1(j) = x1( choice(j));
|
---|
103 | tx2(j) = x2( choice(j));
|
---|
104 | ty1(j) = y1( choice(j));
|
---|
105 | ty2(j) = y2( choice(j));
|
---|
106 |
|
---|
107 | end
|
---|
108 |
|
---|
109 | %generate trial h
|
---|
110 | ht = torr_esth(tx1,ty1,tx2,ty2,4,m3);
|
---|
111 |
|
---|
112 | %get squared errors
|
---|
113 | et = torr_errh(ht,x1,y1,x2,y2, no_matches, m3);
|
---|
114 |
|
---|
115 | %capped residuals
|
---|
116 | cet = min(et,T);
|
---|
117 | sse = cet' * cet;
|
---|
118 |
|
---|
119 |
|
---|
120 | if i ==1
|
---|
121 | h = ht;
|
---|
122 | bestsse = sse;
|
---|
123 | elseif bestsse > sse
|
---|
124 | h = ht;
|
---|
125 | bestsse = sse;
|
---|
126 | end
|
---|
127 |
|
---|
128 | %monitor progress %debug
|
---|
129 | inlier_index = find((et < T) == 1);
|
---|
130 | mapsac_inliers(no_trials) = length(inlier_index);
|
---|
131 | if mapsac_inliers(no_trials) > max_inliers
|
---|
132 | max_inliers = mapsac_inliers(no_trials);
|
---|
133 | else
|
---|
134 | mapsac_inliers(no_trials) = max_inliers;
|
---|
135 | end
|
---|
136 | no_trials = no_trials + 1;
|
---|
137 | %%%%%%%%end debug
|
---|
138 |
|
---|
139 |
|
---|
140 | end
|
---|
141 | %calculate squared errors (distance to manifold of F)
|
---|
142 | h_sq_errors = torr_errh(h,x1,y1,x2,y2, no_matches, m3);
|
---|
143 | %next generate index set of inliers
|
---|
144 | inlier_index = find((h_sq_errors < T) == 1);
|
---|
145 | n_inliers = length(inlier_index);
|
---|
146 |
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 | %%%%%%%%%%debug
|
---|
152 | %for NAPSAC paper
|
---|
153 | no_matches
|
---|
154 | n_inliers
|
---|
155 | no_trials
|
---|
156 |
|
---|
157 | mapsac_inliers(1:30)
|
---|
158 | %find out how many it took to get to n_inliers
|
---|
159 | perc = n_inliers;
|
---|
160 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
161 | perc100 = length(map_index)+1
|
---|
162 | %find out how many it took to get to n_inliers
|
---|
163 |
|
---|
164 | perc = n_inliers * 0.9;
|
---|
165 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
166 | perc90 = length(map_index)+1
|
---|
167 |
|
---|
168 | perc = n_inliers * 0.8;
|
---|
169 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
170 | perc80 = length(map_index)+1
|
---|
171 |
|
---|
172 |
|
---|
173 |
|
---|
174 | perc = n_inliers * 0.7;
|
---|
175 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
176 | perc70 = length(map_index)+1
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 | perc = n_inliers * 0.6;
|
---|
181 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
182 | perc60 = length(map_index)+1
|
---|
183 |
|
---|
184 | n_inliers
|
---|
185 |
|
---|
186 | disp('Napsac');
|
---|