ITK Input/Output Kitware Inc.. Overview IO Factory Mechanism Image File IO Transform File IO SpatialObject File IO Logger.

Slides:



Advertisements
Similar presentations
Doxygen. Links
Advertisements

ITK Architecture Kitware Inc.. ITK Basics C++ Generic Programming Data Pipeline Multi-threading Streaming Exceptions Events / Observers Tcl, Python and.
Getting Started with ITK + VTK
ITKv4 – Spatial Objects Arnaud Gelas – Luis Ibanez.
ITK Registration Methods
ITK-Overview Insight Software Consortium. What is ITK Image Processing Segmentation Registration No Graphical User Interface (GUI) No Visualization.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
1 CSE1303 Part A Data Structures and Algorithms Semester 2, 2006 Lecture A1 – Welcome & Revision.
Copyright © 2012 Pearson Education, Inc. Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)
Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering.
National Alliance for Medical Image Computing ITK The Image Segmentation and Registration Toolkit Julien Jomier Kitware Inc.
NA-MIC National Alliance for Medical Image Computing Slicer and ITK generic image reader module Alex Yarmarkovich.
CSci 6971: Image Registration Lecture 6: Getting Started with ITK January 30, 2004 Prof. Chuck Stewart, RPI Dr. Luis Ibanez, Kitware Prof. Chuck Stewart,
Copyright © 2012 Pearson Education, Inc. Chapter 3: Expressions and Interactivity.
CSci 6971: Image Registration Lecture 8: Registration Components February 6, 2004 Prof. Chuck Stewart, RPI Dr. Luis Ibanez, Kitware Prof. Chuck Stewart,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 15 - C++ As A "Better C" Outline 15.1Introduction.
CSci 6971: Image Registration Lecture 8: Image Resampling February 3, 2004 Prof. Chuck Stewart, RPI Dr. Luis Ibanez, Kitware Prof. Chuck Stewart, RPI Dr.
CSci 6971: Image Registration Lecture 10: Registration Components February 13, 2004 Prof. Chuck Stewart, RPI Dr. Luis Ibanez, Kitware Prof. Chuck Stewart,
Guide To UNIX Using Linux Third Edition
©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit.
Computational Tools for Image Processing Lecture 1, Jan 22nd, 2007 Part 2 (8:10-9:20pm) by Lexing Xie EE4830 Digital Image Processing
CLEO’s User Centric Data Access System Christopher D. Jones Cornell University.
GPU Acceleration in ITK v4
Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Medical Imaging ITK.
Image Registration Lecture 7: Getting Started with ITK March 15, 2005 Prof. Charlene Tsai.
HDF5 A new file format & software for high performance scientific data management.
© Paradigm Publishing Inc. 9-1 Chapter 9 Database and Information Management.
NA-MIC National Alliance for Medical Image Computing Slicer3 and the NA-MIC kit Sonia Pujol, Ph.D. Instructor of Radiology Surgical Planning.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
An Introduction to MINC John G. Sled. What is MINC? A medical image file format based on NetCDF A core set tools and libraries for image processing A.
Ch 10. Input/Output1 Ch. 10 Input/Output Oregon State University Timothy Budd.
Digital Cameras And Digital Information. How a Camera works Light passes through the lens Shutter opens for an instant Film is exposed to light Film is.
Program data (instance variables, local variables, and parameters) is transient, because its lifetime ends with the program...if not, before. Sometimes.
Programming into Slicer3. Sonia Pujol, Ph.D., Harvard Medical School -1- National Alliance for Medical Image Computing Programming into Slicer3 Sonia Pujol,
C++ Streams Lecture-2.
SimITK and SimVTK: ITK and VTK in Simulink DG Gobbi, P Mousavi, KM Li, J Xiang, A Campigotto, A LaPointe, G Fichtinger, P Abolmaesumi Medical Image Analysis.
Chapter 10C++ for Java Programmers1 Chapter 10 Input/Output.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
ITK Introduction and Overview Spring Topics  What Is ITK History Features  Software Engineering Methodology.
C++ Streams Lecture-2. C++ Streams Stream  A transfer of information in the form of a sequence of bytes I/O Operations:  Input stream: A stream that.
Slicer3 for developers – S.Pujol -1- National Alliance for Medical Image Computing Slicer3 Course for developers Sonia Pujol, Ph.D. Surgical Planning Laboratory.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 13 File Input and.
Surgical Planning Laboratory -1- Brigham and Women’s Hospital Converting DTI data into Nrrd file format Sonia Pujol, Ph.D. Gordon.
Basic I/O in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Stream Model of I/O header file: A stream provides a connection.
Module 4: I/O and Strings #1 2000/01Scientific Computing in OOCourse code 3C59 Module 4: I/O In this module we will cover Keyboard/screen input and output.
Expressions and Interactivity. 3.1 The cin Object.
1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image Analysis.
C++ REVIEW INPUT/OUTPUT (I/O). BRIEF NOTE “CLASSES” AND “STRUCTS” AND “TYPES” They are ADTs… They define data and operations on that data The ADTs in.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
ITK Basic Filters Kitware Inc.. ITK Basic Filters Pixel-wise Arithmetic, Casting, Thresholding Mathematical morphology Noise reduction Gaussian, Anisotropic.
Read a DICOM File typedef unsigned charInputPixelType; const unsigned intInputDimension = 2; typedef itk::Image InputImageType; typedef itk::ImageFileReader.
1 Putting Streams to use. 2 Stream Zoo C++ gives you istream, ostream, iostream, ifstream, ofstream, fstream, wistream, wifstream, istrsteam… (18) Java.
ITK Statistical Classification Kitware Inc.. Statistical Classification Multiple Components Images K-Means Markov Random Fields.
NA-MIC National Alliance for Medical Image Computing Three ways to use the NA-MIC kit Sonia Pujol, Ph.D. Instructor of Radiology Surgical.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
Insight Toolkit Introduction Luis Ibáñez William Schroeder Insight Software Consortium.
ITKv4 DICOM Status Mathieu Malaterre, Mark Roden Alexandre Gouaillard, William Ryan, Daniel Blezek.
ITK Video ITK Extensions for Video Processing
Introduction to C++ (Extensions to C)
ITKv4 – Spatial Objects Arnaud Gelas – Luis Ibanez
Slicer and ITK generic image reader module
Chapter 3: Expressions and Interactivity.
CHAPTER 5 JAVA FILE INPUT/OUTPUT
Fall 2010 Slide 1.
Outline Image formats and basic operations Image representation
Working with Strings Lecture 2 Hartmut Kaiser
ITK Architecture Kitware Inc..
Chapter 3: Input/Output
ITK Workshop Software Design October 5-8, 2005.
Presentation transcript:

