File: CannyEdgeDetectionImageFilterConnectVTKITK.tcl

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 80,672 kB
  • ctags: 85,253
  • sloc: cpp: 458,133; ansic: 196,222; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 428; csh: 220; perl: 193; xml: 20
file content (82 lines) | stat: -rw-r--r-- 3,112 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# This file demonstrates how to connect VTK and ITK pipelines together
# in scripted languages with the new ConnectVTKITK wrapping functionality.
# Data is loaded in with VTK, processed with ITK and written back to disc
# with VTK. 
#
# For this to work, you have to build InsightApplications/ConnectVTKITK
# as well.
#
# -- Charl P. Botha <cpbotha AT ieee.org>
# -- Modified to Tcl version by H.J.Huisman (25 March 2004)
# Execute this script by:
#      tclsh CannyEdgeDetectionImageFilterConnectVTKITK.tcl
# You must set the environment variable TCLLIB_DIR to where the tcl
# libraries are on your system. For example:
#      export  TCLLIB_DIR="/data/usr/itk16/lib/InsightToolkit /data/usr/vtk422/lib/vtk /data/prog/InsightApplications-1.6.0/ConnectVTKITK/"
#
puts "Loading VTK package [package require vtk]"
puts "Loading InsightToolkit [package require InsightToolkit]"
puts "Loading ConnectVTKITK [package require ConnectVTKITK]"
wm withdraw .

# VTK will read the PNG image for us
vtkPNGReader reader
reader SetFileName "../../Testing/Data/Input/cthead1.png"

# it has to be a single component, itk::VTKImageImport doesn't support more
vtkImageLuminance lum
lum SetInput [reader GetOutput]

# let's cast the output to float
vtkImageCast imageCast
imageCast SetOutputScalarTypeToFloat
imageCast SetInput [lum GetOutput]

# the end-point of this VTK pipeline segment is a vtkImageExport
vtkImageExport vtkExporter
vtkExporter SetInput [imageCast GetOutput]

# it connects to the itk::VTKImageImport at the beginning of
# the subsequent ITK pipeline; two-dimensional float type
set itkImporter [itkVTKImageImportF2_New]

# Call the magic function that connects the two.  This will only be 
# available if you built ITK with ITK_CSWIG_CONNECTVTKITK set to ON.
ConnectVTKToITKF2 vtkExporter [$itkImporter GetPointer]

# perform a canny edge detection and rescale the output
set canny [itkCannyEdgeDetectionImageFilterF2F2_New]
set rescaler [itkRescaleIntensityImageFilterF2US2_New]
$canny SetInput [$itkImporter GetOutput]
$rescaler SetInput [$canny GetOutput]
$rescaler SetOutputMinimum 0
$rescaler SetOutputMaximum 65535

# this will form the end-point of the ITK pipeline segment
set itkExporter [itkVTKImageExportUS2_New]
$itkExporter SetInput [$rescaler GetOutput]

# the vtkImageImport will bring our data back into VTK-land
vtkImageImport vtkImporter
# do the magic connection call (once again: only available if you built
# ITK with ITK_CSWIG_CONNECTVTKITK set to ON)
ConnectITKUS2ToVTK [$itkExporter GetPointer] vtkImporter

# finally write the image to disk using VTK
vtkPNGWriter writer
writer SetFileName "testout.png"
writer SetInput [vtkImporter GetOutput]

# before we call Write() on the writer, it is prudent to give
# our ITK pipeline an Update() call... this is not necessary
# for normal error-less operation, but ensures that exceptions
# thrown by ITK get through to us in the case of an error;
# This is because the VTK wrapping system does not support
# C++ exceptions.
$rescaler Update

# write the file to disk...
writer Write

puts "\n\nWrote testout.png to current directory."
exit