-
Notifications
You must be signed in to change notification settings - Fork 0
/
normCompare.m
87 lines (61 loc) · 1.92 KB
/
normCompare.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
80
81
82
83
84
85
86
87
% Benjamin Shih
% Section 5.1: Sensitivity to Normalization
tic
close all
clear all
p = 100 * [-2 -1 0 1 2; 10 2 1 2 10];
p = [p; ones(1, length(p))];
ptest = [0; 300; 1];
pSize = size(p);
% Parameters for the normal distribution.
mu = 0;
sigma = 1;
numTrials = 1000;
noNormed = zeros(3, numTrials);
normed = zeros(3, numTrials);
for i=1:numTrials
% Introduce Gaussian noise to the data.
noise = mu + sigma .* randn(pSize);
p_corrupt = p + noise;
% Generate the homographies between the original and corrupted data.
% The homographies produce 3x3 transformation matrices.
H = computeH(p, p_corrupt);
[sim, Hnorm] = computeH_norm(p, p_corrupt);
noNormed(:,i) = H*ptest;
%noNormed(:,i) = noNormed(:,i)./noNormed(3,i); % normalize
%normed(:,i) = inv(sim)*Hnorm*ptest;
normed(:,i) = Hnorm*ptest;
%normed(:,i) = normed(:,i)./normed(3,i); % normalize
end
%% Plot Results
% Plot the resulting point sets in a single plot in order to compare the
% normalized and un-normalized results.
% noNormed = normBS(noNormed);
% normed = normBS(normed);
figure;
hold on;
plot(noNormed(1,1:end), noNormed(2,1:end), 'rx');
plot(normed(1,1:end), normed(2,1:end), 'bo');
%% Covariance Comparison
% Covariance of the transformed test point for both the normalized and
% un-normalized solution.
% Remove the 3rd row from the point matrices such that we just have the 2xN
% matrices of points.
% Input: 3x1000
% Output 2x1000
normed = normed(1:2,:);
noNormed = noNormed(1:2,:);
% Find the covariance of the test points.
% Input: 2x1000
% Output: 1000x1000
covNormed = cov(normed);
covNoNormed = cov(noNormed);
% Find the standard deviations of the test points.
% Input: 1000x1000
% Output: 1000x1
stdevNormed = sqrt(diag(covNormed));
stdevNoNormed = sqrt(diag(covNoNormed));
% Find the radio of the stdev between the unnormalized and normalized
% points.
ratio = stdevNoNormed ./ stdevNormed;
toc