[Insight-users] nifti metadata

Micah Chambers micahc at vt.edu
Mon Jun 8 17:17:04 EDT 2009


I am trying to add some metadata to a nifti file, but for some reason none
of the tags ever get written out. Here is how I am writing the metadata:

----------------------------------------------
    itk::MetaDataDictionary dict = measImage->GetMetaDataDictionary();
    itk::EncapsulateMetaData<double>(dict, "TemporalResolution", 2.0);
    itk::EncapsulateMetaData<unsigned int>(dict, "NumSections", series);
    itk::EncapsulateMetaData<unsigned int>(dict, "TimeDim", 3);
    itk::EncapsulateMetaData<unsigned int>(dict, "SectionDim", 0);
    //fill in mapping of Section Index to number section number i+5
    for(int i=0 ; i<series ; i++ ) {
        ostringstream oss;
        oss.str("");
        oss << "MapIndex " << i;
        itk::EncapsulateMetaData<unsigned int>(dict, oss.str(), i+5);
    }
    measImage->SetMetaDataDictionary(dict);

#ifdef TEST
    itk::EncapsulateMetaData<string>(dict, "0010|0040", "M");
#endif //TEST

#define TEST
#ifdef TEST
    unsigned int tmp1000;
    dict = measImage->GetMetaDataDictionary();
    itk::ExposeMetaData<unsigned int>(dict, "TimeDim", tmp1000);
    cout << "TimeDim " << tmp1000 << endl;;
    dict.Print(cout);
#endif

and I write the file with:
-----------------------------------------------------------------------
    writer->SetFileName("out.nii");
    writer->SetInput(measImage);
    writer->Update();
-----------------------------------------------------------------------

When I used ExposeMetaData/Print, all the metadata gets dumped fine. But if
I then write the image, then load the file, and use Print(), none of it gets
printed. In fact I am relatively sure that the data isn't getting written,
since a call like this:
$ cat out.nii | strings | less
doesn't give me any of the tags, which, unless the tags are somehow encoded,
it should. Is there a trick to adding metadata to nifti headers?

Thanks,

-Micah Chambers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090608/9c44e279/attachment.htm>


More information about the Insight-users mailing list