Write a black-white image stack into a boolean 3D voxel array?

224 Views Asked by At

What is the best and low memory option to read a B&W image stack, which contains the 0/1 values of an ISO volume, and write it into boolean voxel array? i.e. 2k images of 2k squared pixels provides 800MB of boolean.

I started writing a 3D boolan array boolean[z,y,x]... and it doesnt work?!: i need an array of 2D arrays boolean[x,y](how ?)

II have already written a program that traverses the stack of images through the X,Y to detect the edge of the volume, i.e. every point in space where the image changes from 0 to 1 and from 1 to 0, and it gives me the vertices and the normals of objects for a poisson disk meshing. I now need to also traverse in Z, without loading 2000 images N times.

The voxel can be up to 8 billion voxels in total.

Which do i need? How can i declare the arrays in C/C#/JS?

Thanks for any tips.

1

There are 1 best solutions below

1
On

The challenge is to have the smallest data type to represent on/off values for every voxel. Simplify it to a 10x10x10 voxel space.

Its fine to make a 1D boolean array of length 1000, i.e.

var myvoxels : boolean[]= new boolean[x*y*z];

an then to acces it with the function:

function boolreturn(x,y,z) : boolean
{
    return myvoxels[ z*10*10+y*10+x]

}

so the last voxel of size 10x10x10 has array position 900 + 90 + 9 = 999.

it works the same with 100 voxels and with 8 billion of them.

i thought that it was more complicated than that using a 1d array becaues i had converted a marching cubes code which reads every space as modulo and devide/float to know where an object is in the 1d array, which can be mentally taxing and slow to code in 3D. the above should make it easy.