MATLAB 旋转问题

发布于 2024-10-08 18:26:53 字数 2281 浏览 3 评论 0原文

大家好,我需要 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,它给出相同的结果,所以与它有一些关系,但我似乎找不到它。

有人有任何想法、建议、帮助吗?

非常感谢

Hey all, I need rotated versions of a 3D shepp logan phantom and it's corresponding rotation matrix. Now here's the thing, I use a function called phantom3d to create the 3D SLP, the function allows euler angles to specify a rotation. So for example:

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

Now according to the literature you can calculate a rotation matrix using:

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  

However, if I compare the image i create using the phantom3d with a function which applies the rotation matrix on a non-rotated image, they don't rotate in the same way. The code to view the rotated versionof this image is:

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

So I actually need to have img & img2 to be the same, but it's not. I found some case where I set psi, phi & theta to 45 and then add 180 to phi when creating img2 it gives the same result, so there is some relation to it but I can't seem to find it.

Anyone have any ideas, suggestions, help?

Thx a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下凄凉 2024-10-15 18:26:53

问题已解决,显然该函数中 x 轴的旋转是不同的。通常,当您计算欧拉角的旋转矩阵时,它们表示为:

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

C = [1 0 0
0 cos(θ) sin(θ)
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 轴或以标准解释方式进行旋转。

无论如何感谢您的观看

Problem solved, apparently the rotation over the x axis is different in this function. Normally when u calculate the rotation matrix for euler angles they state it to be:

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;

however in my case the C was different, namely a rotation over the old y axis:

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

If somebody encounters similar problems, one should always observe each rotation separately and study the separate rotation matrices, for euler and axis angles, because not every function uses the same x,y,z axis or does the rotations in the standard explained way.

Anyway thanks for viewing

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文