[Insight-users] Problem with writing DICOM using KeepOriginalUID

Martin Kavec martin.kavec at gmail.com
Tue Apr 21 00:16:11 EDT 2009


Hi all,

I have a problem with the code below with ITK-3.12 (gdcm1). What I am trying 
to do is to add another series into the existing study after the images have 
been processed. The code below is largely based on DicomResample written by 
Bill Lorensen. Shortly, in order to add a new series to an existing study, 
the series and frame of reference UIDs are extrected from the 
existing "template" series and for each new slice these are added to the 
metadata dictionary. Additionally, series number, description and several 
other tags are updated KeepOriginalUIDOn is also passed to the gdcm IO.

Now the problem is that with the KeepOriginalUIDOn the resulting dicoms are 
recognized by Osirix as a new series of the original study, but the series 
has few 2-3/182 slices missing, despite of the correct number of the files 
produced. The things work well when KeepOriginalUIDOn is commented out with 
the penalty that the output dicom images are generated as new study, when 
imported to Osirix.

I was hoping that someone (Mathieu our dicom guru) may have some insight what 
could be wrong.

Thanks a lot in advance,

Martin


	DicomReaderType::DictionaryRawPointer inputDict = 
(*(dicomReader->GetMetaDataDictionaryArray()))[0];
	DicomReaderType::DictionaryArrayType  outputDictionaries;

	
	std::string seriesUID = gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
	std::string frameOfReferenceUID = gdcm::Util::CreateUniqueUID(   
gdcmIO->GetUIDPrefix());
	std::string studyUID;
	std::string sopClassUID;
	itk::ExposeMetaData<std::string>(*inputDict, "0020|000d", studyUID);
	itk::ExposeMetaData<std::string>(*inputDict, "0008|0016", sopClassUID);
//	gdcmIO->KeepOriginalUIDOn();
	
	// Series number
	std::string oldSeriesNumber;
	itk::ExposeMetaData<std::string>(*inputDict, "0020|0011", oldSeriesNumber);	
	int newSeriesNumberInt = atoi( &oldSeriesNumber[0] ) + 50;
	
	// Series Description
	itksys_ios::ostringstream seriesDesc;
	std::string oldSeriesDesc;
	itk::ExposeMetaData<std::string>(*inputDict, "0008|103e", oldSeriesDesc);
	seriesDesc.str("");
	seriesDesc << oldSeriesDesc << " blabla";
	
	// This is an long string and there is a 64 character limit in the 
	// standard
	unsigned lengthDesc = seriesDesc.str().length();
	std::string newSeriesDesc( seriesDesc.str(), 0, lengthDesc > 64 ? 64 : 
lengthDesc);
	

	const ImageType::SpacingType& imageSpacing = 
imageReader->GetOutput()->GetSpacing();
	const ImageType::RegionType& imageRegion = 
imageReader->GetOutput()->GetLargestPossibleRegion();
	const ImageType::SizeType& imageSize = imageRegion.GetSize();
	
	for (unsigned int f = 0; f < imageSize[2]; f++)
    {
		// Create a new dictionary for this slice
		DicomReaderType::DictionaryRawPointer dict = new 
DicomReaderType::DictionaryType;
		
		// Copy the dictionary from the first slice
		CopyDictionary (*inputDict, *dict);
		
		// Set the UID's for the study, series, SOP  and frame of reference
		itk::EncapsulateMetaData<std::string>(*dict,"0020|000d", studyUID);
		itk::EncapsulateMetaData<std::string>(*dict,"0020|000e", seriesUID);
		itk::EncapsulateMetaData<std::string>(*dict,"0020|0052", 
frameOfReferenceUID);
				
		std::string sopInstanceUID = gdcm::Util::CreateUniqueUID( 
gdcmIO->GetUIDPrefix());		
		itk::EncapsulateMetaData<std::string>(*dict,"0008|0018", sopInstanceUID);
		itk::EncapsulateMetaData<std::string>(*dict,"0002|0003", sopInstanceUID);


More information about the Insight-users mailing list