# ImageToVTKImageFilter

**URL:** https://discourse.itk.org/t/imagetovtkimagefilter/2409
**Category:** Beginner Questions
**Tags:** python
**Created:** [November 14, 2019, 8:45pm UTC](https://discourse.itk.org/t/imagetovtkimagefilter/2409 "2019-11-14T20:45:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nour](https://discourse.itk.org/user_avatar/discourse.itk.org/nour/32/1145_2.png) [@nour](https://discourse.itk.org/u/nour)
#### Post date: [November 14, 2019, 8:45pm UTC](https://discourse.itk.org/t/imagetovtkimagefilter/2409/1 "2019-11-14T20:45:06Z")

</div>

## 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’

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [November 15, 2019, 10:29pm UTC](https://discourse.itk.org/t/imagetovtkimagefilter/2409/2 "2019-11-15T22:29:28Z")

</div>

Hi @nour

To convert an image to a mesh, the [ITKCuberille](https://github.com/InsightSoftwareConsortium/ITKCuberille) module can be used.

Here is an example:

> <https://github.com/InsightSoftwareConsortium/itkwidgets/blob/master/examples/VisualizeImageLabels.ipynb>
