ITK Workshop - PowerPoint PPT Presentation

About This Presentation
Title:

ITK Workshop

Description:

ITK Workshop Writing a New ITK Filter October 5-8, 2005 ITK Workshop Extending the Toolkit Filters Anatomy Class Hierarchy Inputs Outputs UnaryFunctorFilter ... – PowerPoint PPT presentation

Number of Views:63
Avg rating:3.0/5.0
Slides: 48
Provided by: itkOrgWi
Learn more at: https://itk.org
Category:
Tags: itk | workshop

less

Transcript and Presenter's Notes

Title: ITK Workshop


1
ITK Workshop
Writing a New ITK Filter
  • October 5-8, 2005

2
ITK Workshop Extending the Toolkit
  • Filters Anatomy
  • Class Hierarchy
  • Inputs
  • Outputs
  • UnaryFunctorFilter
  • Casting Example
  • Division by 2 Example
  • Functor with parameters Example
  • Regions and Iterators
  • Defining properties of the Output Image
  • Allocating the output
  • Using Iterators

3
Insight Toolkit - Advanced Course
  • Anatomy of an ITK Filter

4
The Class Hierarchy
itkObject
itkProcessObject
itkDataObject
itkImageBase
itkImageSource
itkImage
itkImageToImageFilter
5
The Class Hierarchy
itkImageToImageFilter
itkInPlaceImageFilter
itkUnaryFunctorImageFilter
itkBinaryFunctorImageFilter
itkTernaryFunctorImageFilter
6
Filter Typical Elements
Filter
Input Image
Output Image
Parameters
7
InPlace Filter Elements
Filter
Input Image
Output Image
Parameters
8
Insight Toolkit - Advanced Course
  • The Unary Functor Image Filter

9
Image Filter Hierarchy
template ltclass TOutputImagegt class ImageSource
public ProcessObject
template ltclass TInputImage, class
TOutputImagegt class ImageToImageFilter public
ImageSourcelt TOutputImage gt
template ltclass TInputImage, class
TOutputImagegt class InPlaceToImageFilter
public ImageToImageFilterlt TOutputImage ,
TOutputImage gt
10
Unary Functor Filter
itkUnaryFunctorImageFilter
Pixel-Wise Image Filter
Input Image
Output Image
11
Unary Functor Filter
  • It should be enough to specify the
  • operation to be applied on each pixel

That is the role of the FUNCTOR
12
Unary Functor Filter
Functor
Filter
template ltclass TInputImage, class TOutputImage,
class TFunctorgt class UnaryFunctorImageFilter
public InPlaceImageFilterlt TInputImage,
TOutputImage gt private TFunctor
m_Functor
13
Insight Toolkit - Advanced Course
  • Exercise 23

Create an Image Filter that performs Casting
14
Unary Functor Filter Example Casting
namespace itk namespace Functor
templatelt class TInput, class TOutputgt class
Cast public Cast()
Cast() inline TOutput operator()(
const TInput A ) return
static_castltTOutputgt( A )
// end of Functor namespace
15
Unary Functor Filter Example Casting
include itkUnaryFunctorImageFilter.h template
ltclass TInputImage, class TOutputImagegt class
MyFunctorImageFilter public
UnaryFunctorImageFilterlt TInputImage,TOutputImage,
FunctorCastlt typename
TInputImagePixelType,
typename TOutputImagePixelTypegt gt
16
Unary Functor Filter Example Casting
public typedef MyFunctorImageFilter
Self typedef UnaryFunctorImageFilterlt
TInputImage, TOutputImage,
FunctorCastlt typename TInputImagePixelType,
typename
TOutputImagePixelType gt
gt Superclass
typedef SmartPointerlt Self gt Pointer
typedef SmartPointerlt const Self gt
ConstPointer itkNewMacro( Self )
itkTypeMacro( MyFunctorImageFilter,
UnaryFunctorImageFilter )
17
Typical Declarations Traits and Macros
  • Traits
  • Self
  • Superclass
  • Pointer
  • ConstPointer
  • Macros
  • NewMacro
  • TypeMacro

