image registration lecture 7: getting started with itk march 15, 2005 prof. charlene tsai

54
Image Registration Lecture 7: Getting Started with ITK March 15, 2005 Prof. Charlene Tsai

Upload: annabel-sanders

Post on 27-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Image Registration Lecture 7: Getting Started with ITK

March 15, 2005

Image Registration Lecture 7: Getting Started with ITK

March 15, 2005

Prof. Charlene TsaiProf. Charlene Tsai

Image Registration Lecture 6 2

The Insight ToolkitThe Insight Toolkit

The Segmentation andRegistration Toolkit

Image Registration Lecture 6 3

What is ITK ?What is ITK ?

Image Processing

Segmentation

Registration

No Graphical User Interface (GUI)

No Visualization

Image Registration Lecture 6 4

ITK SponsorsITK Sponsors

The NationalScienceFoundation

The NationalInstitute for Dental and Craniofacial Research

The National Institute of Neurological Disorders and Stroke

Image Registration Lecture 6 5

ITK DevelopersITK Developers

Image Registration Lecture 6 6

ITK DevelopersITK Developers

GE CRDBill Lorensen

InsightfulLydia Ng

U PennDimitris Metaxas

Harvard BWH*Ron Kikinis

U Penn*Jim Gee

Columbia U.*Celina Imielinska

KitwareWill Schroeder

UNC-CHStephen Aylward

U TennesseeRoss Whitaker

U Pittsburgh*George Stetten

U Utah*Ross Whitaker

* indicates a subcontractor.

Image Registration Lecture 6 7

The Insight ToolkitThe Insight Toolkit

Starting with ITK

Image Registration Lecture 6 8

Integrating ITK in your applicationIntegrating ITK in your application

C++ Glue Code

ITK

ImageProcessing

GUI

{MFC,Qt,wxWinFLTK}

Visualization

{OpenGL, VTK}

Image Registration Lecture 6 9

What do I need ?What do I need ?

C++ Compiler

gcc 2.95 – 3.3Visual C++ 6.0Visual C++ 7.0VC++ 7 2003

Intel 5.0IRIX CC

Borland 5.0Mac - gcc

CMake

www.cmake.org

Image Registration Lecture 6 10

Downloading ITKDownloading ITK

Live on the Edge

CVS

Stability

Release tar files

Insight.tgz CVS anonymous

http://www.itk.org

Or download the not-very-recent copy from the course website

Image Registration Lecture 6 11

Configuring ITKConfiguring ITK

Source Tree

ITK

Common

Algorithms

BasicFilter

Numerics

IO

ITKb

Common

Algorithms

BasicFilter

Numerics

IO

Binary Tree

Recommended !

Out Source Build

InSourceBuild

Image Registration Lecture 6 12

Configuring ITK – MS-WindowsConfiguring ITK – MS-Windows

Run CMake

Select the SOURCE directory

Select the BINARY directory

Select your Compiler

Image Registration Lecture 6 13

Configuring ITK – MS-WindowsConfiguring ITK – MS-Windows

Image Registration Lecture 6 14

Configuring ITK – MS-WindowsConfiguring ITK – MS-Windows

Disable BUILD_EXAMPLES

Disable BUILD_SHARED_LIBS

Disable BUILD_TESTING

Click “Configure” to configure

Click “OK” to generate project files

Image Registration Lecture 6 15

Configuring ITK – UnixConfiguring ITK – Unix

Create the BINARY directory (mkdir)

Change directory to the BINARY directory (cd)

Set the environment variables CC and CXX

setenv CC /usr/bin/gcc; setenv CXX /usr/bin/g++ OR

export CC=/usr/bin/gcc; export CXX=/usr/bin/g++

Type ccmake with argument the SOURCE directory

Image Registration Lecture 6 16

Configuring ITK – UnixConfiguring ITK – Unix

Image Registration Lecture 6 17

Configuring ITK – UnixConfiguring ITK – Unix

Disable BUILD_EXAMPLES

Disable BUILD_SHARED_LIBS

Disable BUILD_TESTING

