1 / 54

Medical Imaging ITK

Medical Imaging ITK. Credit. Some of the slides are taken from the presenation of Jean-Loïc Rose Other contributers are cited at the end. Installing ITK. Download InsightTookit-2.0.1.zip from http://www.itk.org/HTML/Download.htm

ann
Download Presentation

Medical Imaging ITK

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Medical ImagingITK

  2. Credit Some of the slides are taken from the presenation of Jean-Loïc Rose Othercontributers are citedat the end. University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 2

  3. Installing ITK • Download InsightTookit-2.0.1.zip from http://www.itk.org/HTML/Download.htm • Download CMake installer from http://www.cmake.org/HTML/Download.html • Install CMake • Unzip InsightToolkit to folder • Run CMake set PATH\InsightToolkit-2.0.1 as source code folder • Set PATH\InsightToolkit-2.0.1-bin as where to build binaries • Disable BUILD_EXAMPLES and BUILD_TESTING • Click Configure button University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 3

  4. Installing ITK (part 2) • Open ITK.dsw in binary build directory • Select Active Configuration to ALL_BUILD – Win32 RelWithDebInfo • Click Build • Wait 15-20 minutes University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 4

  5. Build Sample Program • Unzip itkdemo.zip to some folder • Run CMake same as for ITK • For ITK_DIR set binary directory • Open itkdemp.dsw in Visual Studio • Itkdemo.exe <infile> <outfile> <scale> University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 5

  6. Contents • What is ITK • Background • Concepts • Data representations • Images and regions • Pixel access in ITK • Developer’s guide • Access pixel data • How to write a filter University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 6

  7. ITK Basics • Image Processing and Analysis Toolkit • No visualization (VTK recommended) • Does not include GUI framework • Designed for Medical Imaging Applications • In general algorithms work in N-dimensions University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 7

  8. Catalog of ITK Features • Image IO • Image processing • Canny Edge • Hough Transform (lines/ellipsoids) • Variable Conductance Diffusion • Geometry IO/representation/processing (Spatial Objects) • Statistics • Registration/Segmentation • Numerics • Optimizers • Finite Element Simulation University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 8

  9. Reader Gaussian Writer File File Image Image How code using ITK is written • Mostly in C++ • Heavily templated/generic programming like STL • Multi-threading capable • Pipeline architecture • Build Pipeline • Execute pipeline • CMake used as build system University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 9

  10. How to find what you need ? • http://www.itk.org/ItkSoftwareGuide.pdf • http://www.itk.org/Doxygen/html/index.html • Follow the link Alphabetical List • Follow the link Groups • Post to the insight-users mailing list University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 10

  11. ITK Image Processing GUI MFC, QT, BBTK, wxWin Visualization OpenGL, VTK How to integrate ITK C++ Glue code University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 11

  12. Concepts • Data Pipeline • Smart Pointers • C++ Generic Programming (Templates) University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 12

  13. Filter Filter Concepts (I)Pipeline architecture • Data pipeline Image Image Filter Image Image Image University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 13

  14. Reader Gaussian Writer File File Image Image Concepts (I)Pipeline architecture • Pipeline architecture • Build Pipeline • Execute pipeline University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 14

  15. memory leak Concepts (II)An aside: Smart pointer • In C++ you typically allocate memory with new and desallocate it with delete • Smart pointers get around this problem by allocating and deallocating memory for you • You do not explicitly delete objects in ITK, this occurs automatically when they go out of scope • Since you can’t forget to delete objects, you can’t leak memory • Cat* pCat = new Cat; • pCat->Meaow(); • delete pCat; University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 15

  16. 1 0 5 4 3 … … … .02 … … … 2.5 … .23 … … … … … .47 … … … 5.6 Concepts (III)C++ generic programming • Generic programming is a method of organizing libraries consisting of generic—or reusable— • Abstraction of Types and Behaviors Example: STL Standard Template Library std::vector<int > std::vector<double > std::vector<char* > std::vector<point > std::vector<image > std::vector< T > University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 16

  17. Concepts (III)C++ generic programming Pixel type (char, int, …) Dimension (2D, 3D, …) Template ? University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 17

  18. Contents • What is ITK • Background • Concepts • Data representations • Images and regions • Pixel access in ITK • Developer’s guide • Access pixel data • How to write a filter Data representations Filtering ITK Features Applications University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 18

  19. ITK separates storage of data from the actions you can perform on data The DataObject class is the base class for the major “containers” into which you can place data Images: N-d rectilinear grids of regularly sampled data Meshes: N-d collections of points linked together into cells (e.g. triangles) Data storage in ITK University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 19

  20. itk::PointSet itk::Mesh Class hierarchy itk::Object itk::DataObject itk::ImageBase itk::Image University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 20

  21. ITK was designed to allow analysis of very large images, even images that far exceed the available RAM of a computer For this reason, ITK distinguishes between an entire image and the part which is actually resident in memory or requested by an algorithm Images and regions University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 21

  22. Algorithms only process a region of an image that sits inside the current buffer The BufferedRegion is the portion of image in physical memory The RequestedRegion is the portion of image to be processed The LargestPossibleRegion describes the entire dataset LargestPossibleRegion::Size BufferedRegion::Size RequestedRegion::Size RequestedRegion::Index BufferedRegion::Index LargestPossibleRegion::Index Images and regions University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 22

  23. Images are templated • Image ITK • Example itk::Image<PixelType, Dimension > Pixel type Dimensionality (value) itk::Image<int,2 > itk::Image<char,4 > itk::Image<RGB,3 > itk::Image< std::vector<double >,2 > Unsigned char, 2 University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 23

  24. Images and regions • The favorite keyword • Declaring an image type • We can now use ImageType in place of the full class name, a nice convenience • Remember that names ending in “Type” are types, not variables or class names typedef typedefitk::Image< char, 2 > ImageType; University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 24

  25. Images and regions • Creating an image pointer • An image is created by invoking the New() operator from the corresponding image type and assigning the result to a SmartPointer. typedefitk::Image< char, 2 > ImageType; ImageType::Pointer image= ImageType::New(); Macro “big New” Pointer is typedef in itk::Image University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 25

  26. Images and regions • Creating an image • Classes can have typedefs as members. In this case, SizeType is a public member of itk::Image. typedefitk::Image< char, 2 > ImageType; ImageType::Pointer image= ImageType::New(); ImageType::SizeType size; size[0] = 512; // x direction size[1] = 512; // y direction ImageType::IndexType start; start[0] = 0; // x direction start[1] = 0; // y direction University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 26

  27. Images and regions • Creating the region of an image typedefitk::Image< char, 2 > ImageType; ImageType::Pointer image= ImageType::New(); ImageType::SizeType size = {{512,512}}; ImageType::IndexType start = {{0,0}}; // Initialize region parameter ImageType::RegionType region; region.SetSize( size ); region.SetIndex( start ); University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 27

  28. Images and regions • Allocate typedefitk::Image< char, 2 > ImageType; ImageType::Pointer image= ImageType::New(); ImageType::SizeType size = {{512,512}}; ImageType::IndexType start = {{0,0}}; // Initialize region parameter ImageType::RegionType region; region.SetSize( size ); region.SetIndex( start ); // Allocate image image->SetRegions( region ); image->Allocate(); image->FillBuffer(0); The SetRegions function sets all 3 regions to the same region and Allocate sets aside memory for the image. University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 28

  29. Image features Data space vs. “physical” space Image IO University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 29

  30. Data space is an N-d array with integer indices, indexed from 0 to (Li - 1) e.g. pixel (3,0,5) in 3D space Physical space relates to data space by defining the origin and spacing of the image Data space vs. “physical” space University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 30

  31. Data space vs. “physical” space • Spacing: We can specify spacing by calling the SetSpacing() function in Image. • Origin: Similarly, we can set the image origin ImageType::SpacingType spacing; spacing[0] = 0.83; // x direction spacing[1] = 2.15; // y direction Image->SetSpacing( spacing); ImageType::IndexType origin; origin[0] = 0.83; // x direction origin[1] = 2.15; // y direction Image->SetIndex( origin); University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 31

  32. Data space vs. “physical” space • The image class contains a number of convenience methods to convert between pixel indices and physical positions (as stored in the Point class) typedefitk::Image< char, 2 > ImageType; ImageType::PointType point; // Physical space ImageType::PixelType pixelIndex;// Data space image->TransformPhysicalPointToIndex( point, pixelIndex ); image->TransformIndexToPhysicalPoint( pixelIndex, point ); University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 32

  33. Image File ImageFileReader Image PNGImageIO MetaImageIO AnalyzeImageIO GIPLImageIO VTKImageIO DICOMImageIO CustomImageIO ITK Image IO Loadable Factories University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 33

  34. Image File Image File ImageFileReader ImageFileWriter Filter Image Image ITK Image IO University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 34

  35. ITK Image IO #include “itkImageFileReader.h” #include “itkImageFileWriter.h” int main() { typedefitk::Image< unsigned char, 2 > ImageType; typedefitk::ImageFileReader< ImageType > ReaderType; ReaderType::Pointer reader=ReaderType::New(); reader->SetFilename( inputFilename ); reader->Update( );// reader->Update( ); typedefitk::ImageFileWiter< ImageType > WriterType; WriterType::Pointer writer=WriterType::New(); writer->SetInput( reader->GetOutput( ) ); writer->SetFilename( outputFilename ); writer->Update( ); } University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 35

  36. Image typedef • Classes can have typedefs as members. typedefitk::Image< char, 2 > ImageType; ImageType::Pointer // Image pointer ImageType::SizeType // Size of image ImageType::IndexType // Index of pixels ImageType::PixelType // Type of pixels ImageType::RegionType // region of pixels ImageType::… University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 36

  37. Contents • What is ITK • Background • Concepts • Data representations • Images and regions • Pixel access in ITK • Developer’s guide • Access pixel data • How to write a filter Data representations Filtering ITK Features Applications University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 37

  38. Pixel access in ITK There are many ways to access pixels in ITK Direct pixel access Iterators - Index in data space - Physical position, in physical space University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 38

  39. Direct pixel access in ITK • The simplest way is to directly address a pixel by knowing either its: The Index object is used to access pixels in an image, in data space ImageType::IndexType pixelIndex; pixelIndex[0] = 27; // x direction pixelIndex[1] = 29; // y direction // To set a pixel ImageType::PixelType pixelValue = 149; Image->SetPixel( pixelIndex,pixelValue ); // To get a pixel ImageType::PixelType pixelValue; pixelValue = Image->GetPixel( pixelIndex ); University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 39

  40. Pixel access in ITK with iterators • An iterator is described as walking its iteration region. • There is no restriction on the dimensionality of the image or on the pixel type of the image. University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 40

  41. Pixel access in ITK with iterators • Moving iterators • Accessing data - GoToBegin() - GoToEnd() - operator++() - operator--() - bool IsAtEnd() - bool IsAtBegin() - IndexType GetIndex() - … - PixelType Get() - void Set( PixelType ) University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 41

  42. Pixel access in ITK with iterators • Iteration loops example (1D, 2D, 3D, 4D…) • Example on a volume (500x500x500) • Direct pixel access: 43.39 s. • Pixel access with iterators: 4.48 s. typedefitk::ImageRegionIterator< ImageType > IteratorType; IteratorTypeit( image, image->GetRequestedRegion() ); for( it.GoToBegin(); !it.IsAtEnd(); it++ ) { std::cout << “Index : ” << it.GetIndex() << std::endl; std::cout << “Value : ” << it.Get() << std::endl; } University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 42

  43. Pixel access in ITK with iterators • Classic image iterators • ImageRegionIterator (basic ITK image iterator) • ImageRegionIteratorWithIndex • Line-by-line iterators • ImageLinearIteratorWithIndex (NextLine(), …) • ImageSliceIteratorWithIndex (NextSlice(), …) • Random iterators • ImageRandomConstIteratorWithIndex • Neighborhood iterator • NeighborhoodIterator University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 43

  44. Pixel access in ITK with iterators • Neighborhood iterator University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 44

  45. Class hierarchy itk::Object itk::ProcessObject itk::DataObject itk::ImageSource itk::ImageBase itk::ImageToImageFilter itk::Image University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 45

  46. Filter typical element typedef itk::ImageToImageFilter < ImageType, ImageType > FilterType; Filter Input Image Output Image Parameters University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 46

  47. Inplace filter element typedef itk::InPlaceImageFilter < ImageType, ImageType > FilterType; Filter Input Image Output Image Parameters The output bulk data is the same block of memory as the input bulk data. University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 47

  48. Create an Image Filter namespace itk { template< class TInput, class TOutput> class MyImageFilter : public ImageToImageFilter< class TInput, class TOutput> { public: typedefMyImageFilterSelf; typedefImageToImageFilter< TInput, TOutput > Superclass; typedef SmartPointer< Self > Pointer;typedef SmartPointer< const Self > ConstPointer; itkNewMacro( Self ); itkTypeMacro( MyImageFilter, ImageToImageFilter ); University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 48

  49. Create an Image Filter protected: MyImageFilter() {} virtual ~MyImageFilter() {} virtual void GenerateData() {}; // The real work private: MyImageFilter( const Self & ); // purposely not implemented void operator=( const Self & ); // purposely not implemented }; // end of class } // end of namespace itk University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 49

  50. Typical Declarations: Traits and Macros • Traits • Self • Superclass • Pointer • ConstPointer • Macros • NewMacro • TypeMacro University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 50

More Related