我正在尝试实施normalized 8-point algorithm to estimate the fundamental matrix。一步是将点标准化,使它们具有中心(0,0)
和平均距离sqrt(2)
。我知道如何翻译和缩放这些点,但我如何将这些步骤表示为一个矩阵,以便在以后的步骤中使用?
我的当前函数转换点如下,但我还需要弄清楚转换矩阵是什么:
%% Normalize points to have center (0,0) and mean distance sqrt(2)
function [pts1, T] = normalizePoints(pts)
Xs = pts(:,1);
Ys = pts(:,2);
%% Compute old center and translate
Xc = mean(Xs);
Yc = mean(Ys);
Xs = Xs - Xc;
Ys = Ys - Yc;
%% Compute mean distance and scale
Ds = sqrt(Xs .^ 2 + Ys .^ 2);
meanD = mean(Ds);
scale = sqrt(2) / meanD;
pts1 = [Xs .* scale, Ys .* scale];
T = ... % How do I represent the previous operations as T?
end
答案 0 :(得分:1)
T = [3;5];
% Normalize points to have center (0,0) and mean distance sqrt(2)
pts = rand(10,2);
Xs = pts(:,1);
Ys = pts(:,2);
% Compute old center and translate
Xc = mean(Xs);
Yc = mean(Ys);
Xs = Xs - Xc;
Ys = Ys - Yc;
% Compute mean distance and scale
Ds = sqrt(Xs .^ 2 + Ys .^ 2);
meanD = mean(Ds);
scale = sqrt(2) / meanD;
% composing transformation matrix
H = eye(3);
H([1,5]) = H([1,5])*scale;
H(1:2,3) = T(:);
% making homogenous coordinates (add ones as z values)
ptsHomo = [pts';ones(1,size(pts,1))];
% apply transform
ptsRes = H*ptsHomo;
ptsRes = bsxfun(@rdivide,ptsRes(1:2,:),ptsRes(3,:))';
subplot(121);
plot(pts(:,1),pts(:,2),'o');
title('original points')
subplot(122);
plot(ptsRes(:,1),ptsRes(:,2),'o');
title('transformed points')