Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::ItkImageIO Class Reference

Wraps ITK image IO objects as mitk::IFileReader and mitk::IFileWriter objects. More...

#include <mitkItkImageIO.h>

Inheritance diagram for mitk::ItkImageIO:
Collaboration diagram for mitk::ItkImageIO:

Public Member Functions

 ItkImageIO (itk::ImageIOBase::Pointer imageIO)
 Construct an ItkImageIO from an ITK ImageIO instance. More...
 
 ItkImageIO (const CustomMimeType &mimeType, itk::ImageIOBase::Pointer imageIO, int rank)
 Construct an ItkImageIO with a custom MIME type and rank. More...
 
ConfidenceLevel GetReaderConfidenceLevel () const override
 Get the confidence level for reading the current file. More...
 
void Write () override
 Write the input data to file. More...
 
ConfidenceLevel GetWriterConfidenceLevel () const override
 Get the confidence level for writing the current data. More...
 
std::vector< itk::SmartPointer< BaseData > > Read () override
 Read data and create a list of BaseData objects. More...
 
DataStorage::SetOfObjects::Pointer Read (mitk::DataStorage &ds) override
 Read data and add it to the given DataStorage. More...
 
- Public Member Functions inherited from mitk::AbstractFileIO
Options GetReaderOptions () const
 Get the reader-specific options. More...
 
us::Any GetReaderOption (const std::string &name) const
 Get the value of a specific reader option. More...
 
void SetReaderOptions (const Options &options)
 Set multiple reader options at once. More...
 
void SetReaderOption (const std::string &name, const us::Any &value)
 Set a single reader option. More...
 
Options GetWriterOptions () const
 Get the writer-specific options. More...
 
us::Any GetWriterOption (const std::string &name) const
 Get the value of a specific writer option. More...
 
void SetWriterOptions (const Options &options)
 Set multiple writer options at once. More...
 
void SetWriterOption (const std::string &name, const us::Any &value)
 Set a single writer option. More...
 
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService (us::ModuleContext *context=us::GetModuleContext())
 Register both reader and writer as CppMicroServices services. More...
 
- Public Member Functions inherited from mitk::AbstractFileIOReader
ConfidenceLevel GetConfidenceLevel () const override
 Get the confidence level of this reader or writer for the current input. More...
 
- Public Member Functions inherited from mitk::AbstractFileReader
void SetInput (const std::string &location) override
 Set the input file path, clearing any previously set input stream. More...
 
void SetInput (const std::string &location, std::istream *is) override
 Set an input stream and associated location label. More...
 
std::string GetInputLocation () const override
 Get the current input location. More...
 
std::istream * GetInputStream () const override
 Get the current input stream. More...
 
MimeType GetRegisteredMimeType () const
 Get the mime-type that was registered for this reader. More...
 
DataStorage::SetOfObjects::Pointer Read (mitk::DataStorage &ds) override
 Read data and add it to the given DataStorage. More...
 
ConfidenceLevel GetConfidenceLevel () const override
 Determine confidence for reading the current input. More...
 
Options GetOptions () const override
 Get the current option values. More...
 
us::Any GetOption (const std::string &name) const override
 Get the value of a specific option. More...
 
void SetOptions (const Options &options) override
 Set multiple options at once. More...
 
void SetOption (const std::string &name, const us::Any &value) override
 Set a single option value. More...
 
void AddProgressCallback (const ProgressCallback &callback) override
 Register a progress callback. More...
 
void RemoveProgressCallback (const ProgressCallback &callback) override
 Remove a previously registered progress callback. More...
 
us::ServiceRegistration< IFileReader > RegisterService (us::ModuleContext *context=us::GetModuleContext())
 Register this reader as a CppMicroServices service. More...
 
void UnregisterService ()
 Unregister this reader from the CppMicroServices registry. More...
 
std::vector< std::string > GetReadFiles () override
 Get the list of files consumed during the last Read() call. More...
 
void SetProperties (const PropertyList *properties) override
 Set base data properties as a source of meta data for reading. More...
 
- Public Member Functions inherited from mitk::IFileReader
 ~IFileReader () override
 
virtual ~IFileReader ()
 
