namespace itk
{
class VectorPixelAccessor
{
public:
using ExternalType = float;
VectorPixelAccessor() {}
VectorPixelAccessor & operator=( const VectorPixelAccessor & vpa ) = default;
ExternalType Get( const InternalType & input ) const
{
return static_cast<ExternalType>( input[ m_Index ] );
}
void SetIndex( unsigned int index )
{
m_Index = index;
}
private:
unsigned int m_Index{0};
};
}
int main( int argc, char *argv[] )
{
if( argc < 4 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << "ImageAdaptor3 inputFileName outputComponentFileName ";
std::cerr << " indexOfComponentToExtract" << std::endl;
return EXIT_FAILURE;
}
using InputPixelType = unsigned char;
using GradientFilterType =
VectorImageType>;
GradientFilterType::Pointer gradient = GradientFilterType::New();
itk::VectorPixelAccessor >;
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
itk::VectorPixelAccessor accessor;
accessor.SetIndex( std::stoi( argv[3] ) );
ReaderType::Pointer reader = ReaderType::New();
gradient->SetInput( reader->GetOutput() );
reader->SetFileName( argv[1] );
gradient->Update();
adaptor->SetImage( gradient->GetOutput() );
OutputImageType>;
RescalerType::Pointer rescaler = RescalerType::New();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );
rescaler->SetOutputMinimum( 0 );
rescaler->SetOutputMaximum( 255 );
rescaler->SetInput( adaptor );
writer->SetInput( rescaler->GetOutput() );
writer->Update();
return EXIT_SUCCESS;
}