Skip to content

Commit

Permalink
broke the normalization process
Browse files Browse the repository at this point in the history
  • Loading branch information
benshih committed Sep 19, 2013
1 parent 45da99a commit 86fecdd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
3 changes: 0 additions & 3 deletions BenFiles/computeH.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
% p1 and p2 are 2xN matrices of corresponding (x,y)' coordinates between
% two images

% pad p1 and p2 with 1s for scale factor
N = length(p1);
p1 = [p1; ones(1, N)];
p2 = [p2; ones(1, N)];

A = zeros(2*N, 9);
zerot = [0 0 0];
Expand Down
35 changes: 33 additions & 2 deletions BenFiles/computeH_norm.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,46 @@
% Section 4.2: Implementation of normalized planar homography in 2D.


function [ H2to1 ] = computeH_norm( p1, p2)
function [ sim, H2to1 ] = computeH_norm( p1, p2)
% Normalize the coordinates p1 and p2 prior to calling compute_H.

% p1 and p2 are 2xN matrices of corresponding (x,y)' coordinates between
% two images

% Translate the centroid of the points to the origin.
mux = mean(p1(1,:));
muy = mean(p1(2,:));
transx = p1(1,:) - mux;
transy = p1(2,:) - muy;

% Scale the points so that the average distance from the origin is sqrt(2).
avgDist = mean(sqrt(transx.^2 + transy.^2));
scale = sqrt(2)/avgDist;

sim = [scale 0 -scale*mux;
0 scale -scale*muy;
0 0 1];

normP2 = sim*p1;

% Translate the centroid of the points to the origin.
mux = mean(p2(1,:));
muy = mean(p2(2,:));
transx = p1(1,:) - mux;
transy = p1(2,:) - muy;

% Scale the points so that the average distance from the origin is sqrt(2).
avgDist = mean(sqrt(transx.^2 + transy.^2));
scale = sqrt(2)/avgDist;

sim = [scale 0 -scale*mux;
0 scale -scale*muy;
0 0 1];

normP1 = sim*p2;

% Compute H.
H2to1 = computeH(normBS(p1), normBS(p2));
H2to1 = computeH(normP1, normP2);


end
Expand Down
33 changes: 20 additions & 13 deletions BenFiles/normBS.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
% Section 5.1 Sensitivity to Normalization

function [ normP ] = normBS( p )
% Input: p is 3xN set of points in 2d, where N is the number of points
% Output: normP is a 3xN set of points in 2d, where N is the number of
% points, but normalized.
% Input: p is 3xN set of points in 2d, where N is the number of points
% Output: normP is a 3xN set of points in 2d, where N is the number of
% points, but normalized.

% Translate the centroid of the points to the origin.
mu = mean(p(:));
trans = p - mu;
% % Translate the centroid of the points to the origin.
% mux = mean(p(1,:));
% muy = mean(p(2,:));
% transx = p(1,:) - mux;
% transy = p(2,:) - muy;
%
% % Scale the points so that the average distance from the origin is sqrt(2).
% avgDist = mean(sqrt(transx.^2 + transy.^2));
% scale = sqrt(2)/avgDist;
%
% sim = [scale 0 -scale*mux;
% 0 scale -scale*muy;
% 0 0 1];
%
% normP = sim*p;



% Scale the points so that the average distance from the origin is sqrt(2).
avgDist = sum(sqrt(trans(1,:).^2 + trans(2,:).^2))/length(trans(1,:));

normP = trans * sqrt(2) / avgDist;

end

end
10 changes: 5 additions & 5 deletions BenFiles/normCompare.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
close all
clear all

p = 100 * [-2 -1 0 1 2; 10 2 1 2 10];
p = 100 * [-2 -1 0 1 2; 10 2 1 2 10; 1 1 1 1 1];
ptest = 100 * [0; 3; 1];


Expand All @@ -28,12 +28,12 @@
% Generate the homographies between the original and corrupted data.
% The homographies produce 3x3 transformation matrices.
H = computeH(p, p_corrupt);
Hnorm = computeH_norm(p, p_corrupt);
[sim, Hnorm] = computeH_norm(p, p_corrupt);


noNormed(:,i) = H*ptest;
%noNormed(:,i) = noNormed(:,i)./noNormed(3,i); % normalize
normed(:,i) = Hnorm*ptest;
normed(:,i) = inv(sim)*Hnorm*ptest;
%normed(:,i) = normed(:,i)./normed(3,i); % normalize


Expand All @@ -43,8 +43,8 @@
% 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);
% noNormed = normBS(noNormed);
% normed = normBS(normed);

figure;
hold on;
Expand Down

0 comments on commit 86fecdd

Please sign in to comment.