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

John Drescher drescherjm at gmail.com
Tue Feb 3 14:20:25 EST 2009


> If I obtain dicom itk::MetaDataDictionary for a CT series (individual
> dicom files) I load it is empty
>
> Also example
> DicomSeriesReadPrintTags
>
> returns
>
> [x:\vc.80\libraries\itk\bin\debug]DicomSeriesReadPrintTags.exe
> I:\clean\Lung\PLuSS\PLuSS_EXT\00001-4\Date_20020302\002\
> Tag 0010|0010 not found in the DICOM header
>
> However if I use the DicomImageReadPrintTags on any of the images from
> the series I do get what I expect:
>
> <snip>
> (0018|1030) Protocol Name = 5.11 LUNG SPORE RESEARCH
> (0018|1100) Reconstruction Diameter = 370.000000
> (0018|1110) Distance Source to Detector = 949.075012
> (0018|1111) Distance Source to Patient = 541.000000
> (0018|1120) Gantry/Detector Tilt = 0.000000
> (0018|1130) Table Height = 155.199997
> (0018|1140) Rotation Direction = CW
> (0018|1150) Exposure Time = 700
> (0018|1151) X-ray Tube Current = 40
> (0018|1152) Exposure = 640
> (0018|1160) Filter Type = BODY FILTER
> (0018|1170) Generator Power = 5600
> (0018|1190) Focal Spot(s) = 0.700000
> (0018|1210) Convolution Kernel = LUNG
> <snip>
>
>
> Why is this? Is it because some info (like Image Position) will be
> different in each dicom file?
>
> BTW, this is InsightToolkit-3.10.1 compiled under VC 2005 on windows XP.
>
I was finally able to get a valid meta dictionary out of a dicom series.
I found the following mail helpful in this issue:
http://www.cmake.org/pipermail/insight-users/2008-November/027999.html

Attached is a working copy of that code.

John
-------------- next part --------------
#include "itkImage.h"
#include "itkImageSeriesReader.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkImageSeriesWriter.h"
#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;
		typedef itk::GDCMImageIO                        ImageIOType;
		typedef itk::GDCMSeriesFileNames                NamesGeneratorType;

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

		namesGenerator->SetInputDirectory( argv[1] );

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

		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 );

		namesGenerator->SetOutputDirectory( argv[2] );

		seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() );

		// 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;
	}
	
}
-------------- next part --------------
PROJECT(DicomSeriesMetaDictionary)

IF(WIN32)
    CMAKE_MINIMUM_REQUIRED(VERSION 2.5 FATAL_ERROR)
    SET(CMAKE_CXX_FLAGS "/WL /GR /EHsc" ) 
    ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(WIN32)

IF(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all executables.")

FIND_PACKAGE( ITK REQUIRED )

INCLUDE( ${ITK_USE_FILE} )

SET( DICOM_SERIES_META_SRCS
	./src/main.cxx
)

LINK_LIBRARIES ( DicomSeriesMetaDictionary ITKCommon ITKBasicFilters ITKIO )

ADD_EXECUTABLE( DicomSeriesMetaDictionary ${DICOM_SERIES_META_SRCS} )


More information about the Insight-users mailing list