[Insight-users] MetaIO image IO (mhd/mha) and metadata
Tom Vercauteren
tom.vercauteren at m4x.org
Wed May 26 07:56:53 EDT 2010
Hi all,
I am trying to use mhd files as a simple means of exchanging data. I
am however unable to store my metadata in it. This is against what is
mentionned in the wiki page ("MetaImage (mhd) [...] Also supports
reading and writing [...] Patient Meta Data (orientation, scan date,
comments, modality, etc. - user extensible)"):
http://www.itk.org/Wiki/ITK_File_Formats#File_Formats_and_Pixel_Types
Here is how I am trying to use it:
typedef itk::Image<short,3> ImageType;
ImageType::Pointer img; // comes from somewhere
itk::MetaDataDictionary & dictionary = img->GetMetaDataDictionary();
itk::EncapsulateMetaData<std::string>(dictionary,itk::ITK_VoxelUnits,std::string("mm"));
std::string datestr = "26-05-2010"; // try to follow analyze format
itk::EncapsulateMetaData<std::string>(dictionary,
itk::ITK_ExperimentDate, datestr );
std::string timestr = "13-44-00.0"; // try to follow analyze format
itk::EncapsulateMetaData<std::string>(dictionary,
itk::ITK_ExperimentTime, timestr );
typedef itk::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput( img );
writer->SetFileName( "test.mhd" );
writer->Update();
The content of the mhd file does not reflect the meta dictionary:
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = False
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 0 0 0
CenterOfRotation = 0 0 0
AnatomicalOrientation = RAI
ElementSpacing = 0.00118899 0.00118899 1
DimSize = 504 422 1
ElementType = MET_SHORT
ElementDataFile = test.raw
Since it is the first time am I trying to use the MetaDataDictionary,
could you confirm that this is the right way of doing it?
If so, I'll file a bug report with a unit test.
Looking at the code here is my understanding of why it is not done:
- MetaImageIO::WriteImageInformation is empty
- MetaImageIO::ReadImageInformation does not use most of the "ITK_*"
tags specified in itkIOCommon.h nor does it seems to iterate on some
generic tags
Let me know if I am missing something or what would be the best way to
fix this problem.
Best regards,
Tom Vercauteren
More information about the Insight-users
mailing list