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;
}
using PixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
AdaptorType::Pointer adaptor = AdaptorType::New();
adaptor->SetImage( reader->GetOutput() );
try
{
reader->Update();
}
{
std::cerr << "Problem reading image file : " << argv[1] << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
using HistogramMeasurementType = PixelType;
AdaptorType,
HistogramType>;
FilterType::Pointer filter = FilterType::New();
constexpr unsigned int numberOfComponents = 1;
size.Fill( 255 );
filter->SetInput( adaptor );
filter->SetHistogramSize( size );
filter->SetMarginalScale( 10 );
HistogramType::MeasurementVectorType min( numberOfComponents );
HistogramType::MeasurementVectorType max( numberOfComponents );
min.Fill( 0 );
max.Fill( 255 );
filter->SetHistogramBinMinimum( min );
filter->SetHistogramBinMaximum( max );
filter->Update();
HistogramType::ConstPointer histogram = filter->GetOutput();
const unsigned int histogramSize = histogram->Size();
std::cout << "Histogram size " << histogramSize << std::endl;
for (unsigned int bin=0; bin < histogramSize; ++bin)
{
std::cout << "bin = " << bin << " frequency = ";
std::cout << histogram->GetFrequency( bin, 0 ) <<std::endl;
}
return EXIT_SUCCESS;
}