7 m_StatisticsCalculated(false)
14 if (m_Histogram != histogram)
16 m_Histogram = histogram;
17 m_StatisticsCalculated =
false;
23 if (!m_StatisticsCalculated)
25 MITK_WARN(
"Statistics have not yet been calculated, running calculation now...");
33 if (!m_StatisticsCalculated)
35 MITK_WARN(
"Statistics have not yet been calculated, running calculation now...");
43 if (!m_StatisticsCalculated)
45 MITK_WARN(
"Statistics have not yet been calculated, running calculation now...");
53 if (!m_StatisticsCalculated)
55 MITK_WARN(
"Statistics have not yet been calculated, running calculation now...");
63 if (m_Histogram.IsNull())
65 throw std::runtime_error(
"Histogram not set in HistogramStatisticsCalculator::CalculateStatistics()");
68 unsigned int nBins = m_Histogram->GetSize()[0];
76 bool medianFound(
false);
78 for (
unsigned int i = 0; i < nBins; i++)
80 partialProbability = m_Histogram->GetFrequency(i, 0) / double( m_Histogram->GetTotalFrequency() );
81 cumulativeProbability += partialProbability;
83 if (partialProbability != 0)
85 m_Entropy -= partialProbability * (std::log2( partialProbability ));
86 m_Uniformity += std::pow(partialProbability, 2);
88 if (m_Histogram->GetMeasurement(i, 0) > 0)
90 m_UPP += std::pow(partialProbability, 2);
95 if (cumulativeProbability >= 0.5 && !medianFound)
99 m_Median = (binMax + binMin) / 2.0;
104 m_StatisticsCalculated =
true;
MeasurementType GetEntropy()
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
MeasurementType GetUniformity()
void SetHistogram(HistogramType::Pointer histogram)
SetHistogram requires a itk::Statistics::Histogram
MeasurementType GetMedian()
void CalculateStatistics()
calculate statistics
HistogramStatisticsCalculator()