[Insight-users] Generating Imag from Histogram using Intensity Function

Lars Nygard lnygard at yahoo.com
Tue Aug 14 18:19:11 EDT 2007

Hi Luis,

Thanks for explaining this. Ive just managed to do the
same with vtk and tcl. However vtk's ImageViewer only
supports RGB or transformations to grayscale using
SetColorWindow and SetColorLevel.
My images look quite different in vtk so I think it's better
to try ITK for this. 
Lars Nygard

----- Original Message ----
From: Luis Ibanez <luis.ibanez at kitware.com>
To: Lars Nygard <lnygard at yahoo.com>
Cc: insight-users at itk.org
Sent: Tuesday, August 14, 2007 11:06:53 AM
Subject: Re: [Insight-users] Generating Imag from Histogram using Intensity Function

Hi Lars,

Thanks for your detailed description of the problem.

The difficulty that you are facing is due to the fact that the 


                        *IS NOT* a pipeline filter.

You are using it under the assumption that Update()
calls will propagate through this class. This is not the case.

This class is equivalent to a "Calculator".

Please read carefully the description of this class in the 

ITK Software Guide



I order to use it properly you must do the following:

1) Call Update() on the filter that is going to provide the 

    input to the histogram generator

2) Set the parameters of the histogram 
    - Number of bins
    - minimum 
    - maximum

3) Call "Compute() on the histogram generator

4) Get the output and pass it to a subsequent filter

    e.g. the HistogramToImage filter

5) Call Update() on that downstream filter.

Note also that if your input image has a single
component per pixel (e.g. it is a Scalar image),
then its Histogram will be a 1-dimensional array,

and when you use the HistogramToImage filter
you will get an image of dimensions 

                       NumberOfBins X 1

If your purpose was to plot the histogram, you
may want to rather use the histogram bin 

iterator in order to recover the count values
from the bins. (as shown in the attached example).

Note that the ITK Statistics Framework is currently

being refactored. As part of this refactoring effort,
most "Generator" and "Calculator" classes have been
converted into actual pipeline filters.  You will find
information about the refactoring at the Wiki page:


The description of the new framework can be seen at:


The migration guide is available at:


The source code of the refactored Framework is available at:


The refactored version of the Statistics Framework is currently
experimental, and will NOT be included in ITK before the release of ITK 3.4.

In the meantime, please find attached the source code 

of your example, after all these issues have been fixed.
(using the current ITK CVS version).

Please give it a try and let us know if you have
any questions,



On 8/14/07, Lars Nygard <lnygard at yahoo.com
> wrote:Hi all,

Im trying to make an applet where I scroll through an image and

where I can see the histogram of every slice. However Im getting
an error from windows when I try to update the HistogramToIntensityImageFilter.
Im first trying with a 2D png image.
Ive tried to catch the error but windows is giving an error and I don't know what's

wrong. The code is bellow. Anybody got an idea what's wrong??
Lars Nygard

//Declare input Image
  typedef unsigned char      PixelType;
  const   unsigned int        Dimension = 2;
  typedef unsigned char MeasurementType ;

  typedef itk::Image< PixelType, Dimension >    ImageType;
  typedef itk::Image< unsigned char, 2> BinImageType;

  typedef itk::ImageFileReader< ImageType >  ReaderType;
  ReaderType::Pointer reader = ReaderType::New();

  reader->SetFileName( "BrainSliceT1.png" );

  //code for generating the histogram
  typedef itk::Statistics::ScalarImageToHistogramGenerator< ImageType > HistogramGenType;
  typedef HistogramGenType::HistogramType  HistogramType;

  HistogramGenType::Pointer genhistogram = HistogramGenType::New();
  genhistogram->SetNumberOfBins( 256 );

  //code for converting histogram to image
  typedef itk::HistogramToIntensityImageFilter< HistogramType > HistogramToImageType;

  HistogramToImageType::Pointer histToImage = HistogramToImageType::New();

    genhistogram->SetInput( reader->GetOutput() );
    histToImage->SetInput( genhistogram->GetOutput() );


//here windows gives an error and the program aborts
  catch( itk::ExceptionObject & excp )
    std::cerr << "Exception thrown while reading image" << excp << std::endl;


Alt i én. Få Yahoo! Mail med adressekartotek, kalender og
notisblokk. http://no.mail.yahoo.com

Insight-users mailing list
Insight-users at itk.org

Alt i én. Få Yahoo! Mail med adressekartotek, kalender og
notisblokk. http://no.mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070814/12267356/attachment.htm

More information about the Insight-users mailing list