Steve on Image Processing

January 24th, 2006

Spatial transformations

Section 5.11 of Digital Image Processing Using MATLAB covers spatial transformations. I'm interested in expanding this material to a full chapter. I'd like to use this blog to explore these topics and get your feedback about them.

Here's a partial list of concepts to cover:

  • Terminology
  • Types of spatial transformations (affine, for example) and their properties
  • Forward mapping versus inverse mapping
  • Interpolation
  • Aliasing and anti-aliasing

I'd also like to cover interesting features and design issues associated with the Image Processing Toolbox functions imtransform and tformarray, such as:

  • Defining the spatial coordinate systems associated with the input and output images
  • Multidimensional operation
  • Options for handling out-of-bounds pixels
  • What is findbounds and how does imtransform use it?

Finally, there are common questions and points of confusion, such as why applying a translation using imtransform appears not to do anything.

What am I leaving out? Please tell me what you'd like to hear about.

10 Responses to “Spatial transformations”

  1. philip batchelor replied on :

    I’m certainly interested in this topic, it took me a while to understand why translating an image doesn’t appear to to do anything ;) and some colleagues have also come to me quite puzzled…I’m still not sure what’s the most correct: I set ‘xdata’, ‘ydata’ using the dimensions of the input image, as I want the transformed one in the same field of view in general, but should it be …,’xdata’,[1,n1], or or [0.5,n1-0.5] ?
    (seemed more correct when I tried to overlay lines to show a defomration).

    I’d be also interested in the issue of speed for tformarray, I have been running code optimizing over 3D spatial transforms, and the profiler shows most of the time is spent there. For the moment I use an external library (mex+vtk) to perform these spatial transforms, with a speedup of ~10. It seems to me the time lost is in interpolation-reslicing parts of the code, it would be great to be able to use tformarray though, as my code doesn’t have the flexibility of ‘custom’ transforms, I need to write new c++/mex code for every new type of transform. So, well, in summary, any design issue related to tformarray I’d be curious to hear about…

  2. Steve replied on :

    Philip – UData, VData, XData, and YData parameters specify the locations of pixel centers, not pixel edges. I’ll get into performance issues later.

  3. Abe replied on :

    I’ve been using tformarray to rotate a entire stack of 3-D CT images (dimensions~512x512x250).
    rot_bone_mask = tformarray(bone_mask, tform_trans, R, [2 1 3],[2 1 3], floor([max_x max_y max_z]), [], []);

    I’ve segmented it and converted it to uint8, hopefully reduce the memory requirements of it. However, it seems that the tformarray takes quite a fair bit of time to run, around 1-2 minutes. I am really interested in hearing your opinion about the performance of tformarray, or how to make the best use of it, as the performance I get here is far for satisfactory. Thanks for your input.

  4. Steve replied on :

    Abe – I profiled a similar case on my laptop, and it ran in about 100 seconds. 75% of that time was in the MEX code for performing separable resampling, and there was no apparent swapping going on. I don’t see anything obvious to suggest to you for speeding up this operation.

  5. Abe replied on :

    Steve, thanks for the time to confirm that I am getting the expected behaviour. The memory usage is definitely acceptable, no swapping. It’s just the time it takes which is a bit long. I was using other softwares to do the same 3-D rotation and like what Philip has got, a few times faster. Anyway, I guess it is probably not fair to compare tformarray to other softwares out in the market which is binary-coded.

    By the way, is there any way I could continuously update my waitbar to reflect at least some “progress” going. It looks as if the GUI freezed for a whole minute or two before tformarray returns, which isn’t very good in terms of usability/presentability. :)

  6. Steve replied on :

    Abe – I think you could probably set up a MATLAB timer object to update your waitbar.

  7. vibin.S replied on :

    Respected Sir
    I am doing X-ray CT reconstruction part,I having some problem in 3D reconstruction, i,e how to stacking the data using MATLAB code. If You have some idea kindly mail me..
    Thank you
    by
    S.Vibin

  8. Steve replied on :

    S.Vibin – Take a look at this contribution on the MATLAB Central File Exchange.

  9. Shai replied on :

    I am also very concerned about the performance of tformarray.
    Is there a way to harness GPU capabilities to assist in this case? GPU is very much tuned to performing all sorts of transformations on images (at least) can it be used to perform image/array transformations in Matlab as well?
    I was thinking of creating a figure with opengl renderer, define an image as a graphical object and apply the transformations to this object. The bottle neck here (as far as I can tell) is reading from the GPU to main memory for further processing. Can you comment about this?

  10. Steve replied on :

    Shai—I don’t think you’ll be able to establish a direct connection between the GPU and a MATLAB figure window. And from what I’ve heard, the bus bandwidth is indeed a problematic bottleneck in GPU-based computation. That is, if you want to get the result back into MATLAB. ;-)


MathWorks
Steve Eddins is a software development manager in the MATLAB and image processing areas at MathWorks. Steve coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.