forked from srama2512/Trifocal-Tensor-Estimation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMLEupdate.m
43 lines (39 loc) · 2.43 KB
/
MLEupdate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [ m_mle ] = MLEupdate( T, m )
% This function computes the MLE correction to the Trifocal Tensor
% Algorithm can be found in section B from https://www.robots.ox.ac.uk/~vgg/publications/1997/Torr97a/torr97a.pdf
J = zeros(4,3);
J(1,1) = T(1,1,1)-T(1,1,3)*m.a3(1)-T(1,3,1)*m.a2(1)+T(1,3,3)*m.a2(1)*m.a3(1);
J(1,2) = -m.a1(1)*T(1,3,1)+m.a1(1)*m.a3(1)*T(1,3,3);
J(1,3) = -m.a1(1)*T(1,1,3)+m.a1(1)*m.a2(1)*T(1,3,3);
J(2,1) = T(1,2,1)-m.a3(1)*T(1,2,3)-m.a2(2)*T(1,3,1)+m.a2(2)*m.a3(1)*T(1,3,3);
J(2,2) = 0;
J(2,3) = -m.a1(1)*T(1,2,3)+m.a1(1)*m.a2(2)*T(1,3,3);
J(3,1) = T(1,1,2)-m.a3(2)*T(1,1,3)-m.a2(1)*T(1,3,3)+m.a2(1)*m.a3(2)*T(1,3,3);
J(3,2) = -m.a1(1)*T(1,3,3)+m.a1(1)*m.a3(2)*T(1,3,3);
J(3,3) = 0;
J(4,1) = T(1,2,2)-m.a3(2)*T(1,2,3)-m.a2(2)*T(1,3,2)+m.a2(2)*m.a3(2)*T(1,3,3);
J(4,2) = 0;
J(4,3) = 0;
r = zeros(4,1);
r(1) = m.a1(1)*T(1,1,1)+m.a1(2)*T(2,1,1)+m.a1(3)*T(3,1,1) ...
-m.a1(1)*m.a3(1)*T(1,1,3)-m.a1(2)*m.a3(1)*T(2,1,3)-m.a1(3)*m.a3(1)*T(3,1,3) ...
-m.a1(1)*m.a2(1)*T(1,3,1)-m.a1(2)*m.a2(1)*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