SlideServe
Menu
Préférences
© SlideServe · v2026

ITK Workshop

francis-floyd avatar
47 diapositives · 601 Views · Nov 19, 2014

Join us for a comprehensive workshop exploring the Insight Toolkit (ITK) for image processing. This session covers the anatomy of ITK filters and the class hierarchy, diving into various filter types including UnaryFunctor, InPlace, and binary filters. We will guide participants through practical examples such as dividing pixel intensity values and defining output image properties. By the end of the workshop, you'll have hands-on experience creating custom image filters that utilize functors, iterators, and advanced filter design techniques.

ITK Workshop - slide 1
01 / 47ITK Workshop
1 / 17

Télécharger la présentation

ITK Workshop
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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 itk::Object itk::ProcessObject itk::DataObject itk::ImageBase itk::ImageSource itk::Image itk::ImageToImageFilter

  5. The Class Hierarchy itk::ImageToImageFilter itk::InPlaceImageFilter itk::UnaryFunctorImageFilter itk::BinaryFunctorImageFilter itk::TernaryFunctorImageFilter

  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 <class TOutputImage> class ImageSource : public ProcessObject {…}; template <class TInputImage, class TOutputImage> class ImageToImageFilter : public ImageSource< TOutputImage > {…}; template <class TInputImage, class TOutputImage> class InPlaceToImageFilter : public ImageToImageFilter< TOutputImage , TOutputImage > {…};

  10. Unary Functor Filter itk::UnaryFunctorImageFilter 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 <class TInputImage, class TOutputImage, class TFunctor> class UnaryFunctorImageFilter : public InPlaceImageFilter< TInputImage, TOutputImage >{ 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 { template< class TInput, class TOutput> class Cast{ public:Cast() {};~Cast() {}; inlineTOutput operator()( const TInput & A ) { returnstatic_cast<TOutput>( A ); } }; } // end of Functor namespace

  15. Unary Functor Filter Example : Casting #include “itkUnaryFunctorImageFilter.h” template<class TInputImage, class TOutputImage> class MyFunctorImageFilter : public UnaryFunctorImageFilter< TInputImage,TOutputImage, Functor::Cast< typenameTInputImage::PixelType,typenameTOutputImage::PixelType> > { …

  16. Unary Functor Filter Example : Casting public: typedefMyFunctorImageFilterSelf; typedefUnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Cast< typenameTInputImage::PixelType,typenameTOutputImage::PixelType > > Superclass; typedef SmartPointer< Self > Pointer;typedef SmartPointer< const Self > 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 itk::Image< unsigned char, 2 > InputImageType; typedef itk::Image< unsigned short, 2 > OutputImageType; typedef itk::MyFunctorImageFilter< InputImageType, OutputImageType> FilterType; FilterType::Pointer filter = FilterType::New(); }

  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 itk::NumericTraits<> and RealType and typename

  22. Exercise namespace itk { namespace Functor { template< class TInput, class TOutput> class Divider { public: Divider() {}; ~Divider() {}; inlineTOutput operator()( const TInput & A ) { typedef typename NumericTraits<TInput>::RealType InputRealType; returnstatic_cast<TOutput>( InputRealType( A ) / 2.0 ); } }; } // end of Functor namespace

  23. Exercise #include “itkUnaryFunctorImageFilter.h” template<class TInputImage, class TOutputImage> class DividerByTwoImageFilter : public UnaryFunctorImageFilter< TInputImage,TOutputImage, Functor::Divider< typenameTInputImage::PixelType, typenameTOutputImage::PixelType> > { public: typedefMyFunctorImageFilterSelf; typedefUnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Divider< typenameTInputImage::PixelType, typenameTOutputImage::PixelType> > 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 { template< class TInput, class TOutput> class Divider { public: Divider() {};~Divider() {}; typedef typename NumericTraits<TInput>::RealType InputRealType; inlineTOutput operator()( const TInput & A ) {returnstatic_cast<TOutput>( InputRealType( A ) / m_Divisor ); } void SetDivisor( const InputRealType & value ) { m_Divisor = value; } private: InputRealTypem_Divisor; };

  26. Exercise : Functors with parameters template<class TInputImage, class TOutputImage> class DividerImageFilter : public UnaryFunctorImageFilter< TInputImage,TOutputImage, Divider< typenameTInputImage::PixelType,typenameTOutputImage::PixelType> > {… public: typedeftypenameSuperclass::FunctorTypeFunctorType; typedeftypenameFunctorType::InputRealTypeInputRealType; void SetDivisor( const InputRealType & value ) {this->GetFunctor().SetDivisor( value ); }

  27. Exercise : Functors with parameters #include “DividerImageFilter.h” int main() { typedef itk::Image< unsigned char, 2 > InputImageType; typedef itk::Image< unsigned short, 2 > OutputImageType; typedef itk::DividerImageFilter< InputImageType,OutputImageType> FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetDivisor( 7.5 ); }

  28. Insight Toolkit - Advanced Course Image Regions

  29. LargestPossibleRegion BufferedRegion RequestedRegion 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(){Superclass::GenerateOutputInformation(); OutputImagePointer outputPtr = this->GetOutput(); outputPtr->SetLargestPossibleRegion(…); outputPtr->SetSpacing(…); outputPtr->SetOrigin(…);}

  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” template<class TInputImage> class FirstQuadrantExtractImageFilter : public ImageToImageFilter< TInputImage,TInputImage > { public: typedefFirstQuadrantExtractImageFilterSelf; typedefImageToImageFilter< TInputImage, TInputImage > Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; itkNewMacro( Self ); itkTypeMacro( FirstQuadrantExtractImageFilter, ImageToImageFilter ); …

  36. 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();

  37. GenerateOutputInformation() Method • Call Superclass::GenerateOutputInformation() • Set Parameters of the Output Image • Spacing • Origin • Direction • LargestPossibleRegion

  38. GenerateOutputInformation() Method template< class TInputImage >void GenerateOutputInformation() { Superclass::GenerateOutputInformation(); ImageConstPointer inputImage = this->GetInput(); ImagePointer outputImage = this->GetOutput(); RegionType inputRegion= inputImage->GetLargestPossibleRegion (); IndexType inputStart=inputRegion.GetIndex(); SizeType inputSize =inputRegion.GetSize();

  39. 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 );

  40. GenerateOutputInformation() Method outputImage->SetLargestPossibleRegion( outputRegion); outputImage->SetSpacing( inputImage->GetSpacing() ); outputImage->SetOrigin( inputImage->GetOrigin() ); outputImage->SetDirection( inputImage->GetDirection() ); } // 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 template< class TInputImage >void GenerateData(){ ImageConstPointer inputImage = this->GetInput(); ImagePointer outputImage = this->GetOutput(); RegionType outputRegion= outputImage->GetLargestPossibleRegion(); outputImage->SetRegions( outputRegion ); outputImage->Allocate(); typedef ImageRegionIterator< TInputImage > ImageIterator; typedef ImageRegionConstIterator< TInputImage > ImageConstIterator; ImageIterator outputIterator( outputImage,outputRegion ); ImageConstIterator inputIterator( inputImage,outputRegion );

  43. Insight Toolkit – Image Regions First Quadrant OutputImageRegion InputImageRegion

  44. GenerateData() Method inputIterator.GoToBegin(); outputIterator.GoToBegin(); 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