Calculates some gray value statistics for segmentations. More...
#include <mitkCalculateGrayValueStatisticsTool.h>
Public Types | |
typedef CalculateGrayValueStatisticsTool | Self |
typedef SegmentationsProcessingTool | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
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 |
Calculates some gray value statistics for segmentations.
Last contributor: $Author$
Definition at line 40 of file mitkCalculateGrayValueStatisticsTool.h.
typedef itk::SmartPointer<const Self> mitk::CalculateGrayValueStatisticsTool::ConstPointer |
Reimplemented from mitk::SegmentationsProcessingTool.
Definition at line 46 of file mitkCalculateGrayValueStatisticsTool.h.
typedef HistogramType::MeasurementType mitk::CalculateGrayValueStatisticsTool::HistogramMeasurementType |
Definition at line 63 of file mitkCalculateGrayValueStatisticsTool.h.
typedef itk::Statistics::Histogram<double> mitk::CalculateGrayValueStatisticsTool::HistogramType |
Definition at line 58 of file mitkCalculateGrayValueStatisticsTool.h.
typedef itk::SmartPointer<Self> mitk::CalculateGrayValueStatisticsTool::Pointer |
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.
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.
{ }
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.
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;
}
void mitk::CalculateGrayValueStatisticsTool::ITKHistogramming | ( | itk::Image< TPixel, VImageDimension > * | referenceImage, |
Image * | segmentation, | ||
std::stringstream & | report | ||
) | [protected] |
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.
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.
Reimplemented from mitk::SegmentationsProcessingTool.
Definition at line 59 of file mitkCalculateGrayValueStatisticsTool.cpp.
{ // clear/prepare report m_CompleteReport.str(""); }
std::stringstream mitk::CalculateGrayValueStatisticsTool::m_CompleteReport [protected] |
Definition at line 91 of file mitkCalculateGrayValueStatisticsTool.h.
HistogramType::Pointer mitk::CalculateGrayValueStatisticsTool::m_ITKHistogram |
Definition at line 59 of file mitkCalculateGrayValueStatisticsTool.h.
Definition at line 44 of file mitkCalculateGrayValueStatisticsTool.h.