diff --git a/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx b/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx index 2958bed4ff4..37186a5ae72 100644 --- a/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx +++ b/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx @@ -1776,6 +1776,17 @@ NiftiImageIO::WriteImageInformation() strcpy(this->m_NiftiImage->aux_file, temp.c_str()); } } + if (itk::ExposeMetaData(thisDic, "ITK_FileNotes", temp)) + { + if (temp.length() > 79) + { + itkExceptionMacro("ITK_FileNotes (Nifti descrip field) too long, Nifti limit is 79 characters"); + } + else + { + strcpy(this->m_NiftiImage->descrip, temp.c_str()); + } + } // Enable RAS conversion based on metadata and flags this->m_ConvertRAS = (m_ConvertRASVectors && this->m_NiftiImage->intent_code == NIFTI_INTENT_VECTOR) || diff --git a/Modules/IO/NIFTI/test/itkNiftiImageIOTest3.cxx b/Modules/IO/NIFTI/test/itkNiftiImageIOTest3.cxx index d20607c26e0..5fa47214ed4 100644 --- a/Modules/IO/NIFTI/test/itkNiftiImageIOTest3.cxx +++ b/Modules/IO/NIFTI/test/itkNiftiImageIOTest3.cxx @@ -148,6 +148,8 @@ TestImageOfVectors(const std::string & fname, const std::string & intentCode = " itk::MetaDataDictionary & dictionary = vi->GetMetaDataDictionary(); itk::EncapsulateMetaData(dictionary, "intent_code", intentCode); } + std::string description("text description of file content"); + itk::EncapsulateMetaData(vi->GetMetaDataDictionary(), "ITK_FileNotes", description); try { itk::IOTestHelper::WriteImage(vi, fname); @@ -190,6 +192,7 @@ TestImageOfVectors(const std::string & fname, const std::string & intentCode = " { const itk::MetaDataDictionary & dictionary = readback->GetMetaDataDictionary(); std::string readIntentCode; + std::string readDescription; if (itk::ExposeMetaData(dictionary, "intent_code", readIntentCode)) { if (readIntentCode != intentCode) @@ -203,6 +206,19 @@ TestImageOfVectors(const std::string & fname, const std::string & intentCode = " std::cout << "The read image should have an intent_code in its dictionary" << std::endl; same = false; } + if (itk::ExposeMetaData(dictionary, "ITK_FileNotes", readDescription)) + { + if (readDescription != description) + { + std::cout << "ITK_FileNotes is different: " << readDescription << " != " << description << std::endl; + same = false; + } + } + else + { + std::cout << "The read image should have a ITK_FileNotes (nifti descrip field) in its dictionary" << std::endl; + same = false; + } } if (readback->GetOrigin() != vi->GetOrigin()) {