Monday, August 1, 2011

Rendering a 3D Volume from a stack of 2D images

I have seen a number of questions related to the title.  I even experienced the question myself.  Here, i would like to document my approach.

The Question

If you are in the medical imaging field, at the time of writing, you are almost guaranteed that you'd need to reconstruct a 3D volume based on a stack of 2D images(let it be a stack of 'gray-scale' images).  The question is how in Matlab?

The Possible Solutions

Part 0 - Assumptions

  • all 2D images are of the same dimension, hence your 3D volume can hold all of them in a rectangular cube
  • majority of the pixels in each of the 2D images have 3D spatial relationships (you can't visualize much if the pixels in each of the 2D images are of some random distribution. )

Part 1 - Visualizing 3D Volume from A Stack of 2D Images

To visualize or reconstruct a 3D volume from a stack of 2D images, you can try the following toolkits in matlab.
Note that if you are familiar with VTK, you can try this: [6] matVTK
I am currently sticking with [5] SliceOMatic for its simplicity and ease of use. However, by default, rendering 3D is quite slow in Matlab. Turning on openGL would give faster rendering. ( Or simply put, set(gcf, 'Renderer', 'OpenGL').

Part 2 - Interpolating pixels in between the slices

To interpolate pixels in between the slices, you need to specify an interpolation method (some of the above toolkits have this capability / flexibility. Otherwise, to give you a head start, some examples for interpolation are bicubic, spline, polynomial etc..(you can work this out by looking up on google or google/scholar for interpolation methods much more specific to your problem domain).

Part 3 - 3D Pre-processing

Looking at the procedures, one may process the volumetric data by processing each of the 2D images first. In many advanced algorithms, or in true 3D processing, what you can do is to process the volumetric data in 3D domain first (simply put, you take the 26 neighbors or more in to account first.). Once this step is done, you can simply output the volumetric data into a stack of 2D images for cross-sectional viewing or supply to one of the aforementioned toolkits for 3D viewing or output to third party 3D viewing applications.

I have followed the above concepts for my own medical imaging research projects.

The above writing is documented here but was aiming at answering this question on StackOverflow.


  1. this is what I want to know. thanks

  2. This is exactly what I am looking for. Would you mind providing more specific examples of the code as I am considered a new user to use Matlab in dealing with 3D volume?

  3. Sure, as the OP was published 2 years ago, a lot has been updated in terms of the rendering procedures. I'll definitely stick some of the examples to this post. In the meantime, do you have questions or anything in doubt or anything you want to achieve? Just leave me a comment, I want to help.

    1. Im doing a project on aorta segmentation and 3d reconstruction... I need sample codes. Can you help?

  4. I have 9 2D images of weather radar reflectivity (.png), each image represents one layer radar elavation. Each image have black color for the backgroud. How to combine these 9 images to one 3D image? How to draw each one with some space between?

  5. I am doing my thesis on "3D reconstruction of abdominal image from 2D MRI slices". The steps I have followed are (i) Noise reduction (ii) Segmentation (iii) Interpolation (iv) Rendering. I have created stack of 2D slices. What approach should I follow next for interpolation and rendering. Will really appreciate your help. Please provide some sample codes for better understanding on how to implement this.

  6. I need a matlab code for reconstructing a 3D image from multiple 2D images.
    Can you please help me by providing a sample code