static void
int
main()
{
constexpr unsigned int MeasurementVectorSize = 3;
CreateImage(image);
CreateHalfMask(image->GetLargestPossibleRegion(), mask);
using HistogramMeasurementVectorType = HistogramFilterType::HistogramMeasurementVectorType;
using HistogramSizeType = HistogramFilterType::HistogramSizeType;
using HistogramType = HistogramFilterType::HistogramType;
histogramFilter->SetInput(image);
histogramFilter->SetMaskImage(mask);
histogramFilter->SetAutoMinimumMaximum(true);
HistogramSizeType histogramSize(MeasurementVectorSize);
histogramSize[0] = 4;
histogramSize[1] = 4;
histogramSize[2] = 4;
histogramFilter->SetHistogramSize(histogramSize);
histogramFilter->SetMarginalScale(10);
histogramFilter->Update();
const HistogramType * histogram = histogramFilter->GetOutput();
HistogramType::ConstIterator histogramIterator = histogram->Begin();
while (histogramIterator != histogram->End())
{
++histogramIterator;
}
HistogramType::MeasurementVectorType mv(3);
mv[0] = 255;
mv[1] = 0;
mv[2] = 0;
std::cout << "Frequency = " << histogram->GetFrequency(histogram->GetIndex(mv)) << std::endl;
return EXIT_SUCCESS;
}
void
{
size[0] = 3;
size[1] = 3;
start[0] = 0;
start[1] = 0;
region.SetSize(size);
image->SetRegions(region);
image->Allocate();
RGBPixelType redPixel;
redPixel.SetRed(255);
redPixel.SetGreen(0);
redPixel.SetBlue(0);
RGBPixelType blackPixel;
blackPixel.SetRed(0);
blackPixel.SetGreen(0);
blackPixel.SetBlue(0);
while (!imageIterator.IsAtEnd())
{
imageIterator.Set(blackPixel);
++imageIterator;
}
index[0] = 0;
index[1] = 0;
image->SetPixel(index, redPixel);
index[0] = 1;
index[1] = 0;
image->SetPixel(index, redPixel);
}
{
mask->SetRegions(region);
mask->Allocate();
mask->FillBuffer(0);
while (!imageIterator.IsAtEnd())
{
if (imageIterator.GetIndex()[0] > regionSize[0] / 2)
{
imageIterator.Set(0);
}
else
{
imageIterator.Set(1);
}
++imageIterator;
}
rescaleFilter->SetInput(mask);
rescaleFilter->Update();
}