SimpleITK/Tutorials/MICCAI2015: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
No edit summary
Line 8: Line 8:
If you answered yes to either of these questions, then this tutorial is for you.
If you answered yes to either of these questions, then this tutorial is for you.


==Goals== 
 


The goal of this half-day tutorial is to introduce students and researchers to SimpleITK’s interface for the ITK version 4 registration framework. SimpleITK is, as the name suggests, a simpler interface to ITK. It provides a procedural interface and bindings to several interpreted languages, facilitating fast experimentation with ITK algorithms. In this tutorial we will use the Python programming language and the IPython Notebook interactive environment to explore the various features of the ITKv4 registration framework. Key features presented include: uniform treatment of linear, deformable and composite transformations, embedded  multi-resolution registration and self calibrating optimizers. Using a hands on approach, participants will experiment with various registration tasks, learning how to use SimpleITK in order to gain insight into the effects of registration component selection and parameter settings on accuracy and running time of ITK based registration algorithms.
The goal of this half-day tutorial is to introduce students and researchers to SimpleITK’s interface for the ITK version 4 registration framework. SimpleITK is, as the name suggests, a simpler interface to ITK. It provides a procedural interface and bindings to several interpreted languages, facilitating fast experimentation with ITK algorithms. In this tutorial we will use the Python programming language and the IPython Notebook interactive environment to explore the various features of the ITKv4 registration framework. Key features presented include: uniform treatment of linear, deformable and composite transformations, embedded  multi-resolution registration and self calibrating optimizers. Using a hands on approach, participants will experiment with various registration tasks, learning how to use SimpleITK in order to gain insight into the effects of registration component selection and parameter settings on accuracy and running time of ITK based registration algorithms.


==Organizers==
==Organizers==
{|cellspacing="40"
| [[File:Lhncbc.jpg | 60px]]  || [[File:Kitware.jpg | 150 px]] || [[File:Upenn.jpg | 120px]] || [[File:Uofiowa.jpg | 120px]] || [[File:Uva.jpg | 100px]]
|}
* Brian Avants, University of Pennsylvania. 
* Hans Johnson, University of Iowa.
* Bradley Lowekamp, Medical Science & Computing and National Institutes of Health.
* Matthew McCormick, Kitware Inc.
* Nick Tustison, University of Virginia.
* Ziv Yaniv, TAJ Technologies Inc. and National Institutes of Health.
==Prerequisites==
We '''do not''' require knowledge of C++ templates, CMake or how to compile code.
We '''do require''' basic knowledge of the Python programming language. If you are not familiar with Python but are well versed in MATLAB, Java, C++... then don't worry. You will be up to speed with a minimal investment of time. Please read or skim through the [https://docs.python.org/2/tutorial/index.html official Python language tutorial] or any of the tutorials listed [https://wiki.python.org/moin/BeginnersGuide/Programmers here].
You will need to bring your laptop (don't forget the adapter plug for your power cord if you are coming from outside of Europe).
The minimal installation of python will have to include the following packages: (1) ipython; (2) numpy; (3) matplotlib; (4) SimpleITK
Two paths forward:
===Lean and Mean===
This path installs the minimal set of required components:
# [https://www.python.org/downloads/ Download] and install Python version 2.7.9.
# (sudo) pip install virtualenv
# virtualenv ~/sitkpy --no-site-packages
# ~/sitkpy/bin/pip install ipython[all]
# ~/sitkpy/bin/pip install numpy
# ~/sitkpy/bin/pip install matplotlib
# [http://www.itk.org/Wiki/SimpleITK/GettingStarted Install SimpleITK]
===Memory's Cheap===
This path installs a full fledged scientific computing environment. Install (free) Python distributions for scientific and numeric computing from commercial vendors, either
Continuum’s [ http://continuum.io/downloads Anaconda] or Enthought’s [https://store.enthought.com/downloads/#default Canopy]. List of packages for [http://docs.continuum.io/anaconda/pkg-docs.html Anaconda] and [https://www.enthought.com/products/canopy/package-index/ Canopy]. 
====Anaconda====
#conda update conda
#conda update anaconda
#conda create -n sitkpy anaconda
#unix/mac: source activate sitkpy, win: activate sitkpy
#conda install -c https://conda.binstar.org/simpleitk SimpleITK
====Canopy====




Line 29: Line 78:
The following script illustrates the use of SimpleITK to perform rigid registration between a CT and MR (registration specific code is highlighted). By the end of the tutorial you will be familiar with the various components that are available as part of the SimpleITK registration framework, easily modifying this example to suite your specific needs.  
The following script illustrates the use of SimpleITK to perform rigid registration between a CT and MR (registration specific code is highlighted). By the end of the tutorial you will be familiar with the various components that are available as part of the SimpleITK registration framework, easily modifying this example to suite your specific needs.  


<source lang="python" highlight="19-22, 28-42">
<source lang="python" highlight="8-28">
import SimpleITK as sitk
import SimpleITK as sitk
def save_combined_central_slice(fixed, moving, transform, file_name_prefix):
    '''
    Transform the moving image using the given transform and create an alpha
    blended slice from the fixed and moving volumes' central z slices. The
    result is saved to a jpg file with the given prefix.
    '''
    central_slice = fixed.GetSize()[2]/2
    alpha = 0.7
    moving_transformed = sitk.Resample(moving, fixed, transform,
                                      sitk.sitkLinear, 0.0,
                                      moving_image.GetPixelIDValue())
    combined_image = (1.0 - alpha)*fixed[:,:,central_slice] + \
                    alpha*moving_transformed[:,:,central_slice]
    sitk.WriteImage(sitk.Cast(sitk.RescaleIntensity(combined_image), sitk.sitkUInt8),
                    file_name_prefix + '.jpg')


#read the images
#read the images
Line 57: Line 90:
                                                       sitk.Euler3DTransform(),  
                                                       sitk.Euler3DTransform(),  
                                                       sitk.CenteredTransformInitializerFilter.GEOMETRY)
                                                       sitk.CenteredTransformInitializerFilter.GEOMETRY)
