SimpleITK  
Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
itk::simple::ImageFileReader Class Reference

Read an image file and return a SimpleITK Image. More...

#include <sitkImageFileReader.h>

+ Inheritance diagram for itk::simple::ImageFileReader:
+ Collaboration diagram for itk::simple::ImageFileReader:

Public Types

using Self = ImageFileReader
 
- Public Types inherited from itk::simple::ImageReaderBase
using Self = ImageReaderBase
 
- Public Types inherited from itk::simple::ProcessObject
using Self = ProcessObject
 

Public Member Functions

Image Execute () override
 Set/Get The output PixelType of the image. More...
 
const std::vector< int > & GetExtractIndex () const
 
const std::vector< unsigned int > & GetExtractSize () const
 
std::string GetFileName () const
 
std::string GetMetaData (const std::string &key) const
 Get the value of a meta-data dictionary entry as a string. More...
 
std::vector< std::string > GetMetaDataKeys () const
 Get the meta-data dictionary keys. More...
 
std::string GetName () const override
 
bool HasMetaDataKey (const std::string &key) const
 Query a meta-data dictionary for the existence of a key. More...
 
 ImageFileReader ()
 
void ReadImageInformation ()
 Read only the meta-data and image information in the file. More...
 
SelfSetExtractIndex (const std::vector< int > &index)
 starting index from the image on disk to extract. More...
 
SelfSetExtractSize (const std::vector< unsigned int > &size)
 size of image to extract from file. More...
 
SelfSetFileName (const std::string &fn)
 
std::string ToString () const override
 
 ~ImageFileReader () override
 
PixelIDValueEnum GetPixelID () const
 Image information methods updated via ReadImageInformation. More...
 
PixelIDValueType GetPixelIDValue () const
 Image information methods updated via ReadImageInformation. More...
 
unsigned int GetDimension () const
 Image information methods updated via ReadImageInformation. More...
 
unsigned int GetNumberOfComponents () const
 Image information methods updated via ReadImageInformation. More...
 
const std::vector< double > & GetOrigin () const
 Image information methods updated via ReadImageInformation. More...
 
const std::vector< double > & GetSpacing () const
 Image information methods updated via ReadImageInformation. More...
 
const std::vector< double > & GetDirection () const
 Image information methods updated via ReadImageInformation. More...
 
const std::vector< uint64_t > & GetSize () const
 Image information methods updated via ReadImageInformation. More...
 
- Public Member Functions inherited from itk::simple::ImageReaderBase
 ImageReaderBase ()
 
 ~ImageReaderBase () override
 
SelfSetOutputPixelType (PixelIDValueEnum pixelID)
 Set/Get The output PixelType of the image. More...
 
PixelIDValueEnum GetOutputPixelType () const
 Set/Get The output PixelType of the image. More...
 
std::string ToString () const override
 Set/Get The output PixelType of the image. More...
 
virtual std::vector< std::string > GetRegisteredImageIOs () const
 Get a vector of the names of registered itk ImageIOs. More...
 
virtual SelfSetLoadPrivateTags (bool loadPrivateTags)
 Set/Get loading private DICOM tags into Image's MetaData. More...
 
virtual bool GetLoadPrivateTags () const
 Set/Get The output PixelType of the image. More...
 
virtual void LoadPrivateTagsOn ()
 Set/Get The output PixelType of the image. More...
 
virtual void LoadPrivateTagsOff ()
 Set/Get The output PixelType of the image. More...
 
virtual SelfSetImageIO (const std::string &imageio)
 Set/Get name of ImageIO to use. More...
 
virtual std::string GetImageIO () const
 Set/Get The output PixelType of the image. More...
 
- Public Member Functions inherited from itk::simple::ProcessObject
virtual void Abort ()
 
virtual int AddCommand (itk::simple::EventEnum event, const std::function< void()> &func)
 Directly add a callback to observe an event. More...
 
virtual int AddCommand (itk::simple::EventEnum event, itk::simple::Command &cmd)
 Add a Command Object to observer the event. More...
 
virtual float GetProgress () const
 An Active Measurement of the progress of execution. More...
 
