【问题标题】:MATLAB rotation problemMATLAB旋转问题
【发布时间】:2011-05-28 17:58:03
【问题描述】:

大家好,我需要 3D shepp logan 幻像的旋转版本及其对应的旋转矩阵。现在事情是这样的,我使用一个名为 phantom3d 的函数来创建 3D SLP,该函数允许欧拉角指定旋转。比如:

phi = 45;
theta = 45;
psi = 45;

%just a matrix of inputs to create the shepp logan phantom
e =[  1  .6900  .920  .810      0       0       0      0+phi      0+theta      0+psi
    -.8  .6624  .874  .780      0  -.0184       0      0+phi      0+theta      0+psi
    -.2  .1100  .310  .220    .22       0       0    -18+phi      0+theta     10+psi
    -.2  .1600  .410  .280   -.22       0       0     18+phi      0+theta     10+psi
     .1  .2100  .250  .410      0     .35    -.15      0+phi      0+theta      0+psi
     .1  .0460  .046  .050      0      .1     .25      0+phi      0+theta      0+psi
     .1  .0460  .046  .050      0     -.1     .25      0+phi      0+theta      0+psi
     .1  .0460  .023  .050   -.08   -.605       0      0+phi      0+theta      0+psi
     .1  .0230  .023  .020      0   -.606       0      0+phi      0+theta      0+psi
     .1  .0230  .046  .020    .06   -.605       0      0+phi      0+theta      0+psi   ];

img = phantom3d(e, 50);

现在根据文献,您可以使用以下方法计算旋转矩阵:

phi = ((phi + 180)/180).*pi;
theta = (theta/180).*pi;
psi = (psi/180).*pi;

cphi = cos(phi);
sphi = sin(phi);
ctheta = cos(theta);
stheta = sin(theta);
cpsi = cos(psi);
spsi = sin(psi);

% Euler rotation matrix
alpha = [cpsi*cphi-ctheta*sphi*spsi   cpsi*sphi+ctheta*cphi*spsi  spsi*stheta;
        -spsi*cphi-ctheta*sphi*cpsi  -spsi*sphi+ctheta*cphi*cpsi cpsi*stheta;
        stheta*sphi  

但是,如果我将使用 phantom3d 创建的图像与将旋转矩阵应用于非旋转图像的函数进行比较,它们不会以相同的方式旋转。查看这张图片的旋转版本的代码是:

img = phantom3d(50);
szout = size(img);
Cf = eye(4);
Cf(1:3, 4) = -szout/2;
Co = Cf;
%previously created alpha
alpha(4,4) = 1;
%Cf & Co are used for translations
Rmatrix = inv(Cf) * alpha * Co;
[x, y, z]=ndgrid(single(1:szout(1)), single(1:szout(2)), single(1:szout(3)));
xyz = [x(:) y(:) z(:) ones(numel(x),1)]*Rmatrix(1:3,:)';
xyz = reshape(xyz,[szout 3]);
img2 = interpn(single(img), xyz(:,:,:,1),xyz(:,:,:,2),xyz(:,:,:,3), 'cubic', 0);

所以我实际上需要让 img 和 img2 相同,但事实并非如此。我发现了一些情况,我将 psi、phi 和 theta 设置为 45,然后在创建 img2 时将 180 添加到 phi,它给出了相同的结果,因此与它有一些关系,但我似乎找不到它。

有人有什么想法、建议、帮助吗?

非常感谢

【问题讨论】:

  • 欧拉角的定义没有一个约定 (en.wikipedia.org/wiki/Euler_angles#Conventions) --- 也许您用于应用转换的两种方法使用不同的约定?无论如何,没有phantom3d的代码很难回答你的问题
  • 您的旋转矩阵中的两个元素似乎被截断了。

标签: matlab rotation euler-angles orthogonal


【解决方案1】:

问题解决了,显然这个函数在 x 轴上的旋转是不同的。通常,当您计算欧拉角的旋转矩阵时,它们会声明它是:

D = [cos(phi) sin(phi) 0 -sin(phi) cos(phi) 0 0 0 1];

C = [1 0 0 0 cos(theta) sin(theta) 0 -sin(theta) cos(theta)];

B = [cos(psi) sin(psi) 0 -sin(psi) cos(psi) 0 0 0 1];

R = B*C*D;

但是在我的情况下,C 是不同的,即在旧的 y 轴上旋转:

C = [cos(theta) 0 -sin(theta) 0 1 0 sin(theta) 0 cos(theta)];

如果有人遇到类似的问题,应该始终单独观察每个旋转并研究单独的旋转矩阵,用于欧拉角和轴角,因为并非每个函数都使用相同的 x、y、z 轴或标准中的旋转解释方式。

感谢观看

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-20
    • 2011-04-10
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多