[Insight-users] histogram
Luis Ibanez
luis . ibanez at kitware . com
Mon, 08 Dec 2003 09:26:41 -0500
Hi David,
An example on how to compute the Histogram of an RGB image
has been commited to the CVS repository under:
Insight/Examples/Statistics/ImageHistogram3.cxx
This example loads a 2D RGB Image (dimension is irrelevant here)
and computes the histogram of its red channel, its blue channel,
and its green channel. Finally it computes the joint histogram
of the RGB values which results in a 3D histogram.
This example uses the new helper class
itk::ImageToHistogramGenerator
that simplifies the setup of the ImageToListSample adaptor, since
you only have to connect the image and select what kind of histogram
you want to compute.
Please let us know if you find any problems,
Thanks
Luis
-----------------------
David Llanos wrote:
> hi all,
>
> I have errors that I don't understand in the following algorithm that
> tries to make the histogram of the red channel of a RGB image:
>
>
>
>
> ///////////////////////////////////////////BEGIN
> CODE///////////////////////////////////////////////////////
>
>
>
> #include "itkScalarImageToListAdaptor.h"
>
> #include "itkImage.h"
>
> #include "itkImageFileReader.h"
>
> #include "itkListSampleToHistogramGenerator.h"
>
> #include "itkImageAdaptor.h"
>
> #include "itkImageRegionIteratorWithIndex.h"
>
> #include "itkRescaleIntensityImageFilter.h"
>
>
>
> class RedChannelPixelAccessor
>
> {
>
> public:
>
> typedef itk::RGBPixel<float> InternalType;
>
> typedef float ExternalType;
>
>
>
> static ExternalType Get( const InternalType & input )
>
> {
>
> return static_cast<ExternalType>( input.GetRed() );
>
> }
>
> };
>
>
>
> int main( int argc, char * argv [] )
>
> {
>
>
>
> if( argc < 2 )
>
> {
>
> std::cerr << "Requiere los siguientes argumentos en la linea de
> comandos:" << std::endl;
>
> std::cerr << "Usage : HaloNucleo FicheroImagenEntrada " <<
>
> std::endl;
>
> return -1;
>
> }
>
>
>
> typedef unsigned char TipoPixel;
>
> const unsigned int Dimension = 2;
>
>
>
>
>
> //////////// LECTURA DE LA IMAGEN ///////////////////////
>
> typedef RedChannelPixelAccessor::InternalType InputPixelType;
>
> typedef itk::Image< InputPixelType, Dimension > ImageType;
>
> typedef itk::ImageAdaptor< ImageType,
>
> RedChannelPixelAccessor > ImageAdaptorType;
>
> ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
>
> typedef itk::ImageFileReader< ImageType > ReaderType;
>
> ReaderType::Pointer reader = ReaderType::New();
>
> reader->SetFileName( argv[1] );
>
> reader->Update();
>
> adaptor->SetImage( reader->GetOutput() );
>
> typedef itk::Statistics::ScalarImageToListAdaptor<
>
> ImageType > TipoAdaptador;
>
> typedef itk::Image< unsigned char, Dimension > OutputImageType;
>
> typedef itk::RescaleIntensityImageFilter< ImageAdaptorType,
>
> OutputImageType
>
> > RescalerType;
>
> RescalerType::Pointer rescaler = RescalerType::New();
>
> rescaler->SetOutputMinimum( 0 );
>
> rescaler->SetOutputMaximum( 255 );
>
> rescaler->SetInput( adaptor );
>
>
>
> ////////// GENERACION DEL HISTOGRAMA
> ///////////////////
>
> typedef TipoPixel TipoMedidaHistograma;
>
> typedef itk::Statistics::ListSampleToHistogramGenerator<
>
> ImageAdaptorType,
>
> TipoMedidaHistograma
>
> > TipoGenerador;
>
> TipoGenerador::Pointer generator = TipoGenerador::New();
>
> typedef TipoGenerador::HistogramType Histograma;
>
> Histograma::SizeType size;
>
> size.Fill( 255 );
>
> generator->SetListSample( rescaler );
>
> generator->SetNumberOfBins( size );
>
> generator->SetMarginalScale( 10.0 );
>
> generator->Update();
>
> Histograma::Pointer histogram = generator->GetOutput();
>
> const unsigned int histogramSize = histogram->Size();
>
> std::cout << "Tamano del histograma" << histogramSize << std::endl;
>
> for( unsigned int bin=0; bin < histogramSize; bin++ )
>
> {
>
> std::cout << "bin = " << bin << " frecuencia = ";
>
> std::cout << histogram->GetFrequency( bin, 0 ) <<std::endl;
>
> }
>
> return 0;
>
> }
>
> /////////////////////// END CODE ///////////////////////////////////////
>
>
>
>
>
> some errors are the following ones:
>
>
>
> Compiling...
> halonucleo.cxx
> E:\Insight\Code\Numerics\Statistics\itkListSampleToHistogramGenerator.h(80)
> : error C2039: 'MeasurementVectorSize' : is not a member of
> 'ImageAdaptor<class itk::Image<class itk::RGBPixel<float>,2>,class
> RedChannelPixelAccessor>'
> E:\C++\halonucleo.cxx(142) : see reference to class template
> instantiation 'itk::Statistics::ListSampleToHistogramGenerator<class
> itk::ImageAdaptor<class itk::Image<class itk::RGBPixel<float>,2>,class
> RedChannelPixelAccessor>,unsigned char,c
> lass itk::Statistics::DenseFrequencyContainer<float> >' being compiled
>
> ...
>
> halonucleo.obj - 7 error(s), 4 warning(s)
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>
> Would somebody know how to say I do to solve them?
>
> Thanks in advange and regards,
>
> David
>
>