[Insight-developers] correct use of ImageToHistogramFilter

Luis Ibanez luis.ibanez at kitware.com
Sun May 9 15:57:15 EDT 2010


Hi Richard


The variable:

              hsize

in your code, is ultimately of type

              itk::Array

Therefore, its number of component must be
set at construction time.

Instead of your current code:

>      typename HistGenType::HistogramSizeType hsize;

you should have

>      typename HistGenType::HistogramSizeType hsize( 1 );


---

What you are observing with

             Hist->SetHistogramSize(100);

is an accidental promotion, by which the number 100 is
used as the constructor for a variable of type

             HistGenType::HistogramSizeType

which ends up being an itk::Array.

Contrary to what you may expect in that expression, the
automatic construction does not result in an array of one
element with that element having the value "100", but
in an array of 100 elements, all of them uninitialized.

Please don't use

            Hist->SetHistogramSize(100);

What you should use is

  typename HistGenType::HistogramSizeType hsize( 1 );
  hsize.Fill( 100 );
  Hist->SetHistogramSize( hsize );




    Regards,


            Luis


--------------------------------------------------------------------------------------------
On Wed, May 5, 2010 at 2:04 AM, Richard Beare <richard.beare at gmail.com> wrote:
> Hello,
>
> I'm struggling getting this filter to work under ITK 3.16, and I
> suspect I'm missing something in the histogram terminology or getting
> mixed up in the decorator macros:
>
>      typedef typename
> itk::Statistics::ImageToHistogramFilter<OutImType> HistGenType;
>      typedef typename HistGenType::HistogramType HistogramType;
>      typename HistGenType::Pointer Hist = HistGenType::New();
>      typename HistGenType::HistogramSizeType hsize;
>      typename HistGenType::HistogramMeasurementVectorType hmeas;
>
>      hsize.Fill(100);
>      hmeas.Fill(0.1);
>      Hist->SetInput(Rescaler->GetOutput());
>      // one component histogram
>
>      Hist->SetHistogramSize(hsize);
>
>      typename HistGenType::HistogramMeasurementVectorType hmin, hmax;
>      hmin.Fill(CmdLineObj.hmin);
>      hmax.Fill(CmdLineObj.hmax);
>
>      Hist->SetHistogramBinMinimum(hmin);
>      Hist->SetHistogramBinMaximum(hmax);
>      Hist->SetMarginalScale(0.1);
>      Hist->Update();
>
>
> I get the following error:
>
> itk::ERROR: SampleToHistogramFilter(0x129ff2d0): Histogram number of
> components: 0 doesn't match Measurement Vector Size: 1
>
>
> if I change the call to
>
> Hist->SetHistogramSize(100);
>
> I get
>
> terminate called after throwing an instance of 'itk::ExceptionObject'
>  what():  /usr/local/hpcmedsw/ITK/ITK-3.16/include/InsightToolkit/Review/Statistics/itkSampleToHistogramFilter.txx:185:
> itk::ERROR: SampleToHistogramFilter(0x1a5ba2d0): Histogram number of
> components: 100 doesn't match Measurement Vector Size: 1
>
>
> What am I doing wrong?
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers
>


More information about the Insight-developers mailing list