The new function imwarp is part of a redesign of workflows involving image registration, geometric transformations, and spatial referencing that began with the R2013a release.
The imwarp function will replace imtransform as the recommended way of applying geometric transformations to images in the Image Processing Toolbox. As you have pointed out, imwarp is significantly faster than imtransform. imwarp supports 3-D geometric transformations, where as imtransform was strictly 2-D. imwarp uses the new spatial referencing classes imref2d and imref3d that were introduced in the R2013a release to allow users to more easily work with images in a non-default or world coordinate system. The 'OutputView' Name/Value is particularly useful for controlling the world limits and resolution of the output image. For more information about the new spatial referencing objects:
The new function imwarp expects that the input geometric transformation is a geometric transformation object. R2013a provides three new classes of geometric transformation objects: affine2d, affine3d, and projective2d.
The affine and projective geometric transformation objects expose methods for applying geometric transformations to points in a forward and inverse sense and they expose a "T" property for accessing the forward transformation matrix.
There are two reasons why the answers produced by imwarp are not exactly the same as those produced by imtransform. The first reason is that the algorithm for automatically determining the world limits of the output image in imwarp when a user does not specify an 'OutputView'
is not the same as the algorithm used by imtransform syntax:
out = imtransform(I,tform);
The second is that imwarp determines and computes the world limits of the input and output images in terms of the outer extents of the first and last pixel in each dimension where as imtransform computes input and output boundaries in terms of the center of the first and last pixel in each dimension.
Finally, I'll provide a bit of code that will hopefully make the differences between imtransform and imwarp more concrete. The following example is taken from the last example in the following post from Steve Eddins' blog:
This was the old code segment:
I = imread('pout.tif');
imshow(I);
T = [1 -sin(pi/4) 0; sin(pi/4) 1 0; 0 0 1];
tform = maketform('affine', T);
udata = [-1 1];
vdata = [-1 1];
xdata = [-0.8 0.8];
ydata = [-0.8 0.8];
output_size = round(size(I)/8);
J = imtransform(I, tform, 'UData', udata, 'VData', vdata, ...
'XData', xdata, 'YData', ydata, 'Size', output_size);
imshow(J)
In R2013a, this can be rewritten using imwarp, geometric transformation objects, and spatial referencing objects:
I = imread('pout.tif');
imshow(I);
T = [1 -sin(pi/4) 0; sin(pi/4) 1 0; 0 0 1];
tform = affine2d(T);
RI = imref2d(size(I),[-1 1],[-1 1]);
Rout = imref2d(round(size(I)/8),[-0.8 0.8],[-0.8 0.8]);
[J,RJ] = imwarp(I,RI,tform,'OutputView',Rout);
imshow(J,RJ)
It is worth clarifying that the results produced in this example by imwarp and imtransform are not equivalent because the XData,YData,UData,VData arguments of imtransform are referenced to the center of the first and last pixel in each dimension where as the world limits defined in the spatial referencing objects passed to imwarp are referenced to the outer extents of the first and last pixel.
We plan on supporting imtransform indefinitely for the large amount of existing customer code the relies on imtransform. imtransform will be de-emphasized in the documentation and more of the toolbox will transition toward the new geometric transformation workflow that involves transformation objects and imwarp.
Best Answer