namespace itk
{
class VectorPixelAccessor
{
public:
typedef float ExternalType;
VectorPixelAccessor() : m_Index(0) {}
VectorPixelAccessor & operator=( const VectorPixelAccessor & vpa )
{
m_Index = vpa.m_Index;
return *this;
}
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;
};
}
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;
}
typedef unsigned char InputPixelType;
VectorImageType> GradientFilterType;
GradientFilterType::Pointer gradient = GradientFilterType::New();
itk::VectorPixelAccessor > ImageAdaptorType;
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
itk::VectorPixelAccessor accessor;
accessor.SetIndex( atoi( argv[3] ) );
adaptor->SetPixelAccessor( accessor );
ReaderType::Pointer reader = ReaderType::New();
gradient->SetInput( reader->GetOutput() );
reader->SetFileName( argv[1] );
gradient->Update();
adaptor->SetImage( gradient->GetOutput() );
RescalerType;
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;
}