20060613-Spatial transformations: findbounds

原文:http://blogs.mathworks.com/steve/2006/06/13/spatial-transformations-findbounds/

To avoid these problems (and to avoid the tech support calls!), the function imtransform uses the function findbounds to determine automatically where to place the output grid and how big it should be.

findbounds first creates a grid of points. These points are located in input space at each corner of the image, as well as in between each corner and in the middle. It looks like this:

I = imread('rice.png');
h = imshow(I);
set(h,'AlphaData',0.3);
axis on, grid on
in_points = [ ...
    0.5000    0.5000
    0.5000  256.5000
  256.5000    0.5000
  256.5000  256.5000
    0.5000  128.5000
  128.5000    0.5000
  128.5000  128.5000
  128.5000  256.5000
  256.5000  128.5000];
hold on
plot(in_points(:,1), in_points(:,2), '.', 'MarkerSize', 18)
hold off

findbounds then calls tformfwd to transform these points into output space. (For this example I'm going to construct an affine tform struct that combines scaling, rotation, shear, and a large translation.)

tform = maketform('affine', ...
    [1.1067 -0.2341 0; 0.5872 1.1769 0; 1000 -300 1]);
out_points = tformfwd(tform, in_points)
plot(out_points(:,1), out_points(:,2), '.', 'MarkerSize', 18)
axis ij, axis image
grid on
The bounding box of the points in output space tells us where to put the output space grid.

When you call imtransform, you can use optional output arguments to determine where the image is located in output space.

[J,XData,YData] = imtransform(I, tform);
XData
You can use this information together with imshow to place the image in the right place on an axes that contains other X-Y data.
h = imshow(J,'XData',XData,'YData',YData);
set(h,'AlphaData',0.3)
hold on
plot(out_points(:,1), out_points(:,2), '.', 'MarkerSize', 18)
axis on
grid on
hold off
axis ij, axis image
So that's the method imtransform uses to determine where the output image should be in output space.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值