[Insight-users] connecting Itk and Vtk in python
Bruno Cassaro
bcdalava at cenpra.gov.br
Fri Feb 25 14:25:12 EST 2005
>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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050225/67651bc9/attachment.html
More information about the Insight-users
mailing list