[Insight-users] DICOM Series Read & Write

jordi targa (salle) jtarga at salleURL.edu
Fri Aug 5 02:40:45 EDT 2005


Hi to All,

Hello Martin,

I had your problem. I read DICOM series but the tags were the same the whole
time.

In the end, I read first the DICOM images and after the tags in the same
order. I have a little class and I push the images and the tags.

This night I will sent you the code.

Sorry me, my english isn't good.

Jordi.

 






-----Mensaje original-----
De: insight-users-bounces+jtarga=salleurl.edu at itk.org
[mailto:insight-users-bounces+jtarga=salleurl.edu at itk.org] En nombre de
Martin SEISER
Enviado el: jueves, 04 de agosto de 2005 16:18
Para: insight-users at itk.org
Asunto: [Insight-users] DICOM Series Read & Write

Hi to all,

during one of my projects at univerity I have encountered several problems
when reading and writing DICOM series with ITK.

First of all ==> my code!;)

// TestITKDICOMCapabilities.cpp : Defines the entry point for the console
application.
//

#include "itkImageSeriesReader.h"
#include "itkImageSeriesWriter.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkNumericSeriesFileNames.h"

int main(int argc, char* argv[]) {
	typedef signed short PixelType;
	const unsigned int Dimension = 3;
	typedef itk::Image<PixelType, Dimension> ImageType;
	typedef itk::ImageSeriesReader<ImageType> ReaderType;
	typedef itk::GDCMImageIO ImageIOType;
	typedef itk::GDCMSeriesFileNames NamesGeneratorType;
	typedef std::vector<std::string> FileNamesContainer;

	typedef signed short OutputPixelType;
	const unsigned int OutputDimension = 2;
	typedef itk::Image<OutputPixelType, OutputDimension> Image2DType;
	typedef itk::ImageSeriesWriter<ImageType, Image2DType>
SeriesWriterType;

	ReaderType::Pointer reader = ReaderType::New();
	ImageIOType::Pointer dicomIO = ImageIOType::New();
	reader->SetImageIO(dicomIO);
	NamesGeneratorType::Pointer nameGenerator =
NamesGeneratorType::New();
	std::string path = "C:\\load";
	nameGenerator->SetInputDirectory(path.c_str());
	FileNamesContainer fileNames = nameGenerator->GetInputFileNames();
	reader->SetFileNames(fileNames);
	reader->Update();

	typedef itk::MetaDataDictionary DictionaryType;
	const DictionaryType & dictionary =
dicomIO->GetMetaDataDictionary();
	typedef itk::MetaDataObject<std::string> MetaDataStringType;
	DictionaryType::ConstIterator itr = dictionary.Begin();
	DictionaryType::ConstIterator end = dictionary.End();
	while (itr != end) {
		itk::MetaDataObjectBase::Pointer entry = itr->second;
		MetaDataStringType::Pointer entryvalue =
		dynamic_cast<MetaDataStringType *>( entry.GetPointer() ) ;
		if (entryvalue) {
			std::string tagkey = itr->first;
			std::string tagvalue =
entryvalue->GetMetaDataObjectValue();
			std::cout << tagkey << " = " << tagvalue <<
std::endl;
		}
		++itr;
	}
	
	SeriesWriterType::Pointer writer = SeriesWriterType::New();
	writer->SetInput(reader->GetOutput());
	typedef itk::NumericSeriesFileNames NameGeneratorType;
	NameGeneratorType::Pointer namesGeneratorWriter =
NameGeneratorType::New();
	std::string format = "C:\\save\\file";
	format += "%03d.";
	format += "dcm"; // filename extension
	namesGeneratorWriter->SetSeriesFormat(format.c_str());
	ImageType::ConstPointer inputImage = reader->GetOutput();
	ImageType::RegionType region =
inputImage->GetLargestPossibleRegion();
	ImageType::IndexType start = region.GetIndex();
	ImageType::SizeType size = region.GetSize();
	const unsigned int firstSlice = start[2];
	const unsigned int lastSlice = start[2] + size[2] - 1;
	namesGeneratorWriter->SetStartIndex(firstSlice);
	namesGeneratorWriter->SetEndIndex(lastSlice);
	namesGeneratorWriter->SetIncrementIndex(1);
	writer->SetFileNames(namesGeneratorWriter->GetFileNames());

	DictionaryType & dictionaryToWrite =
dicomIO->GetMetaDataDictionary();
	
	itk::EncapsulateMetaData<std::string>(dictionaryToWrite,
"0010|0010", "Hugo");
	itk::EncapsulateMetaData<std::string>(dictionaryToWrite,
"0010|0020", "007");
	itk::EncapsulateMetaData<std::string>(dictionaryToWrite,
"0010|0030", "01.01.1800");

	
writer->SetMetaDataDictionaryArray(reader->GetMetaDataDictionaryArray());


	writer->SetImageIO(dicomIO);

	try {
		writer->Update();
	}
	catch( itk::ExceptionObject & excp ) {
		std::cerr << "Exception thrown while writing the image" <<
std::endl;
		std::cerr << excp << std::endl;
	}

	return 0;
}

This code reads the series, displays the metadata and writes the series with
different meta tags. This is as it should be!

But the tags aren't changed and i dont know why! And I have more questions:

1) Why does
 
writer->SetMetaDataDictionaryArray(reader->GetMetaDataDictionaryArray());
   work
   and
         writer->SetMetaDataDictionary(reader->GetMetaDataDictionary());
   doesn't?
2) What is the connection between "MetaDataDictionaryArray" and
"MetaDataDictionary"?
3) If I have to move the meta tag info across methods, do I have to move the
whole Reader? Or is there a way to store a "MetaDataDictionaryArray"?

4) Why arent my TAGS CHANGED????

Would appreciate your help, time's getting short!:(

Thx it advance,

Martin



-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm

_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list