Type “c” to configure

Type “g” to generate the Makefiles

Type “make” to start building

Image Registration Lecture 6 18

Building ITKBuilding ITK

Image Registration Lecture 6 19

Building ITKBuilding ITK

Open ITK.dsw in the Binary Directory

Select ALL_BUILD project

Build it …It will take about 15 minutes …

Image Registration Lecture 6 20

Building ITKBuilding ITK

Image Registration Lecture 6 21

Building ITKBuilding ITK

Open ITK.sln in the Binary Directory

Select ALL_BUILD project

Build it …It will take about 15 minutes …

Image Registration Lecture 6 22

Building ITKBuilding ITK

Most of ITK classes are C++ Templates

Basic libraries are small

they only contain non-templated classes

Basic libraries are built in about 15 min

Image Registration Lecture 6 23

Verifying the BuiltVerifying the Built

Libraries will be found in

In MS-Windows

ITK_BINARY / bin / { Debug, Release }

In UNIX

ITK_BINARY / bin /

Image Registration Lecture 6 24

Verifying the BuiltVerifying the Built

ITKCommon

ITKBasicFilters

ITKAlgorithms

ITKNumerics

ITKFEM

The following libraries should be there

ITKIO

ITKStatistics

ITKMetaIO

itkpng

itkzlib

Image Registration Lecture 6 25

Using ITK – Hello World (Review)Using ITK – Hello World (Review)

Create“CMakeLists.txt”

& cxx filesIn the source

directory

RunCMake

• Select Source Dir• Select Binary Dir

Image Registration Lecture 6 26

Using ITK – Hello WorldUsing ITK – Hello World

Accept the default in

CMAKE_BACKBARD_COMPATIBILITY

Leave empty EXECUTABLE_OUTPUT_PATH

Leave empty LIBRARY_OUTPUT_PATH

Set ITK_DIR to the binary directory

where ITK was built

Image Registration Lecture 6 27

Building the HelloWorld ProjectBuilding the HelloWorld Project

Open HelloWorld.dsw (or .sln)

generated by CMake

Select ALL_BUILD project

Build it …It will take about 3 seconds …

Locate the file HelloWorld.exe

Run it…

It should produce the message:

ITK Hello World !

Image Registration Lecture 6 28

How to Find What Your NeedHow to Find What Your Need

http://www.itk.org/Doxygen/html/index.html

Follow the link Alphabetical List

Follow the link Groups

Post to the insight-users mailing list

http://www.itk.org

Image Registration Lecture 6 29

Doxygen DocumentationDoxygen Documentation

Image Registration Lecture 6 30

Doxygen GroupsDoxygen Groups

Image Registration Lecture 6 31

Doxygen Alphabetical ListDoxygen Alphabetical List

Image Registration Lecture 6 32

ITK ArchitectureITK Architecture

ITK Architecture

Image Registration Lecture 6 33

ITK BasicsITK Basics

C++ Generic Programming Data Pipeline

Multi-threading

Streaming

Exceptions

Events / Observers

Tcl and Python wrapping

Image Registration Lecture 6 34

Generic ProgrammingGeneric Programming

Example: STL Standard Template Library

Abstraction of Types and Behaviors

std::vector< T >

std::vector< int > std::vector< double >

std::vector< char * >

std::vector< Point >

std::vector< Image >

Image Registration Lecture 6 35

ITK Image ClassITK Image Class

itk::Image< PixelType , Dimension >

itk::Image< char , 2 > itk::Image< char , 3 >

itk::Image< char , 4 >

itk::Image< float , 2 >

itk::Image< RGB , 3 >

itk::Image< unsigned short , 2 >

itk::Image< itk::Vector<float,2> , 2 >

Image Registration Lecture 6 36

C++ NamespacesC++ Namespaces

Avoid naming collisions

itk::

itk::Statistics::

itk::fem::

itk::fem::itpack

itk::bio

NEVER DO:

using namespace itk;using namespace std;

Image Registration Lecture 6 37

ITK Most Common KeywordITK Most Common Keyword

typedef

