[Insight-users] Create the histogram of an image
SERIOT Rémi DEC/SPUA/LTEC
SERIOT at DRNCAD . CEA . FR
Thu, 19 Jun 2003 15:13:50 +0200
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]
> Envoyé : mercredi 18 juin 2003 16:02
> À : SERIOT Rémi 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 Rémi 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 and an
> accumulator for
> > compute the number of pixels in each basin from the labeled
> image and then
> > sort this list for keep only the most significant basins.
> >
> > Could I speed it up this process with
> > itk::watershed::Segmenter::flat_region_t information ?
> >
> > Or there is another way to do the same thing ?
> >
> > After that could I have to change the EquivalencyTable ?
> >
> > Thanks for your help
> >
> > Rémi
> >
> >
> >>-----Message d'origine-----
> >>De : Joshua Cates [mailto:cates at sci . utah . edu]
> >>Envoyé : vendredi 13 juin 2003 18:05
> >>À : SERIOT Rémi DEC/SPUA/LTEC
> >>Cc : 'insight-users at public . kitware . com'
> >>Objet : RE: [Insight-users] How to create my own
> >>NeighborhoodOperator ?
> >>
> >>
> >>Hi Rémi,
> >>
> >>Glad to hear the NeighborhoodOperator is working out.
> >>
> >>In order to sort and merge watershed basins based on size you
> >>will have to
> >>modify the itkWatershedSegmenter algorithm to keep track of
> >>basin sizes.
> >>The initial size would need to be computed in the gradient
> >>descent step of
> >>itkWatershedSegmenter and then updated and maintained during
> >>basin merge
> >>operations.
> >>
> >>An alternate approach of a one-time suppression of small
> basins in the
> >>initial output might be interesting (but will result in a different
> >>algorithm and I can't guarantee you won't get some
> >>undesirable grouping of
> >>basins). You could calculate the basin sizes from the the initial
> >>segmentation (zero merge level output) of the
> >>WatershedSegmenter and then
> >>use some of the existing code for basin merges (in
> >>itkWatershedSegmentTreeGenerator, for example) to pre-merge
> >>the smaller
> >>basins in the segment tree.
> >>
> >>Josh.
> >>______________________________
> >> Josh Cates
> >> School of Computer Science
> >> University of Utah
> >> Email: cates at sci . utah . edu
> >> Phone: (801) 587-7697
> >> URL: http://www . sci . utah . edu/~cates
> >>
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at www . itk . org
> > http://www . itk . org/mailman/listinfo/insight-users
> >
>
>
>