0

I would like to modify an image as if it was taken from a slightly different vantage point. I therefore need to manipulate the translation and rotation of the target image by a given transformation matrix.Camera Errors Illustration. I need to be able to iterate on locations in X,Y,Z and also rotation in Rx,Ry,Rz.

I have tried using MATLAB's imwarp() in many scenarios, however I have not been successful getting imwarp() to accept a true 3D 4x4 Transformation Matrix as an input.

Many solutions provide paths for single axis rotations of a 2D image that make use of the imwarp() function. This is straightforward and makes sense to me. However, I have been unable to find any documentation that may suggest how to implement the true level of flexibility that I am hoping to alter my image.

Following the basics outlined here: https://www.mathworks.com/help/images/ref/imwarp.html, I've been trying solutions like this with no luck:

theta_x = 0;
theta_y = 0;
theta_z = 0;

dx = 0;
dy = 0;
dz = 0;

Rx = [1 0 0 0; 0 cosd(theta_x) -sind(theta_x) 0; 0 sind(theta_x) cosd(theta_x) 0; 0 0 0 1];
Ry = [cosd(theta_y) 0 sind(theta_y) 0; 0 1 0 0; -sind(theta_y) 0 cosd(theta_y) 0; 0 0 0 1];
Rz = [cosd(theta_z) -sind(theta_z) 0 0; sind(theta_z) cosd(theta_z) 0 0; 0 0 1 0; 0 0 0 1];
d = [1 0 0 dx; 0 1 0 dy; 0 0 1 dz;0 0 0 1];

A = Rx*Ry*Rz*d;
tform = rigidtform3d(A);

output_image = imwarp(A,tform);
imshow(output_image)

This is obviously not correct, how can I best interface with the imwrap() function to give it a 4x4 transformation matrix?

  • Not sure what you mean by 'true 3D 4x4 Transformation Matrix', but according to the documentation, all you need to provide `rigidtform3d` is a rotation and translation vector. I am also not sure why you give your transformation matrix as the first argument to `imwarp` either. That should be your data, e.g. an mri volume or some other 3d mesh. Also, it looks `A` works out to be an identity matrix anyway. Rotating that by itself should yield a pretty trivial image. – dmedine May 05 '23 at 03:31

0 Answers0