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;
}
typedef float ComponentType;
const unsigned int Dimension = 2;
Dimension > InputPixelType;
typedef unsigned short OutputPixelType;
InputImageType,
ComponentImageType > FilterType;
FilterType::Pointer componentExtractor = FilterType::New();
const unsigned int indexOfComponentToExtract = atoi( 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;
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();
}
{
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;
}