- Public Member Functions inherited from mitk::IFileIO
virtual ~IFileIO ()
 
- Public Member Functions inherited from mitk::AbstractFileIOWriter
ConfidenceLevel GetConfidenceLevel () const override
 Get the confidence level of this reader or writer for the current input. More...
 
- Public Member Functions inherited from mitk::AbstractFileWriter
void SetInput (const BaseData *data) override
 Set the input data for writing. More...
 
const BaseData * GetInput () const override
 Get the input data. More...
 
void SetOutputLocation (const std::string &location) override
 Set the output file-system path, clearing any output stream. More...
 
std::string GetOutputLocation () const override
 Get the current output location. More...
 
void SetOutputStream (const std::string &location, std::ostream *os) override
 Set an output stream and associated location label. More...
 
std::ostream * GetOutputStream () const override
 Get the current output stream. More...
 
ConfidenceLevel GetConfidenceLevel () const override
 Determine confidence for writing the current input data. More...
 
MimeType GetRegisteredMimeType () const
 Get the MIME type that was registered for this writer. More...
 
Options GetOptions () const override
 Get the current option values. More...
 
us::Any GetOption (const std::string &name) const override
 Get the value of a specific option. More...
 
void SetOptions (const Options &options) override
 Set multiple options at once. More...
 
void SetOption (const std::string &name, const us::Any &value) override
 Set a single option value. More...
 
void AddProgressCallback (const ProgressCallback &callback) override
 Register a progress callback. More...
 
void RemoveProgressCallback (const ProgressCallback &callback) override
 Remove a previously registered progress callback. More...
 
us::ServiceRegistration< IFileWriter > RegisterService (us::ModuleContext *context=us::GetModuleContext())
 Register this writer as a CppMicroServices service. More...
 
void UnregisterService ()
 Unregister this writer from the CppMicroServices registry. More...
 
- Public Member Functions inherited from mitk::IFileWriter
 ~IFileWriter () override
 

Static Public Member Functions

static PropertyList::Pointer ExtractMetaDataAsPropertyList (const itk::MetaDataDictionary &dictionary, const std::string &mimeTypeName, const std::vector< std::string > &defaultMetaDataKeys)
 Convert a MetaDataDictionary into a PropertyList for a certain MIME type. More...
 
static Image::Pointer LoadRawMitkImageFromImageIO (itk::ImageIOBase *imageIO, const std::string &path)
 Extract a raw MITK image from the given file path using the specified ImageIOBase. More...
 
static void PreparImageIOToWriteImage (itk::ImageIOBase *imageIO, const Image *image)
 Prepare an ITK ImageIOBase instance for writing the given MITK image. More...
 
static void SavePropertyListAsMetaData (itk::MetaDataDictionary &dictionary, const PropertyList *properties, const std::string &mimeTypeName)
 Save a PropertyList as meta data in an ITK MetaDataDictionary. More...
 
- Static Public Member Functions inherited from mitk::IFileIO
static std::string PROP_DESCRIPTION ()
 Service property name for a human-readable description. More...
 
static std::string PROP_MIMETYPE ()
 Service property name for the mime-type associated with this reader or writer. More...
 
- Static Public Member Functions inherited from mitk::IFileWriter
static std::string PROP_BASEDATA_TYPE ()
 Service property name for the supported mitk::BaseData sub-class. More...
 

Protected Member Functions

virtual std::vector< std::string > FixUpImageIOExtensions (const std::string &imageIOName)
 Fix up file extensions reported by the ITK ImageIO. More...
 
virtual void FixUpCustomMimeTypeName (const std::string &imageIOName, CustomMimeType &customMimeType)
 Fix up the custom MIME type name based on the ITK ImageIO name. More...
 
virtual void InitializeDefaultMetaDataKeys ()
 Fills the m_DefaultMetaDataKeys vector with default values. More...
 
std::vector< itk::SmartPointer< BaseData > > DoRead () override
 Perform the actual reading operation. More...
 
