22 #ifndef otbHistogramStatisticsFunction_hxx
23 #define otbHistogramStatisticsFunction_hxx
30 template <
class TInputHistogram,
class TOutput>
36 template <
class TInputHistogram,
class TOutput>
39 if (m_IsModified ==
true)
46 template <
class TInputHistogram,
class TOutput>
49 if (m_IsModified ==
true)
56 template <
class TInputHistogram,
class TOutput>
59 if (m_IsModified ==
true)
66 template <
class TInputHistogram,
class TOutput>
69 typename TInputHistogram::ConstPointer histogram = m_InputHistogram;
71 typename TInputHistogram::ConstIterator iter = histogram->Begin();
72 typename TInputHistogram::ConstIterator end = histogram->End();
74 RealType entropy = itk::NumericTraits<RealType>::Zero;
75 FrequencyType globalFrequency = histogram->GetTotalFrequency();
76 if (globalFrequency == 0)
78 itkExceptionMacro(<<
"Histogram must contain at least 1 element.");
83 Proba /=
static_cast<RealType>(globalFrequency);
86 entropy -= Proba * std::log(Proba);
91 m_entropy[0] =
static_cast<TOutput
>(entropy);
94 template <
class TInputHistogram,
class TOutput>
97 typename TInputHistogram::ConstPointer histogram = m_InputHistogram;
99 unsigned int NumberOfDimension = histogram->GetSize().GetSize();
100 m_mean.resize(NumberOfDimension);
102 if (histogram->GetTotalFrequency() == 0)
104 itkExceptionMacro(<<
"Histogram must contain at least 1 element.");
107 if (NumberOfDimension > 2)
109 itkExceptionMacro(<<
"Histogram must have 1 or 2 dimension.");
112 for (
unsigned int noDim = 0; noDim < NumberOfDimension; noDim++)
115 for (
unsigned int i = 0; i < histogram->GetSize()[noDim]; ++i)
121 mean /= histogram->GetTotalFrequency();
122 m_mean[noDim] =
static_cast<TOutput
>(
mean);
126 template <
class TInputHistogram,
class TOutput>
131 typename TInputHistogram::ConstPointer histogram = m_InputHistogram;
133 unsigned int NumberOfDimension = histogram->GetSize().GetSize();
134 m_covariance.resize(NumberOfDimension * NumberOfDimension);
136 if (histogram->GetTotalFrequency() == 0)
138 itkExceptionMacro(<<
"Histogram must contain at least 1 element.");
141 for (
unsigned int noDimX = 0; noDimX < NumberOfDimension; noDimX++)
142 for (
unsigned int noDimY = 0; noDimY < NumberOfDimension; noDimY++)
144 MeasurementType covariance = itk::NumericTraits<MeasurementType>::Zero;
145 for (
unsigned int i = 0; i < histogram->GetSize()[noDimX]; ++i)
146 for (
unsigned int j = 0; j < histogram->GetSize()[noDimY]; ++j)
155 covariance += ((valX * freqX) * (valY * freqY));
157 covariance /= histogram->GetTotalFrequency();
158 m_covariance[noDimX * NumberOfDimension + noDimY] =
static_cast<TOutput
>(covariance);
162 template <
class TInputHistogram,
class TOutput>
168 CalculateCovariance();
169 m_IsModified =
false;
172 template <
class TInputHistogram,
class TOutput>
175 Superclass::PrintSelf(os, indent);