20060214-Spatial transformations: maketform, tformfwd, and tforminv

本文介绍了MATLAB中用于图像处理的空间变换工具箱函数,包括构造不同类型的tform结构的maketform函数,实现从输入空间到输出空间变换的tformfwd函数,以及实现逆变换的tforminv函数。通过缩放、旋转和平移实例展示了这些函数的应用。

原文:http://blogs.mathworks.com/steve/2006/02/14/spatial-transformations-maketform-tformfwd-and-tforminv/

Several Image Processing Toolbox functions related to spatial transformations use "tform" structures. A tform structure has data and function handles needed for applying a spatial transformation in the forward or the inverse direction, and sometimes in both directions.

maketform

Function maketform has several syntaxes for constructing different types of tform structures. For example, you can construct an affine transform by providing an A matrix:

A = [2 0 0; 0 2 0; 0 0 1];  % Stretch by a factor of 2 in both directions.
tform = maketform('affine', A);

tformfwd

Toolbox function tformfwd transforms points from input space to output space. For example, to apply the affine transform above to the point (u,v) = (2,3), do this:

uv = [2 3];
xy = tformfwd(tform, uv)

tforminv

Function tforminv transforms points from output space to input space. If we apply the inverse transformation to the point xy computed above, we should get back the original point.

uvp = tforminv(tform, xy)

Introducing George

The spatial transformation functions imtransform, tformarray, tformfwd, tforminv, etc., were introduced to Image Processing Toolbox version 3 in 2001.

% http://blogs.mathworks.com/images/steve/37/george.mat
load george
plot(x,y), axis ij, axis equal, axis([-1 1 -1 1]), grid on

Scaling example

A1 = [2 0 0; 0 2 0; 0 0 1];
tform1 = maketform('affine', A1);
uv1 = tformfwd(tform1, [x y]);

subplot(1,2,1)
plot(x,y), axis ij, axis equal, axis([-2 2 -2 2]), grid on, title('George')

subplot(1,2,2)
plot(uv1(:,1), uv1(:,2)), axis ij, axis equal, axis([-2 2 -2 2])
grid on
title('Scaled by 2')

Rotation example

theta = pi/4;
A2 = [cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1];
tform2 = maketform('affine', A2);
uv2 = tformfwd(tform2, [x y]);

subplot(1,2,1)
plot(x,y), axis ij, axis equal, axis([-2 2 -2 2]), grid on, title('George')

subplot(1,2,2)
plot(uv2(:,1), uv2(:,2)), axis ij, axis equal, axis([-2 2 -2 2])
grid on
title('Rotated by 45\circ')

Translation example

A3 = [1 0 0; 0 1 0; 1 -1 1];
tform3 = maketform('affine', A3);
uv3 = tformfwd(tform3, [x y]);

subplot(1,2,1)
plot(x,y), axis ij, axis equal, axis([-2 2 -2 2]), grid on, title('George')

subplot(1,2,2)
plot(uv3(:,1), uv3(:,2)), axis ij, axis equal, axis([-2 2 -2 2])
grid on
title('Translated')

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值