Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes

mitk::CalculateGrayValueStatisticsTool Class Reference
[Classes related to InteractiveSegmentation]

Calculates some gray value statistics for segmentations. More...

#include <mitkCalculateGrayValueStatisticsTool.h>

Inheritance diagram for mitk::CalculateGrayValueStatisticsTool:
Inheritance graph
[legend]
Collaboration diagram for mitk::CalculateGrayValueStatisticsTool:
Collaboration graph
[legend]

List of all members.

Public Types

typedef
CalculateGrayValueStatisticsTool 
Self
typedef SegmentationsProcessingTool Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer
typedef
itk::Statistics::Histogram
< double > 
HistogramType
typedef
HistogramType::MeasurementType 
HistogramMeasurementType

Public Member Functions

virtual const char * GetClassName () const
virtual const char ** GetXPM () const
 Returns an icon in the XPM format.
virtual const char * GetName () const
 Returns the name of this tool. Make it short!
virtual std::string GetReport () const
HistogramType::ConstPointer GetHistogram ()

Static Public Member Functions

static Pointer New ()

Public Attributes

Message StatisticsCompleted
HistogramType::Pointer m_ITKHistogram

Protected Member Functions

 CalculateGrayValueStatisticsTool ()
virtual ~CalculateGrayValueStatisticsTool ()
virtual void StartProcessingAllData ()
 Subclasses should override this method.
virtual bool ProcessOneWorkingData (DataNode *node)
 Subclasses should override this method.
virtual void FinishProcessingAllData ()
 Subclasses should override this method.
virtual std::string GetErrorMessage ()
 Describes the error (if one occurred during processing).
template<typename TPixel , unsigned int VImageDimension>
void CalculateMinMax (itk::Image< TPixel, VImageDimension > *referenceImage, Image *segmentation, TPixel &minimum, TPixel &maximum)
template<typename TPixel , unsigned int VImageDimension>
void ITKHistogramming (itk::Image< TPixel, VImageDimension > *referenceImage, Image *segmentation, std::stringstream &report)

Protected Attributes

std::stringstream m_CompleteReport

Detailed Description

Calculates some gray value statistics for segmentations.

See also:
mitk::Tool
QmitkInteractiveSegmentation

Last contributor: $Author$

Definition at line 40 of file mitkCalculateGrayValueStatisticsTool.h.


Member Typedef Documentation

Reimplemented from mitk::SegmentationsProcessingTool.

Definition at line 46 of file mitkCalculateGrayValueStatisticsTool.h.

Definition at line 63 of file mitkCalculateGrayValueStatisticsTool.h.

typedef itk::Statistics::Histogram<double> mitk::CalculateGrayValueStatisticsTool::HistogramType

Definition at line 58 of file mitkCalculateGrayValueStatisticsTool.h.

Reimplemented from mitk::SegmentationsProcessingTool.

Definition at line 46 of file mitkCalculateGrayValueStatisticsTool.h.

Reimplemented from mitk::SegmentationsProcessingTool.

Definition at line 46 of file mitkCalculateGrayValueStatisticsTool.h.

Reimplemented from mitk::SegmentationsProcessingTool.

Definition at line 46 of file mitkCalculateGrayValueStatisticsTool.h.


Constructor & Destructor Documentation

mitk::CalculateGrayValueStatisticsTool::CalculateGrayValueStatisticsTool (  ) [protected]

Definition at line 36 of file mitkCalculateGrayValueStatisticsTool.cpp.

{
}
mitk::CalculateGrayValueStatisticsTool::~CalculateGrayValueStatisticsTool (  ) [protected, virtual]

Definition at line 40 of file mitkCalculateGrayValueStatisticsTool.cpp.

{
}

Member Function Documentation

template<typename TPixel , unsigned int VImageDimension>
void mitk::CalculateGrayValueStatisticsTool::CalculateMinMax ( itk::Image< TPixel, VImageDimension > *  referenceImage,
Image segmentation,
TPixel &  minimum,
TPixel &  maximum 
) [protected]

Calculates the minimum and maximum of the pixelvalues. They have to be known to initialize the histogram.

Definition at line 142 of file mitkCalculateGrayValueStatisticsTool.cpp.

References mitk::CastToItkImage(), QuadProgPP::max(), min, and ROUND_P.

