Oct 16, 2015
The ITK Software Guide
Third Edition
Updated for ITK version 4.5
Hans J. Johnson, Matt McCormick, Luis Ibanez, and
the Insight Software Consortium
December 17, 2013
http://itk.org
Email: [email protected]
The purpose of computing is Insight, not numbers.
Richard Hamming
ABSTRACT
The Insight Toolkit (ITK) is an open-source software toolkit for performing registration and
segmentation. Segmentation is the process of identifying and classifying data found in a digi-
tally sampled representation. Typically the sampled representation is an image acquired from
such medical instrumentation as CT or MRI scanners. Registration is the task of aligning or de-
veloping correspondences between data. For example, in the medical environment, a CT scan
may be aligned with a MRI scan in order to combine the information contained in both.
ITK is a cross-platform software. It uses a build environment known as CMake to manage
platform-specific project generation and compilation process in a platform-independent way.
ITK is implemented in C++. ITKs implementation style employs generic programming, which
involves the use of templates to generate, at compile-time, code that can be applied generically
to any class or data-type that supports the operations used by the template. The use of C++
templating means that the code is highly efficient and many issues are discovered at compile-
time, rather than at run-time during program execution. It also means that many of ITKs
algorithms can be applied to arbitrary spatial dimensions and pixel types.
An automated wrapping system integrated with ITK generates an interface between C++ and a
high-level programming language Python. This enables rapid prototyping and faster exploration
of ideas by shortening the edit-compile-execute cycle. In addition to automated wrapping, the
SimpleITK project provides a streamlined interface to ITK that is available for C++, Python,
Java, CSharp, R, Tcl and Ruby.
Developers from around the world can use, debug, maintain, and extend the software because
ITK is an open-source project. ITK uses a model of software development known as Extreme
Programming. Extreme Programming collapses the usual software development methodology
into a simultaneous iterative process of design-implement-test-release. The key features of
Extreme Programming are communication and testing. Communication among the members
of the ITK community is what helps manage the rapid evolution of the software. Testing is
what keeps the software stable. An extensive testing process supported by the system known
as CDash measures the quality of ITK code on a daily basis. The ITK Testing Dashboard is
updated continuously, reflecting the quality of the code at any moment.
This book is a guide to developing software with ITK. It covers building and installation, ar-
chitecture and design, image analysis theory and its applications, as well as the process of
contributing to the ITK community.
The most recent version of this document is available online at
http://itk.org/ItkSoftwareGuide.pdf.
CONTRIBUTORS
The Insight Toolkit (ITK) has been created by the efforts of many talented individuals and
prestigious organizations. It is also due in great part to the vision of the program established by
Dr. Terry Yoo and Dr. Michael Ackerman at the National Library of Medicine.
This book lists a few of these contributors in the following paragraphs. Not all developers of
ITK are credited here, so please visit the Web pages at http://www.itk.org/HTML/About.htm
for the names of additional contributors, as well as checking the GIT source logs for code
contributions.
The following is a brief description of the contributors to this software guide and their contri-
butions.
Luis Ibanez is principal author of this text. He assisted in the design and layout of the text,
implemented the bulk of the LATEX and CMake build process, and was responsible for the bulk
of the content. He also developed most of the example code found in the Insight/Examples
directory.
Will Schroeder helped design and establish the organization of this text and the
Insight/Examples directory. He is principal content editor, and has authored several chap-
ters.
Lydia Ng authored the description for the registration framework and its components, the sec-
tion on the multiresolution framework, and the section on deformable registration methods.
She also edited the section on the resampling image filter and the sections on various level set
segmentation algorithms.
Joshua Cates authored the iterators chapter and the text and examples describing watershed
segmentation. He also co-authored the level-set segmentation material.
Jisung Kim authored the chapter on the statistics framework.
Julien Jomier contributed the chapter on spatial objects and examples on model-based regis-
tration using spatial objects.
vi
Karthik Krishnan reconfigured the process for automatically generating images from all the
examples. Added a large number of new examples and updated the Filtering and Segmentation
chapters for the second edition.
Stephen Aylward contributed material describing spatial objects and their application.
Tessa Sundaram contributed the section on deformable registration using the finite element
method.
YinPeng Jin contributed the examples on hybrid segmentation methods.
Celina Imielinska authored the section describing the principles of hybrid segmentation meth-
ods.
Mark Foskey contributed the examples on the AutomaticTopologyMeshSource class.
MathieuMalaterre contributed the entire section on the description and use of DICOM readers
and writers based on the GDCM library. He also contributed an example on the use of the
VTKImageIO class.
Gavin Baker contributed the section on how to write composite filters. Also known as minip-
ipeline filters.
Since the software guide is generated in part from the ITK source code itself, many ITK de-
velopers have been involved in updating and extending the ITK documentation. These in-
clude David Doria, Bradley Lowecamp,Mark Foskey, Gaetan Lehmann, Andreas Schuh,
Tom Vercauteren, Cory Quammen, Daniel Blezek, Paul Hughett,Matt McCormick, Josh
Cates, Arnaud Gelas, Jim Miller, Brad King, Gabe Hart,Hans Johnson.
Hans Johnson,KentWilliams,Constantine Zakkaroff,Xiaoxiao Liu andMattMcCormick
updated the documentation for the initial ITK Version 4 release.
CONTENTS
I Introduction 1
1 Welcome 3
1.1 Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 How to Learn ITK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Software Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.3.1 Obtaining the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 Downloading ITK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4.1 Downloading Packaged Releases . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4.2 Downloading using Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4.3 Join the Mailing List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4.4 Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4.5 Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4.6 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5 The Insight Community and Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.6 A Brief History of ITK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Installation 11
2.1 Configuring ITK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.1 Preparing CMake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.2 Configuring ITK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Getting Started With ITK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
viii CONTENTS
2.2.1 Hello World ! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 System Overview 17
3.1 System Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Essential System Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2.1 Generic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2.2 Include Files and Class Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2.3 Object Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.2.4 Smart Pointers and Memory Management . . . . . . . . . . . . . . . . . . . . . 20
3.2.5 Error Handling and Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2.6 Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2.7 Multi-Threading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3 Numerics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4 Data Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5 Data Processing Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.6 Spatial Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.7 Wrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
II Design and Functionality 31
4 DataRepresentation 33
4.1 Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.1.1 Creating an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.1.2 Reading an Image from a File . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.1.3 Accessing Pixel Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.1.4 Defining Origin and Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1.5 RGB Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.1.6 Vector Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.1.7 Importing Image Data from a Buffer . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2 PointSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.2.1 Creating a PointSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.2.2 Getting Access to Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.2.3 Getting Access to Data in Points . . . . . . . . . . . . . . . . . . . . . . . . . . 50
CONTENTS ix
4.2.4 RGB as Pixel Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.2.5 Vectors as Pixel Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.2.6 Normals as Pixel Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.3 Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.3.1 Creating a Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.3.2 Inserting Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.3.3 Managing Data in Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.3.4 Customizing the Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.3.5 Topology and the K-Complex . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.3.6 Representing a PolyLine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.3.7 Simplifying Mesh Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4.3.8 Iterating Through Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.3.9 Visiting Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.3.10 More on Visiting Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.4 Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.4.1 Creating a PolyLineParametricPath . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.5 Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5 Spatial Objects 95
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
5.2 Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
5.3 SpatialObject Tree Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
5.4 Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5.5 Types of Spatial Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.5.1 ArrowSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.5.2 BlobSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.5.3 CylinderSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.5.4 EllipseSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.5.5 GaussianSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
5.5.6 GroupSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
5.5.7 ImageSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
5.5.8 ImageMaskSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
x CONTENTS
5.5.9 LandmarkSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.5.10 LineSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5.5.11 MeshSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.5.12 SurfaceSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.5.13 TubeSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
VesselTubeSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
DTITubeSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.6 SceneSpatialObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.7 Read/Write SpatialObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
5.8 Statistics Computation via SpatialObjects . . . . . . . . . . . . . . . . . . . . . . . . . . 126
6 Filtering 129
6.1 Thresholding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
6.1.1 Binary Thresholding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
6.1.2 General Thresholding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
6.2 Edge Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
6.2.1 Canny Edge Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
6.3 Casting and Intensity Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
6.3.1 Linear Mappings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
6.3.2 Non Linear Mappings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.4 Gradients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
6.4.1 Gradient Magnitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
6.4.2 Gradient Magnitude With Smoothing . . . . . . . . . . . . . . . . . . . . . . . 143
6.4.3 Derivative Without Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
6.5 Second Order Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
6.5.1 Second Order Recursive Gaussian . . . . . . . . . . . . . . . . . . . . . . . . . 146
6.5.2 Laplacian Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Laplacian Filter Finite Difference . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Laplacian Filter Recursive Gaussian . . . . . . . . . . . . . . . . . . . . . . . . . 148
6.6 Neighborhood Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
6.6.1 Mean Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
6.6.2 Median Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
CONTENTS xi
6.6.3 Mathematical Morphology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Binary Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Grayscale Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
6.6.4 Voting Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Binary Median Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Hole Filling Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Iterative Hole Filling Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
6.7 Smoothing Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
6.7.1 Blurring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Discrete Gaussian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Binomial Blurring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Recursive Gaussian IIR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
6.7.2 Local Blurring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Gaussian Blur Image Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
6.7.3 Edge Preserving Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Introduction to Anisotropic Diffusion . . . . . . . . . . . . . . . . . . . . . . . . 178
Gradient Anisotropic Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Curvature Anisotropic Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Curvature Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
MinMaxCurvature Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Bilateral Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
6.7.4 Edge Preserving Smoothing in Vector Images . . . . . . . . . . . . . . . . . . . 191
Vector Gradient Anisotropic Diffusion . . . . . . . . . . . . . . . . . . . . . . . . 192
Vector Curvature Anisotropic Diffusion . . . . . . . . . . . . . . . . . . . . . . . 193
6.7.5 Edge Preserving Smoothing in Color Images . . . . . . . . . . . . . . . . . . . 195
Gradient Anisotropic Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Curvature Anisotropic Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
6.8 Distance Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
6.9 Geometric Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
6.9.1 Filters You Should be Afraid to Use . . . . . . . . . . . . . . . . . . . . . . . . 203
6.9.2 Change Information Image Filter . . . . . . . . . . . . . . . . . . . . . . . . . . 203
6.9.3 Flip Image Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
xii CONTENTS
6.9.4 Resample Image Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Importance of Spacing and Origin . . . . . . . . . . . . . . . . . . . . . . . . . . 211
A Complete Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Rotating an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Rotating and Scaling an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Resampling using a deformation field . . . . . . . . . . . . . . . . . . . . . . . . 224
Subsampling and image in the same space . . . . . . . . . . . . . . . . . . . . . . 225
Resampling an Anisotropic image to make it Isotropic . . . . . . . . . . . . . . . 228
6.10 Frequency Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
6.10.1 Computing a Fast Fourier Transform (FFT) . . . . . . . . . . . . . . . . . . . . 233
6.10.2 Filtering on the Frequency Domain . . . . . . . . . . . . . . . . . . . . . . . . . 236
6.11 Extracting Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
6.11.1 Surface extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
7 Reading and Writing Images 243
7.1 Basic Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
7.2 Pluggable Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
7.3 Using ImageIO Classes Explicitly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
7.4 Reading and Writing RGB Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
7.5 Reading, Casting and Writing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
7.6 Extracting Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
7.7 Extracting Slices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
7.8 Reading and Writing Vector Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
7.8.1 The Minimal Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
7.8.2 Producing and Writing Covariant Images . . . . . . . . . . . . . . . . . . . . . 258
7.8.3 Reading Covariant Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
7.9 Reading and Writing Complex Images . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
7.10 Extracting Components from Vector Images . . . . . . . . . . . . . . . . . . . . . . . . 263
7.11 Reading and Writing Image Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
7.11.1 Reading Image Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
7.11.2 Writing Image Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
CONTENTS xiii
7.11.3 Reading and Writing Series of RGB Images . . . . . . . . . . . . . . . . . . . . 269
7.12 Reading and Writing DICOM Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
7.12.1 Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
7.12.2 Reading and Writing a 2D Image . . . . . . . . . . . . . . . . . . . . . . . . . . 272
7.12.3 Reading a 2D DICOM Series and Writing a Volume . . . . . . . . . . . . . . . . 276
7.12.4 Reading a 2D DICOM Series and Writing a 2D DICOM Series . . . . . . . . . . 279
7.12.5 Printing DICOM Tags From One Slice . . . . . . . . . . . . . . . . . . . . . . . 282
7.12.6 Printing DICOM Tags From a Series . . . . . . . . . . . . . . . . . . . . . . . . 286
7.12.7 Changing a DICOM Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
8 Registration 291
8.1 Registration Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
8.2 Hello World Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
8.3 Features of the Registration Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
8.3.1 Direction of the Transform Mapping . . . . . . . . . . . . . . . . . . . . . . . . 302
8.3.2 Registration is done in physical space . . . . . . . . . . . . . . . . . . . . . . . 303
8.4 Monitoring Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
8.5 Multi-Modality Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
8.5.1 Viola-Wells Mutual Information . . . . . . . . . . . . . . . . . . . . . . . . . . 308
8.5.2 Mattes Mutual Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
8.6 Centered Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
8.6.1 Rigid Registration in 2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
8.6.2 Initializing with Image Moments . . . . . . . . . . . . . . . . . . . . . . . . . . 325
8.6.3 Similarity Transform in 2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
8.6.4 Rigid Transform in 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
8.6.5 Centered Affine Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
8.7 Multi-Resolution Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
8.7.1 Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
8.7.2 Parameter Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
8.8 Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
8.8.1 Geometrical Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
8.8.2 Transform General Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
xiv CONTENTS
8.8.3 Identity Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
8.8.4 Translation Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
8.8.5 Scale Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
8.8.6 Scale Logarithmic Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
8.8.7 Euler2DTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
8.8.8 CenteredRigid2DTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
8.8.9 Similarity2DTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
8.8.10 QuaternionRigidTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
8.8.11 VersorTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
8.8.12 VersorRigid3DTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
8.8.13 Euler3DTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
8.8.14 Similarity3DTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
8.8.15 Rigid3DPerspectiveTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
8.8.16 AffineTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
8.8.17 BSplineDeformableTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
8.8.18 KernelTransforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
8.9 Interpolators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
8.9.1 Nearest Neighbor Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
8.9.2 Linear Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
8.9.3 B-Spline Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
8.9.4 Windowed Sinc Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
8.10 Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
8.10.1 Mean Squares Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Exploring a Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
8.10.2 Normalized Correlation Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
8.10.3 Mean Reciprocal Square Differences . . . . . . . . . . . . . . . . . . . . . . . . 389
8.10.4 Mutual Information Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Parzen Windowing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Viola and Wells Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Mattes et al. Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
8.10.5 Kullback-Leibler distance metric . . . . . . . . . . . . . . . . . . . . . . . . . . 392
8.10.6 Normalized Mutual Information Metric . . . . . . . . . . . . . . . . . . . . . . 393
CONTENTS xv
8.10.7 Mean Squares Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
8.10.8 Correlation Coefficient Histogram . . . . . . . . . . . . . . . . . . . . . . . . . 394
8.10.9 Cardinality Match Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
8.10.10 Kappa Statistics Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
8.10.11 Gradient Difference Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
8.11 Optimizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
8.11.1 Registration using Match Cardinality metric . . . . . . . . . . . . . . . . . . . . 399
8.11.2 Registration using the One plus One Evolutionary Optimizer . . . . . . . . . . . 400
8.11.3 Registration using masks constructed with Spatial objects . . . . . . . . . . . . . 401
8.11.4 Rigid registrations incorporating prior knowledge . . . . . . . . . . . . . . . . . 403
8.12 Image Pyramids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
8.13 Deformable Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
8.13.1 FEM-Based Image Registration . . . . . . . . . . . . . . . . . . . . . . . . . . 406
8.13.2 BSplines Image Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
8.13.3 Level Set Motion for Deformable Registration . . . . . . . . . . . . . . . . . . . 413
8.13.4 BSplines Multi-Grid Image Registration . . . . . . . . . . . . . . . . . . . . . . 416
8.13.5 BSplines Multi-Grid Image Registration . . . . . . . . . . . . . . . . . . . . . . 418
8.13.6 BSplines Image Registration in 3D . . . . . . . . . . . . . . . . . . . . . . . . . 419
8.13.7 Image Warping with Kernel Splines . . . . . . . . . . . . . . . . . . . . . . . . 422
8.13.8 Image Warping with BSplines . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
8.14 Demons Deformable Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
8.14.1 Asymmetrical Demons Deformable Registration . . . . . . . . . . . . . . . . . . 428
8.14.2 Symmetrical Demons Deformable Registration . . . . . . . . . . . . . . . . . . 431
8.15 Visualizing Deformation fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
8.15.1 Visualizing 2D deformation fields . . . . . . . . . . . . . . . . . . . . . . . . . 435
8.15.2 Visualizing 3D deformation fields . . . . . . . . . . . . . . . . . . . . . . . . . 436
8.16 Model Based Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
8.17 Point Set Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
8.17.1 Point Set Registration in 2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
8.17.2 Point Set Registration in 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
8.17.3 Point Set to Distance Map Metric . . . . . . . . . . . . . . . . . . . . . . . . . 456
8.18 Registration Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
xvi CONTENTS
8.18.1 Too many samples outside moving image buffer . . . . . . . . . . . . . . . . . . 458
8.18.2 General heuristics for parameter fine-tunning . . . . . . . . . . . . . . . . . . . 459
9 Segmentation 461
9.1 Region Growing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
9.1.1 Connected Threshold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
9.1.2 Otsu Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
9.1.3 Neighborhood Connected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
9.1.4 Confidence Connected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Application of the Confidence Connected filter on the Brain Web Data . . . . . . . 474
9.1.5 Isolated Connected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
9.1.6 Confidence Connected in Vector Images . . . . . . . . . . . . . . . . . . . . . . 477
9.2 Segmentation Based on Watersheds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
9.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
9.2.2 Using the ITK Watershed Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
9.3 Level Set Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
9.3.1 Fast Marching Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
9.3.2 Shape Detection Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
9.3.3 Geodesic Active Contours Segmentation . . . . . . . . . . . . . . . . . . . . . . 504
9.3.4 Threshold Level Set Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . 507
9.3.5 Canny-Edge Level Set Segmentation . . . . . . . . . . . . . . . . . . . . . . . . 511
9.3.6 Laplacian Level Set Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . 516
9.3.7 Geodesic Active Contours Segmentation With Shape Guidance . . . . . . . . . . 519
9.4 Feature Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
9.4.1 Hough Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
Line Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
Circle Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
10 Statistics 539
10.1 Data Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
10.1.1 Sample Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
10.1.2 Sample Adaptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
ImageToListSampleAdaptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
CONTENTS xvii
PointSetToListSampleAdaptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
10.1.3 Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
10.1.4 Subsample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
10.1.5 MembershipSample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
10.1.6 MembershipSampleGenerator . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
10.1.7 K-d Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
10.2 Algorithms and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
10.2.1 Sample Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Mean and Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Weighted Mean and Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
10.2.2 Sample Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
SampleToHistogramFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
NeighborhoodSampler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
10.2.3 Sample Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
10.2.4 Probability Density Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
Gaussian Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
10.2.5 Distance Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
Euclidean Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
10.2.6 Decision Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
Maximum Decision Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
Minimum Decision Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Maximum Ratio Decision Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
10.2.7 Random Variable Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Normal (Gaussian) Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
10.3 Statistics applied to Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
10.3.1 Image Histograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Scalar Image Histogram with Adaptor . . . . . . . . . . . . . . . . . . . . . . . . 580
Scalar Image Histogram with Generator . . . . . . . . . . . . . . . . . . . . . . . 582
Color Image Histogram with Generator . . . . . . . . . . . . . . . . . . . . . . . 584
Color Image Histogram Writing . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
10.3.2 Image Information Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
Computing Image Entropy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
xviii CONTENTS
Computing Images Mutual Information . . . . . . . . . . . . . . . . . . . . . . . 594
10.4 Classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
10.4.1 k-d Tree Based k-Means Clustering . . . . . . . . . . . . . . . . . . . . . . . . 600
10.4.2 K-Means Classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
10.4.3 Bayesian Plug-In Classifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
10.4.4 Expectation Maximization Mixture Model Estimation . . . . . . . . . . . . . . . 615
10.4.5 Classification using Markov Random Field . . . . . . . . . . . . . . . . . . . . 619
III ITK Community Participation 625
11 Iterators 627
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
11.2 Programming Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
11.2.1 Creating Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
11.2.2 Moving Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
11.2.3 Accessing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
11.2.4 Iteration Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
11.3 Image Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
11.3.1 ImageRegionIterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
11.3.2 ImageRegionIteratorWithIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
11.3.3 ImageLinearIteratorWithIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
11.3.4 ImageSliceIteratorWithIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
11.3.5 ImageRandomConstIteratorWithIndex . . . . . . . . . . . . . . . . . . . . . . . 643
11.4 Neighborhood Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
11.4.1 NeighborhoodIterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Basic neighborhood techniques: edge detection . . . . . . . . . . . . . . . . . . . 651
Convolution filtering: Sobel operator . . . . . . . . . . . . . . . . . . . . . . . . 653
Optimizing iteration speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
Separable convolution: Gaussian filtering . . . . . . . . . . . . . . . . . . . . . . 657
Slicing the neighborhood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
Random access iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660
11.4.2 ShapedNeighborhoodIterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
CONTENTS xix
Shaped neighborhoods: morphological operations . . . . . . . . . . . . . . . . . . 663
12 Image Adaptors 667
12.1 Image Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668
12.2 Adapting RGB Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670
12.3 Adapting Vector Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672
12.4 Adaptors for Simple Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674
12.5 Adaptors and Writers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
13 How To Write A Filter 679
13.1 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
13.2 Overview of Filter Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
13.3 Streaming Large Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
13.3.1 Overview of Pipeline Execution . . . . . . . . . . . . . . . . . . . . . . . . . . 682
13.3.2 Details of Pipeline Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684
UpdateOutputInformation() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684
PropagateRequestedRegion() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685
UpdateOutputData() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
13.4 Threaded Filter Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
13.5 Filter Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687
13.5.1 Optional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688
13.5.2 Useful Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688
13.6 How To Write A Composite Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
13.6.1 Implementing a Composite Filter . . . . . . . . . . . . . . . . . . . . . . . . . . 689
13.6.2 A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
14 Software Process 695
14.1 Git Source Code Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
14.2 CDash Regression Testing System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696
14.3 Working The Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698
14.4 The Effectiveness of the Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698
Appendices 709
xx CONTENTS
Licenses 711
.1 Insight Toolkit License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
.2 Third Party Licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716
.2.1 DICOM Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716
.2.2 Double Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717
.2.3 Expat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717
.2.4 GDCM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718
.2.5 GIFTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
.2.6 HDF5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
.2.7 JPEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
.2.8 KWSys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
.2.9 MetaIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724
.2.10 Netlibs SLATEC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724
.2.11 NIFTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
.2.12 NrrdIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
.2.13 OpenJPEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
.2.14 PNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
.2.15 TIFF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
.2.16 VNL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
.2.17 ZLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
LIST OF FIGURES
2.1 CMake user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.1 ITK Image Geometrical Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.2 PointSet with Vectors as PixelType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.1 SpatialObject Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5.2 SpatialObject Transform Computations . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
6.1 BinaryThresholdImageFilter transfer function . . . . . . . . . . . . . . . . . . . . . . . . 130
6.2 BinaryThresholdImageFilter output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
6.3 ThresholdImageFilter using the threshold-below mode. . . . . . . . . . . . . . . . . . . . 132
6.4 ThresholdImageFilter using the threshold-above mode . . . . . . . . . . . . . . . . . . . 132
6.5 ThresholdImageFilter using the threshold-outside mode . . . . . . . . . . . . . . . . . . . 132
6.6 Sigmoid Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
6.7 Effect of the Sigmoid filter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
6.8 GradientMagnitudeImageFilter output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
6.9 GradientMagnitudeRecursiveGaussianImageFilter output . . . . . . . . . . . . . . . . . . 145
6.10 Effect of the Derivative filter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
6.11 Output of the LaplacianRecursiveGaussianImageFilter. . . . . . . . . . . . . . . . . . . . 151
6.12 Output of the LaplacianRecursiveGaussianImageFilter. . . . . . . . . . . . . . . . . . . . 153
6.13 Effect of the MedianImageFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
6.14 Effect of the Median filter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
xxii List of Figures
6.15 Effect of erosion and dilation in a binary image. . . . . . . . . . . . . . . . . . . . . . . . 160
6.16 Effect of erosion and dilation in a grayscale image. . . . . . . . . . . . . . . . . . . . . . 162
6.17 Effect of the BinaryMedian filter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
6.18 Effect of many iterations on the BinaryMedian filter. . . . . . . . . . . . . . . . . . . . . 165
6.19 Effect of the VotingBinaryHoleFilling filter. . . . . . . . . . . . . . . . . . . . . . . . . . 168
6.20 Effect of the VotingBinaryIterativeHoleFilling filter. . . . . . . . . . . . . . . . . . . . . . 170
6.21 DiscreteGaussianImageFilter Gaussian diagram. . . . . . . . . . . . . . . . . . . . . . . . 171
6.22 DiscreteGaussianImageFilter output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
6.23 BinomialBlurImageFilter output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
6.24 Output of the SmoothingRecursiveGaussianImageFilter. . . . . . . . . . . . . . . . . . . 177
6.25 GradientAnisotropicDiffusionImageFilter output . . . . . . . . . . . . . . . . . . . . . . 181
6.26 CurvatureAnisotropicDiffusionImageFilter output . . . . . . . . . . . . . . . . . . . . . . 183
6.27 CurvatureFlowImageFilter output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
6.28 MinMaxCurvatureFlow computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
6.29 MinMaxCurvatureFlowImageFilter output . . . . . . . . . . . . . . . . . . . . . . . . . . 188
6.30 BilateralImageFilter output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
6.31 VectorGradientAnisotropicDiffusionImageFilter output . . . . . . . . . . . . . . . . . . . 193
6.32 VectorCurvatureAnisotropicDiffusionImageFilter output . . . . . . . . . . . . . . . . . . 195
6.33 VectorGradientAnisotropicDiffusionImageFilter on RGB . . . . . . . . . . . . . . . . . . 197
6.34 VectorCurvatureAnisotropicDiffusionImageFilter output on RGB . . . . . . . . . . . . . . 199
6.35 Various Anisotropic Diffusion compared . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
6.36 DanielssonDistanceMapImageFilter output . . . . . . . . . . . . . . . . . . . . . . . . . 201
6.37 SignedDanielssonDistanceMapImageFilter output . . . . . . . . . . . . . . . . . . . . . . 203
6.38 Effect of the MedianImageFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
6.39 Effect of the Resample filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
6.40 Analysis of resampling in common coordinate system . . . . . . . . . . . . . . . . . . . . 208
6.41 ResampleImageFilter with a translation by (30,50) . . . . . . . . . . . . . . . . . . . 2096.42 ResampleImageFilter. Analysis of a translation by (30,50) . . . . . . . . . . . . . . . 2106.43 ResampleImageFilter highlighting image borders . . . . . . . . . . . . . . . . . . . . . . 210
6.44 ResampleImageFilter selecting the origin of the output image . . . . . . . . . . . . . . . . 212
6.45 ResampleImageFilter selecting the origin of the output image . . . . . . . . . . . . . . . . 213
6.46 ResampleImageFilter selecting the origin of the input image . . . . . . . . . . . . . . . . 214
List of Figures xxiii
6.47 ResampleImageFilter use of naive viewers . . . . . . . . . . . . . . . . . . . . . . . . . . 215
6.48 ResampleImageFilter and output image spacing . . . . . . . . . . . . . . . . . . . . . . . 215
6.49 ResampleImageFilter naive viewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
6.50 ResampleImageFilter with non-unit spacing . . . . . . . . . . . . . . . . . . . . . . . . . 217
6.51 Effect of a rotation on the resampling filter. . . . . . . . . . . . . . . . . . . . . . . . . . 218
6.52 Input and output image placed in a common reference system . . . . . . . . . . . . . . . . 218
6.53 Effect of the Resample filter rotating an image . . . . . . . . . . . . . . . . . . . . . . . . 222
6.54 Effect of the Resample filter rotating and scaling an image . . . . . . . . . . . . . . . . . 224
7.1 Collaboration diagram of the ImageIO classes . . . . . . . . . . . . . . . . . . . . . . . . 245
7.2 Use cases of ImageIO factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
7.3 Class diagram of ImageIO factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
8.1 Image Registration Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
8.2 Registration Framework Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
8.3 Fixed and Moving images in registration framework . . . . . . . . . . . . . . . . . . . . . 296
8.4 HelloWorld registration output images . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
8.5 Pipeline structure of the registration example . . . . . . . . . . . . . . . . . . . . . . . . 298
8.6 Trace of translations and metrics during registration . . . . . . . . . . . . . . . . . . . . . 300
8.7 Registration Coordinate Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
8.8 Command/Observer and the Registration Framework . . . . . . . . . . . . . . . . . . . . 306
8.9 Multi-Modality Registration Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
8.10 Multi-Modality Registration outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
8.11 Multi-Modality Registration plot of translations . . . . . . . . . . . . . . . . . . . . . . . 313
8.12 Multi-Modality Registration plot of metrics . . . . . . . . . . . . . . . . . . . . . . . . . 313
8.13 MattesMutualInformationImageToImageMetric output images . . . . . . . . . . . . . . . 316
8.14 MattesMutualInformationImageToImageMetric output plots . . . . . . . . . . . . . . . . 317
8.15 MattesMutualInformationImageToImageMetric number of bins . . . . . . . . . . . . . . . 318
8.16 Rigid2D Registration input images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
8.17 Rigid2D Registration output images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
8.18 Rigid2D Registration output plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
8.19 Rigid2D Registration input images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
8.20 Rigid2D Registration output images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
xxiv List of Figures
8.21 Rigid2D Registration output plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
8.22 Effect of changing the center of rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
8.23 CenteredTransformInitializer input images . . . . . . . . . . . . . . . . . . . . . . . . . . 332
8.24 CenteredTransformInitializer output images . . . . . . . . . . . . . . . . . . . . . . . . . 332
8.25 CenteredTransformInitializer output plots . . . . . . . . . . . . . . . . . . . . . . . . . . 333
8.26 Fixed and Moving image registered with CenteredSimilarity2DTransform . . . . . . . . . 336
8.27 Output of the CenteredSimilarity2DTransform registration . . . . . . . . . . . . . . . . . 336
8.28 CenteredSimilarity2DTransform registration plots . . . . . . . . . . . . . . . . . . . . . . 337
8.29 CenteredTransformInitializer input images . . . . . . . . . . . . . . . . . . . . . . . . . . 341
8.30 CenteredTransformInitializer output images . . . . . . . . . . . . . . . . . . . . . . . . . 341
8.31 CenteredTransformInitializer output plots . . . . . . . . . . . . . . . . . . . . . . . . . . 342
8.32 AffineTransform registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
8.33 AffineTransform output images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
8.34 AffineTransform output plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
8.35 Multi-Resolution Registration Components . . . . . . . . . . . . . . . . . . . . . . . . . 348
8.36 Conceptual representation of Multi-Resolution registration . . . . . . . . . . . . . . . . . 349
8.37 Multi-Resolution registration input images . . . . . . . . . . . . . . . . . . . . . . . . . . 354
8.38 Multi-Resolution registration output images . . . . . . . . . . . . . . . . . . . . . . . . . 355
8.39 Multi-Resolution Registration Input Images . . . . . . . . . . . . . . . . . . . . . . . . . 358
8.40 Multi-Resolution Registration output plots . . . . . . . . . . . . . . . . . . . . . . . . . . 359
8.41 Geometrical representation objects in ITK . . . . . . . . . . . . . . . . . . . . . . . . . . 360
8.42 Mapping moving image to fixed image in Registration . . . . . . . . . . . . . . . . . . . 380
8.43 Need for interpolation in Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
8.44 BSpline Interpolation Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
8.45 Mean Squares Metric Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
8.46 Parzen Windowing in Mutual Information . . . . . . . . . . . . . . . . . . . . . . . . . . 391
8.47 Class diagram of the Optimizer hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . 397
8.48 FEM-based deformable registration results . . . . . . . . . . . . . . . . . . . . . . . . . . 406
8.49 Demons deformable registration output . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
8.50 Demons deformable registration output . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
8.51 Demons deformable registration output . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
8.52 Deformation field magnitudes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
List of Figures xxv
8.53 Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
8.54 Visualized Def field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
8.55 Visualized Def field4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
8.56 Deformation field output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
8.57 Difference image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
8.58 Model to Image Registration Framework Components . . . . . . . . . . . . . . . . . . . . 441
8.59 Model to Image Registration Framework Concept . . . . . . . . . . . . . . . . . . . . . . 442
8.60 SpatialObject to Image Registration results . . . . . . . . . . . . . . . . . . . . . . . . . 451
9.1 ConnectedThreshold segmentation results . . . . . . . . . . . . . . . . . . . . . . . . . . 464
9.2 OtsuThresholdImageFilter output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
9.3 NeighborhoodConnected segmentation results . . . . . . . . . . . . . . . . . . . . . . . 471
9.4 ConfidenceConnected segmentation results . . . . . . . . . . . . . . . . . . . . . . . . . 474
9.5 3DregionGrowingScreenshot1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
9.6 3DregionGrowingScreenshot1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
9.7 IsolatedConnected segmentation results . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
9.8 VectorConfidenceConnected segmentation results . . . . . . . . . . . . . . . . . . . . . . 480
9.9 Watershed Catchment Basins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
9.10 Watersheds Hierarchy of Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
9.11 Watersheds filter composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
9.12 Watershed segmentation output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
9.13 Zero Set Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
9.14 Grid position of the embedded level-set surface. . . . . . . . . . . . . . . . . . . . . . . . 488
9.15 FastMarchingImageFilter collaboration diagram . . . . . . . . . . . . . . . . . . . . . . . 489
9.16 FastMarchingImageFilter intermediate output . . . . . . . . . . . . . . . . . . . . . . . . 495
9.17 FastMarchingImageFilter segmentations . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
9.18 ShapeDetectionLevelSetImageFilter collaboration diagram . . . . . . . . . . . . . . . . . 497
9.19 ShapeDetectionLevelSetImageFilter intermediate output . . . . . . . . . . . . . . . . . . 503
9.20 ShapeDetectionLevelSetImageFilter segmentations . . . . . . . . . . . . . . . . . . . . . 504
9.21 GeodesicActiveContourLevelSetImageFilter collaboration diagram . . . . . . . . . . . . . 505
9.22 GeodesicActiveContourLevelSetImageFilter intermediate output . . . . . . . . . . . . . . 508
9.23 GeodesicActiveContourImageFilter segmentations . . . . . . . . . . . . . . . . . . . . . 509
xxvi List of Figures
9.24 ThresholdSegmentationLevelSetImageFilter collaboration diagram . . . . . . . . . . . . . 509
9.25 Propagation term for threshold-based level set segmentation . . . . . . . . . . . . . . . . 510
9.26 ThresholdSegmentationLevelSet segmentations . . . . . . . . . . . . . . . . . . . . . . . 512
9.27 CannySegmentationLevelSetImageFilter collaboration diagram . . . . . . . . . . . . . . . 514
9.28 Segmentation results of CannyLevelSetImageFilter . . . . . . . . . . . . . . . . . . . . . 516
9.29 LaplacianSegmentationLevelSetImageFilter collaboration diagram . . . . . . . . . . . . . 517
9.30 Segmentation results of LaplacianLevelSetImageFilter . . . . . . . . . . . . . . . . . . . 519
9.31 GeodesicActiveContourShapePriorLevelSetImageFilter collaboration diagram . . . . . . . 521
9.32 GeodesicActiveContourShapePriorImageFilter input image and initial model . . . . . . . 528
9.33 Corpus callosum PCA modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
9.34 GeodesicActiveContourShapePriorImageFilter segmentations . . . . . . . . . . . . . . . . 529
10.1 Sample class inheritance tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
10.2 Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
10.3 Simple conceptual classifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
10.4 Statistical classification framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
10.5 Two normal distributions plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
10.6 Output of the KMeans classifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
10.7 Bayesian plug-in classifier for two Gaussian classes . . . . . . . . . . . . . . . . . . . . . 610
10.8 Output of the ScalarImageMarkovRandomField . . . . . . . . . . . . . . . . . . . . . . . 624
11.1 ITK image iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
11.2 Copying an image subregion using ImageRegionIterator . . . . . . . . . . . . . . . . . . 635
11.3 Using the ImageRegionIteratorWithIndex . . . . . . . . . . . . . . . . . . . . . . . . . . 636
11.4 Maximum intensity projection using ImageSliceIteratorWithIndex . . . . . . . . . . . . . 644
11.5 Neighborhood iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
11.6 Some possible neighborhood iterator shapes . . . . . . . . . . . . . . . . . . . . . . . . . 647
11.7 Sobel edge detection results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654
11.8 Gaussian blurring by convolution filtering . . . . . . . . . . . . . . . . . . . . . . . . . . 658
11.9 Finding local minima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
11.10Binary image morphology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666
12.1 ImageAdaptor concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668
List of Figures xxvii
12.2 Image Adaptor to RGB Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672
12.3 Image Adaptor to Vector Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
12.4 Image Adaptor for performing computations . . . . . . . . . . . . . . . . . . . . . . . . . 677
13.1 Relationship between DataObjects and ProcessObjects . . . . . . . . . . . . . . . . . . . 680
13.2 The Data Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682
13.3 Sequence of the Data Pipeline updating mechanism . . . . . . . . . . . . . . . . . . . . . 683
13.4 Composite Filter Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
13.5 Composite Filter Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
14.1 Dart Quality Dashboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696
LIST OF TABLES
8.1 Geometrical Elementary Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
8.2 Identity Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
8.3 Translation Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
8.4 Scale Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
8.5 Scale Logarithmic Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . 367
8.6 Euler2D Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
8.7 CenteredRigid2D Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . 369
8.8 Similarity2D Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
8.9 QuaternionRigid Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . 371
8.10 Versor Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
8.11 Versor Rigid3D Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . 373
8.12 Euler3D Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
8.13 Similarity3D Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
8.14 Rigid3DPerspective Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . 376
8.15 Affine Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
8.16 BSpline Deformable Transform Characteristics . . . . . . . . . . . . . . . . . . . . . . . 378
8.17 LBFGS Optimizer trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
9.1 ConnectedThreshold example parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 464
9.2 IsolatedConnectedImageFilter example parameters . . . . . . . . . . . . . . . . . . . . . 477
9.3 FastMarching segmentation example parameters . . . . . . . . . . . . . . . . . . . . . . . 496
xxx List of Tables
9.4 ShapeDetection example parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
9.5 GeodesicActiveContour segmentation example parameters . . . . . . . . . . . . . . . . . 507
9.6 ThresholdSegmentationLevelSet segmentation parameters . . . . . . . . . . . . . . . . . 512
11.1 ImageRandomConstIteratorWithIndex usage . . . . . . . . . . . . . . . . . . . . . . . . . 645
Part I
Introduction
CHAPTER
ONE
WELCOME
Welcome to the Insight Segmentation and Registration Toolkit (ITK) Software Guide. This book
has been updated for ITK 4.5 and later versions of the Insight Toolkit software.
ITK is an open-source, object-oriented software system for image processing, segmentation,
and registration. Although it is large and complex, ITK is designed to be easy to use once
you learn about its basic object-oriented and implementation methodology. The purpose of
this Software Guide is to help you learn just this, plus to familiarize you with the important
algorithms and data representations found throughout the toolkit.
ITK is a large system. As a result, it is not possible to completely document all ITK
objects and their methods in this text. Instead, this guide will introduce you to im-
portant system concepts and lead you up the learning curve as fast and efficiently as
possible. Once you master the basics, take advantage of the many resources avail-
able (http://www.itk.org/ITK/help/documentation.html), including example materials,
which provide cookbook recipes that concisely demonstrate how to achieve a given task, the
Doxygen pages, which document the specific algorithm parameters, and the knowledge of the
many ITK community members (see Section 1.5 on page 9.)
The Insight Toolkit is an open-source software system. This means that the community sur-
rounding ITK has a great impact on the evolution of the software. The community can make
significant contributions to ITK by providing code reviews, bug patches, feature patches, new
classes, documentation, and discussions. Please feel free to contribute your ideas through the
ITK community mailing list.
1.1 Organization
This software guide is divided into three parts, each of which is further divided into several
chapters. Part I is a general introduction to ITK, within the next chaptera description of
how to install the Insight Toolkit on your computer. This includes how to build the library from
its source code. Part I also introduces basic system concepts such as an overview of the system
4 Chapter 1. Welcome
architecture, and how to build applications in the C++ and Python programming languages. Part
II describes the design of data structures and application of analysis methods within the system.
An organized survey of algorithms available is presented, and examples are used to illustrate
important system features. Part III is for the ITK contributor. Part III explains how to create
your own classes, extend the system, and be an active participant in the project.
1.2 How to Learn ITK
The key to learning how to use ITK is to become familiar with its palette of objects and the
ways to combine them. There are three categories of documentation to help with the learning
process: high level guidancematerial (the Software Guide), cookbook demonstrations on how
to achieve concrete objectives particular objectives (the examples), and detailed descriptions of
the application programming interface (the Doxygen1 documentation). These resources are
combined in the three recommended stages for learning ITK.
In the first stage, thoroughly read this Introduction, which provides an overview of some of
the key concepts of the system. It also provides guidance on how to build and install the soft-
ware. After running your first hello world program, you are well on your way to advanced
computational image analysis!
The next stage is to execute a few examples and gain familiarity with the available documenta-
tion. By running the examples, one can gain confidence in achieving results and is introduced
the mechanics of the software system. There are three example resources,
1. the Examples directory of the ITK source code repository 2.
2. the Examples pages on the ITK Wiki 3
3. the Sphinx documented ITK Examples 4
To gain familiarity with the available documentation, browse the sections available in Part II
and Part III of this guide. Also, browse the Doxygen application programming interface (API)
documentation for the classes applied in the examples.
Finally, mastery of ITK involves integration of information from multiple sources. Part II of
this guide is a reference to algorithms available, and Part III introduces how to extend them to
your needs and participate in the community. Individual examples are a detailed starting point
to achieve certain tasks. In practice, the Doxygen documentation becomes a frequent reference
as an index of the classes available, their descriptions, and the syntax and descriptions of their
methods. When examples and Doxygen documentation are insufficient, the software unit tests
thoroughly demonstrate how the code is utilized. Last, but not least, the source code itself is an
1http://itk.org/Doxygen/index.html21.43http://itk.org/Wiki/ITK/Examples4http://itk.org/ITKExamples
1.3. Obtaining the Software 5
extremely valuable resource. The code is the most detailed, up-to-date, and definitive descrip-
tion of the software. A great deal of attention and effort is directed to the codes readability, and
its value cannot be understated.
The following sections describe how to obtain the software, summarize the software function-
ality in each directory, and how to locate data.
1.3 Obtaining the Software
There are two different ways to access the ITK source code:
Periodic releases Official releases are available on the ITK web site5. Official releases are
available a twice a year and announced on the ITK web pages and mailing lists. However,
they may not provide the latest and greatest features of the toolkit.
Continuous repository checkout Direct access to the Git source code repository6 provides
immediate availability to the latest toolkit additions. But, on any given day the source
code may not be stable as compared to the official releases.
This software guide assumes that you are using the current released version of ITK, available
on the ITK web site. If you are a new user, we recommend the released version of the software.
It is stable, consistent, and better tested than the code available from the Git repository. When
working from the repository, please be aware of the ITK quality testing dashboard. The Insight
Toolkit is heavily tested using the open-source CDash regression testing system7. Before up-
dating the repository, make sure that the dashboard is green indicating stable code. If not green
it is likely that your software update is unstable. (Learn more about the ITK dashboard and
quality assurance process in Section 14.2 on page 696.)
1.3.1 Downloading Packaged Releases
ITK can be downloaded without cost from the following web site:
http://www.itk.org/ITK/resources/software.html
Then choose the tarball that better fits your system. The options are .zip and .tar.gz files.
The first type is better suited for Microsoft-Windows while the second one is the preferred
format for UNIX systems.
Once you unzip or untar the file a directory called InsightToolkit-4.5.0 will be created in
your disk and you will be ready for starting the configuration process described in Section 2.1.1
on page 12.
5http://itk.org/6http://itk.org/ITK.git7http://open.cdash.org/index.php?project=Insight
6 Chapter 1. Welcome
1.3.2 Downloading From Git
Git is a free and open source distributed version control system. For more information about
Git please see Section 14.1 on page 695. (Note: please make sure that you access the software
via Git only when the ITK quality dashboard indicates that the code is stable.)
Access ITK via Git using the following commands (under a Git Bash shell):
git clone git://itk.org/ITK.git
This will trigger the download of the software into a directory named ITK. Any time you want
to update your version, it will be enough to change into this directory, ITK, and type:
git pull
Once you obtain the software you are ready to configure and compile it (see Section 2.1.1
on page 12). First, however, we recommend reading the following sections that describe the
organization of the software and joining the mailing list.
1.3.3 Data
The Insight Toolkit was designed to support the Visible Human Project and its as-
sociated data. This data is available from the National Library of Medicine at
http://www.nlm.nih.gov/research/visible/visible_human.html .
Another source of data can be obtained from the ITK Web site at either of the following:
http://www.itk.org/ITK/resources/links.html
ftp://public.kitware.com/pub/itk/Data/.
1.4 Software Organization
To begin your ITK odyssey, you will first need to know something about ITKs software orga-
nization and directory structure. It is helpful to know enough to navigate through the code base
to find examples, code, and documentation.
ITK resources are organized into multiple Git repositories. The ITK library source code
are in the ITK8 Git repository. The sphinx Examples are in the ITKExamples9 repository.
Fairly complex applications using ITK (and other systems such as VTK, Qt, and FLTK) are
8http://itk.org/ITK.git9http://itk.org/ITKExamples.git
1.4. Software Organization 7
available from InsightApplications10 repository. The sources for this guide are in the
ITKSoftwareGuide11 repository.
The ITK repository contains the following subdirectories:
ITK/Modules the heart of the software; the location of the majority of the source code. ITK/Documentation some ancillary documentation material. ITK/Examples a suite of simple, well-documented examples used by this guide andto illustrate important ITK concepts.
ITK/Testing a collection of the MD5 files, which are used to link with the ITK dataservers to download test data. This test data is used by tests in ITK/Modules to produce
the ITK Quality Dashboard using CDash. (see Section 14.2 on page 696.)
Insight/Utilities the scripts that support source code development. For example,CTest and Doxygen support.
Insight/Wrapping the wrapping code to build interfaces between the C++ libraryand various interpreted languages (currently Python is supported).
The source code directory structurefound in ITK/Modulesis the most important to under-
stand.
ITK/Modules/Core core classes, macro definitions, typedefs, and other software con-structs central to ITK. The classes in Core are the only ones always compiled as part of
ITK.
ITK/Modules/ThirdParty various third-party libraries that are used to implementimage file I/O and mathematical algorithms. (Note: ITKs mathematical library is based
on the VXL/VNL software package12.)
ITK/Modules/Filtering image processing filters. ITK/Modules/IO classes that support the reading and writing of images, transforms,and geometry.
ITK/Modules/Bridge classes used to connect with the other analysis libraries orvisualization libraries, such as OpenCV13 and VTK14.
ITK/Modules/Registration classes for registration of images or other data struc-tures to each other.
10http://itk.org/ITKApps.git11http://itk.org/ITKSoftwareGuide.git12http://vxl.sourceforge.net13http://opencv.org14http://www.vtk.org
8 Chapter 1. Welcome
ITK/Modules/Segmentation classes for segmentation of images or other data struc-tures.
ITK/Modules/Video classes for input, output and processing of static and real-timedata with temporal components.
ITK/Modules/Compatibility collects together classes for backwards compatibilitywith ITK Version 3, and classes that are deprecated i.e. scheduled for removal from
future versions of ITK.
ITK/Modules/Remote a group of modules distributed outside of the main ITK sourcerepository (most of them are hosted on github.com) whose source code can be down-
loaded via CMake when configuring ITK.
ITK/Modules/External a directory to place in development or non-publicized mod-ules.
ITK/Modules/Numerics a collection of numeric modules, including FEM, Optimiza-tion, Statistics, Neural Networks, etc.
The Doxygen documentation is an essential resource when working with ITK, but it is not
contained in a separate repository. Each ITK class is implemented with a .h and .cxx/.hxx file
(.hxx file for templated classes). All methods found in the .h header files are documented and
provide a quick way to find documentation for a particular method. Doxygen uses this header
documentation to produce its HTML output.
The extensive Doxygen web pages describe in detail every class and method in the system.
It also contains inheritance and collaboration diagrams, listing of event invocations, and data
members. heavily hyper-linked to other classes and to the source code. The nightly generated
Doxygen documentation is online at http://itk.org/Doxygen/html/. Archived versions
for each feature release are also available online; for example, the documentation for the 4.4.0
release are available at http://itk.org/Doxygen44/html/.
The ITKApps contains large, relatively complex examples of ITK usage. See the web pages
at http://www.itk.org/ITK/resources/applications.html for a description. Some of
these applications require GUI toolkits such as Qt and FLTK or other packages such as
VTK (The Visualization Toolkit 15). It is recommend to set the CMake source directory to
ITKApps/Superbuild to build the dependent third-party applications.
1.5 The Insight Community and Support
Joining the community mailing list is strongly recommended. This is one of the primary re-
sources for guidance and help regarding the use of the toolkit. You can subscribe to the com-
munity list online at
15http://www.vtk.org
1.6. A Brief History of ITK 9
http://www.itk.org/ITK/help/mailing.html
ITK was created from its inception as a collaborative, community effort. Research, teaching,
and commercial uses of the toolkit are expected. If you would like to participate in the commu-
nity, there are a number of possibilities. For details on participation, see Part III.
Interaction with other community members is encouraged on the mailing lists by bothasking as answering questions. When issues are discovered, patches submitted to the
code review system are welcome. Performing code reviews, even by novice members, is
encouraged. Improvements and extensions to the documentation are also welcome.
Research partnerships with members of the Insight Software Consortium are encouraged.Both NIH and NLM will likely provide limited funding over the next few years and will
encourage the use of ITK in proposed work.
For those developing commercial applications with ITK, support and consulting are avail-able from Kitware 16. Kitware also offers short ITK courses either at a site of your choice
or periodically at Kitware offices.
Educators may wish to use ITK in courses. Materials are being developed for this pur-pose, e.g., a one-day, conference course and semester-long graduate courses. Check the
Wiki17 for a listing.
1.6 A Brief History of ITK
In 1999 the US National Library of Medicine of the National Institutes of Health awarded six
three-year contracts to develop an open-source registration and segmentation toolkit, that even-
tually came to be known as the Insight Toolkit (ITK) and formed the basis of the Insight Soft-
ware Consortium. ITKs NIH/NLM Project Manager was Dr. Terry Yoo, who coordinated the
six prime contractors composing the Insight consortium. These consortium members included
three commercial partnersGE Corporate R&D, Kitware, Inc., and MathSoft (the company
name is now Insightful)and three academic partnersUniversity of North Carolina (UNC),
University of Tennessee (UT) (Ross Whitaker subsequently moved to University of Utah), and
University of Pennsylvania (UPenn). The Principle Investigators for these partners were, re-
spectively, Bill Lorensen at GE CRD, Will Schroeder at Kitware, Vikram Chalana at Insightful,
Stephen Aylward with Luis Iba nez at UNC (Luis is now at Kitware), Ross Whitaker with
Josh Cates at UT (both now at Utah), and Dimitri Metaxas at UPenn (now at Rutgers). In
addition, several subcontractors rounded out the consortium including Peter Raitu at Brigham
& Womens Hospital, Celina Imielinska and Pat Molholt at Columbia University, Jim Gee at
UPenns Grasp Lab, and George Stetten at the University of Pittsburgh.
16http://www.kitware.com17http://itk.org/Wiki/ITK/Documentation
10 Chapter 1. Welcome
In 2002 the first official public release of ITK was made available. In addition, the National
Library of Medicine awarded thirteen contracts to several organizations to extend ITKs capa-
bilities. The NLM has funded maintenance of the toolkit over the years, and a major funding
effort was started in July 2010 that culminated with the release of ITK 4.0.0 in December 2011.
If you are interested in potential funding opportunities, we suggest that you contact Dr. Terry
Yoo at the National Library of Medicine for more information.
CHAPTER
TWO
INSTALLATION
This section describes the process for installing ITK on your system. Keep in mind that ITK is
a toolkit, and as such, once it is installed in your computer there will be no application to run.
Rather, use ITK to build your own applications. What ITK does providebesides the toolkit
properis a large set of test files and examples that will introduce ITK concepts and will show
how to use ITK in your own projects.
Some of the examples distributed with ITK require third party libraries that may require instal-
lation. For an initial installation of ITK, you may want to ignore these extra libraries and just
build the toolkit itself.
ITK has been developed and tested across different combinations of operating systems, com-
pilers, and hardware platforms including Microsoft Windows, Linux on various architectures,
Solaris, Mac OSX, and Cygwin. It is known to work with the following compilers:
GCC 4.x Visual Studio 8 SP 1 (Until 2015), 9 (Until 2018), 10 (Until 2020) Intel Compiler Suite 11.x, 12.x Darwin-c++-4.2 PPC (Until 2015), x86 64 Win32-mingw-gcc-4.5 Clang 3.3 and later
Support for different platforms is evident on the ITK quality dashboard (see Section 14.2 on
page 696).
Given the advanced usage of C++ features in the toolkit, some compilers may have difficulties
processing the code. If you are currently using an outdated compiler this may be an excellent
excuse for upgrading this old piece of software!