int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile numberOfSamples" << std::endl;
return EXIT_FAILURE;
}
using PixelType = unsigned short;
ImageType::ConstPointer inputImage;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
try
{
reader->Update();
inputImage = reader->GetOutput();
}
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
ConstIteratorType inputIt(inputImage, inputImage->GetRequestedRegion());
inputIt.SetNumberOfSamples(::std::stoi(argv[2]));
inputIt.ReinitializeSeed();
float mean = 0.0f;
for (inputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt)
{
mean += static_cast<float>(inputIt.Get());
}
mean = mean / ::std::stod(argv[2]);
std::cout << "Mean estimate with " << argv[2] << " samples is " << mean
<< std::endl;
return EXIT_SUCCESS;
}