I am using itk and vtk in Python. Specifically I am trying to convert an ITK image to a VTK image using the function itk.ImageToVTKImageFilter. I am currently trying to replicate the code here. If I even try to access this function (just to read the documentation!) then it causes Python to crash and exit.
Has anyone else tested this function and had problems? Should I file a bug report?
OS: Windows 7
ITK v5.0.0.post1 from PyPi
VTK v8.1.2 from PyPi
I tracked it down. The team is aware and will be fixed in the next release.
@Michael_Hogg please try itk-vtkglue 0.3.0 and let us know how it goes.
Just tried itk-vtkglue 0.3.0 - works as expected. Thanks!
I use the latest itk-vtkglue using this : python -m pip install itk-vtkglue on Ubuntu 18, but when I tried to run the example it coredumped. This is the code sample:
if len(sys.argv) != 2:
print('Usage: ’ + sys.argv + ’ ')
imageFileName = sys.argv
Dimension = 2
PixelType = itk.UC
ImageType = itk.Image[PixelType, Dimension]
reader = itk.ImageFileReader[ImageType].New()
itkToVtkFilter = itk.ImageToVTKImageFilter[ImageType].New()
myvtkImageData = itkToVtkFilter.GetOutput()
When running it:
╰─$ python …/itk2vtk.py ./out.nrrd 1 ↵
 16358 segmentation fault (core dumped) python …/itk2vtk.py ./out.nrrd
Any suggestion ?
Welcome to the ITK Discourse!
Thank you for the detailed, self-contained description of the issue. I was able to reproduce the segfault. I am building in Debug to isolate the issue.
After several gooling and research on code, I was able to use itk.ImageToVTKImageFilter by using my own built ITK source code. For those whose are new comer like me, hope this help you. First of all, I compile source code of ITK release version (ITK Release). Note that I tried the ITK Github (ITK Github), but did not succeed. So I recommend you to compile with Release version. For VTK source code, I also used the the Release version 8.2, not the Github code. The next step I did is to enable the ITK VTK Glue in CMakeCache to ON,adn ITK_WRAP_PYTHON to ON. like this:
╰─$ grep Module_ITKVtkGlue CMakeCache.txt
//ADVANCED property for variable: Module_ITKVtkGlue
╰─$ grep PYTHON CMakeCache.txt
//ADVANCED property for variable: PYTHON_EXECUTABLE
//ADVANCED property for variable: PYTHON_INCLUDE_DIR
//ADVANCED property for variable: PYTHON_LIBRARY
//ADVANCED property for variable: PYTHON_LIBRARY_DEBUG
On this step, I encountered many issues which I asked on the thread https://discourse.itk.org/t/itk-python-wrapping-error-void-value-not-ignored-as-it-ought-to-be/948/10. Do the same thing on that thead you can compile the ITK with Python enabled.
The last step is to run the example. Before doing that, I set the PYTHONPATH variable to point to my ITK build like this:
And finally, the work is done without any issues.
@Phong_Tran thank you for sharing your experience!
Just for clarifying the content of that thread: there won’t be issues if you first build
VTK and then
ITK using the same python for both.