[Insight-users] Histogram Computation

Gunderson, Keith R keith-gunderson at uiowa.edu
Thu Oct 16 10:58:11 EDT 2008


Antonio Foncubierta wrote:
> Hello,
> 
> I am trying to obtain the histogram of a 3D Image, but I don't really
> know how to do this. I've been reading the software guide, and
> couldn't find a simple way to achieve it. Also, i've been reading the
> online documentation (which really lacks examples) and i **guessed**
> that I should use itk::Statistics::ImageToHistogramGenerator , but
> still i am lost and I don't know how to use this filter. If I try to
> instantiate it with the "::Pointer ... ::New()" line, i get error
> messages at compile time.       
> 
> Can anyone help me?
> 
> thank you in advance,
> 
> 
> Antonio Foncubierta

I had problems with that class, admittedly using old code.  But, I could
use a few more basic classes to make it work.


Here's a bit of rough code that I used...

 typedef itk::Statistics::ScalarImageToListAdaptor< ImageTypeIn >
AdaptorType;
  AdaptorType::Pointer adaptor = AdaptorType::New();
  adaptor->SetImage( image1  );
  //adaptor->Update();

  typedef itk::Statistics::ListSampleToHistogramGenerator<
  AdaptorType,
    TPixelIn
    > GeneratorType;
  GeneratorType::Pointer generator = GeneratorType::New();

  typedef GeneratorType::HistogramType HistogramType;
  HistogramType::SizeType size;



  HistogramType::MeasurementVectorType min1 ;
  min1[0] = -1024.5;
  HistogramType::MeasurementVectorType max1 ;
  max1[0] = 200.5;
  size.Fill( 1024.5 + 200.5 );
  generator->SetListSample( adaptor );
  generator->SetHistogramMax( max1 );
  generator->SetHistogramMin(min1  );
  generator->SetNumberOfBins( size );
  generator->SetMarginalScale( 10.0 );
  generator->Update();

  const HistogramType * histogram = generator->GetOutput();
  const unsigned int histogramSize = histogram->Size();

  pixel = -1024;

  for( unsigned int bin=0; bin < histogramSize; bin++, pixel++ )
    {

      count =  histogram->GetFrequency( bin, 0 );
	rc = sqlite3_prepare_v2(db, "replace into histograms ( label,
pixel,  count)  values(  ? ,  ?,  ?) ; " ,-1, &stmtInsert, NULL  );


   ...
}




More information about the Insight-users mailing list