typedef itk::Image< char , 2 > ImageTypetypedef itk::ImageFilter< ImageType , ImageType > FilterType

otherwise...

itk::ImageFilter< Image< char , 2 > , Image< char , 2 > > FilterType

Image Registration Lecture 6 38

Smart PointersSmart Pointers

ObjectSmartPointer

SmartPointer

SmartPointer

counter=0counter=1counter=2counter=3

Self - Delete

Image Registration Lecture 6 39

Smart PointersSmart Pointers

typedef itk::Image< char , 2 > ImageTypetypedef itk::ImageFilter< ImageType , ImageType > FilterType

FilterType::Pointer filter = FilterType::New();

ImageType::Pointer image = filter->GetOutput();

NO NEED FOR

filter->Delete();

Image Registration Lecture 6 40

Const CorrectnessConst Correctness

Knowing constancy is Insight.

Not knowing constancy leads to disaster.

Tao Te Ching, XVI. Lao Tsu

Image Registration Lecture 6 41

Const Smart PointersConst Smart Pointers

typedef itk::Image< char , 2 > ImageTypetypedef itk::ImageFilter< ImageType , ImageType > FilterType

FilterType::Pointer filter = FilterType::New();

ImageType::ConstPointer image = filter->GetOutput();

Can only invoke “const” methods

image->GetSpacing ();

Compiler error for “non-const” methods

image->SetSpacing ( spacing );

Image Registration Lecture 6 42

Data PipelineData Pipeline

Image Filter Image

FilterImage Image

ImageFilter

Image Registration Lecture 6 43

Image RegionsImage Regions

LargestPossibleRegion

BufferedRegion

RequestedRegion

Image Registration Lecture 6 44

StreamingStreaming

OutputImage

Filter

Processing Large Images

InputImage

Image Registration Lecture 6 45

Simple Image IOSimple Image IO

ImageFile

ImageFileReader Image

Filter

ImageImage

FileImageFileWriter

Image Registration Lecture 6 46

Simple Image IOSimple Image IO

CustomImageIO

ImageFile

ImageFileReader Image

PNGImageIO

VTKImageIO DICOMImageIOGIPLImageIO

MetaImageIO AnalyzeImageIO

Loadable Factories

Image Registration Lecture 6 47

Simple Image IOSimple Image IO

#include “itkImage.h”#include “itkImageFileReader.h”#include “itkImageFileWriter.h”

typedef itk::Image< char , 2 > ImageType;typedef itk::ImageFileReader< ImageType > ReaderType;typedef itk::ImageFileWriter< ImageType > WriterType;

ReaderType::Pointer reader = ReaderType::New();WriterType::Pointer writer = WriterType::New();

reader->SetFileName( “inputImage.dcm” ); // DICOMwriter->SetFileName( “outputImage.hdr” ); // Analyze

writer->SetInput( reader->GetOutput() ); writer->Update();

Image Registration Lecture 6 48

ExceptionsExceptions

Error Management

ITK Layer

Application Layer

Image Registration Lecture 6 49

ExceptionsExceptions

try {

filter->Update();

}

catch( itk::ExceptionObject & exp )

{

std::cerr << exp << std::endl;

}

Image Registration Lecture 6 50

Events and Commands/ObserversEvents and Commands/Observers

Itk::ObjectItk::Command

itk::Command

itk::Command

itk::Command

itk::Command

Event

Event

Event

Event

Event

Image Registration Lecture 6 51

EventsEvents

Common Events

AnyEvent()

StartEvent()

EndEvent()

ProgressEvent()

IterationEvent()

Image Registration Lecture 6 52

Events and Commands/ObserversEvents and Commands/Observers

Itk::Object

Itk::ProcessObject

Itk::FilterXY

Itk::Command

MyCommand

Execute()

AddObserver( )AnyEvent

MyEvent

Image Registration Lecture 6 53

GUI CommunicationGUI Communication

ITK Layer

GUI LayerWidget

FilterX

CallbackCommand

FilterX

Widget

Observer

Image Registration Lecture 6 54

EndEnd

Enjoy ITK !