What is the difference between IMWARP and IMTRANSFORM?

18 Ansichten (letzte 30 Tage)
Sonoma Rich
Sonoma Rich am 14 Mär. 2013
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.
  2 Kommentare
Aijun Zhu
Aijun Zhu am 6 Jul. 2015
My main sense of the difference btwn the two is that, one is working on as [1 2 3] matrix dimension-oriented and the other is working on as [1 3 2]. Right?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Alex Taylor
Alex Taylor am 14 Mär. 2013
Bearbeitet: Alex Taylor am 14 Mär. 2013
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'
out = imwarp(I,tform);
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:
% 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)
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.
  4 Kommentare
Eric Sampson
Eric Sampson am 18 Mär. 2013
Thanks Alex :)
Bryan
Bryan am 11 Jul. 2017
Is this basically the same reason that maketform is not recommended? Is maketform part of the old codebase that's being phased out? If so, what's the replacement for maketform's 'custom' method that allows function handles so you can have any kind of weird transformation you want?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Nikolay S.
Nikolay S. am 30 Jul. 2014
Bearbeitet: Nikolay S. am 30 Jul. 2014
Hi Alex.
Very interesting answer, I was pretty confused by seeing a few commands doing virtually the same. A few questions aroused:
1) I understand that new functions (IMWARP etc..) and the old functions (IMTRANSFORM) differ in the point of application- for example rotation. In the new ones it is image center while in the old ones it is top left corner. Thus for the same T matrix, different image tranformation will be achieved. The question is, is there an easy and precise way to calculate Tnew, that will achieve the same transformation with IMWARP as Told achieved with IMTRANSFORM? This may be a decent replacement to the wrapper Eric mentioned.
2) I understand that the new transformation functions are much faster (factor of x2, x3). FOrm what I can see, it supports however only linear (affine & projectile) transformation represented by T [3,3] of [4,4] matrix. On the other hand, IMTRANSFORM, MAKETFORM support non linear transformation, as Steve has demonstrated on his wizard image. Is this correct? If so, the optimization comes with a price of loss of generality, and MAKETFORM can not be removed, as projective2d, affine2d replace it only in case of linear transformations.
Thanks!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by