21 #ifndef otbRealMomentsImageFunction_hxx
22 #define otbRealMomentsImageFunction_hxx
25 #include "itkConstNeighborhoodIterator.h"
26 #include "itkNumericTraits.h"
34 template <
class TInputImage,
class TCoordRep>
37 m_NeighborhoodRadius = 1;
42 template <
class TInputImage,
class TCoordRep>
45 this->Superclass::PrintSelf(os, indent);
46 os << indent <<
" p indice maximum value : " << m_Pmax << std::endl;
47 os << indent <<
" q indice maximum value : " << m_Qmax << std::endl;
48 os << indent <<
" Neighborhood radius value : " << m_NeighborhoodRadius << std::endl;
51 template <
class TInputImage,
class TCoordRep>
57 moments.resize(m_Pmax + 1);
59 std::vector<ScalarRealType> valXpY, valXqY;
60 valXpY.resize(m_Pmax + 1);
61 valXqY.resize(m_Qmax + 1);
64 for (
unsigned int p = 0; p <= m_Pmax; p++)
66 moments.at(p).resize(m_Qmax + 1);
68 for (
unsigned int q = 0; q <= m_Qmax; q++)
70 moments.at(p).at(q) = 0.0;
76 if (!this->GetInputImage())
82 if (!this->IsInsideBuffer(index))
88 typename InputImageType::SizeType kernelSize;
89 kernelSize.Fill(m_NeighborhoodRadius);
91 itk::ConstNeighborhoodIterator<InputImageType> it(kernelSize, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion());
94 it.SetLocation(index);
97 const unsigned int size = it.Size();
98 for (
unsigned int i = 0; i < size; ++i)
105 unsigned int pTmp = 1;
106 unsigned int qTmp = 1;
108 while (pTmp <= m_Pmax)
110 valXpY.at(pTmp) = valXpY.at(pTmp - 1) * x;
113 while (qTmp <= m_Qmax)
115 valXqY.at(qTmp) = valXqY.at(qTmp - 1) * y;
121 for (
unsigned int p = 0; p <= m_Pmax; p++)
123 for (
unsigned int q = 0; q <= m_Qmax; q++)
125 moments.at(p).at(q) += valXpY.at(p) * valXqY.at(q) * value;
131 for (
int p = m_Pmax; p >= 0; p--)
133 for (
int q = m_Qmax; q >= 0; q--)
135 moments.at(p).at(q) /= moments.at(0).at(0);