namespace
{
int
ExampleMain(int argc, const char * const 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;
constexpr unsigned int Dimension = 2;
ImageType::Pointer input;
using HistogramGeneratorType =
auto histogramGenerator = HistogramGeneratorType::New();
histogramGenerator->SetInput(input);
histogramGenerator->SetNumberOfBins(256);
histogramGenerator->SetMarginalScale(10.0);
histogramGenerator->SetHistogramMin(-0.5);
histogramGenerator->SetHistogramMax(255.5);
histogramGenerator->Compute();
using HistogramType = HistogramGeneratorType::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();
const 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;
}
}
int
main(int argc, char * argv[])
{
try
{
return ExampleMain(argc, argv);
}
{
std::cerr << "ITK exception caught:\n" << exceptionObject << '\n';
}
catch (const std::exception & stdException)
{
std::cerr << "std exception caught:\n" << stdException.what() << '\n';
}
catch (...)
{
std::cerr << "Unhandled exception!\n";
}
return EXIT_FAILURE;
}
Standard exception handling object.
Templated n-dimensional image class.
TOutputImage::Pointer ReadImage(const std::string &filename)