- Protected Member Functions inherited from mitk::AbstractFileIO
 AbstractFileIO (const AbstractFileIO &other)
 Copy constructor. More...
 
 AbstractFileIO (const std::string &baseDataType)
 Construct with a BaseData type name only. More...
 
 AbstractFileIO (const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
 Construct with a BaseData type, MIME type, and description. More...
 
void SetMimeType (const CustomMimeType &mimeType)
 Set the shared MIME type for both reader and writer. More...
 
const CustomMimeType * GetMimeType () const
 Get the shared MIME type. More...
 
void SetReaderDescription (const std::string &description)
 Set the description for the reader part. More...
 
std::string GetReaderDescription () const
 Get the description of the reader part. More...
 
void SetWriterDescription (const std::string &description)
 Set the description for the writer part. More...
 
std::string GetWriterDescription () const
 Get the description of the writer part. More...
 
void SetDefaultReaderOptions (const Options &defaultOptions)
 Set default options for the reader part. More...
 
Options GetDefaultReaderOptions () const
 Get the default options for the reader part. More...
 
void SetDefaultWriterOptions (const Options &defaultOptions)
 Set default options for the writer part. More...
 
Options GetDefaultWriterOptions () const
 Get the default options for the writer part. More...
 
void SetReaderRanking (int ranking)
 Set the service ranking for the reader part. More...
 
int GetReaderRanking () const
 Get the service ranking for the reader part. More...
 
void SetWriterRanking (int ranking)
 Set the service ranking for the writer part. More...
 
int GetWriterRanking () const
 Get the service ranking for the writer part. More...
 
- Protected Member Functions inherited from mitk::AbstractFileIOReader
 AbstractFileIOReader ()
 
 AbstractFileIOReader (const CustomMimeType &mimeType, const std::string &description)
 
- Protected Member Functions inherited from mitk::AbstractFileReader
 AbstractFileReader ()
 Default constructor. More...
 
 ~AbstractFileReader () override
 
 AbstractFileReader (const AbstractFileReader &other)
 Copy constructor. More...
 
 AbstractFileReader (const CustomMimeType &mimeType, const std::string &description)
 Associate this reader instance with the given MIME type. More...
 
virtual us::ServiceProperties GetServiceProperties () const
 Get the service properties for registration. More...
 
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType (us::ModuleContext *context)
 Register a new CustomMimeType service object. More...
 
void SetMimeType (const CustomMimeType &mimeType)
 Set the MIME type this reader can handle. More...
 
const CustomMimeType * GetMimeType () const
 Get the MIME type this reader can handle. More...
 
void SetMimeTypePrefix (const std::string &prefix)
 Set the prefix used for auto-generated MIME type names. More...
 
std::string GetMimeTypePrefix () const
 Get the current MIME type name prefix. More...
 
void SetDescription (const std::string &description)
 Set the human-readable description of this reader. More...
 
std::string GetDescription () const
 Get the human-readable description of this reader. More...
 
void SetDefaultOptions (const Options &defaultOptions)
 Set the default options for this reader. More...
 
Options GetDefaultOptions () const
 Get the default options for this reader. More...
 
void SetRanking (int ranking)
 Set the service ranking for this file reader. More...
 
int GetRanking () const
 Get the service ranking for this file reader. More...
 
std::string GetLocalFileName () const
 Get a local file name for reading. More...
 
virtual void SetDefaultDataNodeProperties (DataNode *node, const std::string &filePath)
 Set default properties on a DataNode after reading. More...
 
const PropertyList * GetProperties () const override
 Get the properties set via SetProperties(). More...
 
- Protected Member Functions inherited from mitk::AbstractFileIOWriter
 AbstractFileIOWriter (const std::string &baseDataType)
 
 AbstractFileIOWriter (const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
 
- Protected Member Functions inherited from mitk::AbstractFileWriter
 ~AbstractFileWriter () override
 
 AbstractFileWriter (const AbstractFileWriter &other)
 Copy constructor. More...
 
 AbstractFileWriter (const std::string &baseDataType)
 Construct a writer for the given BaseData type name. More...
 
 AbstractFileWriter (const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
 Construct a writer for the given BaseData type, MIME type, and description. More...
 
virtual us::ServiceProperties GetServiceProperties () const
 Get the service properties for registration. More...
 
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType (us::ModuleContext *context)
 Register a new CustomMimeType service object. More...
 
void SetMimeType (const CustomMimeType &mimeType)
 Set the MIME type this writer can handle. More...
 
const CustomMimeType * GetMimeType () const
 Get the MIME type this writer can handle. More...
 
void SetMimeTypePrefix (const std::string &prefix)
 Set the prefix used for auto-generated MIME type names. More...
 
std::string GetMimeTypePrefix () const
 Get the current MIME type name prefix. More...
 
void SetDescription (const std::string &description)
 Set a human-readable description of this writer. More...
 
std::string GetDescription () const
 Get the human-readable description of this writer. More...
 
void SetDefaultOptions (const Options &defaultOptions)
 Set the default options for this writer. More...
 
Options GetDefaultOptions () const
 Get the default options for this writer. More...
 
void SetRanking (int ranking)
 Set the service ranking for this file writer. More...
 
int GetRanking () const
 Get the service ranking for this file writer. More...
 
void SetBaseDataType (const std::string &baseDataType)
 Set the name of the mitk::BaseData sub-class this writer supports. More...
 
virtual std::string GetBaseDataType () const
 Get the name of the mitk::BaseData sub-class this writer supports. More...
 
void ValidateOutputLocation () const
 Validate the output location or stream. More...
 

Additional Inherited Members

- Public Types inherited from mitk::IFileIO
enum  ConfidenceLevel { Unsupported , PartiallySupported , Supported }
 A confidence level describing the reader's or writer's ability to handle the given data or file format. More...
 
typedef std::map< std::string, us::Any > Options
 Options for reading or writing data. More...
 
typedef mitk::MessageAbstractDelegate1< float > ProgressCallback
 Callback delegate type for progress reporting. More...
 
- Protected Attributes inherited from mitk::AbstractFileReader
std::vector< std::string > m_ReadFiles
 List of files consumed during the last Read() call. Must be filled by DoRead(). More...
 

Detailed Description

Wraps ITK image IO objects as mitk::IFileReader and mitk::IFileWriter objects.

Instantiating this class with a given itk::ImageIOBase instance will register corresponding MITK reader/writer services for that ITK ImageIO object. For all ITK ImageIOs that support the serialization of MetaData (e.g. nrrd or mhd) the ItkImageIO ensures the serialization of Identification UID.

See also
AbstractFileIO

Definition at line 34 of file mitkItkImageIO.h.

Constructor & Destructor Documentation

◆ ItkImageIO() [1/2]

mitk::ItkImageIO::ItkImageIO ( itk::ImageIOBase::Pointer  imageIO)

Construct an ItkImageIO from an ITK ImageIO instance.

Parameters
imageIOThe ITK ImageIO base instance to wrap.

◆ ItkImageIO() [2/2]

mitk::ItkImageIO::ItkImageIO ( const CustomMimeType &  mimeType,
itk::ImageIOBase::Pointer  imageIO,
int  rank 
)

Construct an ItkImageIO with a custom MIME type and rank.

Parameters
mimeTypeThe custom MIME type for this IO.
imageIOThe ITK ImageIO base instance to wrap.
rankThe service ranking.

Member Function Documentation

◆ DoRead()

std::vector<itk::SmartPointer<BaseData> > mitk::ItkImageIO::DoRead ( )
overrideprotectedvirtual

Perform the actual reading operation.

Subclasses must implement this method. The implementation should call GetInputStream() first and check for a non-null stream to read from. If the input stream is nullptr, use GetInputLocation() to read from a local file-system path.

If the reader cannot use streams directly, use GetLocalFileName() instead.

Returns
A vector of created BaseData objects.
Exceptions
mitk::Exceptionif reading fails.
See also
GetLocalFileName()
Read()

Implements mitk::AbstractFileReader.

◆ ExtractMetaDataAsPropertyList()

static PropertyList::Pointer mitk::ItkImageIO::ExtractMetaDataAsPropertyList ( const itk::MetaDataDictionary &  dictionary,
const std::string &  mimeTypeName,
const std::vector< std::string > &  defaultMetaDataKeys 
)
static

Convert a MetaDataDictionary into a PropertyList for a certain MIME type.

The function uses the Property serialization service for the conversion.

Parameters
dictionaryReference to the meta data dictionary that contains the information to extract.
mimeTypeNameMIME type that should be assumed for the meta data deserialization.
defaultMetaDataKeysVector of keys that should be assumed as defaults. For defaults no PropertyInfo will be registered at the PropertyPersistence service, as they are assumed to be handled anyways. For all other keys an info will be registered to ensure that they will be serialized again, even if unknown.
Returns
A PropertyList containing the extracted meta data.

◆ FixUpCustomMimeTypeName()

virtual void mitk::ItkImageIO::FixUpCustomMimeTypeName ( const std::string &  imageIOName,
CustomMimeType &  customMimeType 
)
protectedvirtual

Fix up the custom MIME type name based on the ITK ImageIO name.

Parameters
imageIONameThe name of the ITK ImageIO.
customMimeTypeThe custom MIME type to fix up.

◆ FixUpImageIOExtensions()

virtual std::vector<std::string> mitk::ItkImageIO::FixUpImageIOExtensions ( const std::string &  imageIOName)
protectedvirtual

Fix up file extensions reported by the ITK ImageIO.

Parameters
imageIONameThe name of the ITK ImageIO.
Returns
A corrected list of file extensions.

◆ GetReaderConfidenceLevel()

ConfidenceLevel mitk::ItkImageIO::GetReaderConfidenceLevel ( ) const
overridevirtual

Get the confidence level for reading the current file.

Reimplemented from mitk::AbstractFileIO.

◆ GetWriterConfidenceLevel()

ConfidenceLevel mitk::ItkImageIO::GetWriterConfidenceLevel ( ) const
overridevirtual

Get the confidence level for writing the current data.

Reimplemented from mitk::AbstractFileIO.

◆ InitializeDefaultMetaDataKeys()

virtual void mitk::ItkImageIO::InitializeDefaultMetaDataKeys ( )
protectedvirtual

Fills the m_DefaultMetaDataKeys vector with default values.

◆ LoadRawMitkImageFromImageIO()

static Image::Pointer mitk::ItkImageIO::LoadRawMitkImageFromImageIO ( itk::ImageIOBase *  imageIO,
const std::string &  path 
)
static

Extract a raw MITK image from the given file path using the specified ImageIOBase.

Raw means that only the pixel data and geometry information is loaded (no properties, etc.).

Parameters
imageIOThe ITK ImageIOBase instance to use for loading.
pathThe file path to read from.
Returns
The loaded MITK image.

◆ PreparImageIOToWriteImage()

static void mitk::ItkImageIO::PreparImageIOToWriteImage ( itk::ImageIOBase *  imageIO,
const Image *  image 
)
static

Prepare an ITK ImageIOBase instance for writing the given MITK image.

Parameters
imageIOThe ITK ImageIOBase instance to configure.
imageThe MITK image to be written.

◆ Read() [1/2]

std::vector<itk::SmartPointer<BaseData> > mitk::AbstractFileReader::Read
overridevirtual

Read data and create a list of BaseData objects.

The default implementation calls DoRead() and then annotates each resulting BaseData with meta-information about the reader, MIME type, input location, and reader options.

Returns
A vector of created BaseData objects.
Exceptions
mitk::Exceptionif reading fails.

Reimplemented from mitk::AbstractFileReader.

◆ Read() [2/2]

DataStorage::SetOfObjects::Pointer mitk::AbstractFileReader::Read
overridevirtual

Read data and add it to the given DataStorage.

Parameters
[in,out]dsThe DataStorage to add nodes to.
Returns
The set of DataNode objects added to ds.
Exceptions
mitk::Exceptionif reading fails.

Reimplemented from mitk::AbstractFileReader.

◆ SavePropertyListAsMetaData()

static void mitk::ItkImageIO::SavePropertyListAsMetaData ( itk::MetaDataDictionary &  dictionary,
const PropertyList *  properties,
const std::string &  mimeTypeName 
)
static

Save a PropertyList as meta data in an ITK MetaDataDictionary.

Parameters
dictionaryThe target meta data dictionary.
propertiesThe PropertyList to save.
mimeTypeNameThe MIME type to assume for serialization.

◆ Write()

void mitk::ItkImageIO::Write ( )
overridevirtual

Write the input data to file.

Implements mitk::AbstractFileWriter.


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