ITK/Examples/Statistics/SampleToHistogramFilter
From KitwarePublic
< ITK | Examples
Jump to navigationJump to search
Revision as of 21:33, 20 November 2010 by Daviddoria (talk | contribs) (Created page with "==SampleToHistogramFilter.cxx== <source lang="cpp"> #include "itkSampleToHistogramFilter.h" #include "itkListSample.h" #include "itkHistogram.h" typedef itk::Vector<unsigned cha...")
SampleToHistogramFilter.cxx
<source lang="cpp">
- include "itkSampleToHistogramFilter.h"
- include "itkListSample.h"
- include "itkHistogram.h"
typedef itk::Vector<unsigned char, 1> MeasurementVectorType; typedef itk::Statistics::ListSample< MeasurementVectorType > SampleType ;
typedef itk::Statistics::Histogram< float,
itk::Statistics::DenseFrequencyContainer2 > HistogramType;
void CreateSample(SampleType::Pointer image);
int main(int, char *[]) {
SampleType::Pointer sample = SampleType::New(); CreateSample(sample);
typedef itk::Statistics::SampleToHistogramFilter<SampleType, HistogramType> SampleToHistogramFilterType; SampleToHistogramFilterType::Pointer 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) ;
} </source>
CMakeLists.txt
<source lang="cmake"> cmake_minimum_required(VERSION 2.6)
PROJECT(SampleToHistogramFilter)
FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(SampleToHistogramFilter_1D SampleToHistogramFilter_1D.cxx) TARGET_LINK_LIBRARIES(SampleToHistogramFilter_1D ITKBasicFilters ITKCommon ITKIO ITKStatistics)
</source>