ITK Input/Output Kitware Inc.

Overview IO Factory Mechanism Image File IO Transform File IO SpatialObject File IO Logger

IO Factory Mechanism

Why do we need a Factory? How many file formats can you list? … (and many more exist…)

Supported file formats 2D Only - JPEG (.jpg/.jpeg) - Bitmap (.bmp) - PNG (.png) 2D/3D - Analyze GIPL (.gipl) - RAW (.raw) - DICOM - GE 4x,5x - IPLCommon - MetaImage (.mha/.mhd) - Siemens - Stimulate - TIFF - VTKImage - NRRD - LSM - NIFTI

How does the Factory work? reading JPEGImageIO TIFFImageIO DICOMImageIO AnalyzeImageIO Image Filenameitk::Image Image IO Factory … Can you read this file?

How does the Factory work? writing JPEGImageIO TIFFImageIO DICOMImageIO AnalyzeImageIO Image Filename itk::Image Image IO Factory … Can you write this file?

Image File IO

Reading my first image #include typedef unsigned char PixelType; typedef itk::Image ImageType; itk::ImageFileReader ::Pointer reader = itk::ImageFileReader ::New(); reader->SetFileName(“lena.jpg”); try { reader->Update(); } catch (itk::ExceptionObject & e) { std::cerr GetOutput();

Writing my first image #include typedef unsigned char PixelType; typedef itk::Image ImageType; itk::ImageFileWriter ::Pointer writer = itk::ImageFileWriter ::New(); writer->SetFileName(“lena.jpg”); writer->SetInput(image); try { writer- >Update(); } catch (itk::ExceptionObject & e) { std::cerr << e.GetDescription() << std::endl; return EXIT_FAILURE; }

