SimpleITK
|
Read an image file and return a SimpleITK Image. More...
#include <sitkImageFileReader.h>
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).
Definition at line 74 of file sitkImageFileReader.h.
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 |
PathType | 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... | |
Self & | SetExtractIndex (const std::vector< int > &index) |
starting index from the image on disk to extract. More... | |
Self & | SetExtractSize (const std::vector< unsigned int > &size) |
size of image to extract from file. More... | |
Self & | SetFileName (const PathType &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 | |
Self & | SetOutputPixelType (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 Self & | SetLoadPrivateTags (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 Self & | SetImageIO (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< ImageIOBase > | GetImageIOBase (const PathType &fileName) |
Set/Get The output PixelType of the image. More... | |
void | GetPixelIDFromImageIO (const PathType &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 PathType &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::ProcessObject * | GetActiveProcess () |
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 | |
NonCopyable & | operator= (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 |
PathType | m_FileName |
std::unique_ptr< detail::MemberFunctionFactory< MemberFunctionType > > | m_MemberFactory |
std::unique_ptr< MetaDataDictionary > | m_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 PathType &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::EventObject & | GetITKEventObject (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) |
|
private |
Definition at line 239 of file sitkImageFileReader.h.
Definition at line 77 of file sitkImageFileReader.h.
|
override |
itk::simple::ImageFileReader::ImageFileReader | ( | ) |
|
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.
|
private |
|
protected |
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.
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.
const std::vector<int>& itk::simple::ImageFileReader::GetExtractIndex | ( | ) | const |
const std::vector<unsigned int>& itk::simple::ImageFileReader::GetExtractSize | ( | ) | const |
PathType itk::simple::ImageFileReader::GetFileName | ( | ) | const |
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.
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.
|
inlineoverridevirtual |
return user readable name of the filter
Implements itk::simple::ProcessObject.
Definition at line 89 of file sitkImageFileReader.h.
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.
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.
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.
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.
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.
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.
bool itk::simple::ImageFileReader::HasMetaDataKey | ( | const std::string & | key | ) | const |
Query a meta-data dictionary for the existence of a key.
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.
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.
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.
|
overridevirtual |
Print ourselves to string
Reimplemented from itk::simple::ProcessObject.
|
protected |
Internal method which update's this classes stored meta-data and image information.
|
friend |
Definition at line 242 of file sitkImageFileReader.h.
|
private |
Definition at line 255 of file sitkImageFileReader.h.
|
private |
Definition at line 257 of file sitkImageFileReader.h.
|
private |
Definition at line 264 of file sitkImageFileReader.h.
|
private |
Definition at line 263 of file sitkImageFileReader.h.
|
private |
Definition at line 250 of file sitkImageFileReader.h.
|
private |
Definition at line 243 of file sitkImageFileReader.h.
|
private |
Definition at line 252 of file sitkImageFileReader.h.
|
private |
Definition at line 256 of file sitkImageFileReader.h.
|
private |
Definition at line 258 of file sitkImageFileReader.h.
|
private |
Definition at line 248 of file sitkImageFileReader.h.
|
private |
Definition at line 246 of file sitkImageFileReader.h.
|
private |
Definition at line 247 of file sitkImageFileReader.h.
|
private |
Definition at line 254 of file sitkImageFileReader.h.
|
private |
Definition at line 261 of file sitkImageFileReader.h.
|
private |
Definition at line 259 of file sitkImageFileReader.h.