[Insight-developers] MetaIO image IO (mhd/mha) and metadata
Tom Vercauteren
tom.vercauteren at m4x.org
Fri May 28 07:16:49 EDT 2010
Hi all,
I have committed a test that illustrates the loss of metadata when
writing a mhd file through ITK:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Testing/Code/IO/itkReadWriteImageWithDictionaryTest.cxx?revision=1.1&root=Insight&sortby=date&view=markup
The same test can be used with any file format and I have checked that
(after a small bug fix in AnalyzeImageIO), it passes whith a .hdr
file.
In the meantime, I have discovered a bug in MetaIO for which I have
submitted a patch:
http://www.itk.org/Bug/view.php?id=6617
Would someone with write access to MetaIO be kind enough to review the
patch and commit it?
Thanks,
Tom
On Wed, May 26, 2010 at 13:56, Tom Vercauteren <tom.vercauteren at m4x.org> wrote:
> 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-developers
mailing list