1 |
|
---|
2 | % By Philip Torr 2002
|
---|
3 | % copyright Microsoft Corp.
|
---|
4 |
|
---|
5 | %this function corrects all the points in an optimal (first order) manner so that they lie on the manifold
|
---|
6 | %getting the signs right is a bit tricky but basically the 1st order correction is
|
---|
7 | % x = x - (grad r) * (r / ( norm(grad r)^2 )
|
---|
8 |
|
---|
9 | function [corrected_matches,e] = torr_correctx4F(f, nx1,ny1,nx2,ny2, no_matches, m3)
|
---|
10 |
|
---|
11 |
|
---|
12 | %disp('estimating squared errors on f')
|
---|
13 | f = f /norm(f);
|
---|
14 |
|
---|
15 | r = f(1) .* nx1(:).* nx2(:) + f(2).* ny1(:).* nx2(:) + f(3) .* m3.* nx2(:);
|
---|
16 | r = r + f(4) .* nx1(:).* ny2(:) + f(5) .* ny1(:).* ny2(:)+ f(6) .* m3.* ny2(:);
|
---|
17 | r = r + f(7) .* nx1(:).* m3+ f(8) .* ny1(:).* m3+ f(9) .* m3.* m3;
|
---|
18 | r2 = r.^2;
|
---|
19 |
|
---|
20 | fdx1 = f(1) .* nx2(:) + f(4) .* ny2(:) + f(7) .* m3;
|
---|
21 | fdx2 = f(1) .* nx1(:) + f(2).* ny1(:) + f(3) .* m3;
|
---|
22 | fdy1 = f(2).* nx2(:) + f(5) .* ny2(:)+ f(8) .* m3;
|
---|
23 | fdy2 = f(4) .* nx1(:) + f(5) .* ny1(:)+ f(6) .* m3;
|
---|
24 |
|
---|
25 | g = (fdx1 .* fdx1 +fdx2 .* fdx2 +fdy1 .* fdy1 +fdy2 .* fdy2);
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | e = r2./g;
|
---|
30 |
|
---|
31 | g = sqrt(g);
|
---|
32 | e = -r./g;
|
---|
33 | %
|
---|
34 | corrected_matches(:,1) = nx1(:) + e(:) .* (fdx1(:) ./ g(:));
|
---|
35 | corrected_matches(:,2) = ny1(:) + e(:) .* (fdy1(:) ./ g(:));
|
---|
36 | corrected_matches(:,3) = nx2(:) + e(:) .* (fdx2(:) ./ g(:));
|
---|
37 | corrected_matches(:,4) = ny2(:) + e(:) .* (fdy2(:) ./ g(:));
|
---|
38 | %
|
---|
39 | % corrected_matches(:,1) = nx1(:) + e(:) .* fdx1(:);
|
---|
40 | % corrected_matches(:,2) = ny1(:) + e(:) .* fdy1(:);
|
---|
41 | % corrected_matches(:,3) = nx2(:) + e(:) .* fdx2(:);
|
---|
42 | % corrected_matches(:,4) = ny2(:) + e(:) .* fdy2(:);
|
---|
43 |
|
---|
44 | e = e.^2; |
---|