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)
73 print(f
"{canny.GetProgress() * 100.0:.0f}{'%'} done...")
76 pc = itk.itkPyCommand_New()
77 pc.SetCommandCallable(progressEvent)
78 canny.AddObserver(itk.itkProgressEvent(), pc.GetPointer())
82 itkExporter = itk.itkVTKImageExportUS2_New()
83 itkExporter.SetInput(rescaler.GetOutput())
86 vtkImporter = vtk.vtkImageImport()
89 CVIPy.ConnectITKUS2ToVTK(itkExporter, vtkImporter)
92 writer = vtk.vtkPNGWriter()
93 writer.SetFileName(
"./testout.png")
94 writer.SetInput(vtkImporter.GetOutput())
107 print(
"\n\nWrote testout.png to current directory.")