int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Usage: ImageReadImageSeriesWrite inputFile outputPrefix "
"outputExtension"
<< std::endl;
return EXIT_FAILURE;
}
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
WriterType::Pointer writer = WriterType::New();
writer->SetInput(reader->GetOutput());
NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
std::string format = argv[2];
format += "%03d.";
format += argv[3];
nameGenerator->SetSeriesFormat(format.c_str());
try
{
reader->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown while reading the image" << std::endl;
std::cerr << excp << std::endl;
}
ImageType::ConstPointer inputImage = reader->GetOutput();
const unsigned int firstSlice = start[2];
const unsigned int lastSlice = start[2] + size[2] - 1;
nameGenerator->SetStartIndex(firstSlice);
nameGenerator->SetEndIndex(lastSlice);
nameGenerator->SetIncrementIndex(1);
writer->SetFileNames(nameGenerator->GetFileNames());
try
{
writer->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown while reading the image" << std::endl;
std::cerr << excp << std::endl;
}
return EXIT_SUCCESS;
}