Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 MATLAB旋转问题

嘿,我需要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时在phi中添加180,它给出了相同的结果,因此与它存在某种关系,但我似乎找不到它。

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

多谢



回答:

解决了问题,显然该功能在x轴上的旋转是不同的。通常,当您计算欧拉角的旋转矩阵时,它们表示为:

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

C = [1 0 0 0cosθθsinθ0-sinθcosθ];

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

R = B * C * D;

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

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

如果有人遇到类似的问题,则应始终观察欧拉角和轴角,分别观察每个旋转并研究单独的旋转矩阵,因为不是每个函数都使用相同的x,y,z轴或按照标准说明的方式进行旋转。

无论如何,感谢您的收看



更多&回答...
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 04:55


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.