[Insight-users] Histogram creation...

Jean-Philippe Guyon jguyon at ils-inc.com
Fri, 16 Jan 2004 12:09:53 -0500


sorry about the poor naming convention...
I have actually switched back and forth between a
ListSampleToHistogramFilter, and a ListSampleToHistogramGenerator... which
is the reason for the ambiguity :o)

The variable m_HistogramGenerator is indeed an instance of
ListSampleToHistrogramFilter.
It would be more appropriate to call it m_HistogramFilter instead.
Here is a revised version of the code...

----------------------------------------------------------------------------
--------------------------------------

typedef typename itk::Vector<typename InputType::PixelType,1>
VectorType;
typedef typename itk::Statistics::ListSample<VectorType>
ListSampleType;
typedef typename HistogramSampleType::Pointer
ListSamplePointer;
typedef typename itk::Statistics::Histogram<typename MaskType::PixelType,1 >
HistogramType;
typedef typename HistogramType::Pointer
HistogramPointer;
typedef typename HistogramType::SizeType
HistogramSizeType;
typedef itk::Statistics::ListSampleToHistogramFilter<HistogramSampleType,
HistogramType > HistogramFilterType;
typedef typename HistogramFilterType::Pointer
HistogramFilterPointer;

ListSamplePointer 	m_ListSample;
HistogramPointer 	m_Histogram;
HistogramFilterPointer 	m_HistogramFilter;

----------------------------------------------------------------------------
---------------------------------------

HistogramType::SizeType size;
HistogramType::MeasurementVectorType min;
HistogramType::MeasurementVectorType max;

size.Fill(25);
min.Fill(0);
max.Fill(999999);

this->m_Histogram = HistogramType::New();
this->m_Histogram->Initialize(size,min,max);

this->m_ListSample = ListSampleType::New();

this->m_HistogramFilter = HistogramFilterType::New();
this->m_HistogramFilter->SetListSample(this->m_ListSample);
this->m_HistogramFilter->SetHistogram(this->m_Histogram);

while(!maskIt.IsAtEnd())
{
    if(maskIt.Value())
    {
    this->m_ListSample->PushBack(inputIt.Value());
    }
    ++maskIt;
    ++inputIt;
}

this->m_HistogramFilter->Update();

----------------------------------------------------------------------------
--------------------

Typically, why would someone choose to use a ListSampleToHistogramGenerator
rather than a ListSampleToHistogramFilter ??
It seems to me that using the histogram generator is more generic in the
sense that we do not need to know anything about the list of values that is
provided to the filter.

Thanks,

Jean-Philippe




-----Original Message-----
From: Luis Ibanez [mailto:luis.ibanez at kitware.com]
Sent: Friday, January 16, 2004 11:28 AM
To: jguyon at ils-inc.com
Cc: insight-users at itk.org
Subject: Re: [Insight-users] Histogram creation...



Hi Jean-Philippe


It is not clear from your code what the
type of the variable HistogramGenerator
is.

 From the typedefs it may seem that is
a ListSampleToHistogramFilter but from
the name it insinuates to be a
ListSampleToHistogramGenerator.

Could you please post the variable
declarations ?

or even better,

a complete piece of code that we could
compille and run...to try to reproduce
the error that you find.



Thanks,


   Luis


------------------------
Jean-Philippe Guyon wrote:

> Hello,
>
> I am trying to create a histogram that contains values of all the
> pixels within a volume extracted using the GeodesicActiveContour
> approach provided by ITK.
> Basically, the result of the segmentation algorithm is used as a mask
> for the histogram generation.
> I am using the code below and I get the following exception when I call
> the final Update():
>
> itk::ERROR: Histogram(0581A178): One of the measurement components is
> below the minimum
>
> I find it surprising to get that error message since the image processed

> contains only positive values.
> Any idea why this happens ???
>
> Jean-Philippe
>
> --------------------------------------------------------------------------
-------------------------------------
>
> typedef typename itk::Vector<typename
> InputType::PixelType,1>                              VectorType;
> typedef typename itk::Statistics::ListSample<VectorType
>  >                                          HistogramSampleType;
> typedef typename
> HistogramSampleType::Pointer
> HistogramSamplePointer;
> typedef typename itk::Statistics::Histogram<typename
> MaskType::PixelType,1 >    HistogramType;
> typedef typename
> HistogramType::Pointer
> HistogramPointer;
> typedef typename
> HistogramType::SizeType
HistogramSizeType;
> typedef itk::Statistics::ListSampleToHistogramFilter<
> HistogramSampleType, HistogramType > HistogramFilterType;
> typedef typename
> HistogramFilterType::Pointer
> HistogramFilterPointer;
>
> //....
> // Definition of iterators, etc....
> //....
>
> HistogramType::SizeType size;
> HistogramType::MeasurementVectorType min;
> HistogramType::MeasurementVectorType max;
>
> size.Fill(25);
> min.Fill(0);
> max.Fill(999999);
>
> this->m_Histogram = HistogramType::New();
> this->m_Histogram->Initialize(size,min,max);
>
> this->m_HistogramSample = HistogramSampleType::New();
>
> this->m_HistogramGenerator = HistogramFilterType::New();
> this->m_HistogramGenerator->SetListSample(this->m_HistogramSample);
> this->m_HistogramGenerator->SetHistogram(this->m_Histogram);
>
> while(!maskIt.IsAtEnd())
> {
>     if(maskIt.Value())
>     {
>     this->m_HistogramSample->PushBack(inputIt.Value());
>     }
>     ++maskIt;
>     ++inputIt;
> }
>
> this->m_HistogramGenerator->Update();
>
>