Matlab: imwarp over 3x faster than imtransform

Matlab R2013a introduced imwarp(). R2013b Lint warning tells you to use imwarp() instead of imtransform().

On my simple test (a horizontal linear shift) imwarp() was 3.4 times faster than imtransform()

I had this inside a for loop (first I loaded an image to variable ‘bg’)

bg = imread('myimage.jpg');
[nRow,nCol] = size(bg);
...
for ....
if ~oldWay % newway: Matlab R2013 and newer
  tform = affine2d(T);
  RA = imref2d([nCol,nRow],[1 nCol],[1 nRow]);
  data(:,:,i) = imwarp(bg,tform,'outputView',RA);
else % old way  Matlab R2012b and older, and Octave
  tform = maketform('affine',T);
  data(:,:,i) = imtransform(bg,tform,...
                  'Udata',[1 nCol],...
                  'Vdata',[1 nRow],...
                  'Xdata',[1 nCol],...
                  'Ydata',[1 nRow]);
end %if
end %for

Results:
% oldway: 14.30 sec. octave 3.8.1 using 1 CPU core
% oldway: 14.24 sec. R2013b using 4 CPU cores
% newway: 4.19 sec. R2013b using 1 CPU core

Note how Octave is as fast as Matlab imtransform, but Octave only uses 1 CPU core instead of 4!

Leave a Comment