How to rotate a 2D array (2D image) in 3D space around the x-axis?

7 vues (au cours des 30 derniers jours)
IOANNIS
IOANNIS le 21 Jan 2023
Hi everyone,
I have a 2D image ( a 2D array ) and i want to rotate this image in 3D space around the x-axis using an angle
and i want to store the resulted rotated 2D image in a new 2D array.
For example, if i want to rotate this 2D image around the z-axis i can do it using:
A = imread('img.tif');
A_RotZ = imrotate(A,angle,'nearest','loose');
but i can't find how to do the same around x-axis.
A_RotX = ???
Any ideas?
  2 commentaires
Matt J
Matt J le 21 Jan 2023
i want to store the resulted rotated 2D image in a new 2D array.
Surely you mean you want to store it in a 3D array. If the image is rotated about the x-axis it will no longer occupy the xy plane, so how would you be able to express it in 2D form?
IOANNIS
IOANNIS le 21 Jan 2023
Modifié(e) : IOANNIS le 21 Jan 2023
Thank you for the quick response.
If you keep a real 2D image in your hands and rotate it vertical, it will not become a 3D image. It is a rotated 2D image in a 3D space (check image attached). There are several similar question in matlabcentral/answers but, they explain how to make the visualization of this process, not how to get the image in a 2D-array.
he has 2D points in a star form, and he rotates the 2D star in 3D space. The star is again 2D, but with other origin.
In my case i have an image, and i want to get back this rotated image as a 2D array (which will look like the 2D rotated star in the example)

Connectez-vous pour commenter.

Réponse acceptée

IOANNIS
IOANNIS le 21 Jan 2023
Finally!!
tform = projective2d([ cosd(TH) 0 0 ; 0 1 0 ; 0 0 cosd(TH) ]);
A_rotX = imwarp(A, tform);
imshowpair(A, A_rotX, 'montage');
I dont know why, but it worked!

Plus de réponses (1)

Matt J
Matt J le 21 Jan 2023
Modifié(e) : Matt J le 21 Jan 2023
A=rand(5)
A = 5×5
0.9780 0.1184 0.2270 0.7351 0.5083 0.1574 0.6862 0.4062 0.9613 0.1056 0.8993 0.0520 0.0274 0.8168 0.0247 0.0745 0.2219 0.3940 0.5630 0.1267 0.5624 0.1992 0.1596 0.5698 0.8510
theta=90;
R=eye(3);
R(2:3,2:3) = [ cosd(theta) -sind(theta); ...
sind(theta) cosd(theta)];
A=cat(3,0*A,A,0*A);
A_RotX = imwarp(A, rigid3d(R,[0;0;0]'))
A_RotX =
A_RotX(:,:,1) = 0 0 0 0 0 0.5624 0.1992 0.1596 0.5698 0.8510 0 0 0 0 0 A_RotX(:,:,2) = 0 0 0 0 0 0.0745 0.2219 0.3940 0.5630 0.1267 0 0 0 0 0 A_RotX(:,:,3) = 0 0 0 0 0 0.8993 0.0520 0.0274 0.8168 0.0247 0 0 0 0 0 A_RotX(:,:,4) = 0 0 0 0 0 0.1574 0.6862 0.4062 0.9613 0.1056 0 0 0 0 0 A_RotX(:,:,5) = 0 0 0 0 0 0.9780 0.1184 0.2270 0.7351 0.5083 0 0 0 0 0
  4 commentaires
Matt J
Matt J le 21 Jan 2023
That is what I have given you.
IOANNIS
IOANNIS le 21 Jan 2023
Modifié(e) : IOANNIS le 21 Jan 2023
This works
tform = projective2d([1 -0.1 0.001; 0 1 0; 0 0 1]);
A_rotX = imwarp(A, tform);
imshowpair(A, A_rotX, 'montage');
but i dont know how to put the angle in it.
I tried to use in projective2d:
R=eye(3);
R(2:3,2:3) = [ cosd(theta) -sind(theta); ...
sind(theta) cosd(theta)];
but no success

Connectez-vous pour commenter.

Catégories

En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by