Any way to apply sparse matrix in vtkImageData?

I have skull CT images (about 500 images) and detect the skull data to do some test.
The CT data is so large, example: 1024 * 1024 * 500, about 500 million points. After detecting the skull data, we found the skull data is about 20% or lower, and the rest is zero.
Is there any way to reduce the memory usage?

There is vtkImageStencilData for sparse binary images, but there is no general-purpose sparse image type.

You can reduce the memory somewhat by cropping with e.g. vtkExtractVOI.

This is a very high-level question and specific solution depends on what exactly you want to do and what your constraints are. But in general, you can crop and resample the image to the minimum clinically necessary size.

For example, 1024 size suggests that it is the full reconstructed image of the CT bore. Typically you don’t need the full image resolution over the entire image. If you only need to keep 30% of the image along 3 axes and you can downsample by a factor of 2 without losing clinically relevant information then you already achieved about 300x memory reduction.

If you are only worried about storage space then, you can set all the voxels outside the head to -1000, which will compress better than the random noise. Lossy compression makes a big difference, too, but you need to be careful with artifacts that it may introduce.

1 Like

Our algorithm needs the resolution lower than 0.5mm, So the 1024 * 1024 * 500 size is the minimum requirement. So downsample or vtkExtractVOI is not suitable.
We simulate a light go through the data space, and check all the voxels in the light way. Most of voxels are zero, so I want to store the valuable data in memory, not zero data.
But we need to reslice the data, using vtkImageReslice, which needs the entire data.
It comes a big confilct.

It may simplify things if input data grid has the same resolution and type as the computation grid, but this is not a requirement.

A good example is volume rendering, where the generated image can be higher or lower resolution than the input data.

Volume rendering may be also interesting for you because it simulates how light goes through the material. The CPU volume raycaster keeps a lower-resolution copy of the data set for making computation faster for sparse volumes using space leaping.

If your data is very sparse then you may get better performance and lower memory needs by using unstructured grid instead of a structured grid (image). You can generate volumetric mesh using external software (for example, for medical images, Cleaver works quite well, and you can use it directly in 3D Slicer - see here).

Thank you very much!
I will try to use unstructured grid to solve my problem.