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;
reader->SetFileName(argv[1]);
reader->Update();
adaptor->SetImage(reader->GetOutput());
IteratorType it(adaptor, adaptor->GetBufferedRegion());
double sum = 0.0;
while (!it.IsAtEnd())
{
const float value = it.Get();
sum += value;
++it;
}
std::cout << "Sum of pixels is: " << sum << std::endl;
return EXIT_SUCCESS;
}