如何将平移和缩放表示为矩阵?

How to represent translation and scaling as a matrix?

我正在尝试实施 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

使用Homogeneous coordinates:

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')