18
Unary Functor Filter Example Casting
protected MyFunctorImageFilter() virtual
MyFunctorImageFilter() private
MyFunctorImageFilter( const Self ) //
purposely not implemented void operator(
const Self ) // purposely not
implemented // end of class // end of
namespace itk
19
Unary Functor Filter Example Casting
include MyFunctorImageFilter.h int main()
typedef itkImagelt unsigned char, 2 gt
InputImageType typedef itkImagelt unsigned
short, 2 gt OutputImageType typedef
itkMyFunctorImageFilterlt
InputImageType,
OutputImageType
gt FilterType
FilterTypePointer filter FilterTypeNew()
20
Insight Toolkit - Advanced Course
  • Exercise 24

Create an Image Filter that divides all the
intensity values by 2
21
Insight Toolkit - Advanced Course
  • NOTE

The use of itkNumericTraitsltgt
and RealType and typename
22
Exercise
namespace itk namespace Functor
templatelt class TInput, class TOutputgt class
Divider public Divider()
Divider() inline TOutput operator()(
const TInput A ) typedef typename
NumericTraitsltTInputgtRealType InputRealType
return static_castltTOutputgt( InputRealType( A )
/ 2.0 ) // end of Functor
namespace
23
Exercise
include itkUnaryFunctorImageFilter.h templatelt
class TInputImage, class TOutputImagegt class
DividerByTwoImageFilter public
UnaryFunctorImageFilterlt TInputImage,TOutputImage,
FunctorDividerlt typename
TInputImagePixelType,
typename TOutputImagePixelTypegt
gt public typedef MyFunctorImageFilter
Self typedef UnaryFunctorImageFilterlt
TInputImage, TOutputImage,
FunctorDividerlt typename TInputImagePixelType,
typename
TOutputImagePixelTypegt
gt Superclass
24
Insight Toolkit - Advanced Course
  • Exercise 25

Create an Image Filter that divides all the
intensity values by a given value
25
Exercise Functors with parameters
namespace itk namespace Functor templatelt
class TInput, class TOutputgt class Divider
public Divider() Divider()
typedef typename NumericTraitsltTInputgtRealType
InputRealType inline TOutput operator()(
const TInput A ) return
static_castltTOutputgt( InputRealType( A ) /
m_Divisor ) void SetDivisor( const
InputRealType value )
m_Divisor value private
InputRealType m_Divisor
26
Exercise Functors with parameters
templateltclass TInputImage, class
TOutputImagegt class DividerImageFilter
public UnaryFunctorImageFilterlt
TInputImage,TOutputImage,
Dividerlt typename TInputImagePixelType,
typename TOutputImagePixelT
ypegt gt public typedef typename
SuperclassFunctorType FunctorType
typedef typename FunctorTypeInputRealType
InputRealType void SetDivisor( const
InputRealType value )
this-gtGetFunctor().SetDivisor( value )
27
Exercise Functors with parameters
include DividerImageFilter.h int main()
typedef itkImagelt unsigned char, 2 gt
InputImageType typedef itkImagelt unsigned
short, 2 gt OutputImageType typedef
itkDividerImageFilterlt
InputImageType,
OutputImageType
gt FilterType
FilterTypePointer filter FilterTypeNew()
filter-gtSetDivisor( 7.5 )
filter-gtUpdate()
28
Insight Toolkit - Advanced Course
  • Image Regions

29
Insight Toolkit Image Regions
30
Filter Typical Elements
Filter
Input Image
Output Image
Region
Region
Parameters
31
Insight Toolkit Image Regions
Input Image
Output Image
Input Region
Output Region
32
Generate Output Information Method
Filter
virtual voidGenerateOutputInformation()
SuperclassGenerateOutputInformation()
OutputImagePointer outputPtr
this-gtGetOutput() outputPtr-gtSetLargest
PossibleRegion() outputPtr-gtSetSpacing()
outputPtr-gtSetOrigin()
33
Generate Output Information Method
This method configures the Output Image
  • Spacing
  • Origin
  • Orientation (Direction)
  • LargestPossibleRegion

by default it copies meta data from the Input
34
Insight Toolkit - Advanced Course
  • Exercise 26

