Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Medical Imaging ITK.

Similar presentations


Presentation on theme: "Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Medical Imaging ITK."— Presentation transcript:

1 Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Medical Imaging ITK

2 Credit Some of the slides are taken from the presenation of Jean-Loïc Rose Other contributers are cited at 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 http://www.itk.org/HTML/Download.htm  Download CMake installer from http://www.cmake.org/HTML/Download.html 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 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 How code using ITK is written  Mostly in C++  Heavily templated/generic programming like STL  Multi-threading capable  Pipeline architecture 1.Build Pipeline 2.Execute pipeline  CMake used as build system Reader Image File Gaussian Image Writer File University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 9

10  http://www.itk.org/ItkSoftwareGuide.pdf 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 How to find what you need ? University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 10

11 How to integrate ITK ITK Image Processing C++ Glue code Visualization OpenGL, VTK GUI MFC, QT, BBTK, wxWin 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 Concepts (I) Pipeline architecture Image Filter Image Filter  Data pipeline Image University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 13

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

15 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 memory leak 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 … … … … … … … … … … 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 1 1 0 0 5 5 4 4 3 3.02 2.5.23.47 5.6 … … … … … … … … … … … … … … … … … … … … University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 16

17 Concepts (III) C++ generic programming Template ? Pixel type (char, int, …) Dimension (2D, 3D, …) 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 ITK Features Data representations Filtering Applications University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 18

19 Data storage in ITK  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) University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 19

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

21 Images and regions  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 University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 21

22 Images and regions 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::Index BufferedRegion::Index RequestedRegion::Index RequestedRegion::Size BufferedRegion::Size LargestPossibleRegion::Size University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 22

23 Images are templated  Image ITK  Example Pixel type Dimensionality (value) Unsigned char, 2 itk::Image itk::Image, 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 itk::Image ImageType; typedef 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. Pointer is typedef in itk::Image Macro “big New” typedef itk::Image ImageType; ImageType::Pointer image = ImageType::New(); 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. typedef itk::Image 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  Creating the region of an image Images and regions typedef itk::Image 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 typedef itk::Image 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 ); Images and regions  Allocate 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 vs. “physical” space  Data space is an N-d array with integer indices, indexed from 0 to (L i - 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 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) typedef itk::Image 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 ITK Image IO CustomImageIO Image File ImageFileReader Image PNGImageIO VTKImageIODICOMImageIOGIPLImageIO MetaImageIOAnalyzeImageIO Loadable Factories University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 33

34 ITK Image IO Image File ImageFileReader Image Filter Image File ImageFileWriter Image 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() { typedef itk::Image ImageType; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFilename( inputFilename ); reader->Update( ); // reader->Update( ); typedef itk::ImageFileWiter 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. typedef itk::Image 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 ITK Features Data representations Filtering 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. typedef itk::ImageRegionIterator IteratorType; IteratorType it( 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::DataObject itk::Object itk::ImageBase itk::Image itk::ProcessObject itk::ImageSource itk::ImageToImageFilter University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 45

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

47 Inplace filter element Input Image Output Image Filter Parameters typedef itk::InPlaceImageFilter FilterType; 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 MyImageFilter : public ImageToImageFilter { public: typedef MyImageFilter Self; typedef ImageToImageFilter Superclass; typedef SmartPointer Pointer; typedef SmartPointer 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

51 Create an Image Filter #include “MyImageFilter.h” int main() { typedef itk::Image InputImageType; typedef itk::Image OutputImageType; typedef itk::MyImageFilter< InputImageType, OutputImageType > FilterType; FilterType::Pointer filter = FilterType::New(); Filter->SetInput( reader->GetOuput() ); Filter->Update( ); OutputImageType::Pointer image = Filter->GetOutput( ); } University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 51

52 References  http://www.itk.org/ItkSoftwareGuide.pdf http://www.itk.org/ItkSoftwareGuide.pdf  http://www.itk.org/Doxygen/html/index.html http://www.itk.org/Doxygen/html/index.html  http://www.itk.org/HTML/Tutorials.htm http://www.itk.org/HTML/Tutorials.htm University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 52

53 References  http://caddlab.rad.unc.edu/Public/InsightIn90Minutes.ppt  ITK CVS Online documentation http://www.itk.org/Doxygen/html/index.html  ITK 2.0 (preliminary) Software Guide http://prdownloads.sourceforge.net/itk/ItkSoftwareGuide- 2.0.0.pdf?download  http://www.itk.org/CourseWare/Training/GettingStarted-I.pdf http://www.itk.org/CourseWare/Training/GettingStarted-I.pdf  Neurolib tutorial (excellent for research use of ITK) http://www.ia.unc.edu/dev/tutorials/InstallLib/index.htm University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 53

54 The End University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 54


Download ppt "Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Medical Imaging ITK."

Similar presentations


Ads by Google