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;
reader->SetFileName(argv[1]);
adaptor->SetImage(reader->GetOutput());
try
{
reader->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Problem reading image file : " << argv[1] << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
using HistogramMeasurementType = PixelType;
using FilterType =
itk::Statistics::SampleToHistogramFilter<AdaptorType, HistogramType>;
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();
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;
}