int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Usage: ImageReadImageSeriesWrite inputFile outputPrefix "
"outputExtension"
<< std::endl;
return EXIT_FAILURE;
}
reader->SetFileName(argv[1]);
writer->SetInput(reader->GetOutput());
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;
}
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;
}