class CastPixelAccessor
{
public:
using InternalType = unsigned char;
using ExternalType = float;
static void Set(InternalType & output, const ExternalType & input)
{
output = static_cast<InternalType>( input );
}
static ExternalType Get( const InternalType & input )
{
return static_cast<ExternalType>( input );
}
};
int main( int argc, char *argv[] )
{
if( argc < 2 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << "ImageAdaptor1 inputFileName" << std::endl;
return EXIT_FAILURE;
}
using InputPixelType = unsigned char;
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
reader->Update();
adaptor->SetImage( reader->GetOutput() );
IteratorType it( adaptor, adaptor->GetBufferedRegion() );
double sum = 0.0;
while( !it.IsAtEnd() )
{
float value = it.Get();
sum += value;
++it;
}
std::cout << "Sum of pixels is: " << sum << std::endl;
return EXIT_SUCCESS;
}