[Insight-users] itk::MetaDataDictionary for a DICOM series

John Drescher drescherjm at gmail.com
Tue Feb 3 17:42:07 EST 2009


Okay. Now when I tried to put the changes in my real application I
still had the problem. And I believe it comes down to the differences
between GDCMImageIO and DICOMImageIO2. If I use GDCMImageIO  and its
associated classes I get the MetaDataDictionary with all the data I
expect. If I use DICOMImageIO2 the MetaDataDictionary contains only
ITK_ImageOrigin.

Is this the expected behavior?

Attached is the new program that uses either GDCMImageIO or
DICOMImageIO2 depending on if USE_GDCM is defined.

John
-------------- next part --------------
//#define USE_GDCM

#include "itkImage.h"
#include "itkImageSeriesReader.h"
#include "itkImageSeriesWriter.h"

#ifdef USE_GDCM
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#else
#include "itkDICOMImageIO2.h"
#include "itkDICOMSeriesFileNames.h"
#endif //def USE_GDCM

#include <iostream>


int main(int argc, char *argv[]) 
{
	if (argc > 2) {
		typedef signed short    PixelType;
		const unsigned int      Dimension = 3;
		typedef itk::Image< PixelType, Dimension >      ImageType;
		typedef itk::ImageSeriesReader< ImageType >     ReaderType;
		typedef itk::ImageFileReader< ImageType >       ReaderMHDType;

#ifdef USE_GDCM
		typedef itk::GDCMImageIO                        ImageIOType;
		typedef itk::GDCMSeriesFileNames                NamesGeneratorType;
#else
		typedef itk::DICOMImageIO2                        ImageIOType;

		typedef  itk::DICOMSeriesFileNames				SeriesFileNamesType;
		typedef  SeriesFileNamesType					NamesGeneratorType;
#endif //def USE_GDCM
		

		ImageIOType::Pointer gdcmIO = ImageIOType::New();
		NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();

#ifdef USE_GDCM
		namesGenerator->SetInputDirectory( argv[1] );

		const ReaderType::FileNamesContainer & filenames =
			namesGenerator->GetInputFileNames();

		namesGenerator->SetInputDirectory( argv[1] );

#else

		namesGenerator->SetDirectory( argv[1] );

		const ReaderType::FileNamesContainer & filenames =
			namesGenerator->GetFileNames();

#endif //def USE_GDCM

		ReaderType::Pointer reader = ReaderType::New();

		reader->SetImageIO( gdcmIO );
		reader->SetFileNames( filenames );

		reader->Update();

		// BEGIN IMPORTANT CODE*

		unsigned int nbSlices = filenames.size();

		ReaderType::DictionaryRawPointer dictionary;
		ReaderType::DictionaryArrayType outputArray;

		for (unsigned int i = 0; i < nbSlices; i++)
		{
			dictionary = (*(reader->GetMetaDataDictionaryArray()))[i];

			std::string entryId("0008|103e");
			std::string value("MARTIN IS THE BEST"); // it was just a test ;-)*
				itk::EncapsulateMetaData<std::string>( *dictionary, entryId, value
				);
			outputArray.push_back(dictionary);
		}  

		// END*


		typedef signed short    OutputPixelType;
		const unsigned int      OutputDimension = 2;

		typedef itk::Image< OutputPixelType, OutputDimension >    Image2DType;

		typedef itk::ImageSeriesWriter< ImageType, Image2DType >
			SeriesWriterType;

		SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();

		seriesWriter->SetInput( reader->GetOutput() );
		seriesWriter->SetImageIO( gdcmIO );

#ifdef USE_GDCM
		namesGenerator->SetOutputDirectory( argv[2] );

		seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );
#else
		namesGenerator->SetDirectory( argv[2] );

		seriesWriter->SetFileNames( namesGenerator->GetFileNames() );
#endif //def USE_CDCM

		// BEGIN IMPORTANT CODE*
			seriesWriter->SetMetaDataDictionaryArray( &outputArray );
			// instead of :
			// seriesWriter->SetMetaDataDictionaryArray(
			// reader->GetMetaDataDictionaryArray());
		// END*

			seriesWriter->Update();

	}
	else
	{
		std::cout << "Usage: "<< argv[0] << " <input folder> <output folder> " << std::endl;
	}
	
}


More information about the Insight-users mailing list