[37] | 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_mapsac_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:no_samp)
|
---|
| 46 |
|
---|
| 47 | choice = randperm(no_matches);
|
---|
| 48 |
|
---|
| 49 | %set up local design matrix
|
---|
| 50 | for (j = 1:4)
|
---|
| 51 | tx1(j) = x1( choice(j));
|
---|
| 52 | tx2(j) = x2( choice(j));
|
---|
| 53 | ty1(j) = y1( choice(j));
|
---|
| 54 | ty2(j) = y2( choice(j));
|
---|
| 55 |
|
---|
| 56 | end
|
---|
| 57 |
|
---|
| 58 | %generate trial h
|
---|
| 59 | ht = torr_esth(tx1,ty1,tx2,ty2,4,m3);
|
---|
| 60 |
|
---|
| 61 | %get squared errors
|
---|
| 62 | et = torr_errh(ht,x1,y1,x2,y2, no_matches, m3);
|
---|
| 63 |
|
---|
| 64 | %capped residuals
|
---|
| 65 | cet = min(et,T);
|
---|
| 66 | sse = cet' * cet;
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | if i ==1
|
---|
| 70 | h = ht;
|
---|
| 71 | bestsse = sse;
|
---|
| 72 | elseif bestsse > sse
|
---|
| 73 | h = ht;
|
---|
| 74 | bestsse = sse;
|
---|
| 75 | end
|
---|
| 76 |
|
---|
| 77 | %monitor progress %debug
|
---|
| 78 | inlier_index = find((et < T) == 1);
|
---|
| 79 | mapsac_inliers(no_trials) = length(inlier_index);
|
---|
| 80 | if mapsac_inliers(no_trials) > max_inliers
|
---|
| 81 | max_inliers = mapsac_inliers(no_trials);
|
---|
| 82 | else
|
---|
| 83 | mapsac_inliers(no_trials) = max_inliers;
|
---|
| 84 | end
|
---|
| 85 | no_trials = no_trials + 1;
|
---|
| 86 | %%%%%%%%end debug
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | end
|
---|
| 90 | %calculate squared errors (distance to manifold of F)
|
---|
| 91 | h_sq_errors = torr_errh(h,x1,y1,x2,y2, no_matches, m3);
|
---|
| 92 | %next generate index set of inliers
|
---|
| 93 | inlier_index = find((h_sq_errors < T) == 1);
|
---|
| 94 | n_inliers = length(inlier_index);
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | %%%%%%%%%%debug
|
---|
| 101 | %for NAPSAC paper
|
---|
| 102 | no_matches
|
---|
| 103 | n_inliers
|
---|
| 104 | no_trials
|
---|
| 105 |
|
---|
| 106 | mapsac_inliers(1:30)
|
---|
| 107 | %find out how many it took to get to n_inliers
|
---|
| 108 | perc = n_inliers;
|
---|
| 109 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 110 | perc100 = length(map_index)+1
|
---|
| 111 | %find out how many it took to get to n_inliers
|
---|
| 112 |
|
---|
| 113 | perc = n_inliers * 0.9;
|
---|
| 114 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 115 | perc90 = length(map_index)+1
|
---|
| 116 |
|
---|
| 117 | perc = n_inliers * 0.8;
|
---|
| 118 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 119 | perc80 = length(map_index)+1
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | perc = n_inliers * 0.7;
|
---|
| 124 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 125 | perc70 = length(map_index)+1
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | perc = n_inliers * 0.6;
|
---|
| 130 | map_index = find((mapsac_inliers < perc) == 1);
|
---|
| 131 | perc60 = length(map_index)+1
|
---|
| 132 |
|
---|
| 133 | n_inliers
|
---|
| 134 |
|
---|
| 135 | disp('Mapsac');
|
---|