#include "itkImage.h" #include "itkImageFileWriter.h" #include "itkGDCMImageIO.h" #include "itkMetaDataObject.h" using std::string; int main( int argc, char* argv[] ) { char* outputFileName = "output.dcm"; typedef signed short PixelType; const unsigned int Dimension = 2; typedef itk::Image< PixelType, Dimension > ImageType; typedef itk::GDCMImageIO ImageIOType; ImageIOType::Pointer gdcmImageIO = ImageIOType::New(); typedef itk::ImageFileWriter< ImageType > WriterType; WriterType::Pointer writer = WriterType::New(); // This is used just for creating a writer object. ImageType::Pointer dummyImage = ImageType::New(); writer->SetFileName( outputFileName ); writer->SetInput( dummyImage ); writer->SetImageIO( gdcmImageIO ); // In order to set the UID values to the desired value: gdcmImageIO->KeepOriginalUIDOn(); //Do not use the MetaDataDictionary from the input writer->UseInputMetaDataDictionaryOff (); itk::MetaDataDictionary & dictWriter = gdcmImageIO->GetMetaDataDictionary(); // Study Instance UID string tagID = "0020|000D"; string tagValue = "0.0.0.0.2.8811.20010413115754.12432"; itk::EncapsulateMetaData(dictWriter, tagID, tagValue); try { std::cout << "Started updating the writer...." << std::endl; writer->Update(); } catch (itk::ExceptionObject & e) { std::cerr << "exception in file writer " << std::endl; std::cerr << e << std::endl; return EXIT_FAILURE; } std::cout << "End of the Program." << std::endl; system("Pause"); return EXIT_SUCCESS; }