5

I am new to 3D image processing . I would like to know how to view the dicom series in python. I tried using matplotlib and VTK. In matplot I am not able to view the volume like I view in matlab using volViewer. Regarding VTK I am not able to import VTKRAyCASt for viewing 3D. The version I am using is 8.2.0.

I am doing the processing using scipy.ndimages

Kindly suggest me some resources to my volume dicom files

Anju Kaimal
  • 83
  • 1
  • 1
  • 4

2 Answers2

6

You can try ipyvolume https://github.com/maartenbreddels/ipyvolume for interactive plotting, I found it quite useful. Also, you can plot them with matplotlib by using marching cubes to obtain the surface mesh but it is quite slow though:

from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import numpy as np
from skimage import measure

def plot_3d(image, threshold=-300): 
    p = image.transpose(2,1,0)
    verts, faces, normals, values = measure.marching_cubes_lewiner(p, threshold)
    fig = plt.figure(figsize=(10, 10))
    ax = fig.add_subplot(111, projection='3d')
    mesh = Poly3DCollection(verts[faces], alpha=0.1)
    face_color = [0.5, 0.5, 1]
    mesh.set_facecolor(face_color)
    ax.add_collection3d(mesh)
    ax.set_xlim(0, p.shape[0])
    ax.set_ylim(0, p.shape[1])
    ax.set_zlim(0, p.shape[2])

    plt.show()

The threshold of -300 HU is fine for visualizing chest CT scans but change it if you going to use MRI (check your intensity values distribution) or binary volumes (threshold =0).

There is some example of visualization:

Chest CT example

Primakov
  • 286
  • 3
  • 10
2

With vtkplotter you should be able to do this easily:

from vtkplotter import *

volume = load(mydicomdir) #returns a vtkVolume object
show(volume, bg='white')

To install: pip install vtkplotter

mmusy
  • 1,292
  • 9
  • 10
  • `vtkplotter` looked promising, but worked on it for a half an hour and couldn't get it to not crash on `.load` with `Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)` – rawkintrevo Apr 29 '20 at 13:19
  • uhmm does it work with some test dataset? E.g. `from vtkplotter import datadir, load` then `load(datadir+'embryo.tif').show()` – mmusy Apr 29 '20 at 14:52
  • On two of my machines it was crashing when trying to load DICOM data, and also- there was no test dataset with my install (via pip). Also- this is a bad forum for bug reporting- happy to go to a mailing list or git issues. – rawkintrevo Apr 29 '20 at 19:46
  • Feel free to submit to https://github.com/marcomusy/vtkplotter/issues – mmusy Apr 30 '20 at 00:02