[Insight-users] convert vtk mesh to a nifti image in python

Jude FERNANDO jude.f at hotmail.fr
Tue May 14 12:30:32 EDT 2013


Hi all,

I have a vtk mesh that I would like to register with a nifti image.
I tried to convert it to an image using this page, by changing the c++ code to python : http://www.paraview.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData
It gave me a MetaImage (a .mhd file and .raw file) that doesn't help me for the registration...

How could I get a nifti image from this mesh ? (nifti or any other image format that I could register with a nifti)

Here is the Python vtk code to create the mesh (generates a long cylinder named 'stem' and a smaller one named 'c1') :

  import vtk

  # create a rendering window and renderer
  ren = vtk.vtkRenderer()
  renWin = vtk.vtkRenderWindow()
  renWin.AddRenderer(ren)
  
  # create a renderwindowinteractor
  iren = vtk.vtkRenderWindowInteractor()
  iren.SetRenderWindow(renWin)


  # create stem
  stem = vtk.vtkCylinderSource()
  stem.SetCenter(0,0.73875,0)
  stem.SetRadius(0.0063)
  stem.SetHeight(1.5225) # 2.25 + 150
  stem.SetResolution(100) # number of facets to define cylinder

  # create c1
  c1 = vtk.vtkCylinderSource()
  c1.SetCenter(0,0,0)
  c1.SetRadius(0.00635)
  c1.SetHeight(0.03)
  c1.SetResolution(100)

  # mappers
  stemMapper = vtk.vtkPolyDataMapper()
  stemMapper.SetInput(stem.GetOutput())

  c1mapper = vtk.vtkPolyDataMapper()
  c1mapper.SetInput(c1.GetOutput())

  # actors
  stemActor = vtk.vtkActor()
  stemActor.SetMapper(stemMapper)

  c1Actor = vtk.vtkActor()
  c1Actor.SetMapper(c1mapper)
  c1Actor.GetProperty().SetColor(1.0,0,0)

  # assign actors to the renderer
  ren.AddActor(stemActor)
  ren.AddActor(c1Actor)

  # display axes
  axes = vtk.vtkAxesActor()
  ren.AddActor(axes)

  # enable user interface interactor
  iren.Initialize()
  renWin.Render()
  iren.Start()


Thank you for your help. Regards,

Jude
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130514/6e67d25c/attachment.htm>


More information about the Insight-users mailing list