void CreateImage(ImageType::Pointer image);
int main(int, char *[])
{
constexpr unsigned int MeasurementVectorSize = 3;
constexpr unsigned int binsPerDimension = 4;
ImageType::Pointer image = ImageType::New();
CreateImage(image);
ImageToHistogramFilterType::HistogramType::MeasurementVectorType lowerBound(MeasurementVectorSize);
lowerBound.Fill(0);
ImageToHistogramFilterType::HistogramType::MeasurementVectorType upperBound(MeasurementVectorSize);
upperBound.Fill(255);
size.Fill(binsPerDimension);
ImageToHistogramFilterType::Pointer imageToHistogramFilter = ImageToHistogramFilterType::New();
imageToHistogramFilter->SetInput(image);
imageToHistogramFilter->SetHistogramBinMinimum(lowerBound);
imageToHistogramFilter->SetHistogramBinMaximum(upperBound);
imageToHistogramFilter->SetHistogramSize(size);
imageToHistogramFilter->SetAutoMinimumMaximum(false);
imageToHistogramFilter->Update();
ImageToHistogramFilterType::HistogramType* histogram = imageToHistogramFilter->GetOutput();
unsigned int totalBins = 1;
for(unsigned int i = 0; i < size.GetNumberOfElements(); ++i)
{
totalBins *= histogram->GetSize()[i];
}
std::cout << "totalBins: " << totalBins << std::endl;
std::cout << "Frequency = ";
for(unsigned int i = 0; i < totalBins; ++i)
{
std::cout << histogram->GetFrequency(i) << " ";
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
void CreateImage(ImageType::Pointer image)
{
image->SetRegions(region);
image->Allocate();
RGBPixelType zeroPixel;
zeroPixel.SetRed(0);
zeroPixel.SetGreen(0);
zeroPixel.SetBlue(0);
image->FillBuffer(zeroPixel);
RGBPixelType pixel;
pixel.SetRed(110);
pixel.SetGreen(110);
pixel.SetBlue(110);
while(!imageIterator.IsAtEnd())
{
std::cout << "Setting pixel " << imageIterator.GetIndex() << " to " << pixel << std::endl;
imageIterator.Set(pixel);
++imageIterator;
}
}