0
votes

I need to rotate an image around a the y axis using Matlab.

I insert my image in a 3D array and then I apply the transformation matrix using affine3d and imwarp commands.

This is an example:

c = cos(theta); s=sin(theta);
ux =0; uy=1; uz=0;
tx =0; ty=0; tz=0;
tt = [(1-c)*ux^2+c (1-c)*ux*uy-s*uz (1-c)*ux*uz+s*uy tx;...
(1-c)*ux*uy+s*uz (1-c)*uy^2+c (1-c)*uy*uz-s*ux ty;...
(1-c)*ux*uz-s*uy (1-c)*uy*uz+s*ux (1-c)*uz^2+c tz; 0 0 0 1];
tform = affine3d(tt);
R = imref3d(size(image));
imrot = imwarp(image,R,tform);

In this way I get a rotation around the origin axis, but I want the rotation around the centre of the image so I change the value of ty.

ty=128

But affine3d wants only [0 0 0 1] as last column.

There is a way to rotate using these commands or do I have to find another way?

1
With a quick look at the doc my guess is that you need to use the last row to encode a shift, not the last column. - A. Donda

1 Answers

0
votes

I've answered a very similar question here: Homographic image transformation distortion issue

With that answer you can rotate about any axis, and with any point as the origin.

EDIT

You can use the Affine matrix form here (with [0 0 0 1] as the last row), you'll just need to add a "1" to each column index (i.e. instead of a <3x3> R*[x y z]', you'll want to do with a <4x4> R*[x y z 1]. (Note transpose to make that row a column.)