他是我在这里的第一个问题,所以请告诉我。我简要地描述了情况:有一个大小为512x512xN的体素集合(N是断层切片的数目)(新的BitArray (512x512xN))。作为一种分割算法的结果,得到了该集中填充体素的索引,使用BitArray数组表示所需的体素,其中值为true的索引为分段,false为背景。因此,我想知道如何使用二进制掩码来找到边界体素(像素),它存储它们的坐标(x,y,z)和背景信息(真-假),只得到段信封。下面是定义边界指数的代码,但这是不正确的:
private static async Task<BitArray> EdgeArray(Vector3Int size, BitArray data)
{
return await Task.Run(() =>
{
var edges = new BitArray(data.Length);
var mask3d = new Dictionary<Vector3Int,bool>();
Parallel.For(0, data.Count, i =>
{
lock (mask3d)
{
mask3d.Add(size.GetIndex3D(i),data[i]);
}
});
var voxels = mask3d.Keys.ToList();
Parallel.For(0, voxels.Count, i =>
{
if (voxels[i].x == 0 || voxels[i].x == size.x - 1 || voxels[i].y == 0 ||
voxels[i].y == size.y - 1 || voxels[i].z == 0 || voxels[i].z == size.z - 1)
{
if (mask3d[voxels[i]])
{
var index = voxels[i].ToIndex3D(size.x, size.y, size.z);
edges[index] = true;
Debug.Log(index);
}
}
else
{
if (mask3d[voxels[i]] && (!mask3d[voxels[i-1]] || !mask3d[voxels[i+1]]))
{
var index = voxels[i].ToIndex3D(size.x, size.y, size.z);
edges[index] = true;
Debug.Log(index);
}
}
});
return edges;
});
}次要职能:
/// <summary>
/// returns the index in the 3d representation
/// </summary>
/// <param name="vector3Int"> array size in 3d representation </param>
/// <param name="index"> 1d index </param>
/// <returns>index in the 3d representation</returns>
public static Vector3Int GetIndex3D(this Vector3Int vector3Int, int index)
{
return new Vector3Int
{
z = index / (vector3Int.x * vector3Int.y),
y = index % (vector3Int.x * vector3Int.y) / vector3Int.x,
x = index % (vector3Int.x * vector3Int.y) % vector3Int.x
};
}
public static int ToIndex3D(this Vector3Int vector3Int, int width, int height, int depth)
{
return vector3Int.z * width * height + vector3Int.y * width + vector3Int.x*depth;
}发布于 2021-02-19 11:48:38
我认为GetIndex3D()和ToIndex3D()函数可能是错误的。ToIndex3D()应该是:
return vector3Int.z * width * height + vector3Int.y * width + vector3Int.x;GetIndex3D()应该是:
z = index / (vector3Int.x * vector3Int.y),
y = (index / vector3Int.x) % vector3Int.y
x = index % vector3Int.x(这是内存中未经测试的猜测,但我认为这是将3D数组转换为一维数组的一种好方法,反之亦然)
https://stackoverflow.com/questions/66276532
复制相似问题