#save alpha-blended central slice
save_combined_central_slice(fixed_image, moving_image,
                            initial_transform, 'initialAlignment')


#multi-resolution rigid registration using Mutual Information
#multi-resolution rigid registration using Mutual Information
Line 79: Line 109:


sitk.WriteTransform(final_transform, 'ct2mrT1.tfm')
sitk.WriteTransform(final_transform, 'ct2mrT1.tfm')
#save alpha-blended central slice
save_combined_central_slice(fixed_image, moving_image,
                            final_transform, 'finalAlignment')
</source>
</source>




To run this example you will need to download the [http://midas3.kitware.com/midas/download/?items=317034,1 CT] and [http://midas3.kitware.com/midas/download/?items=317035,1 MR] data. These are part of the training data provided by the [http://www.insight-journal.org/rire/ Retrospective Image Registration Evaluation Project].
To run this example you will need to download the [http://midas3.kitware.com/midas/download/?items=317034,1 CT] and [http://midas3.kitware.com/midas/download/?items=317035,1 MR] data. These are part of the training data provided by the [http://www.insight-journal.org/rire/ Retrospective Image Registration Evaluation Project].

Revision as of 20:58, 12 May 2015

SimpleITK Registration: An Interactive, Python-Based Introduction to Registration with the Insight Toolkit (ITK)

Who Should Attend

  • Do you want your students to gain practical experience with registration while minimizing their programming load?
  • Do you want to easily experiment with various ITK registration configurations, or optimize the settings of a specific registration configuration?

If you answered yes to either of these questions, then this tutorial is for you.


The goal of this half-day tutorial is to introduce students and researchers to SimpleITK’s interface for the ITK version 4 registration framework. SimpleITK is, as the name suggests, a simpler interface to ITK. It provides a procedural interface and bindings to several interpreted languages, facilitating fast experimentation with ITK algorithms. In this tutorial we will use the Python programming language and the IPython Notebook interactive environment to explore the various features of the ITKv4 registration framework. Key features presented include: uniform treatment of linear, deformable and composite transformations, embedded multi-resolution registration and self calibrating optimizers. Using a hands on approach, participants will experiment with various registration tasks, learning how to use SimpleITK in order to gain insight into the effects of registration component selection and parameter settings on accuracy and running time of ITK based registration algorithms.

Organizers

Lhncbc.jpg Kitware.jpg Upenn.jpg Uofiowa.jpg Uva.jpg
  • Brian Avants, University of Pennsylvania.
  • Hans Johnson, University of Iowa.
  • Bradley Lowekamp, Medical Science & Computing and National Institutes of Health.
  • Matthew McCormick, Kitware Inc.
  • Nick Tustison, University of Virginia.
  • Ziv Yaniv, TAJ Technologies Inc. and National Institutes of Health.

Prerequisites

We do not require knowledge of C++ templates, CMake or how to compile code.

We do require basic knowledge of the Python programming language. If you are not familiar with Python but are well versed in MATLAB, Java, C++... then don't worry. You will be up to speed with a minimal investment of time. Please read or skim through the official Python language tutorial or any of the tutorials listed here.

You will need to bring your laptop (don't forget the adapter plug for your power cord if you are coming from outside of Europe).

The minimal installation of python will have to include the following packages: (1) ipython; (2) numpy; (3) matplotlib; (4) SimpleITK

Two paths forward:

Lean and Mean

This path installs the minimal set of required components:

  1. Download and install Python version 2.7.9.
  2. (sudo) pip install virtualenv
  3. virtualenv ~/sitkpy --no-site-packages
  4. ~/sitkpy/bin/pip install ipython[all]
  5. ~/sitkpy/bin/pip install numpy
  6. ~/sitkpy/bin/pip install matplotlib
  7. Install SimpleITK

Memory's Cheap

This path installs a full fledged scientific computing environment. Install (free) Python distributions for scientific and numeric computing from commercial vendors, either Continuum’s [ http://continuum.io/downloads Anaconda] or Enthought’s Canopy. List of packages for Anaconda and Canopy.

Anaconda

  1. conda update conda
  2. conda update anaconda
  3. conda create -n sitkpy anaconda
  4. unix/mac: source activate sitkpy, win: activate sitkpy
  5. conda install -c https://conda.binstar.org/simpleitk SimpleITK

Canopy

Tentative Program

  • 8:30am: Setup and introduction.
  • 9:00am: SimpleITK basics: loading data, image access, image transformations, image resampling, basic filters.
  • 10:00am: Coffee break.
  • 10:30am: Registration 1: composite transform, transformation initialization, embedded multi-resolution, scale parameter estimation, optimization termination criteria.
  • 11:30am: Registration 2: nonrigid registration - Nonrigid registration, Bspline and displacement field transformations.
  • 12:30pm: Lunch.

SimpleITK Registration, It's Really Simple

The following script illustrates the use of SimpleITK to perform rigid registration between a CT and MR (registration specific code is highlighted). By the end of the tutorial you will be familiar with the various components that are available as part of the SimpleITK registration framework, easily modifying this example to suite your specific needs.

<source lang="python" highlight="8-28"> import SimpleITK as sitk

  1. read the images

fixed_image = sitk.ReadImage('training_001_ct.mha', sitk.sitkFloat32) moving_image = sitk.ReadImage('training_001_mr_T1.mha', sitk.sitkFloat32)

  1. initial alignment of the two volumes

initial_transform = sitk.CenteredTransformInitializer(fixed_image,

                                                     moving_image, 
                                                     sitk.Euler3DTransform(), 
                                                     sitk.CenteredTransformInitializerFilter.GEOMETRY)
  1. multi-resolution rigid registration using Mutual Information

registration_method = sitk.ImageRegistrationMethod() registration_method.SetMetricAsMattesMutualInformation(numberOfHistogramBins=50) registration_method.SetMetricSamplingStrategy(registration_method.RANDOM) registration_method.SetMetricSamplingPercentage(0.01) registration_method.SetInterpolator(sitk.sitkLinear) registration_method.SetOptimizerAsGradientDescent(learningRate=1.0,

                                                 numberOfIterations=100, 
                                                 convergenceMinimumValue=1e-6, 
                                                 convergenceWindowSize=10)

registration_method.SetOptimizerScalesFromPhysicalShift() registration_method.SetShrinkFactorsPerLevel(shrinkFactors = [4,2,1]) registration_method.SetSmoothingSigmasPerLevel(smoothingSigmas=[2,1,0]) registration_method.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn() registration_method.SetInitialTransform(initial_transform, inPlace=False) final_transform = registration_method.Execute(fixed_image, moving_image)

sitk.WriteTransform(final_transform, 'ct2mrT1.tfm') </source>


To run this example you will need to download the CT and MR data. These are part of the training data provided by the Retrospective Image Registration Evaluation Project.