How do I retrieve full image after 3D voume rotation

1 view (last 30 days)
Dear all,
I have a problem with retrieving the full 3D volume(I'm using MRI Data) after I do rotation. I'm rotating and shifting a volume with a rotation matrix and interp3 with zero filling the NaN.
If I want to shift it back with the same angles, I do not retrieve the original image back. So I tried padding the image using padarray(volume,[40 40 40]) but this still gives me black areas. I'm rotating between -10 and 10 degrees so padding with 40 is enough for a volume 256x152x20.
Does anyone knows the solution for this?
  2 Comments
Matt J
Matt J on 10 Oct 2013
You mean the padded array does successfully contain the whole forward transformed object, but the reverse transformed object is cropped at the edges?
If so, we need to see how you are computing the inverse rototranslation.
Benjamin
Benjamin on 10 Oct 2013
Here is the code for only rotation:
%Set angles
psi = 5*pi/180;
phi = -8*pi/180;
theta = 5*pi/180;
Data = DCE(:,:,1:NumSlices,1)
centerx = (size(edgeon,1)/2);
centery = (size(edgeon,2)/2);
centerz = (NumSlices/2);
[X,Y,Z] = meshgrid(-centery+1:centery,-centerx+1:centerx,-centerz+1:centerz);
% Rotation unit vector
Wx = cos(theta)*cos(phi);
Wy = sin(theta)*cos(phi);
Wz = sin(phi);
%Rotation matrix
Xq = X*((cos(psi)+(Wx).^2*(1-cos(psi)))) + Y*(Wx*Wy*(1-cos(psi))-Wz*sin(psi)) + Z*(Wy*sin(psi)+Wx*Wz*(1-cos(psi)));
Yq = X*(Wz*sin(psi)+Wx*Wy*(1-cos(psi))) + Y*(cos(psi)+(Wy).^2*(1-cos(psi))) + Z*(-Wx*sin(psi)+Wy*Wz*(1-cos(psi)));
Zq = X*(-Wy*sin(psi)+Wx*Wz*(1-cos(psi))) + Y*(Wx*sin(psi)+ Wy*Wz*(1-cos(psi))) + Z*(cos(psi)+(Wz).^2*(1-cos(psi)));
Rotated_image = interp3(X,Y,Z,Data,Xq,Yq,Zq,'cubic',0);
My input is a volume with size 256x152x20 and after padding it is 336x232x100.
What I do is the following, I run this code first and then run it again with input Rotated_image with the opposite angles (-5 8 -5) to retrieve the original image

Sign in to comment.

Accepted Answer

Matt J
Matt J on 10 Oct 2013
What I do is the following, I run this code first and then run it again with input Rotated_image with the opposite angles (-5 8 -5) to retrieve the original image
No, you cannot obtain the inverse rotation this way. This is something you can directly verify. With (5,-8, 5) the rotation matrix is
>> R1 =
0.9999 0.0125 0.0070
-0.0118 0.9962 -0.0860
-0.0080 0.0859 0.9963
Negating the angles gives
>> R2
R2 =
0.9999 0.0118 0.0080
-0.0125 0.9962 0.0859
-0.0070 -0.0860 0.9963
It is straightforward to verify that they are not inverses
>> R2-inv(R1)
ans =
0.0000 0.0236 0.0161
-0.0249 -0.0000 -0.0000
-0.0140 0.0000 0
Bottom line. Compute and store the complete forward rotation matrix. Then you can apply its inverse linear algebraically.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!