33 import InsightToolkit
as itk
34 import ConnectVTKITKPython
as CVIPy
38 reader = vtk.vtkPNGReader()
39 reader.SetFileName(
"../../Testing/Data/Input/cthead1.png")
42 lum = vtk.vtkImageLuminance()
43 lum.SetInput(reader.GetOutput())
46 imageCast = vtk.vtkImageCast()
47 imageCast.SetOutputScalarTypeToFloat()
48 imageCast.SetInput(lum.GetOutput())
51 vtkExporter = vtk.vtkImageExport()
52 vtkExporter.SetInput(imageCast.GetOutput())
56 itkImporter = itk.itkVTKImageImportF2_New()
60 CVIPy.ConnectVTKToITKF2(vtkExporter, itkImporter.GetPointer())
63 canny = itk.itkCannyEdgeDetectionImageFilterF2F2_New()
64 rescaler = itk.itkRescaleIntensityImageFilterF2US2_New()
65 canny.SetInput(itkImporter.GetOutput())
66 rescaler.SetInput(canny.GetOutput())
67 rescaler.SetOutputMinimum(0)
68 rescaler.SetOutputMaximum(65535)
72 print "%.0f%s done..." % (canny.GetProgress() * 100.0,
'%')
74 pc = itk.itkPyCommand_New()
75 pc.SetCommandCallable(progressEvent)
76 canny.AddObserver(itk.itkProgressEvent(), pc.GetPointer())
80 itkExporter = itk.itkVTKImageExportUS2_New()
81 itkExporter.SetInput(rescaler.GetOutput())
84 vtkImporter = vtk.vtkImageImport()
87 CVIPy.ConnectITKUS2ToVTK(itkExporter.GetPointer(), vtkImporter)
90 writer = vtk.vtkPNGWriter()
91 writer.SetFileName(
'./testout.png')
92 writer.SetInput(vtkImporter.GetOutput())
105 print "\n\nWrote testout.png to current directory."