Error: ImageToVTKImageFilter returning none in python, ITK 5.0.1

Hello,

i’m using Itk 5.0.1 with Vtk 8.2 copiled by myself with itkVtkGlue and python wrapping on Windows, both static. When i call ImageToVTKImageFilter in python, it returns None.

I have Itk 5.0.1 and Vtk 8.2 compiled on linux for C++ working correctly with itkVtkGlue. Also have Itk 4.13.2 with Vtk 8.2 compiled on windows for python and working correctly with itkVtkGlue.

itkToVtkFilter = itk.ImageToVTKImageFilter[type(itkImageMask)].New()

itkToVtkFilter.SetInput(itkImageMask)
itkToVtkFilter.Update()

print(itkToVtkFilter.GetOutput())

Result: None

Why it’s ImageToVTKImageFilter returning none and how to solve it?

Hello Ramiro,

A few limitations to be aware of:

  • VTK Python currently requires a shared instead of a static build
  • VTK 8.1.2 is recommended over 8.2, which has issues with Python loading

HTH,
Matt

1 Like

Thanks for the tips @matt.mccormick .

Tried with ITK 5.0.1 and VTK 8.1.2, VTK with shared build this time, it happens the same problem

Temporal solution: As i use python as lab and the final code it’s in C++, i use a temporal folder to save itk image as DICOM, then open those DICOM with vtk. This way ensures all spatial information is preserved. I know it’s not a proper way to do it, but maybe it can help those with the same problem until a solution is found. The code it’s:

if itk.Version.GetITKMajorVersion() == 5:   #Patch to solve ImageToVTKImage Filter problem with itk
     temporalPath = os.path.join(outputPath, "tempExpObj")
     if os.path.exists(temporalPath) and os.path.isdir(temporalPath):
          shutil.rmtree(temporalPath)
     os.makedirs(temporalPath, exist_ok=True)
     saveSeveralDcm(itkImage, temporalPath , "", itkReader)
     vtkPoly = readDicomVtk(temporalPath)
     vtkPoly = imageToObj(vtkPoly)
1 Like

Solved the issue, now ImageToVTKImageFilter work as intended.

I document here the changes i think led to it working and important flags.
Shared vtk worked great, thanks Matt.

Win itk 5
cmake_Thread_libs = -lpthread

Win vtk 8.2
build_shared_libs = enabled
cmake_Thread_libs = -lpthread
Module_vtkPython = enabled
Module_vtkWrappingPythonCore = enabled //Same as before but important
VTK_USE_SYSTEM_LIBRARIES = enabled
VTK_WRAP_PYTHON = enabled //Same as before but important