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;
Dimension >;
using OutputPixelType = unsigned short;
InputImageType,
ComponentImageType >;
FilterType::Pointer componentExtractor = FilterType::New();
const unsigned int indexOfComponentToExtract = std::stoi( argv[4] );
if( indexOfComponentToExtract >= Dimension )
{
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 );
ComponentImageType,
OutputImageType >;
RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
rescaler->SetOutputMinimum( itk::NumericTraits< OutputPixelType >::min() );
rescaler->SetOutputMaximum( itk::NumericTraits< OutputPixelType >::max() );
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();
}
{
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;
}