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 -1;
}
const unsigned int Dimension = 2;
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::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return -1;
}
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 0;
}