My file format converter itk::ImageFileReader ::Pointer reader = itk::ImageFileReader ::New(); itk::ImageFileWriter ::Pointer writer = itk::ImageFileWriter ::New(); reader->SetFileName(“myImage.jpg”) writer->SetFileName(“myImage.tiff”); writer->SetInput(reader->GetOutput()); try { writer- >Update(); } catch (itk::ExceptionObject & e) { std::cerr << e.GetDescription() << std::endl; return EXIT_FAILURE; }

How to avoid using the Factory? #include itk::TIFFImageIO::Pointer tiffImageIO = itk::TIFFImageIO::New(); reader->SetFilename(“myimage.tiff”); reader->SetImageIO(tiffImageIO); reader->Update(); I know the type of images I want to read/write Factory can be slow

Reading RAW images #include itk::RawImageIO ::Pointer io; io = itk::RawImageIO ::New(); io->SetFileName(“myimage.raw”); unsigned int dim[2] = {800,60}; double spacing[2] = {0.8, 0.8}; double origin[2] = {0.0,0.0}; for(unsigned int i=0; i SetDimensions(i,dim[i]); io->SetSpacing(i,spacing[i]); io->SetOrigin(i,origin[i]); } io->SetHeaderSize(0); io->SetByteOrderToLittleEndian(); io->SetPixelType(itk::ImageIOBase::SCALAR); io->SetNumberOfComponents(1);

Reading RAW images (2) itk::ImageFileReader ::Pointer reader = itk::ImageFileReader ::New(); reader->SetFileName(“myImage.raw”); reader->SetImageIO(io); try { reader->Update(); } catch (itk::ExceptionObject & e) { std::cerr << e.GetDescription() << std::endl; return EXIT_FAILURE; }

Creating a MetaImage Header NDims = 3 DimSize = ElementSpacing = ElementType = MET_UCHAR ElementByteOrderMSB = False ElementDataFile = HeadMRVolume.raw OR ElementDataFile = HeadMRVolume%04d.raw Create a simple text file with the.mhd extension Set the appropriate MetaData Example:

Dealing with DICOM images Often consists of several files Uses the GDCM library GDCMSeriesFileNames to construct the serie: 1. Image Orientation & Image Position 2. 'Image Number‘ 3. Lexicographical order

Reading DICOM images // Select the correct files from the directory typedef itk::ImageSeriesReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); typedef itk::GDCMSeriesFileNames NamesGeneratorType; NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New(); nameGenerator->SetUseSeriesDetails( true ); nameGenerator->SetDirectory( “./MyDirectory/” ); typedef std::vector FileNamesContainer; FileNamesContainer fileNames; fileNames = nameGenerator->GetFileNames( seriesIdentifier ); reader->SetFileNames( fileNames ); // Set the DicomIO typedef itk::GDCMImageIO ImageIOType; ImageIOType::Pointer dicomIO = ImageIOType::New(); reader->SetImageIO( dicomIO ); reader->Update();

More on Series Filenames NumericSeriesFilenames - ordered sequence of filenames - unique, non-negative, integral value - Set(Start/End)Index and SetIncrementIndex() RegularExpressionSeriesFilenames - ordered sequence that matches RegEx - ordered by submatch or numerically

Metadata

MetaData Extra information attached to an image itk::Image defines: - Spacing (size of the voxels in mm) - Origin (physical location of (0,0,0)) - Size (size of the largest region of the image) - Orientation (direction cosines)

MetaData Dictionary itkMetaDataDictionary Filled in by the reader (when available) Not passed through the filters Accessing the dictionary: ImageType::Pointer image = reader->GetOutput(); typedef itk::MetaDataDictionary DictionaryType; DictionaryType & dictionary = image->GetMetaDataDictionary();

Transform File IO

Transform IO Special ITK File format Uses IO Factory Write Parameters of the transforms as well as Fixed Parameters Concatenation of transforms in a single file

Write Transform Example #include "itkTransformFileWriter.h” #include "itkAffineTransform.h” typedef itk::AffineTransform AffineTransformType; AffineTransformType::Pointer affine = AffineTransformType::New(); itk::TransformFileWriter::Pointer writer; writer = itk::TransformFileWriter::New(); writer->AddTransform(affine); writer->SetFileName( “AffineTransform.txt" ); try { writer->Update(); } catch( itk::ExceptionObject & excp ) { std::cerr << excp << std::endl; return EXIT_FAILURE; }

