#include <vector>
#include "itksys/SystemTools.hxx"
int main( int argc, char* argv[] )
{
if( argc < 3 )
{
std::cerr << "Usage: " << argv[0];
std::cerr << " InputImage OutputDicomDirectory" << std::endl;
return EXIT_FAILURE;
}
typedef signed short PixelType;
const unsigned int Dimension = 3;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
}
{
std::cerr << "Exception thrown while writing the image" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ImageIOType::Pointer gdcmIO = ImageIOType::New();
const char * outputDirectory = argv[2];
itksys::SystemTools::MakeDirectory( outputDirectory );
typedef signed short OutputPixelType;
const unsigned int OutputDimension = 2;
ImageType, Image2DType > SeriesWriterType;
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
std::string tagkey, value;
tagkey = "0008|0060";
value = "MR";
itk::EncapsulateMetaData<std::string>(dict, tagkey, value );
tagkey = "0008|0008";
value = "DERIVED\\SECONDARY";
itk::EncapsulateMetaData<std::string>(dict, tagkey, value);
tagkey = "0008|0064";
value = "DV";
itk::EncapsulateMetaData<std::string>(dict, tagkey, value);
SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
seriesWriter->SetInput( reader->GetOutput() );
seriesWriter->SetImageIO( gdcmIO );
ImageType::RegionType region =
reader->GetOutput()->GetLargestPossibleRegion();
ImageType::IndexType start = region.GetIndex();
ImageType::SizeType size = region.GetSize();
std::string format = outputDirectory;
format += "/image%03d.dcm";
namesGenerator->SetSeriesFormat( format.c_str() );
namesGenerator->SetStartIndex( start[2] );
namesGenerator->SetEndIndex( start[2] + size[2] - 1 );
namesGenerator->SetIncrementIndex( 1 );
seriesWriter->SetFileNames( namesGenerator->GetFileNames() );
try
{
seriesWriter->Update();
}
{
std::cerr << "Exception thrown while writing the series " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}