#include <list>
#include <fstream>
int
main(int argc, char * argv[])
{
if (argc < 5)
{
std::cerr << "Usage: " << argv[0]
<< " DicomImage OutputDicomImage Entry Value\n";
return EXIT_FAILURE;
}
using InputPixelType = signed short;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO(gdcmImageIO);
try
{
reader->Update();
}
catch (
const itk::ExceptionObject &
e)
{
std::cerr << "exception in file reader " << std::endl;
std::cerr <<
e.GetDescription() << std::endl;
std::cerr <<
e.GetLocation() << std::endl;
return EXIT_FAILURE;
}
InputImageType::Pointer inputImage = reader->GetOutput();
DictionaryType & dictionary = inputImage->GetMetaDataDictionary();
for (int i = 3; i < argc; i += 2)
{
std::string entryId(argv[i]);
std::string value(argv[i + 1]);
itk::EncapsulateMetaData<std::string>(dictionary, entryId, value);
}
Writer1Type::Pointer writer1 = Writer1Type::New();
writer1->SetInput(reader->GetOutput());
writer1->SetFileName(argv[2]);
writer1->SetImageIO(gdcmImageIO);
try
{
writer1->Update();
}
catch (
const itk::ExceptionObject &
e)
{
std::cerr << "exception in file writer " << std::endl;
std::cerr <<
e.GetDescription() << std::endl;
std::cerr <<
e.GetLocation() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}