ITK, VTK and Python

foremanyellowΛογισμικό & κατασκευή λογ/κού

7 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

152 εμφανίσεις

Getting Started with ITK in
Python Language

I. Introduction to ITK, Python Wrapping
and VTK
-
ITK Connection

Outline


ITK Overview (most slides are adopted from
Documents in Insight Toolkit 1.2 CD)


Python Wrapping


Installations


Examples


Filter


Registration


ITK
-
VTK connection


Where to get help?


What is ITK

Open Source C++ Toolkit

Medical Image

Processing

Registration

Segmentation

ITK Overview


Core design concepts


Generic programming (e.g. temper late,
containers, iterators.)


Smart pointers for memory management


Object factories for adaptable object
instantiation


Command/observer design paradigm for event
management


Multithreading support


Cross
-
platform (CMake)

The Big Picture

ITK

Common

Basic Filters

Algorithms

Numerics

Common

Common

Data

System

Pipeline

PointSet

Mesh

Image

ListFeatures

Histogram

Basic

VectorContainer

MapContainer

MultiThreader

Mutex

Point

Matrix

Vector

Size

Exceptions

ProcessObject

DataObject

Events

Observer

Transforms

Index

Numerics

Numerics

VNL

Linear

Algebra

Matrix

Vector

SVD

Eigen

Optimizers

Evolutionary

Algorithms

Gradient


Descent

Membership

Functions

Optimizers

Statistics

FEM

Classifiers

Element

Node

Solver

Load

Material

Histogram

methods

List

methods

MorphoMath

Basic Filters

Basic Filters

PixelWise

Neighborhood

Arithmetic

Trigonometric

Global

Median

Derivative

Laplacian

DistanceMap

HaussdorfDistance

Anisotropic

Diffusion

EdgeDetection

Connected

Components

PNG

VTK

DICOM

Meta

IO

Intensity Transf

Algorithms

Algorithms

Registration

Metrics

Transforms

Interpolators

Optimizers

Multi

Resolution

Level Sets

PDE

Deformable

Models

Connectedness

Fast

Marching

Narrow

Band

Shape

Detection

Geodesic

Contours

Watershed

Demons

CurvatureFlow

Fuzzy

Hard

SimpleFuzzy

Balloon Force

Markov RF

Pipeline Architecture


Data Flow


Data Objects


Image


Mesh


Process Objects (Algorithms)


Segmentation


Registration


Image Processing


Streaming capable

Pipeline Architecture

Image

Filter

Filter

Image

Filter

Image

Image

Image

Output

Image

Architecture

Filter

Streaming


Processing Large Images

Input

Image

Registration Framework

Image

Registration

Framework

Multi

Resolution

Registration

Framework

PDE

Based

Registration

FEM

Based

Registration

Components

Registration Components

Fixed

Image

Moving

Image

Metric

Transform

Interpolator

Optimizer

Registration Method

Other Frameworks


Level Set Framework for segmentation


FEM Framework

A subsystem for solving general FEM problems,
in particular non
-
rigid registration


IO Framework

Use a flexible object factory mechanism to
support a variety of file formats


Why Python Wrapping ?


Interpreted Language


Interactive


Simplifies teaching and learning


Facilitates rapid prototyping


Large python
-
vtk user base in our Labs

How Does It Work?


ITK Core is implemented in C++


Tcl and Python bindings are generated
automatically using a combination of


gccxml
--

a modified version of gcc


Cable
--

processes XML info from gccxml and
generates input for CSWIG


CSWIG
--

modified version of SWIG that
produces Python (or Tcl ) binding


Under active development, no binary
installation package yet.

How does it work ?

Python wrapping requires fully specified C++ types

Image<T,N>

Image<ushort,2>

Image<ushort,3>

Image<float,2>

Image<float,3>

ImageUS2

C++

Python

ImageUS3

ImageF2

ImageF3

How does it work ?

ITK Filters are Templated over Image Type

GaussianImageFilter<
InputImage
, OutputImage >

GaussianImageFilter<
ImageU2
,
ImageU2
>

GaussianImageFilter<
ImageF2
,
ImageF2
>

GaussianImageFilter<
ImageU2
,
ImageF2
>

GaussianImageFilter<
ImageF2
,
ImageU2
>

GaussianImageFilter<
ImageF3
,
ImageU3
>

How does it work?

Python wrapper for filters should define type combinations

GaussianImageFilter<
ImageUS2
,
ImageUS2
>

GaussianImageFilter<
ImageF2
,
ImageF2
>

GaussianImageFilter<
ImageUS2
,
ImageF2
>

GaussianImageFilter<
ImageF2
,
ImageUS2
>

GaussianImageFilter<
ImageF3
,
ImageUS3
>

C++

Python

GaussianFilterUS2US2

GaussianFilterF2F2

GaussianFilterUS2F2

GaussianFilterF2US2

GaussianFilterF3US3

VTK
-
ITK Connection in Python


Implemented as an module ConnectVTKITK
in InsightApplication repository


Connect the pipeline with Import and Export
classed in VTK and ITK


VTK exporter


ITK importer


ITK exporter


VTK importer


Use ITK for image processing, registration,
segmentation and VTK for visualization



Status: Under active development

Installation


What do I need?


C++ Compiler
--

gcc 2.95 to 3.3, Visual C++ 6
-
7.1 )


CMake (1.67 or cvs checkout)


Python (2.1,
2.2
, or 2.3)


VTK (4.2.2 or cvs checkout)


Insight (cvs checkout)


InsightApplications


Installation for Python
-
VTK
-
ITK is not straight forward
right now, no binary distribution. A step by step
instruction will be posted on Image Lab coders’ web
page.

Step 1 Python and modules


Linux comes with python and tcl/tk


Windows: python 2.2, tcl/tk 8.3


Numpy (Numeric Python)


Scientific Python (Install NetCDF library first
for NetCDF and MINC support)

Step 2 CMake

Download the latest (1.67) binary for your
platform from www.cmake.org

Step 3 Install VTK


Install VTK 4.2.2 from source distribution .
Turn on the following flags


VTK_USE_HYBRID


VTK_USE_PATENTED


VTK_WRAP_PYTHON


VTK_USE_ANSI_STDLIB


Step 4 Install Insight


Get the source


cvs


Build with CMake


CSWIG_WRAP_PYTHON


USE_VTK

Step 5 Install InsightApplications


CVS checkout


CMake


CONNECT_VTK_ITK

Step 6 Environment Variables


Linux/Unix


PYTHONPATH


LD_LIBRARY_PATY



Windows


PATH


PYTHONPATH


Examples


CurvatureAnisotropicDiffusionImageFilter.py


Examples


ImageRegistration3.py

Examples : VTK
-
ITK Connection


CannyEdgeDetectionImageFilterConnectVTKITK.py

Where to get help?


www.itk.org


ITK Software Guild : PDF document (Over 500
pages)


Doxygen generated manual pages


Insight
-
users Mailing Lists


Image Labs coders mailing lists:


http://www.imaging.robarts.ca/coders