int
main(int argc, char ** argv)
{
if (argc < 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputVectorImageFile outputScalarImageFile";
std::cerr << " outupNormalizedScalarImageFile";
std::cerr << " componentToExtract" << std::endl;
return EXIT_FAILURE;
}
using ComponentType = float;
using OutputPixelType = unsigned short;
using FilterType =
ComponentImageType>;
FilterType::Pointer componentExtractor = FilterType::New();
const unsigned int indexOfComponentToExtract = std::stoi(argv[4]);
{
std::cerr << "You are requesting an index out of the range for the "
"Vector dimension"
<< std::endl;
std::cerr <<
"Vector dimension is = " <<
Dimension << std::endl;
std::cerr << "but your requested index = " << indexOfComponentToExtract
<< std::endl;
return EXIT_FAILURE;
}
componentExtractor->SetIndex(indexOfComponentToExtract);
using RescaleFilterType =
RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
const char * inputFilename = argv[1];
const char * outputFilename = argv[3];
reader->SetFileName(inputFilename);
writer->SetFileName(outputFilename);
componentExtractor->SetInput(reader->GetOutput());
rescaler->SetInput(componentExtractor->GetOutput());
writer->SetInput(rescaler->GetOutput());
try
{
writer->Update();
}
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
ComponentWriterType::Pointer componentWriter = ComponentWriterType::New();
componentWriter->SetInput(componentExtractor->GetOutput());
componentWriter->SetFileName(argv[2]);
componentWriter->Update();
return EXIT_SUCCESS;
}