解决方案的新尝试:
按照教程http://blogs.mathworks.com/steve/2006/08/17/spatial-transformations-three-dimensional-rotation/ 并进行一些小的更改,我可能会有一些可以帮助您的东西。请记住,我对 MATLAB 中的体积数据几乎没有经验,因此实现起来非常麻烦。
在下面的代码中,我使用 tformarray() 在空间中旋转结构。首先,将数据居中,然后使用 rotationmat3D 进行旋转以产生空间变换,然后再将数据移回其原始位置。
由于我以前从未使用过 tformarray,因此我通过简单地用零填充数据矩阵 (NxMxP) 来处理旋转后落在定义区域之外的数据点。如果有人知道更好的方法,请告诉我们:)
代码:
%Synthetic dataset, 25x50x25
blob = flow();
%Pad to allow for rotations in space. Bad solution,
%something better might be possible to better understanding
%of tformarray()
blob = padarray(blob,size(blob));
f1 = figure(1);clf;
s1=subplot(1,2,1);
p = patch(isosurface(blob,1));
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
daspect([1 1 1]);
view([1 1 1])
camlight
lighting gouraud
%Calculate center
blob_center = (size(blob) + 1) / 2;
%Translate to origin transformation
T1 = [1 0 0 0
0 1 0 0
0 0 1 0
-blob_center 1];
%Rotation around [0 0 1]
rot = -pi/3;
Rot = rotationmat3D(rot,[0 1 1]);
T2 = [ 1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1];
T2(1:3,1:3) = Rot;
%Translation back
T3 = [1 0 0 0
0 1 0 0
0 0 1 0
blob_center 1];
%Total transform
T = T1 * T2 * T3;
%See http://blogs.mathworks.com/steve/2006/08/17/spatial-transformations-three-dimensional-rotation/
tform = maketform('affine', T);
R = makeresampler('linear', 'fill');
TDIMS_A = [1 2 3];
TDIMS_B = [1 2 3];
TSIZE_B = size(blob);
TMAP_B = [];
F = 0;
blob2 = ...
tformarray(blob, tform, R, TDIMS_A, TDIMS_B, TSIZE_B, TMAP_B, F);
s2=subplot(1,2,2);
p2 = patch(isosurface(blob2,1));
set(p2, 'FaceColor', 'red', 'EdgeColor', 'none');
daspect([1 1 1]);
view([1 1 1])
camlight
lighting gouraud
下面的任意可视化只是为了确认数据按预期旋转,当数据传递值“1”时绘制一个闭合曲面。使用 blob2,您应该知道能够使用简单的求和进行投影。
figure(2)
subplot(1,2,1);imagesc(sum(blob,3));
subplot(1,2,2);imagesc(sum(blob2,3));