virtual bool HasCommand (itk::simple::EventEnum event) const
 Query of this object has any registered commands for event. More...
 
 ProcessObject ()
 
virtual void RemoveAllCommands ()
 Remove all registered commands. More...
 
virtual ~ProcessObject ()
 
virtual void DebugOn ()
 
virtual void DebugOff ()
 
virtual bool GetDebug () const
 
virtual void SetDebug (bool debugFlag)
 
virtual void SetNumberOfThreads (unsigned int n)
 
virtual unsigned int GetNumberOfThreads () const
 
virtual void SetNumberOfWorkUnits (unsigned int n)
 
virtual unsigned int GetNumberOfWorkUnits () const
 

Protected Member Functions

template<class TImageType >
Image ExecuteInternal (itk::ImageIOBase *)
 
void UpdateImageInformationFromImageIO (const itk::ImageIOBase *iobase)
 
- Protected Member Functions inherited from itk::simple::ImageReaderBase
itk::SmartPointer< ImageIOBaseGetImageIOBase (const std::string &fileName)
 Set/Get The output PixelType of the image. More...
 
void GetPixelIDFromImageIO (const std::string &fileName, PixelIDValueType &outPixelType, unsigned int &outDimensions)
 Set/Get The output PixelType of the image. More...
 
void GetPixelIDFromImageIO (const itk::ImageIOBase *iobase, PixelIDValueType &outPixelType, unsigned int &outDimensions)
 Set/Get The output PixelType of the image. More...
 
unsigned int GetDimensionFromImageIO (const std::string &fileName, unsigned int i)
 Set/Get The output PixelType of the image. More...
 
unsigned int GetDimensionFromImageIO (const itk::ImageIOBase *iobase, unsigned int i)
 Set/Get The output PixelType of the image. More...
 
- Protected Member Functions inherited from itk::simple::ProcessObject
virtual unsigned long AddITKObserver (const itk::EventObject &, itk::Command *)
 
virtual itk::ProcessObjectGetActiveProcess ()
 
virtual void OnActiveProcessDelete ()
 
virtual void onCommandDelete (const itk::simple::Command *cmd) noexcept
 
virtual void PreUpdate (itk::ProcessObject *p)
 
virtual void RemoveITKObserver (EventCommand &e)
 
- Protected Member Functions inherited from itk::simple::NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 

Private Types

typedef Image(Self::* MemberFunctionType) (itk::ImageIOBase *)
 

Private Member Functions

template<class TImageType , class TInternalImageType >
Image ExecuteExtract (TInternalImageType *itkImage)
 

Private Attributes

unsigned int m_Dimension
 
std::vector< double > m_Direction
 
std::vector< int > m_ExtractIndex
 
std::vector< unsigned int > m_ExtractSize
 
std::string m_FileName
 
std::unique_ptr< detail::MemberFunctionFactory< MemberFunctionType > > m_MemberFactory
 
std::unique_ptr< MetaDataDictionarym_MetaDataDictionary
 
unsigned int m_NumberOfComponents
 
std::vector< double > m_Origin
 
std::function< std::string(const std::string &)> m_pfGetMetaData
 
std::function< std::vector< std::string >)> m_pfGetMetaDataKeys
 
std::function< bool(const std::string &)> m_pfHasMetaDataKey
 
PixelIDValueEnum m_PixelType
 
std::vector< uint64_t > m_Size
 
std::vector< double > m_Spacing
 

Friends

struct detail::MemberFunctionAddressor< MemberFunctionType >
 

Additional Inherited Members

- Static Public Member Functions inherited from itk::simple::ImageReaderBase
static std::string GetImageIOFromFileName (const std::string &fileName)
 Get the automatic ImageIO from the ImageIOFactory. More...
 
- Static Public Member Functions inherited from itk::simple::ProcessObject
static bool GetGlobalDefaultDebug ()
 
static void GlobalDefaultDebugOff ()
 
static void GlobalDefaultDebugOn ()
 
static void SetGlobalDefaultDebug (bool debugFlag)
 