{
  typedef itk::Image<TPixel, VImageDimension> ImageType;
  typedef itk::Image<Tool::DefaultSegmentationDataType, VImageDimension> SegmentationType;

  typename SegmentationType::Pointer segmentationItk;
  CastToItkImage(segmentation, segmentationItk);

  typename SegmentationType::RegionType segmentationRegion =
      segmentationItk->GetLargestPossibleRegion();

  segmentationRegion.Crop(referenceImage->GetLargestPossibleRegion());

  itk::ImageRegionConstIteratorWithIndex<SegmentationType> segmentationIterator(segmentationItk,
      segmentationRegion);
  itk::ImageRegionConstIteratorWithIndex<ImageType> referenceIterator(referenceImage,
      segmentationRegion);

  segmentationIterator.GoToBegin();
  referenceIterator.GoToBegin();

  minimum = std::numeric_limits<TPixel>::max();
  maximum = std::numeric_limits<TPixel>::min();

  while (!segmentationIterator.IsAtEnd())
  {
    itk::Point<float, 3> pt;
    segmentationItk->TransformIndexToPhysicalPoint(segmentationIterator.GetIndex(), pt);

    typename ImageType::IndexType ind;
    itk::ContinuousIndex<float, 3> contInd;
    if (referenceImage->TransformPhysicalPointToContinuousIndex(pt, contInd))
    {
      for (unsigned int i = 0; i < 3; ++i)
        ind[i] = ROUND_P(contInd[i]);

      referenceIterator.SetIndex(ind);

      if (segmentationIterator.Get() > 0)
      {

        if (referenceIterator.Get() < minimum)
          minimum = referenceIterator.Get();
        if (referenceIterator.Get() > maximum)
          maximum = referenceIterator.Get();
      }
    }

    ++segmentationIterator;
  }

}
void mitk::CalculateGrayValueStatisticsTool::FinishProcessingAllData (  ) [protected, virtual]

Subclasses should override this method.

See also:
ProcessAllObjects

Reimplemented from mitk::SegmentationsProcessingTool.

Definition at line 130 of file mitkCalculateGrayValueStatisticsTool.cpp.

References mitk::SegmentationsProcessingTool::FinishProcessingAllData().

{
  SegmentationsProcessingTool::FinishProcessingAllData();

  // show/send results
  StatisticsCompleted.Send();
  //MITK_INFO << m_CompleteReport.str() << std::endl;
}
virtual const char* mitk::CalculateGrayValueStatisticsTool::GetClassName (  ) const [virtual]

Reimplemented from mitk::SegmentationsProcessingTool.

std::string mitk::CalculateGrayValueStatisticsTool::GetErrorMessage (  ) [protected, virtual]

Describes the error (if one occurred during processing).

Reimplemented from mitk::SegmentationsProcessingTool.

Definition at line 54 of file mitkCalculateGrayValueStatisticsTool.cpp.

{
  return "No statistics generated for these segmentations:";
}
mitk::CalculateGrayValueStatisticsTool::HistogramType::ConstPointer mitk::CalculateGrayValueStatisticsTool::GetHistogram (  )

Definition at line 330 of file mitkCalculateGrayValueStatisticsTool.cpp.

{
  return m_ITKHistogram.GetPointer();
}
const char * mitk::CalculateGrayValueStatisticsTool::GetName (  ) const [virtual]

Returns the name of this tool. Make it short!

This name has to fit into some kind of button in most applications, so take some time to think of a good name!

Implements mitk::Tool.

Definition at line 49 of file mitkCalculateGrayValueStatisticsTool.cpp.

{
  return "Statistics";
}
std::string mitk::CalculateGrayValueStatisticsTool::GetReport (  ) const [virtual]

Definition at line 325 of file mitkCalculateGrayValueStatisticsTool.cpp.

{
  return m_CompleteReport.str();
}
const char ** mitk::CalculateGrayValueStatisticsTool::GetXPM (  ) const [virtual]

Returns an icon in the XPM format.

This icon has to fit into some kind of button in most applications, so make it smaller than 25x25 pixels.

XPM is e.g. supported by The Gimp. But if you open any XPM file in your text editor, you will see that you could also "draw" it with an editor.

Implements mitk::Tool.

Definition at line 44 of file mitkCalculateGrayValueStatisticsTool.cpp.

{
  return mitkCalculateGrayValueStatisticsTool_xpm;
}
template<typename TPixel , unsigned int VImageDimension>
void mitk::CalculateGrayValueStatisticsTool::ITKHistogramming ( itk::Image< TPixel, VImageDimension > *  referenceImage,
Image segmentation,
std::stringstream &  report 
) [protected]
  • initializes and fills the histogram
  • calculates mean, sd and quantiles

Definition at line 198 of file mitkCalculateGrayValueStatisticsTool.cpp.

