Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB


Steve on Image Processing with MATLAB has been archived and will not be updated.

Spatial transformations: Translation confusion

The last time I wrote about spatial transformations, I explained that imtransform uses the function findbounds to locate the transformed image in output space. By default, imtransform computes an output image grid that is just big enough to capture the output image, wherever it is located.

We designed imtransform this way because we thought it was what users would expect most of the time. Generally, this default behavior works out just fine. The big exception, though, is when users call imtransform to apply a pure translation. Let's try it and see.

I = imread('pout.tif');

Now make an affine tform struct representing a pure translation:

T = [1 0 0; 0 1 0; 50 100 1];
tform = maketform('affine', T);

Apply the translation:

I2 = imtransform(I, tform);

And compare the two images:

title('original image')

title('translated image')

They're the same! Hence, the confusion.

Here imtransform has been a little "smarter" than users want. By automatically adjusting the output-space grid to capture the output image wherever it moves, the translation gets removed.

There are a couple of things you can do to make this work better. First, you can ask imtransform to give you more information about the output space coordinates of the output image, and then you can use this information when displaying the image. Here's how that might work:

[I2,xdata,ydata] = imtransform(I,tform);

xdata is a two-element vector specifying where the first and last columns of I2 are located in output space. Similarly, ydata specifies where the first and last rows are located. You can pass this information along to the display function, imshow.

axis on
axis([0 400 0 400])

axis on
axis([0 400 0 400])

A second technique is to tell imtransform what output-space rectangle to use.

I3 = imtransform(I,tform,'XData',[1 290],'YData',[1 391]);

If you understand the XData and YData parameters, you can use these techniques separately or in combination to implement whatever translation effect you'd like.

Since translation is a regular source of calls to tech support, we are exploring ways to alleviate the confusion. If you have suggestions, please leave a blog comment. Thanks!

Published with MATLAB® 7.2

  • print


コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。