[37] | 1 | % By Philip Torr 2002
|
---|
| 2 | % copyright Microsoft Corp.
|
---|
| 3 |
|
---|
| 4 | %this is a set of functions for minimizing F
|
---|
| 5 |
|
---|
| 6 | function [f, f_sq_errors, n_inliers,inlier_index,F] = torr_estimateF( matches, m3, f_optim_parameters, method, set_rank2, f_init)
|
---|
| 7 |
|
---|
| 8 | no_matches = length(matches);
|
---|
| 9 | x1 = matches(:,1);
|
---|
| 10 | y1 = matches(:,2);
|
---|
| 11 | x2 = matches(:,3);
|
---|
| 12 | y2 = matches(:,4);
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | if nargin <5
|
---|
| 16 | set_rank2 = 0;
|
---|
| 17 | end
|
---|
| 18 |
|
---|
| 19 | switch lower(method)
|
---|
| 20 | %as in ransac and torr mlesac/mapsac papers
|
---|
| 21 | case {'mlesac',0}
|
---|
| 22 | no_samp = f_optim_parameters(1);
|
---|
| 23 | T = f_optim_parameters(2);
|
---|
| 24 | f = torr_mlesac_F(x1,y1,x2,y2, no_matches, m3, no_samp, T);
|
---|
| 25 | %function f = mlesac_F(x1,y1,x2,y2, n_matches, m3, no_samp, f_threshold)
|
---|
| 26 | %as in ransac and torr mlesac/mapsac papers
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | case {'mapsac',1}
|
---|
| 30 | if isempty(f_optim_parameters)
|
---|
| 31 | no_samp =1000;
|
---|
| 32 | T = 4;
|
---|
| 33 | else
|
---|
| 34 | no_samp = f_optim_parameters(1);
|
---|
| 35 | T = f_optim_parameters(2);
|
---|
| 36 | end
|
---|
| 37 | [f,f_sq_errors, n_inliers,inlier_index] = torr_mapsac_F(x1,y1,x2,y2, no_matches, m3, no_samp, T);
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | case {'linear',2}
|
---|
| 41 | f = torr_estf(x1,y1,x2,y2, no_matches,m3);
|
---|
| 42 |
|
---|
| 43 | %as in Torr & Fitzgibbon paper
|
---|
| 44 | case {'bookstein',3}
|
---|
| 45 | f = torr_estf_bookstein(x1,y1,x2,y2, no_matches,m3);
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | case {'b+sampson','boosam',4}
|
---|
| 50 | f = torr_estf_bookstein_sampson(x1,y1,x2,y2, no_matches,m3);
|
---|
| 51 |
|
---|
| 52 | case {'non_linear',5}
|
---|
| 53 | f = torr_nonlinf_mincon2x2(f_init, x1,y1,x2,y2, no_matches, m3);
|
---|
| 54 |
|
---|
| 55 | case {'lin+non_lin',6}
|
---|
| 56 | set_rank2 = 1;
|
---|
| 57 | f = torr_estimateF(matches, m3, [], 'linear',set_rank2);
|
---|
| 58 | f = torr_estimateF(matches, m3, [], 'non_linear',set_rank2,f);
|
---|
| 59 |
|
---|
| 60 | case {'hegel1',7}
|
---|
| 61 | f = torr_estimateF(matches, m3, [], 'linear');
|
---|
| 62 | f = ant_fnsf(x1,y1,x2,y2,m3,f);
|
---|
| 63 |
|
---|
| 64 | otherwise
|
---|
| 65 | disp('Unknown method.')
|
---|
| 66 | end
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | F = reshape(f, 3, 3);
|
---|
| 71 | %make it my way round
|
---|
| 72 | F = F';
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | %the F matrix is defined like:
|
---|
| 77 | % (nx2, ny2, m3) f(1 2 3) nx1
|
---|
| 78 | % (4 5 6) ny1
|
---|
| 79 | % (7 8 9) m3
|
---|
| 80 |
|
---|
| 81 | % disp('before rank 2')
|
---|
| 82 | % F
|
---|
| 83 | if set_rank2
|
---|
| 84 | [U,S,V] = svd(F);
|
---|
| 85 | S(3,3) = 0;
|
---|
| 86 | F = U*S*V';
|
---|
| 87 | f = reshape(F',9,1);
|
---|
| 88 | end
|
---|
| 89 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 90 | % disp('after rank 2')
|
---|
| 91 | % F
|
---|
| 92 |
|
---|
| 93 | % % Unit fro-norm F:
|
---|
| 94 | % fn = norm(F(:));
|
---|
| 95 | % fn = 2^(-floor(log(fn) / log(2)));
|
---|
| 96 | % F = F * fn;
|
---|
| 97 |
|
---|
| 98 | F = F/norm(F,'fro');
|
---|
| 99 | f = f/norm(f);
|
---|
| 100 |
|
---|
| 101 | switch lower(method)
|
---|
| 102 | case {'bookstein',3,'linear',2,'bookstein',3,'b+sampson','boosam',4,'non_linear',5,'lin+non_lin',6, ...
|
---|
| 103 | 'hegel1',7}
|
---|
| 104 | %f = reshape(F',9,1); %calculate squared errors (distance to manifold of F)
|
---|
| 105 | f_sq_errors = torr_errf2(f,x1,y1,x2,y2, no_matches, m3);
|
---|
| 106 | %next generate index set of inliers
|
---|
| 107 | T = 10;
|
---|
| 108 | inlier_index = find((f_sq_errors < T) == 1);
|
---|
| 109 | n_inliers = length(inlier_index);
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | end
|
---|
| 113 |
|
---|