static void GlobalWarningDisplayOn ()
 
static void GlobalWarningDisplayOff ()
 
static void SetGlobalWarningDisplay (bool flag)
 
static bool GetGlobalWarningDisplay ()
 
static double GetGlobalDefaultCoordinateTolerance ()
 Access the global tolerance to determine congruent spaces. More...
 
static void SetGlobalDefaultCoordinateTolerance (double)
 Access the global tolerance to determine congruent spaces. More...
 
static double GetGlobalDefaultDirectionTolerance ()
 Access the global tolerance to determine congruent spaces. More...
 
static void SetGlobalDefaultDirectionTolerance (double)
 Access the global tolerance to determine congruent spaces. More...
 
static bool SetGlobalDefaultThreader (const std::string &threader)
 Set/Get the default threader used for process objects. More...
 
static std::string GetGlobalDefaultThreader ()
 Set/Get the default threader used for process objects. More...
 
static void SetGlobalDefaultNumberOfThreads (unsigned int n)
 
static unsigned int GetGlobalDefaultNumberOfThreads ()
 Set/Get the default threader used for process objects. More...
 
- Static Protected Member Functions inherited from itk::simple::ProcessObject
template<class TImageType >
static TImageType::ConstPointer CastImageToITK (const Image &img)
 
template<class TPixelType , unsigned int VImageDimension, unsigned int VLength, template< typename, unsigned int > class TVector>
static Image CastITKToImage (itk::Image< TVector< TPixelType, VLength >, VImageDimension > *img)
 
template<unsigned int VImageDimension, unsigned int VLength, template< unsigned int > class TVector>
static Image CastITKToImage (itk::Image< TVector< VLength >, VImageDimension > *img)
 
template<class TImageType >
static Image CastITKToImage (TImageType *img)
 
static const itk::EventObjectGetITKEventObject (EventEnum e)
 
template<typename T >
static std::ostream & ToStringHelper (std::ostream &os, const T &v)
 
static std::ostream & ToStringHelper (std::ostream &os, const char &v)
 
static std::ostream & ToStringHelper (std::ostream &os, const signed char &v)
 
static std::ostream & ToStringHelper (std::ostream &os, const unsigned char &v)
 

Detailed Description

Read an image file and return a SimpleITK Image.

The reader can handle scalar images, and vector images. Pixel types such as RGB, RGBA are loaded as multi-component images with vector pixel types. Additionally, tensor images are loaded with the pixel type being a 1-d vector.

An interface is also provided to access the information from the underlying itk::ImageIO. This information can be loaded with the ReadImageInformation method. The information is from the itk::ImageIO interface. In some degenerate cases reading the bulk data may produce different results. Please see itk::ImageFileReader for more details.

Reading takes place by the ITK ImageIO factory mechanism. ITK contains many ImageIO classes which are responsible for reading separate file formats. By default, each ImageIO is asked if it "can read" the file, and the first one which "can read" the format is used. The list of available ImageIOs can be obtained using the GetRegisteredImageIOs method. The ImageIO used can be overridden with the SetImageIO method. This is useful in cases when multiple ImageIOs "can read" the file and the user wants to select a specific IO (not the first).

See also
itk::simple::ReadImage for the procedural interface
Examples
CppInPlace/CppInPlace.cxx, Elastix/elx.cxx, Elastix/tfx.cxx, FilterProgressReporting/FilterProgressReporting.cxx, ImageIOSelection/ImageIOSelection.cxx, ITKIntegration/ITKIntegration.cxx, Segmentation/ConnectedThresholdImageFilter.cxx, Segmentation/NeighborhoodConnectedImageFilter.cxx, SimpleGaussian/SimpleGaussian.cxx, and SimpleIO/SimpleIO.cxx.

Definition at line 60 of file sitkImageFileReader.h.

Member Typedef Documentation

◆ MemberFunctionType

typedef Image(Self::* itk::simple::ImageFileReader::MemberFunctionType) (itk::ImageIOBase *)
private

Definition at line 200 of file sitkImageFileReader.h.

◆ Self

Definition at line 64 of file sitkImageFileReader.h.

