int
main(int argc, char ** argv)
{
if (argc < 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " input3DImageFile output2DImageFile sliceNumber"
<< std::endl;
return EXIT_FAILURE;
}
using InputPixelType = short;
using OutputPixelType = short;
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
reader->SetFileName(inputFilename);
writer->SetFileName(outputFilename);
filter->InPlaceOn();
filter->SetDirectionCollapseToSubmatrix();
reader->UpdateOutputInformation();
reader->GetOutput()->GetLargestPossibleRegion();
size[2] = 0;
const unsigned int sliceNumber = std::stoi(argv[3]);
start[2] = sliceNumber;
desiredRegion.SetIndex(start);
filter->SetExtractionRegion(desiredRegion);
filter->SetInput(reader->GetOutput());
writer->SetInput(filter->GetOutput());
try
{
writer->Update();
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Standard exception handling object.
Data source that reads image data from a single file.
Writes image data to a single file.
void SetSize(const SizeType &size)
Templated n-dimensional image class.
ImageBaseType::RegionType RegionType
ImageBaseType::IndexType IndexType
ImageBaseType::SizeType SizeType
const IndexValueType * GetIndex() const
const SizeValueType * GetSize() const