ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Numerics/Statistics/CreateHistogramFromListOfMeasurements/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "itkListSample.h"
#include "itkHistogram.h"
using MeasurementVectorType = itk::Vector<unsigned char, 1>;
void
CreateSample(SampleType::Pointer sample);
int
main()
{
auto sample = SampleType::New();
CreateSample(sample);
using SampleToHistogramFilterType = itk::Statistics::SampleToHistogramFilter<SampleType, HistogramType>;
auto sampleToHistogramFilter = SampleToHistogramFilterType::New();
sampleToHistogramFilter->SetInput(sample);
SampleToHistogramFilterType::HistogramSizeType histogramSize(1);
histogramSize.Fill(10);
sampleToHistogramFilter->SetHistogramSize(histogramSize);
sampleToHistogramFilter->Update();
const HistogramType * histogram = sampleToHistogramFilter->GetOutput();
std::cout << "Histogram vector size: " << histogram->GetMeasurementVectorSize() << std::endl;
for (unsigned int i = 0; i < histogram->GetSize()[0]; ++i)
{
std::cout << "Frequency of " << i << " : (" << histogram->GetBinMin(0, i) << " to " << histogram->GetBinMax(0, i)
<< ") = " << histogram->GetFrequency(i) << std::endl;
}
std::cout << "Total count " << histogram->GetTotalFrequency() << std::endl;
return EXIT_SUCCESS;
}
void
CreateSample(SampleType::Pointer sample)
{
MeasurementVectorType mv;
mv[0] = 1.0;
sample->PushBack(mv);
mv[0] = 1.0;
sample->PushBack(mv);
mv[0] = 2.0;
sample->PushBack(mv);
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::Statistics::ListSample
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
itk::Statistics::Histogram
This class stores measurement vectors in the context of n-dimensional histogram.
Definition: itkHistogram.h:77
itkSampleToHistogramFilter.h
itkHistogram.h
itkListSample.h
New
static Pointer New()