MATLAB: How to achieve a faster 3D Translation

2d3daffineImage Processing ToolboximtransforminterpolationmaketformMATLABprojectivetformarraytransformationtranslation

I'm making a GUI to allow a user to do image translation on set of 3D image data.
I want the user to be able to visually see the effects of the shift (using XY, XZ, and YZ slices).
I've tried this for 3D:
% 3D transform:
trslt = [eye(3) xyz'; 0 0 0 1]';
tform = maketform('affine', trslt);
data = tformarray(data, tform, rsmp, [2 1 3], [2 1 3], sizXYZ([2 1 3]), [], 0);
However, performing the following 2D operations runs in a fraction of the time:
xyTform = maketform('projective',[1 1; 1 sizY; sizX 1; sizX sizY],[1+x 1+y; 1+x sizY+y; sizX+x 1+y; sizX+x sizY+y]);
zTform = maketform('projective',[1 1; 1 sizY; sizZ 1; sizZ sizY],[1+z 1; 1+z sizY; sizZ+z 1; sizZ+z sizY]);
data = tformarray(data, zTform, rsmp, [3 1], [3 1], sizXYZ([3 1]), [], 0);
data = tformarray(data, xyTform, rsmp, [2 1], [2 1], sizXYZ([2 1]), [], 0);
Is there any better (or faster) way to do this?
Edit: Just to clarify, I'm using this transform to allow shifting by "fractional" pixel amounts. I know this would be easier if shifting by whole pixels.

Best Answer

You may be able to get better speeds with griddedInterpolant(), especially if you have to do this multiple times at the same query points.