Steve on Image Processing

April 28th, 2006

Spatial transformations: Forward mapping

I've written previously about defining a spatial transform as a function, (x,y) = T{(u,v)}, that maps points from one space (input space) to another (output space). Given such a function, how do you go about spatially transforming an image?

The most obvious procedure is called forward mapping. It works like this:

Consider each input image pixel in turn. For each input image pixel:

  • Determine its location in input space, (uk,vk).
  • Map that location to output space using (xk,yk) = T{(uk,vk)}.
  • Figure out which output pixel contains the location (xk,yk).
  • Copy the input pixel value to that output pixel.
This diagram illustrates the procedure:

Forward mapping has two main disadvantages as a computational procedure: gaps and overlaps. Depending on specific spatial transform function, you may have some output pixels that did not receive any input image pixels; these are the gaps. You may also have some output pixels that received more than one input image pixel; these are the overlaps. In both cases, it is challenging to figure out a reasonable way to set those output pixels.

One way to overcome these problems is to map pixel rectangles in input space to output space quadrilaterals, as shown here:

With this procedure, the input pixel value is allocated to different output pixels depending on the relative fractional coverage of the quadrilateral. Although this procedure can produce good results, it is complicated to implement and it takes a long time to compute.

Because of the problems with forward mapping, many (most?) image spatial transform implementations use a different technique, called inverse mapping. I'll describe that in a future post.

6 Responses to “Spatial transformations: Forward mapping”

  1. Leonardo replied on :

    Dear Steve,
    I have an input image from which I digitized grid points.
    I know the real distance between the grid points, so I can create an output array. I would like to specify a transformation using these points, so I can assign the real location to each point from the input.
    Is it possible?
    Best
    Leonardo

  2. Steve replied on :

    Leonardo—Sounds like you could use cp2tform to estimate a spatial transform fitting your points.

  3. Rudolph replied on :

    Hi Steve,

    I need to perform lense calibration on an image taken with specific camera. The lense coefficients are available.

    The distortions on the lense are radial distortion, decentering of the principal point and some affinity. According to me I’ll have to calculate the (subpixel units) distance which I have to move each pixel in the x and y direction. So each pixel will have it’s own resulting transformation. I went through most of your blogs and I want to create a custom tform struct which I can implement on bulk images.

    Now I can’t see how I will be able to do this with inverse mapping, true? Will imtransform deal with the overlapping and gaps for me automatically with chosen interpolation? How do I deal with a pixel that moves 0.166 pixels up for instance? How will matlab save the info on output space?

    Any guidence would be appreciated.

  4. Rudolph replied on :

    I managed to overcome the idea of linear indexing which imtransform use to determine the custom spatial transform. Thanks

  5. douglas replied on :

    Could you tell how to apply the grid points (data points from the transformation grid) in the transformation ?

    [Points edited out for space.]

  6. Steve replied on :

    Douglas—Use cp2tform to infer a spatial transformation from your point set. One of the spatially varying ones might be best. Then use imtransform to warp your image.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

  • Steve: Kezia—Try imrotate.
  • kezia: steve, how to perform rotation of structuring element by 15 degrees. kindly answer my question. thank u kezia...
  • Steve: Tasha—I only accept comments that are relevant to the particular blog post or are questions or comments...
  • Tasha: Steve,I send you a comment here but still didn’t get any reply yet.I did not see my comment posted here...
  • Steve: Carsten—Thanks for your input.
  • Carsten: Another vote for either imtranslate.m, or at least a blurb in the imtransform help why pure translation...
  • Loren Shure: If you look towards the end of the fftfilt program, you will see that there’s a check to see if...
  • Steve: Sonja—My imwritesize submission on the MATLAB Central File Exchange might be helpful. It was posted...
  • Steve: Grant—Sorry, but it won’t be for R2010a. That development deadline has already passed.
  • Sonja: My publisher is wanting images for a new book to be 300 dpi. Only 5 of the 19 images are 300, the rest are...

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