-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalign1.m
37 lines (25 loc) · 1.01 KB
/
align1.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
%{
Description: Align two given pointsets of equal cardinality via similarity
transformations assuming that the pointset representations are standardized
to pre-shape space.
Inputs:
ref [DxN] : The standardized pointset that serves as the alignment
reference
p [DxN] : The standardized pointset being aligned to ref
Outputs:
aligned [DxN] : p after being aligned to ref via rotation
%}
function aligned = align1(ref, p)
[D, N] = size(ref);
W = eye(N); % Assume weights to be identity
XWY = p * W * ref'; % DxD
[U, ~, V] = svd(XWY);
R = V * U'; % DxD
% If det is -1, follow the results obtained by [S Umeyama 1991 IEEE, Kanatani 1994 IEEE TPAMI]
if det(R) < 0 % In theory, it should be det(R) == -1, but <0 is used to ensure numerical stability
corner = eye(D);
corner(D, D) = -1;
R = V * corner * U';
end
aligned = R*p;
end