Constructor & Destructor Documentation

◆ ~ImageFileReader()

itk::simple::ImageFileReader::~ImageFileReader ( )
override

◆ ImageFileReader()

itk::simple::ImageFileReader::ImageFileReader ( )

Member Function Documentation

◆ Execute()

Image itk::simple::ImageFileReader::Execute ( )
overridevirtual

Set/Get The output PixelType of the image.

By default the value is sitkUnknown, which enable the output pixel type to be same as the file. If the pixel type is specified then the itk::ConvertPixelBuffer will be used to convert the pixels.

Implements itk::simple::ImageReaderBase.

Examples
CppInPlace/CppInPlace.cxx, Elastix/elx.cxx, Elastix/tfx.cxx, FilterProgressReporting/FilterProgressReporting.cxx, ImageIOSelection/ImageIOSelection.cxx, ITKIntegration/ITKIntegration.cxx, Segmentation/ConnectedThresholdImageFilter.cxx, Segmentation/NeighborhoodConnectedImageFilter.cxx, SimpleGaussian/SimpleGaussian.cxx, and SimpleIO/SimpleIO.cxx.

◆ ExecuteExtract()

template<class TImageType , class TInternalImageType >
Image itk::simple::ImageFileReader::ExecuteExtract ( TInternalImageType *  itkImage)
private

◆ ExecuteInternal()

template<class TImageType >
Image itk::simple::ImageFileReader::ExecuteInternal ( itk::ImageIOBase )
protected

◆ GetDimension()

unsigned int itk::simple::ImageFileReader::GetDimension ( ) const

Image information methods updated via ReadImageInformation.

These accessor methods are valid after a call to ReadImageInformation or Execute. They contain the image information from the file via the itk::ImageIO. Information such as NumberOfComponents is based of the file format, so the number of components for internal types such as RGB or complex may not be described the same as with SimpleITK's Image interface.

The PixelID has been converted from the ITK type to SimpleITK's interpretation, and will not change when loaded as a SimpleITK Image.

◆ GetDirection()

const std::vector<double>& itk::simple::ImageFileReader::GetDirection ( ) const

Image information methods updated via ReadImageInformation.

These accessor methods are valid after a call to ReadImageInformation or Execute. They contain the image information from the file via the itk::ImageIO. Information such as NumberOfComponents is based of the file format, so the number of components for internal types such as RGB or complex may not be described the same as with SimpleITK's Image interface.

The PixelID has been converted from the ITK type to SimpleITK's interpretation, and will not change when loaded as a SimpleITK Image.

◆ GetExtractIndex()

const std::vector<int>& itk::simple::ImageFileReader::GetExtractIndex ( ) const

◆ GetExtractSize()

const std::vector<unsigned int>& itk::simple::ImageFileReader::GetExtractSize ( ) const

◆ GetFileName()

std::string itk::simple::ImageFileReader::GetFileName ( ) const

◆ GetMetaData()

std::string itk::simple::ImageFileReader::GetMetaData ( const std::string &  key) const

Get the value of a meta-data dictionary entry as a string.

If the key is not in the dictionary then an exception is thrown.

String types in the dictionary are returned as their native string. Other types are printed to string before returning.

◆ GetMetaDataKeys()

std::vector<std::string> itk::simple::ImageFileReader::GetMetaDataKeys ( ) const

Get the meta-data dictionary keys.

This is only valid after successful ReadImageInformation or Execute of this filter.

Returns a vector of keys to the key/value entries in the file's meta-data dictionary. Iterate through with these keys to get the values.

◆ GetName()

std::string itk::simple::ImageFileReader::GetName ( ) const
inlineoverridevirtual

return user readable name of the filter

Implements itk::simple::ProcessObject.

Definition at line 74 of file sitkImageFileReader.h.

◆ GetNumberOfComponents()

unsigned int itk::simple::ImageFileReader::GetNumberOfComponents ( ) const

Image information methods updated via ReadImageInformation.

