[Insight-users] Create the histogram of an image

Jisung Kim bahrahm at yahoo . com
Fri, 20 Jun 2003 08:53:12 -0700 (PDT)


How about adding two generators?

1) ScalarPixelImageToListSampleGenerator: all the
sample class expects the data element should a type of
array (itk::FixedArray or its subclasses). Therefore,
when users want to plug in an image to
ImageToListAdaptor, they have to cast the original
image to an image with array pixel type. This
generator will encapsulat such casting process.
 
2) ImageToHistogramGenerator: Just as you suggested.
Using the PixelTraits, if casting is neccessary, this
generator also does the casting.


--- "Miller, James V (Research)" <millerjv at crd . ge . com>
wrote:
> Jisung,
> 
> Should be an adaptor such that step #1 doesn't need
> to copy the image?
> 
> Should we have an encapsulation of these steps to
> make it easier on
> the user?  Something like a
> ImageToHistogramGenerator that would perform
> the steps you outlined.
> 
> Jim
> 
> 
> 
> > -----Original Message-----
> > From: Jisung Kim [mailto:bahrahm at yahoo . com]
> > Sent: Thursday, June 19, 2003 9:44 PM
> > To: SERIOT_Rimi________DEC/SPUA/LTEC;
> Insight-Users
> > Subject: Re: [Insight-users] Create the histogram
> of an image
> > 
> > 
> > Hi.
> > 
> > You might want to look at the
> ImageToListAdaptor.cxx
> > and ListSampleToHistogramGenerator.cxx in the
> "insight
> > src dir"/Examples/Statistics.
> > 
> > In ImageToListAdaptor.cxx, you can find how to
> create
> > a ListSample from an image. In
> > ListSampleToHistogramGenerator.cxx, you will find
> a
> > way to create a equi-size bin histogram from a
> > ListSample.
> > 
> > The procedure would be:
> > 1) cast the original image(scalar pixel type) to
> an
> > image with array pixel type. (use the
> > itk::ScalarToArrayCastImageFilter)
> > 2) plug in the output image from the step 1) to
> the
> > itk::Statistics::ImageToListAdaptor.
> > 3) create an equi-interval bin histogram using the
> > itk::Statistics::ListSampleToHistogramGenerator.
> (The
> > input for the generator is the ImageToListAdaptor
> > object from the step 2).
> > 
> > I hope this help.
> > 
> > Thanks,  
> > --- SERIOT_Remi________DEC/SPUA/LTEC
> > <SERIOT at DRNCAD . CEA . FR> wrote:
> > > Hi Luis,
> > > 
> > > Thanks for your help, but do you have a simple
> way
> > > for create the histogram
> > > of an image ?
> > > 
> > > I found this code...may be you've got something
> more
> > > simple...
> > > 
> > > 
> > >
> >
>
itk::MinimumMaximumImageCalculator<ImageType>::Pointer
> > > rangeCalculator = 
> > > 	
> > >
> >
>
itk::MinimumMaximumImageCalculator<ImageType>::New();
> > > 	rangeCalculator->SetImage( m_image );
> > > 	rangeCalculator->Compute();
> > > 
> > > 	MinValue = rangeCalculator->GetMinimum();
> > > 	MaxValue = rangeCalculator->GetMaximum();
> > > 
> > > 	typedef itk::Statistics::Histogram<PixelType,
> 1>
> > > HistogramType;
> > > 	histogram = HistogramType::New();
> > > 
> > > 	HistogramType::SizeType size;
> > > 	size[0] = MaxValue;
> > > 	histogram->Initialize( size );
> > > 
> > > 	for ( int ibin = 0; ibin < MaxValue - 1; ibin++
> ) {
> > > 		histogram->SetBinMin( 0, ibin, ibin );
> > > 		histogram->SetBinMax( 0, ibin, ( ibin + 1 ) );
> > >     }
> > > 	// put each image pixel into the histogram
> > > 	typedef
> itk::ImageRegionConstIterator<ImageType>
> > > ConstIterator;
> > > 	ConstIterator iter( m_image,
> > > m_image->GetBufferedRegion() );
> > > 
> > > 	while ( !iter.IsAtEnd() ) {
> > > 		
> > > 		PixelType value = iter.Get();
> > > 		
> > > 		if ( static_cast<double>(value) >= MinValue &&
> 
> > > 			 static_cast<double>(value) <= MaxValue ) {
> > >       
> > > 			// add sample to histogram
> > > 
> > > 			HistogramType::IndexType index;
> > > 			HistogramType::InstanceIdentifier id;
> > > 			HistogramType::MeasurementVectorType 
> > measurement;
> > >   
> > > 			measurement[0] = value;
> > > 			index = histogram->GetIndex( measurement );
> > > 			id = histogram->GetInstanceIdentifier( index
> );
> > > 			histogram->IncreaseFrequency( id, 1 );
> > > 		}
> > > 		++iter;
> > > 	}
> > > 
> > > Thanks
> > > 
> > > Remi
> > > 
> > > > -----Message d'origine-----
> > > > De : Luis Ibanez
> [mailto:luis . ibanez at kitware . com]
> > > > Envoye : mercredi 18 juin 2003 16:02
> > > > A : SERIOT Remi DEC/SPUA/LTEC
> > > > Cc : 'Joshua Cates';
> > > 'insight-users at public . kitware . com'; Jisung Kim
> > > > Objet : Re: [Insight-users] Sorting watershed
> > > basins based on size
> > > > 
> > > > 
> > > > 
> > > > Hi Remi,
> > > > 
> > > > It sounds like you could simply compute the
> > > Histogram
> > > > of the labeled image.
> > > > 
> > > > The histogram will give you the number of
> pixels
> > > assigned
> > > > to each one of the labels, and since the
> labels
> > > are unique,
> > > > you will get the number of pixels on each
> watersed
> > > basin.
> > > > 
> > > > You will find details on the use of the ITK
> > > histogram
> > > > in the Statistics chapter of the
> SoftwareGuide.
> > > > 
> > > >    'insight-users at public . kitware . com'
> > > > 
> > > > Section 9.1.3, pdf-page 320
> > > > 
> > > > The associated example is available in
> > > > 
> > > >     Insight/Examples/Statistics/Histogram.cxx
> > > > 
> > > > In the same chapter you will find options for
> > > sorting.
> > > > 
> > > > 
> > > > 
> > > > Regards,
> > > > 
> > > > 
> > > >     Luis
> > > > 
> > > > 
> > > > -------------------------------
> > > > SERIOT Remi DEC/SPUA/LTEC wrote:
> > > > > Hi,
> > > > > 
> > > > > I would like to sort watershed basins based
> on
> > > size, so I 
> > > > need to calculate
> > > > > the size of each basin from the labeled
> image. I
> > > need to do 
> > > > that and I don't
> > > > > wont to re-invent something already done.
> > > > > I think that I could use a simple
> ImageIterator
> 
=== message truncated ===


=====
Jisung Kim
bahrahm at yahoo . com
106 Mason Farm Rd.
129 Radiology Research Lab., CB# 7515
Univ. of North Carolina at Chapel Hill
Chapel Hill, NC 27599-7515

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc . yahoo . com