从 3D 数组中提取任意旋转的数据平面作为 2D 数组
我在 matlab 中有一个 3D 数据矩阵,但我想从该矩阵中提取任意旋转的数据切片并将其存储为我可以访问的 2D 矩阵。与 slice() 函数显示以任意角度切片的数据类似,但我还希望能够像数组一样查看和修改数据。
我有平面枢轴点的坐标以及旋转角度(在 x、y 和 z 轴上),我还计算了以下形式的平面方程:
Ax + By + Cz = D
并且可以提取仅包含落在该平面上的数据,但我不知道如何将其转换为简单的二维数组。
另一种方法是以某种方式沿平面角度的相反方向旋转源矩阵,以便将数据平面与 XY 轴对齐,并简单地提取矩阵的该部分,但我这样做不知道是否可以旋转这样的矩阵。
我希望这个问题没有在其他地方得到解答,我已经在谷歌上搜索了一整天,但似乎没有一个问题与我的完全匹配。
谢谢
I have a 3D matrix of data in matlab, but I want to extract an arbitrarily rotated slice of data from that matrix and store it as a 2D matrix, which I can access. Similar to how the slice() function displays data sliced at any angle, except I would also like to be able to view and modify the data as if it were an array.
I have the coordinates of the pivot-point of the plane as well as the angles of rotation (in x, y and z axis), I have also calculated the equation of the plane in the form:
Ax + By + Cz = D
and can extract a 3D matrix containing only the data that fall on that plane, but I don't know how to then convert that into a simple 2D array.
Another way of doing it would be to somehow rotate the source matrix in the opposite direction of the angle of the plane, so as to line up the plane of data with the XY axis, and simply extract that portion of the matrix, but I do not know if rotating a matrix like that is possible.
I hope this hasn't been answered elsewhere, I've been googling it all day, but none of the problems seem to exactly match mine.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在此处查看代码。我认为该功能与您要解决的问题类似。
函数从体积中提取任意平面平面的大小、平面的中心点和平面法线,即[A,B,C]。它还输出平面上每个像素的体积索引和坐标。
You can take a look at the code here. I think the function is similar to what you are trying to solve.
The function extracts an arbitrary plane from a volume given the size of the plane, the center point of the plane, and the plane normal, i.e. [A,B,C]. It also outputs the volumetric index and coordinate of each pixel on the plane.
啊哈!可能自己刚刚解决了。
为了生成平面方程,我使用旋转矩阵旋转 (0,0,1) 的法线向量,然后找到 D。如果我还旋转以下向量:
并且
我将得到表示 x 坐标的梯度,在我进入数组中的下一列或下一行之前,y,z 必须更改。
我会尽快模拟它,并将其标记为答案(如果它有效)
编辑:好的,稍作改动,当我旋转向量时,我还应该旋转 3D 空间中表示 x=0,y= 的 xyz 坐标的点0,z=0(虽然我是绕着结构的中心旋转,所以它实际上是-sizex/2,-sizey/2,-sizez/2,其中size是数据的大小,然后我简单地添加尺寸/2 至旋转后的每个坐标将其平移回应有的位置)。
现在,随着我增加 2D 数组的 x 坐标,我有了 3D 梯度变化,并且随着我增加 y 坐标,梯度也发生了变化,我可以简单地循环遍历所有可能的 x 和 y 坐标(结果数组将为 50x50) 50x50x50 数组,我不确定 2D 数组中的不规则尺寸(我最终需要计算出来)会是什么,并计算数据中平面上生成的 3D 坐标。我的旋转角值作为起点。万岁!
只需要为此包含所有角度制定一个良好的测试,然后我会批准它作为答案
Aha! May have just solved it myself.
To produce the plane equation I rotate a normal vector of (0,0,1) using rotation matrices and then find D. If I also rotate the following vectors:
and
I'll have the gradients that denote how much my coordinates in x,y,z have to change before I step to the next column in my array, or to the next row.
I'll mock this up ASAP and mark it as the answer if it works
EDIT: Ok slight alteration, when I'm rotating my vectors I should also rotate the point in 3D space that represents the xyz coordinates of x=0,y=0,z=0 (although I'm rotating around the centre of the structure, so it's actually -sizex/2,-sizey/2,-sizez/2, where size is the size of the data, and then I simply add size/2 to each coordinate after the rotations to translate it back to where it should be).
Now that I have the gradient change in 3D as I increase the x coordinate of my 2D array and the gradient change as I increase the y coordinate, I can simply loop through all possible x and y coordinates (the resulting array will be 50x50 for a 50x50x50 array, I'm not sure what it will be for irregular sizes, which I'll need to work out eventually) in my 2D array and calculate the resulting 3D coordinates on my plane in the data. My rotated corner value serves as the starting point. Hooray!
Just got to work out a good test for this encompassing all angles and then I'll approve this as an answer