int main( int argc, char * argv [] )
{
if( argc < 2 )
{
std::cerr << "Missing command line arguments" << std::endl;
std::cerr << "Usage : ImageHistogram1 inputImageFileName " << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char PixelType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
}
{
std::cerr << "Problem reading image file : " << argv[1] << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ImageType > HistogramGeneratorType;
HistogramGeneratorType::Pointer histogramGenerator =
HistogramGeneratorType::New();
histogramGenerator->SetInput( reader->GetOutput() );
histogramGenerator->SetNumberOfBins( 256 );
histogramGenerator->SetMarginalScale( 10.0 );
histogramGenerator->SetHistogramMin( -0.5 );
histogramGenerator->SetHistogramMax( 255.5 );
histogramGenerator->Compute();
typedef HistogramGeneratorType::HistogramType HistogramType;
const HistogramType * histogram = histogramGenerator->GetOutput();
const unsigned int histogramSize = histogram->Size();
std::cout << "Histogram size " << histogramSize << std::endl;
unsigned int bin;
for( bin=0; bin < histogramSize; bin++ )
{
std::cout << "bin = " << bin << " frequency = ";
std::cout << histogram->GetFrequency( bin, 0 ) << std::endl;
}
HistogramType::ConstIterator itr = histogram->Begin();
HistogramType::ConstIterator end = histogram->End();
unsigned int binNumber = 0;
while( itr != end )
{
std::cout << "bin = " << binNumber << " frequency = ";
std::cout << itr.GetFrequency() << std::endl;
++itr;
++binNumber;
}
return EXIT_SUCCESS;
}