[37] | 1 | % By Philip Torr 2002
|
---|
| 2 | % copyright Microsoft Corp.
|
---|
| 3 | function [f,f_sq_errors, n_inliers,inlier_index] = torr_mapsac_F(x1,y1,x2,y2, no_matches, m3, no_samp, T)
|
---|
| 4 | %disp('This just does calculation of perfect data,for test')
|
---|
| 5 | %disp('Use estf otherwise')
|
---|
| 6 | %f = rand(9);% estimate fundamental matrix from perfect points??
|
---|
| 7 |
|
---|
| 8 | function f = torr_mapsach(x1,y1,x2,y2, no_matches,m3, no_samp, T)
|
---|
| 9 | %disp('This just does calculation of perfect data,for test')
|
---|
| 10 | %disp('Use estf otherwise')
|
---|
| 11 | f = rand(9);
|
---|
| 12 | no_samp = 200;
|
---|
| 13 | ptot = 0.0;
|
---|
| 14 |
|
---|
| 15 | et = errh(f,x1,y1,x2,y2, no_matches, m3);
|
---|
| 16 | bestsse = norm(et) * norm(et);
|
---|
| 17 |
|
---|
| 18 | for(i = 1:no_samp)
|
---|
| 19 |
|
---|
| 20 | choice = randperm(no_matches);
|
---|
| 21 |
|
---|
| 22 | %set up local design matrix
|
---|
| 23 | for (j = 1:4)
|
---|
| 24 | tx1(j) = x1( choice(j));
|
---|
| 25 | tx2(j) = x2( choice(j));
|
---|
| 26 | ty1(j) = y1( choice(j));
|
---|
| 27 | ty2(j) = y2( choice(j));
|
---|
| 28 |
|
---|
| 29 | end
|
---|
| 30 |
|
---|
| 31 | ft = esth(tx1,ty1,tx2,ty2,4,m3);
|
---|
| 32 | et = errh(ft,x1,y1,x2,y2, no_matches, m3);
|
---|
| 33 | sse(i) = norm(et) * norm(et);
|
---|
| 34 | % use sse 0 to bring it to a reasonable value
|
---|
| 35 |
|
---|
| 36 | if i ==0
|
---|
| 37 | f = ft;
|
---|
| 38 | bestsse = sse(i);
|
---|
| 39 | elseif bestsse > sse(i)
|
---|
| 40 | f = ft;
|
---|
| 41 | bestsse = sse(i);
|
---|
| 42 | end
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | p(i) = exp( -sse(i));
|
---|
| 47 | ptot = ptot + p(i);
|
---|
| 48 |
|
---|
| 49 | end
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | %bayes factor
|
---|
| 53 | bf = 0.0;
|
---|
| 54 | logptot = log(ptot);
|
---|
| 55 | for(i = 1:no_samp)
|
---|
| 56 | sse2(i) = - sse(i) - logptot;
|
---|
| 57 | %integrate p(D|R)p(R)
|
---|
| 58 | p(i) =p(i)* exp( sse2(i) );
|
---|
| 59 | bf = bf + p(i);
|
---|
| 60 | end
|
---|
| 61 |
|
---|
| 62 | %ptot
|
---|
| 63 | bf
|
---|
| 64 | logbf = log(bf)
|
---|
| 65 | %log(p)
|
---|
| 66 | %maybe do a better fit after
|
---|