NA-MIC National Alliance for Medical Image Computing ITK Workshop October 5-8, 2005 Writing a New ITK Filter.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
NA-MIC National Alliance for Medical Image Computing ITK Workshop October 5-8, 2005 Multi-Threading.
NA-MIC National Alliance for Medical Image Computing ITK Workshop October 5-8, 2005 Software Design.
ITK Architecture Kitware Inc.. ITK Basics C++ Generic Programming Data Pipeline Multi-threading Streaming Exceptions Events / Observers Tcl, Python and.
ITK Segmentation Methods
ITK Registration Methods
ITK Deformable Registration
National Alliance for Medical Image Computing Slicer3 plugins: Going Further Common architecture for interactive and batch processing.
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
National Alliance for Medical Image Computing Slicer3 plugins Common architecture for interactive and batch processing.
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
GPU Acceleration in ITK v4
C++ Basics Variables, Identifiers, Assignments, Input/Output.
Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 4 Images in ITK Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering.
1 ITK Lecture 7 - Writing Filters, Part 1 Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods.
Chapter 14: Overloading and Templates
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
1 ITK Lecture 2 A brief C++ review Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
LECTURE LECTURE 17 More on Templates 20 An abstract recipe for producing concrete code.
GPU Acceleration in ITK v4
Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Medical Imaging ITK.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
CSE 332: C++ Type Programming: Associated Types, Typedefs and Traits A General Look at Type Programming in C++ Associated types (the idea) –Let you associate.
The content of these slides by John Galeotti, © Carnegie Mellon University (CMU), was made possible in part by NIH NLM contract# HHSN P,
Object Oriented Programming Elhanan Borenstein copyrights © Elhanan Borenstein.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.
1 ITK Lecture 8 - Neighborhoods Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
NA-MIC National Alliance for Medical Image Computing Slicer and ITK Raul San Jose.
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Operator Overloading.
Chapter 9 Questions 1. What are the difference between constructors and member functions? 2. Design and implement a simple class as you want, with constructors.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates.
CS212: Object Oriented Analysis and Design Lecture 22: Generic Class Design.
Review of Function Overloading Allows different functions to have the same name if they have different types or numbers of arguments, e.g. int sqr(int.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
1 Classes struct Public and Private Parts of a struct Class Scope of a Class Overloading Member Functions Class in a Class Static Members of Classes this.
Learners Support Publications Operators.
CSE 332: C++ templates and generic programming II Review: Concepts and Models Templates impose requirements on type parameters –Types that are plugged.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
National Alliance for Medical Image Computing Slicer3 Plugins Common architecture for interactive and batch processing.
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
Motivation for Generic Programming in C++
C++ Lesson 1.
How to be generic Lecture 10
Data types Data types Basic types
Introduction to C++ Systems Programming.
Lecture 19 ITK Filters: How to Write Them
Array Lists Chapter 6 Section 6.1 to 6.3
Lecture 19 Write Your Own ITK Filters, Part2
Object-Oriented Programming (OOP) Lecture No. 39
ITK Architecture Kitware Inc..
Lecture 19 ITK’s Path Framework
Abstraction: Generic Programming, pt. 2
Variables, Identifiers, Assignments, Input/Output
Prof. Bhushan Trivedi Director GLS Institute of Computer Technology
From C to C++: Summary of weeks 1 - 4
ITK Workshop Software Design October 5-8, 2005.
Recitation Course 0603 Speaker: Liu Yu-Jiun.
Class rational part2.
SPL – PS3 C++ Classes.
Presentation transcript:

NA-MIC National Alliance for Medical Image Computing ITK Workshop October 5-8, 2005 Writing a New ITK Filter

National Alliance for Medical Image Computing ITK Workshop – Extending the Toolkit Filters Anatomy –Class HierarchyClass Hierarchy –InputsInputs –OutputsOutputs UnaryFunctorFilter –Casting ExampleCasting Example –Division by 2 ExampleDivision by 2 Example –Functor with parameters ExampleFunctor with parameters Example Regions and Iterators –Defining properties of the Output ImageDefining properties of the Output Image –Allocating the outputAllocating the output –Using IteratorsUsing Iterators

National Alliance for Medical Image Computing Anatomy of an ITK Filter Insight Toolkit - Advanced Course

National Alliance for Medical Image Computing The Class Hierarchy itk::ProcessObject itk::DataObject itk::Object itk::ImageBase itk::Image itk::ImageSource itk::ImageToImageFilter

National Alliance for Medical Image Computing The Class Hierarchy itk::InPlaceImageFilter itk::UnaryFunctorImageFilteritk::BinaryFunctorImageFilter itk::TernaryFunctorImageFilter itk::ImageToImageFilter

National Alliance for Medical Image Computing Filter Typical Elements Input Image Output Image Filter Parameters

National Alliance for Medical Image Computing InPlace Filter Elements Input Image Output Image Filter Parameters

National Alliance for Medical Image Computing The Unary Functor Image Filter Insight Toolkit - Advanced Course

National Alliance for Medical Image Computing Image Filter Hierarchy template class ImageToImageFilter : public ImageSource {…}; template class InPlaceToImageFilter : public ImageToImageFilter {…}; template class ImageSource : public ProcessObject {…};

National Alliance for Medical Image Computing Unary Functor Filter itk::UnaryFunctorImageFilter Pixel-Wise Image Filter Input ImageOutput Image

National Alliance for Medical Image Computing It should be enough to specify the operation to be applied on each pixel Unary Functor Filter That is the role of the FUNCTOR

National Alliance for Medical Image Computing Unary Functor Filter Filter Functor template class UnaryFunctorImageFilter : public InPlaceImageFilter { private: TFunctor m_Functor; };

National Alliance for Medical Image Computing Exercise 23 Insight Toolkit - Advanced Course Create an Image Filter that performs Casting

National Alliance for Medical Image Computing namespace itk { namespace Functor { template class Cast { public: Cast() {}; ~Cast() {}; inline TOutput operator()( const TInput & A ) { return static_cast ( A ); } }; } // end of Functor namespace Unary Functor Filter Example : Casting

National Alliance for Medical Image Computing Unary Functor Filter Example : Casting #include itkUnaryFunctorImageFilter.h template class MyFunctorImageFilter : public UnaryFunctorImageFilter< TInputImage,TOutputImage, Functor::Cast > { …

National Alliance for Medical Image Computing public: typedef MyFunctorImageFilter Self; typedef UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Cast > Superclass; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; itkNewMacro( Self ); itkTypeMacro( MyFunctorImageFilter, UnaryFunctorImageFilter ); Unary Functor Filter Example : Casting

National Alliance for Medical Image Computing Typical Declarations: Traits and Macros Traits Self Superclass Pointer ConstPointer Macros NewMacro TypeMacro

National Alliance for Medical Image Computing 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 Unary Functor Filter Example : Casting

National Alliance for Medical Image Computing #include MyFunctorImageFilter.h int main() { typedef itk::Image InputImageType; typedef itk::Image OutputImageType; typedef itk::MyFunctorImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); } Unary Functor Filter Example : Casting

National Alliance for Medical Image Computing Exercise 24 Insight Toolkit - Advanced Course Create an Image Filter that divides all the intensity values by 2

National Alliance for Medical Image Computing NOTE Insight Toolkit - Advanced Course The use of itk::NumericTraits<> and RealType and typename

National Alliance for Medical Image Computing namespace itk { namespace Functor { template class Divider { public: Divider() {}; ~Divider() {}; inline TOutput operator()( const TInput & A ) { typedef typename NumericTraits ::RealType InputRealType; return static_cast ( InputRealType( A ) / 2.0 ); } }; } // end of Functor namespace Exercise

National Alliance for Medical Image Computing Exercise #include itkUnaryFunctorImageFilter.h template class DividerByTwoImageFilter : public UnaryFunctorImageFilter< TInputImage,TOutputImage, Functor::Divider > { public: typedef MyFunctorImageFilter Self; typedef UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Divider > Superclass; …

National Alliance for Medical Image Computing Exercise 25 Insight Toolkit - Advanced Course Create an Image Filter that divides all the intensity values by a given value

National Alliance for Medical Image Computing namespace itk { namespace Functor { template class Divider { public: Divider() {}; ~Divider() {}; typedef typename NumericTraits ::RealType InputRealType; inline TOutput operator()( const TInput & A ) { return static_cast ( InputRealType( A ) / m_Divisor ); } void SetDivisor( const InputRealType & value ) { m_Divisor = value; } private: InputRealType m_Divisor; }; Exercise : Functors with parameters

National Alliance for Medical Image Computing Exercise : Functors with parameters template class DividerImageFilter : public UnaryFunctorImageFilter< TInputImage,TOutputImage, Divider > {…{… public: typedef typename Superclass::FunctorType FunctorType; typedef typename FunctorType::InputRealType InputRealType; void SetDivisor( const InputRealType & value ) { this->GetFunctor().SetDivisor( value ); }

National Alliance for Medical Image Computing #include DividerImageFilter.h int main() { typedef itk::Image InputImageType; typedef itk::Image OutputImageType; typedef itk::DividerImageFilter FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetDivisor( 7.5 ); filter->Update(); } Exercise : Functors with parameters

National Alliance for Medical Image Computing Image Regions Insight Toolkit - Advanced Course

National Alliance for Medical Image Computing Insight Toolkit – Image Regions LargestPossibleRegion BufferedRegion RequestedRegion

National Alliance for Medical Image Computing Filter Typical Elements Input Image Output Image Filter Parameters Region

National Alliance for Medical Image Computing Insight Toolkit – Image Regions Input Region Output Region Input ImageOutput Image

National Alliance for Medical Image Computing Generate Output Information Method Filter virtual void GenerateOutputInformation() { Superclass::GenerateOutputInformation(); OutputImagePointer outputPtr = this->GetOutput(); outputPtr->SetLargestPossibleRegion(…); outputPtr->SetSpacing(…); outputPtr->SetOrigin(…); }

National Alliance for Medical Image Computing Generate Output Information Method Spacing Origin Orientation (Direction) LargestPossibleRegion This method configures the Output Image by default it copies meta data from the Input

National Alliance for Medical Image Computing Exercise 26 Insight Toolkit - Advanced Course Create an Image Filter that extracts the first quadrant of an image

National Alliance for Medical Image Computing Quadrant Extract Image Filter Example #include itkImageToImageFilter.h template class FirstQuadrantExtractImageFilter : public ImageToImageFilter { public: typedef FirstQuadrantExtractImageFilter Self; typedef ImageToImageFilter Superclass; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; itkNewMacro( Self ); itkTypeMacro( FirstQuadrantExtractImageFilter, ImageToImageFilter ); …

National Alliance for Medical Image Computing Quadrant Extract Image Filter Example typedef typename TInputImage::RegionType RegionType; typedef typename TInputImage::SizeType SizeType; typedef typename TInputImage::IndexType IndexType; typedef typename TInputImage::Pointer ImagePointer; typedef typename TInputImage::ConstPointer ImageConstPointer; protected: FirstQuadrantExtractImageFilter() {}; ~FirstQuadrantExtractImageFilter() {}; void PrintSelf( std::ostream &os, Indent indent) const; void GenerateOutputInformation(); void GenerateData();

National Alliance for Medical Image Computing GenerateOutputInformation() Method Call Superclass::GenerateOutputInformation() Set Parameters of the Output Image Spacing Origin Direction LargestPossibleRegion

National Alliance for Medical Image Computing GenerateOutputInformation() Method template void GenerateOutputInformation() { Superclass::GenerateOutputInformation(); ImageConstPointer inputImage = this->GetInput(); ImagePointer outputImage = this->GetOutput(); RegionType inputRegion = inputImage->GetLargestPossibleRegion (); IndexType inputStart = inputRegion.GetIndex(); SizeType inputSize = inputRegion.GetSize();

National Alliance for Medical Image Computing GenerateOutputInformation() Method IndexType outputStart; SizeType outputSize; const unsigned int Dimension = TInputImage::ImageDimension; for( unsigned int i = 0; i < Dimension; i++ ) { outputSize[i] = inputSize[i] / 2; outputStart[i] = inputStart[i]; } RegionType outputRegion; outputRegion.SetIndex( outputStart ); outputRegion.SetSize( outputSize );

National Alliance for Medical Image Computing GenerateOutputInformation() Method outputImage->SetLargestPossibleRegion( outputRegion ); outputImage->SetSpacing( inputImage->GetSpacing() ); outputImage->SetOrigin( inputImage->GetOrigin() ); outputImage->SetDirection( inputImage->GetDirection() ); } // end of GenerateOutputInformation() method

National Alliance for Medical Image Computing 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

National Alliance for Medical Image Computing GenerateData() Method template void GenerateData() { ImageConstPointer inputImage = this->GetInput(); ImagePointer outputImage = this->GetOutput(); RegionType outputRegion = outputImage->GetLargestPossibleRegion(); outputImage->SetRegions( outputRegion ); outputImage->Allocate(); typedef ImageRegionIterator ImageIterator; typedef ImageRegionConstIterator ImageConstIterator; ImageIterator outputIterator( outputImage, outputRegion ); ImageConstIterator inputIterator( inputImage, outputRegion );

National Alliance for Medical Image Computing Insight Toolkit – Image Regions First Quadrant Input Image Region Output Image Region

National Alliance for Medical Image Computing GenerateData() Method inputIterator.GoToBegin(); outputIterator.GoToBegin(); while( ! outputIterator.IsAtEnd() ) { outputIterator.Set( inputIterator.Get() ); ++inputIterator; ++outputIterator; }

National Alliance for Medical Image Computing Exercise 26b Insight Toolkit - Advanced Course Modify the code for extracting the central thirds an image

National Alliance for Medical Image Computing Insight Toolkit – Image Regions Input Image Region Output Image Region Central Third

National Alliance for Medical Image Computing END Insight Toolkit - Advanced Course