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