Stack of PNG files to be rendered as 3D

Hi Team,

I’m looking for option in C++ example where I can convert stack of 2D images (PNG format) to render 3D object.

Any help would be greatly appreciated.


What software saves a 3D volume as a series of 2D PNGs? In PNG series you cannot properly save spacing, image directions, cannot save 16-bit data, cannot reliably detect missing slices, etc., so it would be better to save directly to a 3D image format instead (nrrd, metaimage, …).

1 Like

Hello Andras,

Let me put this question in a better way, we are working in a stack of 2D images (it could be PNG, or any format), and our goal is to get the 3d image.
To be more precise, we are taking images of objects (2D) at many different timeframes, now our goal is to get a 3d object out of those stack.

If PNG format is not good for this job, then can you kindly suggest me which format of 2D would be better in this case.

In some examples, I was looking into (vtkVolume16Reader) where it creates a volume from the series of 2D images (pgm format). So at this point I’m not sure which format is suited.

Here are the steps for PGM format I took.
vtkVolume16Reader -> vtkContourFilter -> vtkPolyDataNormals --> vtkStripper --> vtkPolyDataMapper --> vtkActor --> vtkRender --> vtkRenderWindow -> vtkRederWindowInteractor

vtkVolume16Reader -> vtkMarchingCubes -> vtkPolyDataMapper --> vtkActor --> vtkRender --> vtkRenderWindow -> vtkRederWindowInteractor.

May be I had just converted PNG files to PGM files using linux tool (convert in.png out.pgm).

So I’m not sure whether the direction I’ve taken to solve the problem is correct or not.

Hence I require your help here

  1. Which stack of 2D format will be best to get the 3D object ?
  2. From the above two steps, which one is corrrect ?

Your help will be greatly appreciated.

Thanks & Regards,

If your image stack consists of time sequence of 2D images (2D space + time) and 3D volume (3D space) then it is OK to have them in separate files. If they are photos (3x8 bit RGB) then it is OK to store them in PNG.

What is odd that normally it is not meaningful to visualize a 2D+t stack as a 3D image. What is your application domain (clinical imaging, microscopy, geo, etc.)? What kind of images do you work with and how are they acquired?

Hello Andras,

We are working in 3D printing technology. While we are generating a model (3D print model), we take multiple 2D images until the 3d image is completed ?


OK, so you actually have slices of a 3D volume (it is just a coincidence that you happen to acquire it as a time sequence). So, it is more appropriate and convenient to store it as a 3D volume file. There are a couple of file formats to consider:

  • .vtk: legacy VTK data file
    • good: simple file format, VTK fully supports all of its features, recognized by a number of non-VTK-based software
    • somewhat confusing that extensions by this filename can contain polydata, unstructured grid, etc.; it is considered “legacy” file format in VTK
  • .vti: VTK image
    • good: VTK fully supports all of its features
    • bad: somewhat complex file-format, only VTK-based software can read it (third-party software developers don’t bother with reimplement it without VTK)
  • .mha: metaimage
    • good: very simple format, commonly supported by many software
    • bad: intent of image axes are not explicitly specified in the file (which axes is spatial, which one is color, etc.), VTK does not support all of its features (multi-file voxel storage, 4D+ images, etc.)
  • .nrrd: NRRD
    • good: very simple format, commonly supported by many software, intent of image axes are clearly specified in the file
    • bad: VTK does not support all of its features (multi-file voxel storage, 4D+ images, etc.)

Overall, I would recommend using NRRD format for simplicity and compatibility with third-party software.

If you store your data in this format then you can read it directly into VTK and if you want to visualize it in 3D then you can directly feed into volume rendering or convert it to polydata using contour filter and display the polydata.

Hello Andras,

Thanks for your help.

On the other note, if anyone is after the solution
vtkPNGReader -> vtkMarchingCubes -> vtkPolyDataNormals -> vtkStripper -> vtkPolyDataMapper -> vtkActor -> vtkRenderer -> vtkRenderWindowInteractor


1 Like