How to Connect ITK and VTK Pipelines
February 17, 2016
Some things just go together well.
Mom and apple pie.
Bread and butter.
Cheese and wine.
What is better than just ITK and VTK?
ITK / VTK and Python!
The recent release of VTK 7.0.0 and ITK 4.9.0 now makes it possible to connect ITK / VTK pipelines in Python 3. The snippet below demonstates how easy it is to avoid code duplication and use the “best of breed” from each toolkit: visualization with VTK and image analysis with ITK.
import sys import itk import vtk if len(sys.argv) < 2: print('Usage: ' + sys.argv[0] + ' <InputFileName>') sys.exit(1) imageFileName = sys.argv[1] Dimension = 2 PixelType = itk.UC ImageType = itk.Image[PixelType, Dimension] reader = itk.ImageFileReader[ImageType].New() reader.SetFileName(imageFileName) itkToVtkFilter = itk.ImageToVTKImageFilter[ImageType].New() itkToVtkFilter.SetInput(reader.GetOutput()) itkToVtkFilter.Update() myvtkImageData = itkToVtkFilter.GetOutput() print(myvtkImageData)
For more information, including a downloadable version with code and data, see the full example.
Great article ! Illustrated, simple, to the point 🙂
I might have a preference for the third combination though.
Many thanks to the authors. Yet, I noticed one question, is that there is no ImageToVTKImageFilter in itk library. What I found is
https://stackoverflow.com/questions/10889519/how-to-convert-itk-image-file-to-vtk-with-python
but that is not quite the answer either. Is there any other possibilities to conver ITK images to VTK in python enviornment?
Since there are now VTK Python packages, we are working on Python so these filters can be installed with:
pip install itk-vtkglue
To keep track of the progress, subscribe to this GitHub issue:
https://github.com/InsightSoftwareConsortium/ITKVTKGlue/issues/1