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;
}
typedef unsigned short PixelType;
ImageType > ConstIteratorType;
ImageType::ConstPointer inputImage;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
inputImage = reader->GetOutput();
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
ConstIteratorType inputIt( inputImage, inputImage->GetRequestedRegion() );
inputIt.SetNumberOfSamples( ::atoi( argv[2]) );
inputIt.ReinitializeSeed();
float mean = 0.0f;
for ( inputIt.GoToBegin(); ! inputIt.IsAtEnd(); ++inputIt)
{
mean += static_cast<float>( inputIt.Get() );
}
mean = mean / ::atof( argv[2] );
std::cout << "Mean estimate with " << argv[2] << " samples is " << mean << std::endl;
return EXIT_SUCCESS;
}