How do I rotate a 3d image without using imrotate?

7 ビュー (過去 30 日間)
JayJay
JayJay 2018 年 7 月 17 日
コメント済み: JayJay 2018 年 7 月 18 日
I have a CT image which I want to rotate, how can I do this without using imrotate? After rotating, I want to use that image to perform a MIP. I also want to know how the matrix changes.

採用された回答

Walter Roberson
Walter Roberson 2018 年 7 月 17 日
If you want to rotate it for display purposes, then parent the graphics object against a hgtransform group, and to do the rotation, change the rotation matrix associated with the hgtransform group.
If you want to rotate it computationally, then create a rotation matrix and multiply the rotation matrix by the coordinates of the image location in order to get the new coordinates.
But if you are creating a new array from that, then you need to be careful about whether you "push" values or "pull" values.
"Push" in this sense is to start with the original coordinates and apply the rotation matrix, and to assign the pixel values into the calculated locations. It is known that if you do that, then you can end up with gaps in the output image.
"Pull" on the other hand starts with output coordinates and from each and (effectively) the inverse of the rotation matrix, calculates the source coordinates and extracts values from there. If you do this, you will not end up with gaps in the output image.
Any given output location is likely to involve values from multiple input locations.
If you are working on the topic of Projection Pursuit, then you should consider using one of the established packages, probably written in another programming language. I used to use a nice package for multidimensional projection pursuit, but that was 20-ish years ago and I know longer recall the program name :( Ah, I see even some MATLAB code, https://github.com/erikapat/Projection-Pursuit
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 7 月 17 日
You do not apply the rotation matrix to the contents of the array: you apply the rotation matrix to the coordinates.
For example,
YourMatrix = sort( randi([0 255], 512, 512, 384, 'uint8') ); %sample data
[Y, X, Z] = ndgrid(1:size(YourMatrix,1), 1:size(YourMatrix,2), 1:size(YourMatrix,3));
XYZ0 = [X(:), Y(:), Z(:), zeros(numel(X),1)];
M = makehgtform('yrotate', 7 * pi/180); %7 degrees
newXYZ0 = XYZ0 * M;
nX = reshape(newXYZ0(:,1), size(X));
nY = reshape(newXYZ0(:,2), size(Y));
nZ = reshape(newXYZ0(:,3), size(Z));
Now the revised coordinates for the X, Y, Z points are the corresponding nX, nY, nZ values.
You know exactly where each original pixel will be located after the rotation. The image has been rotated in one very real and important sense. For example you could now
surf(nX(:,:,1), nY(:,:,1), nZ(:,:,1), YourImage(:,:,1) 'edgecolor', 'none')
to display the first plane.
... and now what?
JayJay
JayJay 2018 年 7 月 18 日
Wasn't too clear with concepts before, thanks for helping me!

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2018 年 7 月 17 日
You can use imwarp... But what advantage over imrotate are you looking for?
  5 件のコメント
Walter Roberson
Walter Roberson 2018 年 7 月 18 日
imrotate() is always relative to the center of the images as if it were 2D. imwrap() can take an arbitrary transform matrix.
JayJay
JayJay 2018 年 7 月 18 日
You're right. Imrotate is perfect. Made a rookie mistake. Thanks for your help!

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by