[ITK-users] reading 3D temporal MRA dicom: miss ordered [SOLVED]

Jerome Plumat j.plumat at auckland.ac.nz
Thu May 26 21:27:27 EDT 2016


Hi Ehsan,
Thanks a lot for your answer. Your indication guided me to the solution.

Below is the core part of the code to load the DCM angiography with MRI 
(MRA) on Siemens.
Hope it may help further.
Jerome

Note: DCMDate is an object storing the acquisition content and the 
pointer to the image, sortByAcquisitionDate is a simple ordering 
function see http://www.cplusplus.com/articles/NhA0RXSz/

// ....

     // order the angiography capture using Content Time
     const std::string entry_id = "0008|0033";

     ImageIOType::Pointer        dicomIO = ImageIOType::New();
     NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
     DCMReaderType::Pointer reader = DCMReaderType::New();

     reader->SetImageIO( dicomIO );

     // get all the dicom slices in the pointing folder
     nameGenerator->SetDirectory( inputPath ); // point to the folder 
containing the dcm files

     const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
     std::string seriesIdentifier = seriesUID.begin()->c_str();
     FileNamesContainer fileNames;
     fileNames = nameGenerator->GetFileNames( seriesIdentifier );

     std::vector<DCMDate> dcm_list = std::vector<DCMDate>(fileNames.size());

     // Read all the DCM files and find the content time
     for( int i=0; i<fileNames.size(); i++ ){
         singleDCMReaderType::Pointer f_reader = singleDCMReaderType::New();
         if(verbose) std::cout << fileNames.at(i) << std::endl;
         f_reader->SetFileName( fileNames.at(i));
         // read the slice
         DCMImageType::Pointer im;
         try{
             f_reader->Update();
             im = f_reader->GetOutput();
         }catch(itk::ExceptionObject &err ){
             std::cerr << err << std::endl;
             return EXIT_FAILURE;
         }

         // find the acquisition date
         const DictionaryType & dictionary = im->GetMetaDataDictionary();
         DictionaryType::ConstIterator tagItr = dictionary.Find( entry_id );
         if( tagItr == dictionary.End() ){
             std::cerr << ">> Tag " << entry_id;
             std::cerr << " not found in the DICOM header" << std::endl;
             return EXIT_FAILURE;
     }
         MetaDataStringType::ConstPointer entryvalue =
             dynamic_cast<const MetaDataStringType *>( 
tagItr->second.GetPointer() );
         // if we find the value, create an object
         if( entryvalue ){
             std::string tagkey = tagItr->first;
             std::string labelId;
             bool found = itk::GDCMImageIO::GetLabelFromTag( tagkey, 
labelId );
             std::string tagvalue = entryvalue->GetMetaDataObjectValue();
             if(found){
                 if(verbose){
                     std::cout.precision(16);
                     std::cout << "(" << tagkey << ") ";
                     std::cout << labelId << " = " << 
atof(tagvalue.c_str());
                     std::cout << std::endl;
                 }
                 dcm_list.at(i) = DCMDate(atof(tagvalue.c_str()), 
im.GetPointer());
             }
         }else{
             std::cerr << "Entry not found." << std::endl;
             return EXIT_FAILURE;
         }
         im = DCMImageType::New();
     }

     // order all the slice by acquisition time
     std::sort(dcm_list.begin(), dcm_list.end(), sortByAcquisitionDate);

// then, save each element of the list on a slice of a volume and write 
the volume on HD.


On 24/05/16 12:54, ebasafa wrote:
> Does this mean that all slices have the same location information and you
> want them to be ordered based on the time stamp? If so, I am afraid GDCM
> might not be able to sort them properly. If all slices have the same
> location (Image Position Patient) and orientation (Image Orientation
> Patient), the sorting might fail. Take a look at how GDCM sorts DICOM slices
> (https://itk.org/Doxygen/html/classitk_1_1GDCMSeriesFileNames.html):
>
> "This class generates a sequence of files whose filenames point to a DICOM
> file. The ordering is based on the following strategy: Read all images in
> the directory (assuming there is only one study/series)
>
> 1) Extract Image Orientation & Image Position from DICOM images, and then
> calculate the ordering based on the 3D coordinate of the slice.
> 2) If for some reason this information is not found or failed, another
> strategy is used: the ordering is based on 'Image Number'.
> 3) If this strategy also failed, then the filenames are ordered by
> lexicographical order."
>
> HTH
> Ehsan
>
>
>
>
> --
> View this message in context: http://itk-insight-users.2283740.n2.nabble.com/ITK-users-reading-3D-temporal-MRA-dicom-miss-ordered-tp7588890p7588892.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users



More information about the Insight-users mailing list