This notebook gives a basic introduction to using the 'dicom2stl.py'
script to extract an iso-surface from a volume image.
import os, sys
# download dicom2stl if it's not here already
if not os.path.isdir('dicom2stl'):
!{'git clone https://github.com/dave3d/dicom2stl.git'}
# Get the latest version
!{'cd dicom2stl; git pull'}
# Install required packages
!{sys.executable} -m pip install SimpleITK
!{sys.executable} -m pip install vtk
!{sys.executable} -m pip install itkwidgets
from dicom2stl.tests import create_data
tetra = create_data.make_tetra()
import itkwidgets
itkwidgets.view(tetra, cmap='Grayscale', vmin=100)
import SimpleITK as sitk
sitk.WriteImage(tetra, "tetra.nii.gz")
!{'./dicom2stl/dicom2stl.py -h'}
The '-i'
flag tells the script the intensity value to use for the iso-surface, 150
in this case. The '-o'
flag specifies the output file, tetra.stl
. The script can output STL, VTK or PLY files. And tetra.nii.gz
is input volume.
!{'./dicom2stl/dicom2stl.py -i 150 -o tetra.stl tetra.nii.gz'}
from dicom2stl.utils import vtkutils
mesh = vtkutils.readMesh('tetra.stl')
itkwidgets.view(tetra, cmap='Grayscale', geometries=[mesh], vmin=100)