These accessor methods are valid after a call to ReadImageInformation or Execute. They contain the image information from the file via the itk::ImageIO. Information such as NumberOfComponents is based of the file format, so the number of components for internal types such as RGB or complex may not be described the same as with SimpleITK's Image interface.

The PixelID has been converted from the ITK type to SimpleITK's interpretation, and will not change when loaded as a SimpleITK Image.

◆ GetOrigin()

const std::vector<double>& itk::simple::ImageFileReader::GetOrigin ( ) const

Image information methods updated via ReadImageInformation.

These accessor methods are valid after a call to ReadImageInformation or Execute. They contain the image information from the file via the itk::ImageIO. Information such as NumberOfComponents is based of the file format, so the number of components for internal types such as RGB or complex may not be described the same as with SimpleITK's Image interface.

The PixelID has been converted from the ITK type to SimpleITK's interpretation, and will not change when loaded as a SimpleITK Image.

◆ GetPixelID()

PixelIDValueEnum itk::simple::ImageFileReader::GetPixelID ( ) const

Image information methods updated via ReadImageInformation.

These accessor methods are valid after a call to ReadImageInformation or Execute. They contain the image information from the file via the itk::ImageIO. Information such as NumberOfComponents is based of the file format, so the number of components for internal types such as RGB or complex may not be described the same as with SimpleITK's Image interface.

The PixelID has been converted from the ITK type to SimpleITK's interpretation, and will not change when loaded as a SimpleITK Image.

◆ GetPixelIDValue()

PixelIDValueType itk::simple::ImageFileReader::GetPixelIDValue ( ) const

Image information methods updated via ReadImageInformation.

These accessor methods are valid after a call to ReadImageInformation or Execute. They contain the image information from the file via the itk::ImageIO. Information such as NumberOfComponents is based of the file format, so the number of components for internal types such as RGB or complex may not be described the same as with SimpleITK's Image interface.

The PixelID has been converted from the ITK type to SimpleITK's interpretation, and will not change when loaded as a SimpleITK Image.

◆ GetSize()

const std::vector<uint64_t>& itk::simple::ImageFileReader::GetSize ( ) const

Image information methods updated via ReadImageInformation.

These accessor methods are valid after a call to ReadImageInformation or Execute. They contain the image information from the file via the itk::ImageIO. Information such as NumberOfComponents is based of the file format, so the number of components for internal types such as RGB or complex may not be described the same as with SimpleITK's Image interface.

The PixelID has been converted from the ITK type to SimpleITK's interpretation, and will not change when loaded as a SimpleITK Image.

◆ GetSpacing()

const std::vector<double>& itk::simple::ImageFileReader::GetSpacing ( ) const

Image information methods updated via ReadImageInformation.

These accessor methods are valid after a call to ReadImageInformation or Execute. They contain the image information from the file via the itk::ImageIO. Information such as NumberOfComponents is based of the file format, so the number of components for internal types such as RGB or complex may not be described the same as with SimpleITK's Image interface.

The PixelID has been converted from the ITK type to SimpleITK's interpretation, and will not change when loaded as a SimpleITK Image.

◆ HasMetaDataKey()

bool itk::simple::ImageFileReader::HasMetaDataKey ( const std::string &  key) const

Query a meta-data dictionary for the existence of a key.

◆ ReadImageInformation()

void itk::simple::ImageFileReader::ReadImageInformation ( )

Read only the meta-data and image information in the file.

This method can be used to determine what the size and pixel type of an image file is without reading the whole image. Even if SimpleITK does not support an image of a certain dimension or type, the meta-information can still be read.

◆ SetExtractIndex()

Self& itk::simple::ImageFileReader::SetExtractIndex ( const std::vector< int > &  index)

starting index from the image on disk to extract.

Missing dimensions are treated the same as 0.

/sa ExtractImageFilter

◆ SetExtractSize()

Self& itk::simple::ImageFileReader::SetExtractSize ( const std::vector< unsigned int > &  size)

size of image to extract from file.

By default the reader loads the entire image, this is specified when the size has zero length.

If specified, then the image returned from Execute will be of this size. If the ImageIO and file support reading just a region, then the reader will perform streaming.