Read Transform Example #include "itkTransformFileReader.h” itk::TransformFileReader::Pointer reader; reader = itk::TransformFileReader::New(); reader->SetFileName( “AffineTransform.txt" ); reader->Update(); typedef itk::TransformFileReader::TransformListType * TransformListType; TransformListType transforms = reader->GetTransformList(); itk::TransformFileReader::TransformListType::const_iterator it; it = transforms->begin(); if(!strcmp((*it)->GetNameOfClass(),"AffineTransform")) { AffineTransformType::Pointer affineTransform = static_cast ((*it).GetPointer()); }

Object File IO

Spatial Objects Represents Physical Objects (not only images) Scene Graph Concept Common coordinate frame Support a common IO framework through MetaIO

Spatial Object Example Liver Tumor Blood Vessels Abdomen Kidneys

Spatial Objects IO Uses the IO Factory Uses MetaIO file format Conversion is done internally Concatenation of objects in a single file Easy to extend

Writing Spatial Objects #include "itkSpatialObjectWriter.h” #include "itkEllipseSpatialObject.h” typedef itk::EllipseSpatialObject SphereType; SphereType::Pointer sphere = SphereType::New(); sphere->SetRadius(2); typedef itk::SpatialObjectWriter WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetInput(sphere); writer->SetFileName("ellipse.meta"); writer->Update();

Reading Spatial Objects #include "itkSpatialObjectReader.h” typedef itk::SpatialObjectReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName("ellipse.meta"); reader->Update(); // Return an itk::SceneSpatialObject with all the objects in the file ReaderType::ScenePointer scene = reader->GetScene(); // Return an itk::GroupSpatialObject with all the objects in the file ReaderType::GroupPointer group = reader->GetGroup(); ReaderType::SceneType::ObjectListType * sceneChildren = scene->GetObjects(999); ReaderType::SceneType::ObjectListType::const_iterator objectIterator; objectIterator = sceneChildren->begin(); if(!strcmp((* objectIterator)->GetTypeName(),“EllipseSpatialObject")) { SphereType::Pointer sphere = dynamic_cast ((*objectIterator).GetPointer()); }

Writing an itkMesh #include "itkSpatialObjectWriter.h” #include "itkMeshSpatialObject.h” typedef itk::DefaultDynamicMeshTraits MeshTrait; typedef itk::Mesh MeshType; MeshType::Pointer mesh = MeshType::New(); // Create the mesh Spatial Object MeshSpatialObjectType::Pointer meshSO = MeshSpatialObjectType::New(); meshSO->SetMesh(mesh); // Writing the file typedef itk::SpatialObjectWriter WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetInput(meshSO); writer->SetFileName("metamesh.txt"); writer->Update();

Logging Capabilities

Logger Record output information and send the output to a stream (or multiple streams) Priority Level (Fatal, Critical, Warning, Info, Debug…) AddLogOutput() : attach an output stream to the logger Write() : send information to the logger

Logger in use #include #include itk::Logger::Pointer logger = itk::Logger::New(); itk::StdStreamLogOutput::Pointer output = itk::StdStreamLogOutput::New(); output->SetStream(std::cout); logger->SetName(“MyLogger”); logger->SetPriorityLevel(itk::LoggerBase::INFO); logger->SetLevelForFlushing(itk::LoggerBase::CRITICAL); logger->AddLogOutput(output); logger->Write(itk::LoggerBase::INFO, "This is the INFO message.\n");

Logger Manager Centralize several loggers AddLogger() CreateLogger() / CreateThreadLogger Write() Flush()

References Culp, Timothy R. "Industrial Strength Pluggable Object Factories". C++ Report Online. ArticleID= ArticleID=1520 P. Chandra, L. Ibanez, "ImageIO: Design of an Extensible Image Input/Output Library", ACM Crossroad online magazine, April Available online at 4/imageIO.htmlhttp:// 4/imageIO.html E. Gamma, R. Helm, R. Johnson, J. Vlissides, "Design Patterns", Addison Wesley, 1995.

Enjoy ITK !