21 #ifndef otbRadiometricMomentsFunctor_h
22 #define otbRadiometricMomentsFunctor_h
24 #include "itkVariableLengthVector.h"
38 template <
class TNeighIter,
class TPrecision =
float>
46 typedef itk::VariableLengthVector<ScalarRealType>
OutputType;
59 moments.Fill(itk::NumericTraits<ScalarRealType>::Zero);
62 sum1 = itk::NumericTraits<ScalarRealType>::Zero;
63 sum2 = itk::NumericTraits<ScalarRealType>::Zero;
64 sum3 = itk::NumericTraits<ScalarRealType>::Zero;
65 sum4 = itk::NumericTraits<ScalarRealType>::Zero;
68 const unsigned int size = it.Size();
69 for (
unsigned int i = 0; i < size; ++i)
77 sum3 += value * value2;
78 sum4 += value2 * value2;
83 moments[0] = sum1 / size;
85 moments[1] = (sum2 - (sum1 * moments[0])) / (size - 1);
90 const double epsilon = 1E-10;
91 if (std::abs(moments[1]) > epsilon)
94 moments[2] = ((sum3 - 3.0 * moments[0] * sum2) / size + 2.0 * moments[0] * mean2) / (moments[1] * sigma);
96 moments[3] = ((sum4 - 4.0 * moments[0] * sum3 + 6.0 * mean2 * sum2) / size - 3.0 * mean2 * mean2) / (moments[1] * moments[1]) - 3.0;