class RedChannelPixelAccessor
{
public:
typedef float ExternalType;
static ExternalType Get( const InternalType & input )
{
return static_cast<ExternalType>( input.GetRed() );
}
};
int main( int argc, char *argv[] )
{
if( argc < 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << "ImageAdaptor2 inputRGBFileName outputRedChannelFileName" << std::endl;
return EXIT_FAILURE;
}
typedef RedChannelPixelAccessor::InternalType InputPixelType;
const unsigned int Dimension = 2;
RedChannelPixelAccessor > ImageAdaptorType;
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
reader->Update();
adaptor->SetImage( reader->GetOutput() );
OutputImageType
> 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() );
try
{
writer->Update();
}
{
std::cerr << "Exception caught " << excp << std::endl;
return EXIT_FAILURE;
}
class GreenChannelPixelAccessor
{
public:
typedef float ExternalType;
static ExternalType Get( const InternalType & input )
{
return static_cast<ExternalType>( input.GetGreen() );
}
};
class BlueChannelPixelAccessor
{
public:
typedef float ExternalType;
static ExternalType Get( const InternalType & input )
{
return static_cast<ExternalType>( input.GetBlue() );
}
};
return EXIT_SUCCESS;
}