20060817-Spatial transformations: Three-dimensional rotation

原文:http://blogs.mathworks.com/steve/2006/08/17/spatial-transformations-three-dimensional-rotation/

The Image Processing Toolbox function tformarray is a very general multidimensional spatial transformer and can be used for three-dimensional rotation. Here's how.

Make a three-dimensional blob

First, let's make a three-dimensional image containing a blob that will easily show the effect of a rotation.

[x,y,z] = ndgrid(-1:.025:1);
blob = z <= 0 & z >= -0.75 & x.^2 + y.^2 <= sqrt(0.25);
blob = blob | (z > 0 & (abs(x) + abs(y) <= (0.5 - z)));
Display the blob using isosurface and patch.

p = patch(isosurface(blob,0.5));
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
daspect([1 1 1]);
view(3)
camlight
lighting gouraud
Make a 3-D affine tform struct

We want to rotate the blob about its own center. For me, the simplest way to construct an affine transform matrix that will do that is to use three steps:

  1. Translate the middle of the blob to the origin.
  2. Rotate the blob.
  3. Translate the rotated blob back to its starting location.

Here's the first translation:

blob_center = (size(blob) + 1) / 2
T1 = [1 0 0 0
    0 1 0 0
    0 0 1 0
    -blob_center 1]

Now here's the rotation. In this example we'll rotate about the second dimension.

theta = pi/8;
T2 = [cos(theta)  0      -sin(theta)   0
    0             1              0     0
    sin(theta)    0       cos(theta)   0
    0             0              0     1]

And here's the final translation.

T3 = [1 0 0 0
    0 1 0 0
    0 0 1 0
    blob_center 1]

The forward mapping is the composition of T1, T2, and T3.

T = T1 * T2 * T3
tform = maketform('affine', T);

Let's do a quick sanity check: the tform struct should map the blob center to itself.

tformfwd(blob_center, tform)
What the tformarray inputs mean

Now let's see how to make the inputs to the tformarray function. The syntax of tformarray is B = tformarray(A, T, R, TDIMS_A, TDIMS_B, TSIZE_B, TMAP_B, F).


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值