How to Convert Euler Angles (Z-X-Z Convention) to Axis Angles for Image Stack Rotation
89 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have Eularian angles ( based on Z-X-Z convention) that I would like to convert to axis angles prior to using the function "imrotate3" to rotate a 3-D image stack. I have searched different resources for this, including Martin John Baker (http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToAngle/index.htm), and I know there is an option to use "angle2quat", but I'd like to skip purchasing the package just for that.
Below, I have included my attempt; however, I am not getting the correct output. I really appreciate your input.
% Note: The input angles are: -330.592, -351.265, and -330.767 based on Proper Euler angles (i.e. Z-X-Z convention)
alpha = deg2rad(-330.592);
beta = deg2rad(-351.265);
gamma = deg2rad(-330.767);
% Construct Individual Rotation Matrix
z1_rot_Mat = [cos(alpha) -sin(alpha) 0;
sin(alpha) cos(alpha) 0;
0 0 1];
x_rot_Mat = [1 0 0
0 cos(beta) -sin(beta);
0 sin(beta) cos(beta)];
z2_rot_Mat = [cos(gamma) -sin(gamma) 0;
sin(gamma) cos(gamma) 0;
0 0 1];
% Combined Rotation Matrix
R = z1_rot_Mat * x_rot_Mat * z2_rot_Mat;
theta = acos((trace(R) - 1)/2);
multi = 1/(2 * sin(theta));
rx = multi * (R(3, 2) - R(2, 3)) * theta;
ry = multi * (R(1, 3) - R(3, 1)) * theta;
rz = multi * (R(2, 1) - R(1, 2)) * theta;
% Convert to degree
angle1 = rad2deg(rx);
angle2 = rad2deg(ry);
angle3 = rad2deg(rz);
% Rotate image stack via angle axis
rot1 = imrotate3(dataset,-angle1,[1 0 0],'crop'); % rot about Z
rot2 = imrotate3(rot1,-angle2,[1 0 0],'crop'); % rot about X
rot3 = imrotate3(rot2,-angle3,[0 0 1],'crop'); % rot about Z
0 comentarios
Respuestas (3)
Matt J
el 21 de Oct. de 2019
Editada: Matt J
el 21 de Oct. de 2019
If you're going to use imrotate3 why not obtain rot3 in a single rotation of the dataset?
[V,d]=eig(R,'vector');
[~,i]=min(abs(d-1));
W=V(:,i);
N=null(W.'); N=N(:,1);
angle=atan2d( det([W,N,R*N]) , N.'*R*N)
rot3=imrotate3(dataset,angle,W);
Alternatively, if you insist on decomposing into 3 rotations why not do them with the Z-X-Z rotation angles that you already have?
% Rotate image stack via angle axis
rot1 = imrotate3(dataset,alpha,[0 0 1],'crop'); % rot about Z
rot2 = imrotate3(rot1,beta,[1 0 0],'crop'); % rot about X
rot3 = imrotate3(rot2,gamma,[0 0 1],'crop'); % rot about Z
2 comentarios
Matt J
el 21 de Oct. de 2019
The only thing I can think of is that maybe the Z-X-Z angles from DataViewer are intrinsic rotation angles?? That would be very strange, though. If possible, I would see if DataViewer can output the 3x3 rotation matrix directly.
James Tursa
el 21 de Oct. de 2019
An Euler Angle conversion routine by John Fuller that handles all possible conventions can be found here:
It will convert between Euler Angles, Direction Cosine Matrices, and Quaternions.
0 comentarios
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!