I just installed Matlab 2013a with the image processing toolbox. It has a new function IMWARP. It is very similar to the existing IMTRANSFORM function when performing 2D transformations on an image. I performed the same transformation on an image using both IMWARP and IMTRANSFORM. IMWARP is significantly faster (2X to 3X). I compared both images and they gave similar, but not exactly the same results. Also each function uses a difference version of the TFORM object. I was wondering is someone can describe the differences and advantages between these two functions.
Prashant Kumar answered .
2025-11-20
out = imwarp(I,tform);
is not the same as the algorithm used by imtransform syntax:
out = imtransform(I,tform);
% Read and display image
I = imread('pout.tif');
imshow(I);
% Create geometric transformation
T = [1 -sin(pi/4) 0; sin(pi/4) 1 0; 0 0 1];
tform = maketform('affine', T);
% Define input spatial referencing
udata = [-1 1];
vdata = [-1 1];
% Define output spatial referencing
xdata = [-0.8 0.8];
ydata = [-0.8 0.8];
output_size = round(size(I)/8);
% Apply geometric transformation to image
J = imtransform(I, tform, 'UData', udata, 'VData', vdata, ...
'XData', xdata, 'YData', ydata, 'Size', output_size);
% Display transformed image
imshow(J)
In R2013a, this can be rewritten using imwarp, geometric transformation objects, and spatial referencing objects:
% Read and display image
I = imread('pout.tif');
imshow(I);
% Create geometric transformation object
T = [1 -sin(pi/4) 0; sin(pi/4) 1 0; 0 0 1];
tform = affine2d(T);
% Define input spatial referencing. World limits of input image are from
% -1 to 1 in both X and Y directions.
RI = imref2d(size(I),[-1 1],[-1 1]);
% Define output spatial referencing. World limits out output image are
% from -0.8 to 0.8 in both X and Y directions. Output grid size is 1/8
% that of the input image.
Rout = imref2d(round(size(I)/8),[-0.8 0.8],[-0.8 0.8]);
% Apply geometric transformation to image
[J,RJ] = imwarp(I,RI,tform,'OutputView',Rout);
% Display transformed image
imshow(J,RJ)