[Insight-users] histogram questions

Sergio Aguirre sergio.aguirre at gmail.com
Wed Apr 11 17:37:46 EDT 2012


Hi everyone

I am calculating a histogram of a grayscale image (3D volume) using a
ImageToListSampleAdaptor and a SampleToHistogramFilter pipeline (see below)
- I feel I control the bounds of the bins better this way.

So I am interested in extracting some information from the resulting 1
dimensional histogram, specifically the frequency container vector or the
maximum value (bin index and frequency value) of the frequency container
vector.

Any suggestions on how to do this? I could not identify a straightforward
way of doing this...

Do I need to traverse the histogram and calculate the max value separately?

Any suggestions are appreciated.

Sergio

Code -----
typedef itk::FixedArray< short, 1 > MeasurementVectorType;
typedef itk::Image< MeasurementVectorType, 3 > ArrayImageType;
typedef itk::ScalarToArrayCastImageFilter< ImageType, ArrayImageType >
CasterType;
typedef itk::Statistics::ImageToListSampleAdaptor< ArrayImageType >
SampleType;
typedef itk::Statistics::Histogram<
short,itk::Statistics::DenseFrequencyContainer2 > HistogramType;
typedef itk::Statistics::SampleToHistogramFilter<SampleType, HistogramType>
SampleToHistogramFilterType;

CasterType::Pointer caster = CasterType::New();
caster->SetInput( reader->GetOutput() );
caster->Update();

SampleType::Pointer sample = SampleType::New();
sample->SetImage( caster->GetOutput() );

SampleToHistogramFilterType::Pointer sampleToHistogramFilter =
SampleToHistogramFilterType::New();
sampleToHistogramFilter->SetInput(sample);

SampleToHistogramFilterType::HistogramSizeType histogramSize(1);
histogramSize.Fill((max-min)+1);
sampleToHistogramFilter->SetHistogramSize(histogramSize);

sampleToHistogramFilter->Update();

const HistogramType* histogram = sampleToHistogramFilter->GetOutput();

for ( short i = 0; i < histogram->GetSize()[0]; i++ )
{
   std::cout << i << " - " << histogram->GetBinMin(0, i) << " - " <<
histogram->GetBinMax(0, i) << " - " << histogram->GetFrequency(i) <<
std::endl;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120411/ef20aa55/attachment.htm>


More information about the Insight-users mailing list