/usr/include/OTB-5.8/otbRadiometricMomentsFunctor.h is in libotb-dev 5.8.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | /*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbRadiometricMomentsFunctor_h
#define otbRadiometricMomentsFunctor_h
#include "itkVariableLengthVector.h"
#include "otbMath.h"
namespace otb
{
namespace Functor
{
/** \class RadiometricMomentsFunctor
* \brief
*
* \ingroup Functor
*
* \ingroup OTBMoments
*/
template <class TNeighIter, class TPrecision = float>
class RadiometricMomentsFunctor
{
public:
typedef RadiometricMomentsFunctor Self;
typedef TNeighIter IteratorType;
typedef typename IteratorType::PixelType PixelType;
typedef TPrecision ScalarRealType;
typedef itk::VariableLengthVector< ScalarRealType > OutputType;
RadiometricMomentsFunctor() {}
~RadiometricMomentsFunctor() {}
inline OutputType operator ()(TNeighIter& it) const
{
OutputType moments;
moments.SetSize(4);
moments.Fill( itk::NumericTraits< ScalarRealType >::Zero );
ScalarRealType sum1, sum2, sum3, sum4;
sum1 = itk::NumericTraits< ScalarRealType >::Zero;
sum2 = itk::NumericTraits< ScalarRealType >::Zero;
sum3 = itk::NumericTraits< ScalarRealType >::Zero;
sum4 = itk::NumericTraits< ScalarRealType >::Zero;
//it.GoToBegin();
const unsigned int size = it.Size();
for (unsigned int i = 0; i < size; ++i)
{
ScalarRealType value = static_cast<ScalarRealType>(it.GetPixel(i));
ScalarRealType value2 = value * value;
// Update cumulants
sum1 += value;
sum2 += value2;
sum3 += value * value2;
sum4 += value2 * value2;
}
// final computations
// Mean
moments[0] = sum1 / size;
// Variance
moments[1] = (sum2 - (sum1 * moments[0])) / (size - 1);
ScalarRealType sigma = vcl_sqrt(moments[1]);
ScalarRealType mean2 = moments[0] * moments[0];
const double epsilon = 1E-10;
if (vcl_abs(moments[1]) > epsilon)
{
// Skewness
moments[2] = ((sum3 - 3.0 * moments[0] * sum2) / size + 2.0 * moments[0] * mean2) / (moments[1] * sigma);
// Kurtosis
moments[3] = ((sum4 - 4.0 * moments[0] * sum3 + 6.0 * mean2 * sum2) / size - 3.0 * mean2 * mean2)
/ (moments[1] * moments[1]) - 3.0;
}
return moments;
}
};
}
}
#endif
|