Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何将平移和缩放表示为矩阵?_Matlab_Matrix_Computer Vision_Transformation - Fatal编程技术网

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

Matlab 如何将平移和缩放表示为矩阵?,matlab,matrix,computer-vision,transformation,Matlab,Matrix,Computer Vision,Transformation,我正在努力实现这个目标。一个步骤是规范化点,使其具有中心(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 =

我正在努力实现这个目标。一个步骤是规范化点,使其具有中心
(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
使用:

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