The dimension of the image can be reduced by specifying a dimension's size as 0. For example a size of $[10,20,30,0,0]$ results in a 3D image with size of $[10,20,30]$. This enables reading a 5D image into a 3D image. If the length of the specified size is greater than the dimension of the image file, an exception will be generated. If the size's length is less than the image's dimension then the missing values are assumed to be zero.

When the dimension of the image is reduced, the direction cosine matrix will be set to the identity. However, the spacing for the selected axis will remain. The matrix from the file can still be obtained by ImageFileReader::GetDirection.

/sa ExtractImageFilter

◆ SetFileName()

Self& itk::simple::ImageFileReader::SetFileName ( const std::string &  fn)

◆ ToString()

std::string itk::simple::ImageFileReader::ToString ( ) const
overridevirtual

Print ourselves to string

Reimplemented from itk::simple::ProcessObject.

Examples
ImageIOSelection/ImageIOSelection.cxx.

◆ UpdateImageInformationFromImageIO()

void itk::simple::ImageFileReader::UpdateImageInformationFromImageIO ( const itk::ImageIOBase iobase)
protected

Internal method which update's this classes stored meta-data and image information.

Friends And Related Function Documentation

◆ detail::MemberFunctionAddressor< MemberFunctionType >

Definition at line 203 of file sitkImageFileReader.h.

Member Data Documentation

◆ m_Dimension

unsigned int itk::simple::ImageFileReader::m_Dimension
private

Definition at line 216 of file sitkImageFileReader.h.

◆ m_Direction

std::vector<double> itk::simple::ImageFileReader::m_Direction
private

Definition at line 218 of file sitkImageFileReader.h.

◆ m_ExtractIndex

std::vector<int> itk::simple::ImageFileReader::m_ExtractIndex
private

Definition at line 225 of file sitkImageFileReader.h.

◆ m_ExtractSize

std::vector<unsigned int> itk::simple::ImageFileReader::m_ExtractSize
private

Definition at line 224 of file sitkImageFileReader.h.

◆ m_FileName

std::string itk::simple::ImageFileReader::m_FileName
private

Definition at line 211 of file sitkImageFileReader.h.

◆ m_MemberFactory

std::unique_ptr<detail::MemberFunctionFactory<MemberFunctionType> > itk::simple::ImageFileReader::m_MemberFactory
private

Definition at line 204 of file sitkImageFileReader.h.

◆ m_MetaDataDictionary

std::unique_ptr<MetaDataDictionary> itk::simple::ImageFileReader::m_MetaDataDictionary
private

Definition at line 213 of file sitkImageFileReader.h.

◆ m_NumberOfComponents

unsigned int itk::simple::ImageFileReader::m_NumberOfComponents
private

Definition at line 217 of file sitkImageFileReader.h.

◆ m_Origin

std::vector<double> itk::simple::ImageFileReader::m_Origin
private

Definition at line 219 of file sitkImageFileReader.h.

◆ m_pfGetMetaData

std::function<std::string(const std::string &)> itk::simple::ImageFileReader::m_pfGetMetaData
private

Definition at line 209 of file sitkImageFileReader.h.

◆ m_pfGetMetaDataKeys

std::function<std::vector<std::string>)> itk::simple::ImageFileReader::m_pfGetMetaDataKeys
private

Definition at line 207 of file sitkImageFileReader.h.

◆ m_pfHasMetaDataKey

std::function<bool(const std::string &)> itk::simple::ImageFileReader::m_pfHasMetaDataKey
private

Definition at line 208 of file sitkImageFileReader.h.

◆ m_PixelType

PixelIDValueEnum itk::simple::ImageFileReader::m_PixelType
private

Definition at line 215 of file sitkImageFileReader.h.

◆ m_Size

std::vector<uint64_t> itk::simple::ImageFileReader::m_Size
private

Definition at line 222 of file sitkImageFileReader.h.

◆ m_Spacing

std::vector<double> itk::simple::ImageFileReader::m_Spacing
private

Definition at line 220 of file sitkImageFileReader.h.


The documentation for this class was generated from the following file: