ImageToVTKImageFilter

Hi, I am working with MRI database with Nifti format (.nii.gz) and I need to convert them to meshes (.vtk)
I am building from sources and install to the system site-packages directory.(ITK and VTK)
But I have some trouble with running this code :

import itk
import vtk
import sys
if len(sys.argv) != 2:
print(‘Usage: ’ + sys.argv[0] + ’ <con1.nii.gz>’)
sys.exit(1)
imageFileName = sys.argv[1]
Dimension = 2
PixelType = itk.UC
ImageType = itk.Image[PixelType, Dimension]
print(“Image”, ImageType)
reader = itk.ImageFileReader[ImageType].New()
reader.SetFileName(imageFileName)
reader.Update()
itkToVtkFilter = itk.ImageToVTKImageFilter[ImageType].New()
itkToVtkFilter.SetInput(reader.GetOutput())
itkToVtkFilter.Update()
myvtkImageData = itkToVtkFilter.GetOutput()
print(“myvtkImageData”)

ERROR:
File “mesh.py”, line 19, in
itkToVtkFilter = itk.ImageToVTKImageFilter[ImageType].New()
File “/home/nour/anaconda3/lib/python3.7/site-packages/itkLazy.py”, line 48, in getattribute
value = types.ModuleType.getattribute(self, attr)
AttributeError: module ‘itk’ has no attribute ‘ImageToVTKImageFilter’

Hi @nour

To convert an image to a mesh, the ITKCuberille module can be used.

Here is an example:

1 Like