Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB

空间的转换:翻译混乱

Thelast time I wrote about spatial transformations, I explained thatimtransformuses the functionfindboundsto locate the transformed image in output space. By default,imtransformcomputes an output image grid that is just big enough to capture the output image, wherever it is located.

We designedimtransformthis 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 callimtransformto apply a pure translation. Let's try it and see.

I = imread('pout.tif'); imshow(I)

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:

subplot(1,2,1) imshow(I) title('original image') subplot(1,2,2) imshow(I2) title('translated image')

They're the same! Hence, the confusion.

Hereimtransformhas 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 askimtransformto 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);

xdatais a two-element vector specifying where the first and last columns ofI2are located in output space. Similarly,ydataspecifies where the first and last rows are located. You can pass this information along to the display function,imshow.

subplot(1,2,1) imshow(I) axisonaxis([0 400 0 400]) subplot(1,2,2) imshow(I2,“XData”,xdata,'YData',ydata) axisonaxis([0 400 0 400])

A second technique is to tellimtransformwhat output-space rectangle to use.

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

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
  • send email

Comments

To leave a comment, please clickhereto sign in to your MathWorks Account or create a new one.