References mitk::CastToItkImage(), QuadProgPP::max(), QuadProgPP::mean(), min, ROUND_P, and QuadProgPP::sqrt().

{
  typedef itk::Image<TPixel, VImageDimension> ImageType;
  typedef itk::Image<Tool::DefaultSegmentationDataType, VImageDimension> SegmentationType;

  typename SegmentationType::Pointer segmentationItk;
  CastToItkImage( segmentation, segmentationItk );

  // generate histogram
  typename SegmentationType::RegionType segmentationRegion = segmentationItk->GetLargestPossibleRegion();

  segmentationRegion.Crop( referenceImage->GetLargestPossibleRegion() );

  itk::ImageRegionConstIteratorWithIndex< SegmentationType > segmentationIterator( segmentationItk, segmentationRegion);
  itk::ImageRegionConstIteratorWithIndex< ImageType >        referenceIterator( referenceImage, segmentationRegion);

  segmentationIterator.GoToBegin();
  referenceIterator.GoToBegin();

  m_ITKHistogram = HistogramType::New();

  TPixel minimum = std::numeric_limits<TPixel>::max();
  TPixel maximum = std::numeric_limits<TPixel>::min();
    
  CalculateMinMax(referenceImage, segmentation, minimum, maximum);

  //initialize the histogram to the range of the cropped region
  HistogramType::SizeType size;
#if defined(ITK_USE_REVIEW_STATISTICS)
  typedef typename HistogramType::SizeType::ValueType HSizeValueType;
#else
  typedef typename HistogramType::SizeType::SizeValueType HSizeValueType;
#endif
  size.Fill(static_cast<HSizeValueType> (maximum - minimum + 1));
  HistogramType::MeasurementVectorType lowerBound;
  HistogramType::MeasurementVectorType upperBound;
  lowerBound[0] = minimum;
  upperBound[0] = maximum;
  m_ITKHistogram->Initialize(size, lowerBound, upperBound);

  double mean(0.0);
  double sd(0.0);
  double voxelCount(0.0);

  //iterate through the cropped region add the values to the histogram
  while (!segmentationIterator.IsAtEnd())
  {
    itk::Point< float, 3 > pt;
    segmentationItk->TransformIndexToPhysicalPoint( segmentationIterator.GetIndex(), pt );

    typename ImageType::IndexType ind;
    itk::ContinuousIndex<float, 3> contInd;
    if (referenceImage->TransformPhysicalPointToContinuousIndex(pt, contInd))
    {
      for (unsigned int i = 0; i < 3; ++i) ind[i] = ROUND_P(contInd[i]);

      referenceIterator.SetIndex( ind );

      if ( segmentationIterator.Get() > 0 )
      {
        HistogramType::MeasurementVectorType currentMeasurementVector;

        currentMeasurementVector[0]
            = static_cast<HistogramType::MeasurementType> (referenceIterator.Get());
        m_ITKHistogram->IncreaseFrequency(currentMeasurementVector, 1);

        mean = (mean * (static_cast<double> (voxelCount) / static_cast<double> (voxelCount + 1))) // 3 points:   old center * 2/3 + currentPoint * 1/3;
            + static_cast<double> (referenceIterator.Get()) / static_cast<double> (voxelCount + 1);

        voxelCount += 1.0;
      }
    }

    ++segmentationIterator;
  }

  // second pass for SD
  segmentationIterator.GoToBegin();
  referenceIterator.GoToBegin();
  while ( !segmentationIterator.IsAtEnd() )
  {
    itk::Point< float, 3 > pt;
    segmentationItk->TransformIndexToPhysicalPoint( segmentationIterator.GetIndex(), pt );

    typename ImageType::IndexType ind;
    itk::ContinuousIndex<float, 3> contInd;
    if (referenceImage->TransformPhysicalPointToContinuousIndex(pt, contInd))
    {
      for (unsigned int i = 0; i < 3; ++i) ind[i] = ROUND_P(contInd[i]);

      referenceIterator.SetIndex( ind );

      if ( segmentationIterator.Get() > 0 )
      {
        sd += ((static_cast<double>(referenceIterator.Get() ) - mean)*(static_cast<double>(referenceIterator.Get() ) - mean));
      }
    }

    ++segmentationIterator;
  }

  sd /= static_cast<double>(voxelCount - 1);
  sd = sqrt( sd );

  // generate quantiles
  TPixel histogramQuantileValues[5];
  histogramQuantileValues[0] = m_ITKHistogram->Quantile(0, 0.05);
  histogramQuantileValues[1] = m_ITKHistogram->Quantile(0, 0.25);
  histogramQuantileValues[2] = m_ITKHistogram->Quantile(0, 0.50);
  histogramQuantileValues[3] = m_ITKHistogram->Quantile(0, 0.75);
  histogramQuantileValues[4] = m_ITKHistogram->Quantile(0, 0.95);

  // report histogram values
report     << "         Minimum:" << minimum
           << "\n  5% quantile: " << histogramQuantileValues[0]
           << "\n 25% quantile: " << histogramQuantileValues[1]
           << "\n 50% quantile: " << histogramQuantileValues[2]
           << "\n 75% quantile: " << histogramQuantileValues[3]
           << "\n 95% quantile: " << histogramQuantileValues[4]
           << "\n      Maximum: " << maximum
           << "\n         Mean: " << mean
           << "\n           SD: " << sd
           << "\n";
}
static Pointer mitk::CalculateGrayValueStatisticsTool::New (  ) [static]
bool mitk::CalculateGrayValueStatisticsTool::ProcessOneWorkingData ( DataNode node ) [protected, virtual]

