[Insight-users] How to convert SimpleITK image to VTK data
Samuel Pichardo
sammeuly at gmail.com
Mon Sep 16 08:00:26 EDT 2013
Hi
You convert first from a VTK array to numpy array (using "from vtk.util
import numpy_support") then to SimpleITK array. This is the way I read
Dicom files with VTK, in my case a 3D MRI dataset,
reader = vtk.vtkDICOMImageReader()
reader.SetDirectoryName(dirpath) #dirpath is the directory with group
of dicom files
reader.Update();
origin = reader.GetImagePositionPatient()
dimensions = reader.GetDataExtent()
spacing = reader.GetPixelSpacing()
data = reader.GetOutput().GetPointData() # get VTK-formatted data
data = numpy_support.vtk_to_numpy(data.GetArray(0)) # convert VTK
data to numpy data
data =
data.reshape((dimensions[5]+1,dimensions[3]+1,dimensions[1]+1)) #
reshape data from 1D -> 3D
then to convert to simpleITK,
dataITK = sitk.GetImageFromArray(data)
You'd need to adapt it to NRRD reader but it should be similar.
Personally, I'd stop in converting to numpy array and from there use
matplotlib or chaco for the display, depending on if you are looking
for GUI or a simple display. From there, you can figure out for the
inverse process from SimpleITK (GetArrayFromImage) to Numpy and then
to VTK using an object vtk.vtkImageImport() (there is a lot of examples
for this)
good luck
Sam
On Sun 15 Sep 2013 11:59:49 AM EDT, jmerkow wrote:
> I am looking to do something similar. I have an NRRD that I read in VTK. I
> am using ImageReslice to obtain slices along a path (3D path along
> vasculature). I want to reslice the image and display a single slice. Since
> display is significantly easier in SimpltITK, I wanted to convert the
> vtkImageData to a format that SimpleITK can read. I would also love to do
> be able to do this for various other reasons. Since this post is about 2
> years old, are there any updated methods in SimpleITK or VTK6 to convert VTK
> -> SimpleITK, SimpleITK -> VTK?
>
>
>
> --
> View this message in context: http://itk-users.7.n7.nabble.com/How-to-convert-SimpleITK-image-to-VTK-data-tp15192p32352.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list