[37] | 1 | % By Philip Torr 2002
|
---|
| 2 | % copyright Microsoft Corp.
|
---|
| 3 | %MAPSAC is the Bayesian version of MLESAC, and it is easier to pronounce!
|
---|
| 4 | %
|
---|
| 5 | % %designed for the good of the world by Philip Torr based on ideas contained in
|
---|
| 6 | % copyright Philip Torr and Microsoft Corp 2002
|
---|
| 7 | %
|
---|
| 8 | % [f,f_sq_errors, n_inliers,inlier_matches] = torr_mapsac_F(x1,y1,x2,y2, no_matches, m3, no_samp, T)
|
---|
| 9 | % f is fundamentalmatrix in 9 vector
|
---|
| 10 | % f_sq_errors are non robust errors on each match
|
---|
| 11 | % n_inliers is the no of inliers
|
---|
| 12 | % inlier_index is a vector with index no of each inlier
|
---|
| 13 | %
|
---|
| 14 | % x1,y1,x2,y2 are column vectors of the data no_matches by 4
|
---|
| 15 | % m3 is the 3rd homogeneous coordinate (256)
|
---|
| 16 | % no_samp is the number of samples to be taken (set to 0 if jump out required, at the moment jump out not implemented
|
---|
| 17 | % T is the threshold on the residuals, derived from MLESAC?MAPSAC paper
|
---|
| 18 | %
|
---|
| 19 | % at the moment it is assumed all is normalized so that Gaussian noise has sigma 1
|
---|
| 20 |
|
---|
| 21 | % /*
|
---|
| 22 | %
|
---|
| 23 | % @inproceedings{Torr93b,
|
---|
| 24 | % author = "Torr, P. H. S. and Murray, D. W.",
|
---|
| 25 | % title = "Outlier Detection and Motion Segmentation",
|
---|
| 26 | % booktitle = "Sensor Fusion VI",
|
---|
| 27 | % editor = "Schenker, P. S.",
|
---|
| 28 | % publisher = "SPIE volume 2059",
|
---|
| 29 | % note = "Boston",
|
---|
| 30 | % pages = {432-443},
|
---|
| 31 | % year = 1993 }
|
---|
| 32 | %
|
---|
| 33 | %
|
---|
| 34 | % @phdthesis{Torr:thesis,
|
---|
| 35 | % author="Torr, P. H. S.",
|
---|
| 36 | % title="Outlier Detection and Motion Segmentation",
|
---|
| 37 | % school=" Dept. of Engineering Science, University of Oxford",
|
---|
| 38 | % year=1995}
|
---|
| 39 | %
|
---|
| 40 | %
|
---|
| 41 | %
|
---|
| 42 | % @article{Torr97c,
|
---|
| 43 | % author="Torr, P. H. S. and Murray, D. W. ",
|
---|
| 44 | % title="The Development and Comparison of Robust Methods for Estimating the Fundamental Matrix",
|
---|
| 45 | % journal="IJCV",
|
---|
| 46 | % volume = 24,
|
---|
| 47 | % number = 3,
|
---|
| 48 | % pages = {271--300},
|
---|
| 49 | % year=1997
|
---|
| 50 | % }
|
---|
| 51 | %
|
---|
| 52 | %
|
---|
| 53 | %
|
---|
| 54 | %
|
---|
| 55 | % @article{Torr99c,
|
---|
| 56 | % author = "Torr, P. H. S. and Zisserman, A",
|
---|
| 57 | % title ="MLESAC: A New Robust Estimator with Application to Estimating Image Geometry ",
|
---|
| 58 | % journal = "CVIU",
|
---|
| 59 | % Volume = {78},
|
---|
| 60 | % number = 1,
|
---|
| 61 | % pages = {138-156},
|
---|
| 62 | % year = 2000}
|
---|
| 63 | %
|
---|
| 64 | % %MAPSAC is the Bayesian version of MLESAC, and it is easier to pronounce!
|
---|
| 65 | % it is described in:
|
---|
| 66 | %
|
---|
| 67 | % @article{Torr02d,
|
---|
| 68 | % author = "Torr, P. H. S.",
|
---|
| 69 | % title ="Bayesian Model Estimation and Selection for Epipolar Geometry and
|
---|
| 70 | % Generic Manifold Fitting",
|
---|
| 71 | % journal = "IJCV",
|
---|
| 72 | % Volume = {?},
|
---|
| 73 | % number = ?,
|
---|
| 74 | % pages = {?},
|
---|
| 75 | % url = "http://research.microsoft.com/~philtorr/",
|
---|
| 76 | % year = 2002}
|
---|
| 77 | %
|
---|
| 78 |
|
---|
| 79 | %threshold is the maximum squared value of the residuals
|
---|
| 80 | %no_matches is the number of matches
|
---|
| 81 | %no_samp is the number of random samples to be taken
|
---|
| 82 | %m3 is the estimate of the 3rf projective coordinate (f in pixels)
|
---|
| 83 |
|
---|
| 84 | %the F matrix is defined like:
|
---|
| 85 | % (nx2, ny2, m3) f(1 2 3) nx1
|
---|
| 86 | % (4 5 6) ny1
|
---|
| 87 | % (7 8 9) m3
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | %we minimize a robust function min(e^2,T) see mapsac paper.
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | function [f,f_sq_errors, n_inliers,inlier_index] = torr_mapsac_F(x1,y1,x2,y2, no_matches, m3, no_samp, T)
|
---|
| 95 | %disp('This just does calculation of perfect data,for test')
|
---|
| 96 | %disp('Use estf otherwise')
|
---|
| 97 | %f = rand(9);
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | %%%%%%%%%%debug
|
---|
| 101 | %used for debugging:
|
---|
| 102 | no_trials = 1;
|
---|
| 103 | max_inliers = 0;
|
---|
| 104 | %%%%%%%%%%end debug
|
---|
| 105 |
|
---|
| 106 | for(i = 1:no_samp)
|
---|
| 107 | choice = randperm(no_matches);
|
---|
| 108 | %set up local design matrix, here we estimate from 7 matches
|
---|
| 109 | for (j = 1:7)
|
---|
| 110 | tx1(j) = x1( choice(j));
|
---|
| 111 | tx2(j) = x2( choice(j));
|
---|
| 112 | ty1(j) = y1( choice(j));
|
---|
| 113 | ty2(j) = y2( choice(j));
|
---|
| 114 | end % for (j = 1:7)
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | %produces 1 or 3 solutions.
|
---|
| 118 | % [no_F big_result]= torr_F_constrained_fit(tx1,ty1,tx2,ty2,m3);
|
---|
| 119 | [no_F big_result]= torr_F_constrained_fit(tx1,ty1,tx2,ty2,m3);
|
---|
| 120 |
|
---|
| 121 | for j = 1:no_F
|
---|
| 122 | ft = big_result(j,:);
|
---|
| 123 |
|
---|
| 124 | %get squared errors
|
---|
| 125 | et = torr_errf2(ft,x1,y1,x2,y2, no_matches, m3);
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | %capped residuals
|
---|
| 131 | cet = min(et,T);
|
---|
| 132 | sse = cet' * cet;
|
---|
| 133 | % use sse 0 to bring it to a reasonable value
|
---|
| 134 | if ((i ==1) & (j ==1))
|
---|
| 135 | f = ft;
|
---|
| 136 | bestsse = sse;
|
---|
| 137 | elseif bestsse > sse
|
---|
| 138 | f = ft;
|
---|
| 139 | bestsse = sse;
|
---|
| 140 | bestcet = cet; %store best set of residuals
|
---|
| 141 | end %if
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | %monitor progress %debug
|
---|
| 145 | inlier_index = find((et < T) == 1);
|
---|
| 146 | mapsac_inliers(no_trials) = length(inlier_index);
|
---|
| 147 | if mapsac_inliers(no_trials) > max_inliers
|
---|
| 148 | max_inliers = mapsac_inliers(no_trials);
|
---|
| 149 | else
|
---|
| 150 | mapsac_inliers(no_trials) = max_inliers;
|
---|
| 151 | end
|
---|
| 152 | no_trials = no_trials + 1;
|
---|
| 153 | %%%%%%%%end debug
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | end
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | end %for(i = 1:no_samp)
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | %calculate squared errors (distance to manifold of F)
|
---|
| 165 | f_sq_errors = torr_errf2(f,x1,y1,x2,y2, no_matches, m3);
|
---|
| 166 | %next generate index set of inliers
|
---|
| 167 | inlier_index = find((f_sq_errors < T) == 1);
|
---|
| 168 | n_inliers = length(inlier_index);
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | % %%%%%%%%%%debug
|
---|
| 173 | % %for NAPSAC paper
|
---|
| 174 | % no_matches
|
---|
| 175 | % n_inliers
|
---|
| 176 | % no_trials
|
---|
| 177 | %
|
---|
| 178 | % mapsac_inliers(1:30)
|
---|
| 179 | % %find out how many it took to get to n_inliers
|
---|
| 180 | % perc = n_inliers;
|
---|
| 181 | % map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 182 | % perc100 = length(map_index)+1
|
---|
| 183 | % %find out how many it took to get to n_inliers
|
---|
| 184 | %
|
---|
| 185 | % perc = n_inliers * 0.9;
|
---|
| 186 | % map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 187 | % perc90 = length(map_index)+1
|
---|
| 188 | %
|
---|
| 189 | % perc = n_inliers * 0.8;
|
---|
| 190 | % map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 191 | % perc80 = length(map_index)+1
|
---|
| 192 | %
|
---|
| 193 | %
|
---|
| 194 | %
|
---|
| 195 | % perc = n_inliers * 0.7;
|
---|
| 196 | % map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 197 | % perc70 = length(map_index)+1
|
---|
| 198 | %
|
---|
| 199 | %
|
---|
| 200 | %
|
---|
| 201 | % perc = n_inliers * 0.6;
|
---|
| 202 | % map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 203 | % perc60 = length(map_index)+1
|
---|
| 204 | %
|
---|
| 205 | % n_inliers
|
---|
| 206 | %
|
---|
| 207 | % disp('Mapsac');
|
---|
| 208 | %
|
---|
| 209 | %
|
---|
| 210 | %
|
---|
| 211 | % %
|
---|
| 212 | % % figure
|
---|
| 213 | % % hold on
|
---|
| 214 | % % for i = 1:no_trials-1
|
---|
| 215 | % % plot(i, mapsac_inliers(i),'rs');
|
---|
| 216 | % % end
|
---|
| 217 | % % hold off
|
---|
| 218 | % % %%%%%%%%%%%%end debug
|
---|
| 219 | %
|
---|
| 220 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 221 |
|
---|
| 222 | |
---|