20060707-Spatial transformations: Translation confusion

本文探讨了使用imtransform函数进行图像纯平移时遇到的问题。默认情况下,该函数会自动调整输出空间网格来完全捕捉变换后的图像,这反而消除了平移效果。文章介绍了两种解决方法:一是获取并利用输出空间坐标信息;二是指定输出空间范围。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文: http://blogs.mathworks.com/steve/2006/07/07/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');
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')
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.
subplot(1,2,1)
imshow(I)
axis on
axis([0 400 0 400])

subplot(1,2,2)
imshow(I2,'XData',xdata,'YData',ydata)
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]);
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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值