![](/img/trans.png)
[英]Reconstruction 3d on plane from 2d projection with camera calibration parametrs of plane
[英]3d grayscale volume projection onto 2D plane
我有一个与超声数据相对应的三维灰度音量。 在Matlab中,这个3-D体积只是MxNxP的3-D矩阵。 我感兴趣的结构不是沿着z轴定向,而是沿着已知的局部坐标系( x'y'z' ) 定向 。 到目前为止我所拥有的是如下图所示,描绘了原始( xyz )和局部坐标系( x'y'z' ):
我想通过局部坐标系上的特定平面(例如z'= z0 )获得该体积(即图像)的二维投影。 我怎样才能做到这一点?
如果体积沿z轴取向,则可以容易地实现该投影。 即如果Matlab中的音量为V ,则:
projection = sum(V,3);
因此,投影可以被计算为沿着阵列的第三维的总和。 然而,随着方向的改变,问题变得更加复杂。
我一直在研究氡变换(2D,仅适用于二维图像而不是体积)并且还在考虑ortographic投影,但此时我对于该做什么一无所知!
谢谢你的建议!
解决方案的新尝试:
按照教程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));
假设您可以访问坐标基R = [x'y'z'],并且这些向量是正交的,您可以通过将数据乘以3x3矩阵R(其中x'),在此基础上简单地提取表示, y',z'是列向量。
利用存储在D(Nx3)中的数据,您可以通过乘以它得到R的表示:Dmarked = D * R;
现在D = Dmarked * inv(R),所以前后来回是很难的。
以下代码可能会提供有关查看转换的帮助。 在这里,我创建一个合成数据集,旋转它,然后将其旋转回来。 总和(DR(:,3))将是你沿z'的总和
%#Create synthetic dataset
N1 = 250;
r1 = 1;
dr1 = 0.1;
dz1 = 0;
mu1 = [0;0];
Sigma1 = eye(2);
theta1 = 0 + (2*pi).*rand(N1,1);
rRand1 = normrnd(r1,dr1,1,N1);
rZ1 = rand(N1,1)*dz1+1;
D = [([rZ1*0 rZ1*0] + repmat(rRand1',1,2)).*[sin(theta1) cos(theta1)] rZ1];
%Create roation matrix
rot = pi/8;
R = rotationmat3D(rot,[0 1 0]);
% R = 0.9239 0 0.3827
% 0 1.0000 0
% -0.3827 0 0.9239
Rinv = inv(R);
%Rotate data
DR = D*R;
%#Visaulize data
f1 = figure(1);clf
subplot(1,3,1);
plot3(DR(:,1),DR(:,2),DR(:,3),'.');title('Your data')
subplot(1,3,2);
plot3(DR*Rinv(:,1),DR*Rinv(:,2),DR*Rinv(:,3),'.r');
view([0.5 0.5 0.2]);title('Representation using your [xmarked ymarked zmarked]');
subplot(1,3,3);
plot3(D(:,1),D(:,2),D(:,3),'.');
view([0.5 0.5 0.2]);title('Original data before rotation');
如果有两个标准化的 3x1向量x2
和y2
对应于本地坐标系(x'和y')。
然后,对于位置P
,其局部坐标将是xP=P'x2
和yP=P'*y2
。
因此,您可以尝试使用accumarray投影您的音量:
[x y z]=ndgrid(1:M,1:N,1:P);
posP=[x(:) y(:) z(:)];
xP=round(posP*x2);
yP=round(posP*y2);
xP=xP+min(xP(:))+1;
yP=yP+min(yP(:))+1;
V2=accumarray([xP(:),yP(:)],V(:));
如果您提供数据,我会测试它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.