Create an Image Filter that extractsthe first
quadrant of an image
35
Quadrant Extract Image Filter Example
include itkImageToImageFilter.h templateltclass
TInputImagegt class FirstQuadrantExtractImageFilte
r public ImageToImageFilterlt
TInputImage,TInputImage gt public typedef
FirstQuadrantExtractImageFilter Self
typedef ImageToImageFilterlt TInputImage,
TInputImage gt Superclass typedef
SmartPointerlt Self gt Pointer typedef
SmartPointerlt const Self gt ConstPointer
itkNewMacro( Self ) itkTypeMacro(
FirstQuadrantExtractImageFilter,
ImageToImageFilter )
36
Quadrant Extract Image Filter Example
typedef typename TInputImageRegionType
RegionTypetypedef typename
TInputImageSizeType SizeTypetypedef
typename TInputImageIndexType
IndexType typedef typename
TInputImagePointer ImagePointertypedef
typename TInputImageConstPointer
ImageConstPointer protected
FirstQuadrantExtractImageFilter()
FirstQuadrantExtractImageFilter() void
PrintSelf( stdostream os, Indent indent)
const void GenerateOutputInformation()
void GenerateData()
37
GenerateOutputInformation() Method
  • Call SuperclassGenerateOutputInformation()
  • Set Parameters of the Output Image
  • Spacing
  • Origin
  • Direction
  • LargestPossibleRegion

38
GenerateOutputInformation() Method
templatelt class TInputImage gtvoid
GenerateOutputInformation()
SuperclassGenerateOutputInformation()
ImageConstPointer inputImage
this-gtGetInput() ImagePointer
outputImage this-gtGetOutput() RegionType
inputRegion inputImage-gtGetLargestPossibleRegion
() IndexType inputStart
inputRegion.GetIndex() SizeType inputSize
inputRegion.GetSize()
39
GenerateOutputInformation() Method
IndexType outputStart SizeType
outputSize const unsigned int Dimension
TInputImageImageDimension for( unsigned
int i 0 i lt Dimension i )
outputSizei inputSizei / 2
outputStarti inputStarti
RegionType outputRegion outputRegion.SetIndex(
outputStart ) outputRegion.SetSize(
outputSize )
40
GenerateOutputInformation() Method
outputImage-gtSetLargestPossibleRegion(
outputRegion ) outputImage-gtSetSpacing(
inputImage-gtGetSpacing() ) outputImage-gtSetOrig
in( inputImage-gtGetOrigin() ) outputImage-gtSetD
irection( inputImage-gtGetDirection() ) //
end of GenerateOutputInformation() method
41
GenerateData() Method
  • Get Input and Output Image pointers
  • Invokes GetInput()
  • Invokes GetOutput()
  • Allocate memory for the Output Image (s)
  • Invokes SetRegions()
  • Invokes Allocate()
  • Computes pixels of Output Image
  • Usually requires Image Iterators

42
GenerateData() Method
templatelt class TInputImage gtvoid
GenerateData() ImageConstPointer inputImage
this-gtGetInput() ImagePointer
outputImage this-gtGetOutput() RegionType
outputRegion outputImage-gtGetLargestPossibleRegi
on() outputImage-gtSetRegions( outputRegion
) outputImage-gtAllocate() typedef
ImageRegionIteratorlt TInputImage gt
ImageIterator typedef ImageRegionConstIteratorlt
TInputImage gt ImageConstIterator
ImageIterator outputIterator( outputImage,
outputRegion ) ImageConstIterator
inputIterator( inputImage, outputRegion )
43
Insight Toolkit Image Regions
OutputImageRegion
InputImageRegion
First Quadrant
44
GenerateData() Method
inputIterator.GoToBegin() outputIterator.GoToBegi
n() while( ! outputIterator.IsAtEnd() )
outputIterator.Set( inputIterator.Get() )
inputIterator outputIterator
45
Insight Toolkit - Advanced Course
  • Exercise 26b

Modify the code for extractingthe central thirds
an image
46
Insight Toolkit Image Regions
OutputImageRegion
Central Third
InputImageRegion
47
Insight Toolkit - Advanced Course
  • END
Write a Comment
User Comments (0)
About PowerShow.com