finetjul
(Julien Finet)
1
How can I convert a VTK image into an ITK image without itk-vtkglue in Python ? (see current issue)
Is there a solution as simple as converting from ITK to VTK ?
data = itk.GetArrayViewFromImage(myITKImage).tostring()
dataImporter = vtk.vtkImageImport()
dataImporter.CopyImportVoidPointer(data, len(data))
dataImporter.SetDataExtent(volumeExtent)
dataImporter.SetWholeExtent(volumeExtent)
dataImporter.SetDataOrigin(volumeOrigin)
dataImporter.SetDataScalarType(volumeDataType)
dataImporter.SetDataSpacing(spacing)
dataImporter.SetNumberOfScalarComponents(volumeComponents)
dataImporter.Update()
Thanks,
Julien.
dchen
(Dave Chen)
2
There’s a corresponding function itk.GetImageViewFromArray
that converts a numpy array to an ITK image. Here’s a blog post about that:
To get from a VTK image to NumPy array you can use the vtk_to_numpy
in numpy_support
. Here’s stackoverflow thread describing that process:
I wrote a function that goes from VTK to SimpleITK that is essentially the same thing:
2 Likes
Yes, NumPy can be used as a bridge.
Here is a patch to add itk.vtk_image_from_image
and itk.image_from_vtk_image
:
without itk-vtkglue.