[Insight-users] connecting Itk and Vtk in python

Eduardo Suarez eduardo at ctm.ulpgc.es
Mon Feb 28 11:50:12 EST 2005


It worked. I won't use 'itkVTKImageExportUS2_New()' anymore.

Thanks,
-Eduardo

Bruno Cassaro wrote:
>  >Hi,
>  >
>  >i'm trying to connect itk and vtk in python. I tried:
>  >>>> conector=itkVTKImageExportUS2_New()
>  >
>  >but
>  >
>  >>>> dir(conector)
>  >['AbortGenerateDataOff',... >'GetNumberOfValidRequiredInputs',
>  >'GetOutputs', 'GetPipelineModifiedCallback',... ]
>  >
>  >I didn't find a 'GetOutput' method, but a 'MakeOutput' >and 'GetOutputs'.
>  >On the other hand, i have seen the Insight Application
>  >'ConnectVTKITKPython' in the itk examples.
>  >
>  >What is the right way to do the connection in python? Is >the
>  >itkVTKImageExport still working? What
>  >
>  >Thanks a lot,
>  >
>  >-Eduardo
> Hi Eduardo,
> 
> First you'll need compile InsightApplication ..... so you con use 
> ConnectVTKITK !!!!
> 
> For example try this code :
> 
>  
> 
>  
> 
> ##################################################
> 
> import vtk
> 
> import InsightToolkit as itk
> 
> import ConnectVTKITK as vtkitk
> 
> reader = vtk.vtkImageReader()
> 
> ...
> 
>  
> 
> # transform in FLOAT
> 
> imageCast = vtk.vtkImageCast()
> 
> imageCast.SetInput(reader.GetOutput())
> 
> imageCast.SetOutputScalarTypeToFloat()
> 
> imageCast.Update()
> 
> #VTK export
> 
> vtkExporter = vtk.vtkImageExport()
> 
> vtkExporter.SetInput(imageCast.GetOutput())
> 
> itkImporter = itk.itkVTKImageImportF2_New()
> 
> vtkitk.ConnectVTKToITKF2(vtkExporter, itkImporter.GetPointer())
> 
> itkImporter.Update()
> 
>  
> 
> # filter
> 
> otsu = itk.itkOtsuThresholdImageCalculatorF2_New()
> 
> otsu.SetImage(itkImporter.GetOutput())
> 
> otsu.Compute()
> 
>  
> 
> # ITK - > VTK
> 
> itkExporter = itk.itkVTKImageExportF2_New()
> 
> itkExporter.SetInput(itkImporter.GetOutput())
> 
> vtkImporter = vtk.vtkImageImport()
> 
> vtkitk.ConnectITKF2ToVTK(itkExporter.GetPointer(), vtkImporter)
> 
> vtkImporter.Update()
> 
> # print
> 
> mapper2D = vtk.vtkImageMapper()
> 
> mapper2D.SetInput(vtkImporter.GetOutput())#thresh.GetOutput())
> 
> mapper2D.SetColorLevel(level)
> 
> mapper2D.SetColorWindow(window)
> 
> imageActor2D = vtk.vtkActor2D()
> 
> imageActor2D.SetMapper(mapper2D)
> 
> ren2D = vtk.vtkRenderer()
> 
> ren2D.AddActor(imageActor2D)
> 
> win2D = vtk.vtkRenderWindow()
> 
> win2D.AddRenderer(ren2D)
> 
> win2D.Render()
> 
>  
> 
> ##################################################
> 
> to work with this you will have set PYTHONPATH with InsightToolkit 
> ,Application and VTK
> 
> Bruno Cassaro
> 
>  
> 
>  
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list