PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
algo4.m
Go to the documentation of this file.
1 % Algorithm 4
2 % Minimization over Position, Orientation, and Arc lengths
3 %
4 % created: Nov 30, 2000
5 % modified: Mar 4, 2002
6 % Sangyoon Lee
7 
8 clear all
9 flops(0)
10 
11 
12 % Loading data files
13 %slice = 4; % Image slice number
14 p = load('Kel_p9.dat'); % Position vectors of rods
15 v = load('Kel_v9.dat'); % Direction vectors of rods
16 %y = load('CRW_y2_9.dat'); % Coordinates of fiducials in image plane
17 y = load('Syn_y4_9.dat'); % Coordinates of fiducials in image plane
18 R0 = [0.9848 0.0000 -0.1736; 0.0000 1.0000 0.0000; 0.1736 0.0000 0.9848];
19 b0 = [19.3969 -20.0000 5.4202]';
20 N = size(p,2) % # of rods
21 
22 
23 % Initializations
24 R = eye(3); % Initial rotation matrix
25 limit = 100; % # of iterations
26 iter = 1:1:limit';
27 error1 = zeros(limit, 1); % To store error at each iteration
28 error2 = zeros(limit, 2); % To store error at each iteration
29 
30 % Calculation by iteration
31 cnt = 1;
32 while cnt <= limit
33  lv = zeros(3*N, 1);
34  mat = zeros(3*N, N+6);
35  for i = 1:N
36  lv(3*i-2) = p(1,i) - dot(R(1,:), y(:,i));
37  lv(3*i-1) = p(2,i) - dot(R(2,:), y(:,i));
38  lv(3*i) = p(3,i) - dot(R(3,:), y(:,i));
39 
40  % Skew symmetric matrix corresponding to vector y
41  skew_Y = [0 -y(3,i) y(2,i); y(3,i) 0 -y(1,i); -y(2,i) y(1,i) 0];
42  mat(3*i-2, i) = -v(1,i);
43  mat(3*i-1, i) = -v(2,i);
44  mat(3*i, i) = -v(3,i);
45  mat((3*i-2):(3*i), (N+1):(N+3)) = -R * skew_Y;
46  mat((3*i-2):(3*i), (N+4):(N+6)) = eye(3);
47  end
48  q = (inv(mat' * mat)) * (mat' * lv);
49  s = q(1:N); % Arc lengths
50  av = q((N+1):(N+3)); % Angular velocity
51  b = q((N+4):(N+6)); % Translation vector
52 
53  % Error
54  for i = 1:N
55  tmp_e(:,i) = (p(:,i) + s(i) * v(:,i)) - (R * y(:,i) + b);
56  error1(cnt) = error1(cnt) + norm(tmp_e(:,i));
57  end
58  error1(cnt) = error1(cnt) / N;
59  error2(cnt, :) = [sqrt(6 - 2 * trace(R0' * R)) norm(b0 - b)]; % NOTE
60 
61  % Update
62  R = rot_up2_3(R, av);
63  cnt = cnt + 1;
64 end
65 flops_is = flops
66 psv_Ryb = error1(limit)
67 dist_se3 = error2(limit, :)
68 R
69 q_is = q'
70 
71 
72 
73 
74 
75 
76 % Plots
77 figure(1) % Error vs # of iterations
78 plot(iter, error1, 'k-')
79 xlabel('Number of iterations')
80 ylabel('Error (cm)')
81 %logerror = log(error);
82 %plot(iter, logerror, 'k:')
83 %plot(iter, logerror, 'k-')
84 %xlabel('Number of iterations')
85 %ylabel('log(Error)')
86 %tit = sprintf('Algorithm 3 for 6*1 approach, slice %d', slice);
87 %title(tit)
88 %legend('solid: synthetic data', 'dotted: real data')
89 grid on
const uint32_t * data
Definition: phidget22.h:3971
To store error at each iteration Calculation by iteration cnt
Definition: algo4.m:31
Algorithm Minimization over and Arc lengths created
Definition: algo4.m:2
iter
Definition: algo4.m:26
To store error at each iteration Calculation by iteration(velocity vector is calculated) cnt
error1
Definition: algo4.m:27
To store error at each iteration error2
Definition: algo4.m:28
Positive constant for(deldot)
double * velocity
Definition: phidget22.h:3326
b0
Definition: algo4.m:19
Initial rotation matrix R
Definition: algo3.m:24
for i
Initial rotation matrix b
Definition: algo3.m:25
Image slice number p
Definition: algo4.m:14
Initial rotation matrix limit
Definition: algo4.m:25
Algorithm Minimization over Position
Definition: algo4.m:2
Algorithm Minimization over Orientation
Definition: algo4.m:2
N
Definition: algo4.m:20
Algorithm Minimization over and Arc lengths modified
Definition: algo4.m:2
Position vectors of rods v
Definition: algo4.m:15
Algorithm Minimization over and Arc lengths Sangyoon Lee clear all flops(0) % Loading data files %slice
close all
Coordinates of fiducials in image plane R0
Definition: algo4.m:18
Direction vectors of rods y
Definition: algo4.m:16