Featured post
MATLAB rotation problem -
hey all, need rotated versions of 3d shepp logan phantom , it's corresponding rotation matrix. here's thing, use function called phantom3d create 3d slp, function allows euler angles specify rotation. example:
phi = 45; theta = 45; psi = 45; %just matrix of inputs create 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 literature can calculate 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 compare image create using phantom3d function applies rotation matrix on non-rotated image, don't rotate in same way. code view rotated versionof 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 used 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 need have img & img2 same, it's not. found case set psi, phi & theta 45 , add 180 phi when creating img2 gives same result, there relation can't seem find it.
anyone have ideas, suggestions, help?
thx lot
problem solved, apparently rotation on x axis different in function. when u calculate rotation matrix euler angles state 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 case c different, namely rotation on old y axis:
c = [cos(theta) 0 -sin(theta) 0 1 0 sin(theta) 0 cos(theta)];
if encounters similar problems, 1 should observe each rotation separately , study separate rotation matrices, euler , axis angles, because not every function uses same x,y,z axis or rotations in standard explained way.
anyway viewing
- Get link
- X
- Other Apps
Comments
Post a Comment