itk.ImageToVTKImageFilter crashing Python

Hi,

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?

Versions:
OS: Windows 7
Python 3.6
ITK v5.0.0.post1 from PyPi
VTK v8.1.2 from PyPi

Cheers,
Michael

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.

Hi Matt,

Just tried itk-vtkglue 0.3.0 - works as expected. Thanks!

Michael

1 Like

Hi Matt,
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:
import itk
import sys

if len(sys.argv) != 2:
print('Usage: ’ + sys.argv[0] + ’ ')
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)

When running it:
╭─phongtd@nguyenth ~/tmp/itk-vtk-glue/build
╰─$ python …/itk2vtk.py ./out.nrrd 1 ↵
[1] 16358 segmentation fault (core dumped) python …/itk2vtk.py ./out.nrrd

Any suggestion ?

Hi Phong,

Welcome to the ITK Discourse! :sunny:

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.

Matt

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:

╭─phongtd@nguyenth ~/workingspace/InsightToolkit-5.0.1/build_other
╰─$ grep Module_ITKVtkGlue CMakeCache.txt
Module_ITKVtkGlue:BOOL=ON
//ADVANCED property for variable: Module_ITKVtkGlue
Module_ITKVtkGlue-ADVANCED:INTERNAL=1

╭─phongtd@nguyenth ~/workingspace/InsightToolkit-5.0.1/build_other
╰─$ grep PYTHON CMakeCache.txt
ITK_WRAP_PYTHON:BOOL=ON
ITK_WRAP_PYTHON_LEGACY:BOOL=ON
PYTHON_EXECUTABLE:FILEPATH=/usr/bin/python
PYTHON_INCLUDE_DIR:PATH=/usr/include/python3.6m
PYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
PYTHON_LIBRARY_DEBUG:FILEPATH=PYTHON_LIBRARY_DEBUG-NOTFOUND
ITK_WRAP_PYTHON_BINARY_DIR:INTERNAL=/home/phongtd/workingspace/InsightToolkit-5.0.1/build_other/Wrapping/Generators/Python
ITK_WRAP_PYTHON_SOURCE_DIR:INTERNAL=/home/phongtd/workingspace/InsightToolkit-5.0.1/Wrapping/Generators/Python
//ADVANCED property for variable: PYTHON_EXECUTABLE
PYTHON_EXECUTABLE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: PYTHON_INCLUDE_DIR
PYTHON_INCLUDE_DIR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: PYTHON_LIBRARY
PYTHON_LIBRARY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: PYTHON_LIBRARY_DEBUG
PYTHON_LIBRARY_DEBUG-ADVANCED:INTERNAL=1

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:

export PYTHONPATH=/home/phongtd/workingspace/InsightToolkit-5.0.1/build_other/Wrapping/Generators/Python:$PYTHONPATH

And finally, the work is done without any issues.

1 Like

@Phong_Tran thank you for sharing your experience!

Thanks @Phong_Tran!

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.

1 Like