-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFA3R.m
80 lines (63 loc) · 1.87 KB
/
FA3R.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
% Fast Analytical 3D Registration
% Authors: Jin Wu
% Copytight (c) 2019
function [C, T, time, loss, expn] = FA3R( MM, r_base, b_base, compute_expn, compute_metric )
nn = length(b_base(1, :));
mean_X = zeros(3, 1);
mean_Y = zeros(3, 1);
for i = 1 : nn
mean_X = mean_X + 1 / nn * r_base(:, i);
mean_Y = mean_Y + 1 / nn * b_base(:, i);
end
if(MM == 0)
MM = zeros(3, 3);
for i = 1 : length(b_base(1, :))
MM = MM + 1 / nn * (b_base(:, i) - mean_Y) * (r_base(:, i) - mean_X)';
end
end
if(compute_expn)
HX = [];
HY = [];
HZ = [];
end
tic;
hx = MM(:, 1)';
hy = MM(:, 2)';
hz = MM(:, 3)';
for iter = 1 : 10
k = 2.0 / (hx(1) * hx(1) + hx(2) * hx(2) + hx(3) * hx(3) + ...
hy(1) * hy(1) + hy(2) * hy(2) + hy(3) * hy(3) + ...
hz(1) * hz(1) + hz(2) * hz(2) + hz(3) * hz(3) + 1);
hx_ = hx; hy_ = hy; hz_ = hz;
hz = (hz_ + cross(hx_, hy_)) * k;
hy = (hy_ + cross(hz_, hx_)) * k;
hx = (hx_ + cross(hy_, hz_)) * k;
if(compute_metric)
HX = [HX hx'];
HY = [HY hy'];
HZ = [HZ hz'];
end
end
C = [hx; hy; hz];
T = mean_X - C * mean_Y;
time = toc;
if(compute_expn)
expn = zeros(iter, 1);
HX = HX';
HY = HY';
HZ = HZ';
for i = 1 : iter
C = [HX(i, :); HY(i, :); HZ(i, :)];
expn(i) = 0;
for j = 1 : nn
expn(i) = expn(i) + 1 / nn * norm(r_base(:, j) - C * b_base(:, j) - T)^2;
end
end
end
if(compute_metric)
loss = 0;
for i = 1 : nn
loss = loss + 1 / nn * norm(r_base(:, i) - C * b_base(:, i) - T)^2;
end
end
end