c# - 如何在 3D 空间中旋转一堆图像?
问题描述
我有一堆二维图像。让我们说下面是这个卷的尺寸。
深度(图像数量) - 100
宽度(X 轴像素) - 200
高度(Y 轴像素) - 200
我想旋转这个卷并从中创建位图。我C#
用来实现这一点。
这是我所做的:
List<short[]> volumebuffer = new List<short[]>(noImages);
for (int img = 0; imge<noImages; img++)
{
short[] tmpArray = new short[ImgTotalHeight * ImgTotalWidth];
int index = 0;
for (int aHeight = 0; aHeight<ImgTotalHeight; aHeight++)
{
for (int aWidth = 0; aWidth<ImgTotalWidth; aWidth++)
{
tmpArray[index++] = image[aWidth + aHeight * ImgTotalWidth];
}
}
#append this tmpArray to a List<>
vomumebuffer.Add(tmpArray);
}
在上面的代码中,volumebuffer 将包含所有图像的所有像素值。我正在将每个图像的每个短数组转换为字节数组并从中创建位图。
现在我想旋转这个卷并从中创建位图。我只想创建 90 度方向。
我试图读取不同轴上的像素值。就像在 Width-> Depth -> Height order 等中读取像素值一样。
但这对于每个方向都需要许多 for 循环。
有没有更好的方法来实现体积的方向?
请帮助我了解如何在不同方向将这个音量旋转 90 度。
提前致谢。
解决方案
您应该添加方法来按 x、y、z 坐标索引体积。然后,以 90 度的步长旋转将只是切换索引的位置,保持一维固定。例如
bitmap[u, v] = volume[0, v, u]
或者
bitmap[u, v] = volume[v, 0, u]
或者
bitmap[u, v] = volume[xSize - v, u, 0]
总共应该有 24 个有效组合
您可以将 0 替换为您想要的任何有效值,并且您需要确保 u/y 坐标限制为相应的体积维度。
编辑:
使用多维数组以使索引更清晰的示例。您需要将其与相应的代码进行交换,并将结果转换为位图。
var volume = new ushort[1, 2, 3];
var bitmap = new ushort[volume.GetLength(2), volume.GetLength(1)];
for (int v = 0; v < bitmap.GetLength(1); v++)
{
for (int u = 0; u < bitmap.GetLength(0); u++)
{
bitmap[u, v] = volume[0, v, u];
}
}
推荐阅读
- asp.net-mvc - 如何在 ASP.NET MVC 中将数据从一个 API 传输到另一个 API?
- python-3.x - 如何在数据框中获得多个聚合?cumsum 和 count 列
- c++ - 将 QString 转换为 const char*
- python-3.x - 按键从字典列表中删除重复记录,但保留一个具有最多键的记录
- python - 如何在 8 位移位寄存器上切换单个引脚(Python - Raspberry Pi)
- python - Python List Comprehension 在 Numpy Array 中增加了另一个维度
- javascript - 用 JS 关闭一个模态
- python - Pandas 在不同数据帧上的乘法
- python - 仅在打开的文件中出现 Python 错误,而不是在关闭的文件中
- angular - Angular + Express PWA 504 网关