Subclasses should override this method.

See also:
ProcessAllObjects

Reimplemented from mitk::SegmentationsProcessingTool.

Definition at line 65 of file mitkCalculateGrayValueStatisticsTool.cpp.

References AccessFixedDimensionByItk_2, mitk::ProgressBar::AddStepsToDo(), mitk::StatusBar::DisplayText(), mitk::DataNode::GetData(), mitk::StatusBar::GetInstance(), mitk::ProgressBar::GetInstance(), mitk::DataNode::GetName(), mitk::ImageTimeSelector::New(), and mitk::ProgressBar::Progress().

{
  if (node)
  {
    Image::Pointer image = dynamic_cast<Image*>( node->GetData() );
    if (image.IsNull()) return false;

    DataNode* referencenode = m_ToolManager->GetReferenceData(0);
    if (!referencenode) return false;

    try
    {
      ProgressBar::GetInstance()->AddStepsToDo(1);

      // add to report
      std::string nodename("structure");
      node->GetName(nodename);

      std::string message = "Calculating statistics for ";
      message += nodename;

      StatusBar::GetInstance()->DisplayText(message.c_str());

      Image::Pointer refImage = dynamic_cast<Image*>( referencenode->GetData() );
      Image::Pointer image = dynamic_cast<Image*>( node->GetData() );

      m_CompleteReport << "======== Gray value analysis of " << nodename << " ========\n";

      if (image.IsNotNull() && refImage.IsNotNull() )
      {
        for (unsigned int timeStep = 0; timeStep < image->GetTimeSteps(); ++timeStep)
        {
          ImageTimeSelector::Pointer timeSelector = ImageTimeSelector::New();
          timeSelector->SetInput( refImage );
          timeSelector->SetTimeNr( timeStep );
          timeSelector->UpdateLargestPossibleRegion();
          Image::Pointer refImage3D = timeSelector->GetOutput();

          ImageTimeSelector::Pointer timeSelector2 = ImageTimeSelector::New();
          timeSelector2->SetInput( image );
          timeSelector2->SetTimeNr( timeStep );
          timeSelector2->UpdateLargestPossibleRegion();
          Image::Pointer image3D = timeSelector2->GetOutput();

          if (image3D.IsNotNull() && refImage3D.IsNotNull() )
          {
            m_CompleteReport << "=== " << nodename << ", time step " << timeStep << " ===\n";
            AccessFixedDimensionByItk_2( refImage3D, ITKHistogramming, 3, image3D, m_CompleteReport );
          }
        }
      }

      m_CompleteReport << "======== End of analysis for " << nodename << " ===========\n\n\n";

      ProgressBar::GetInstance()->Progress();
    }
    catch(...)
    {
      return false;
    }
  }

  return true;
}
void mitk::CalculateGrayValueStatisticsTool::StartProcessingAllData (  ) [protected, virtual]

Subclasses should override this method.

See also:
ProcessAllObjects

Reimplemented from mitk::SegmentationsProcessingTool.

Definition at line 59 of file mitkCalculateGrayValueStatisticsTool.cpp.

{
  // clear/prepare report
  m_CompleteReport.str("");
}

Member Data Documentation

Definition at line 91 of file mitkCalculateGrayValueStatisticsTool.h.

Definition at line 59 of file mitkCalculateGrayValueStatisticsTool.h.

Definition at line 44 of file mitkCalculateGrayValueStatisticsTool.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines