如何(倾斜)旋转 500 x 1000 矩阵? - Matlab

How to (tilt) rotate a 500 by 1000 matrix? - Matlab

我正在尝试将 500 x 1000 矩阵倾斜 5 度,然后对新矩阵进行颜色映射。

我首先将 .txt 文件中的数据调用到矩阵 A 中:

rows = 1000;
cols = 500;
theta = pi/36;   %5 Degrees
fid = fopen('TEST.txt', 'r');
A = fscanf(fid, '%f', [cols rows])';    %transpose so rows of matrix correspond to rows in text

fclose(fid)

之后我想将此数据倾斜 5 度。我希望在 Matlab 中使用 makehgtform 函数,但没有成功。这就是我的尝试:

R = makehgtform('zrotate', theta);
R = R(1:3,1:3);
Try(1:500,1:1000) = 1;
center = repmat(Try,1,1);
so = R*(s-center) + center;

上面这一部分是我不断出错的地方,我一直没能找到正确的解决方案。理想情况下,在这一点之后,我将按如下方式对新矩阵进行颜色映射:

%figure('Renderer', 'painters', 'Position', [10 10 500 1000])
imagesc(so)
colorbar;
caxis([0 100])
shading interp

到目前为止,我还没有成功,我不知道如何让它发挥作用。

您可以使用 imrotate 来达到这个目的:

Ans=imrotate(your_matrix,5);

如果你还是喜欢另一种方式:

phi =deg2rad(5);
Rot_matrix = [cos(phi) sin(phi) 0; -sin(phi) cos(phi) 0; 0 0 1];
tform_R =maketform('affine', Rot_matrix );
resamp = makeresampler({'linear','linear'},'fill'); % (interpolant, pad-method)
Ans=imtransform(your_matrix,tform_R ,resamp);
imagesc(Ans)