I would like to know how to rotate a 2D image along its Z-axis using Matlab R2016b and to obtain an image after performing this procedure.
For example, let's take this 2D image:
Now, I rotate it of 45° roughly:
And now, of 90°:
Do you know if it is possible to perform the same operation in Matlab R2016b, please ?
Thank you very much for your help
Images Source: https://www.youtube.com/watch?v=m89mVexWQZ4
Yes it's possible. The easiest thing to do would be to map the image on the
y = 0
plane in 3D, then rotate the camera to the desired azimuth or the angle with respect to they
axis. Once you do that, you can use thegetframe / cdata
idiom to actually capture the actual image data in a variable itself. The reason why you do this with respect to they
plane is because the method that I will be using to present the image is through thesurf
command that plots surface plots in 3D, but they
axis here is the axis that goes into and out of the screen. Thex
axis is the horizontal and thez
axis would be the vertical when displaying data.First read in your image using something like
imread
, then you need to define the 4 corners of the image that map to the 3D plane and then rotate the camera. You can use theview
function to help you rotate the camera by adjusting the azimuthal angle (first parameter) and leaving the elevation angle as 0.Something like this could work. I'll be using the peppers image that is part of the image processing toolbox:
rot_im
contains the rotated image. To appreciate the rotation of the image, we can loop through angles from 0 to 360 in real time. At each angle, we can useview
to dynamically rotate the camera and usedrawnow
to update the figure. I've also updated the title of the figure to show you what the angle is at each update. The code for that is below as well as the output saved as an animated GIF: