21 #ifndef otbHuMomentsImageFunction_hxx
22 #define otbHuMomentsImageFunction_hxx
25 #include "itkConstNeighborhoodIterator.h"
26 #include "itkNumericTraits.h"
35 template <
class TInputImage,
class TCoordRep>
38 m_NeighborhoodRadius = 1;
41 template <
class TInputImage,
class TCoordRep>
44 this->Superclass::PrintSelf(os, indent);
45 os << indent <<
" Neighborhood radius value : " << m_NeighborhoodRadius << std::endl;
48 template <
class TInputImage,
class TCoordRep>
56 moments.Fill(itk::NumericTraits<ScalarRealType>::Zero);
59 if (!this->GetInputImage())
65 if (!this->IsInsideBuffer(index))
71 typedef std::complex<ScalarRealType> ComplexType;
74 ComplexType c11, c20, c02, c30, c03, c21, c12;
75 c11 = itk::NumericTraits<ComplexType>::Zero;
76 c20 = itk::NumericTraits<ComplexType>::Zero;
77 c02 = itk::NumericTraits<ComplexType>::Zero;
78 c30 = itk::NumericTraits<ComplexType>::Zero;
79 c03 = itk::NumericTraits<ComplexType>::Zero;
80 c21 = itk::NumericTraits<ComplexType>::Zero;
81 c12 = itk::NumericTraits<ComplexType>::Zero;
86 typename InputImageType::SizeType kernelSize;
87 kernelSize.Fill(m_NeighborhoodRadius);
89 itk::ConstNeighborhoodIterator<InputImageType> it(kernelSize, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion());
92 it.SetLocation(index);
95 const unsigned int size = it.Size();
96 for (
unsigned int i = 0; i < size; ++i)
103 ComplexType xpy(x, y), xqy(x, -y);
107 c11 += xpy * xqy * value;
108 c20 += xpy * xpy * value;
109 c02 += xqy * xqy * value;
110 c30 += xpy * xpy * xpy * value;
111 c03 += xqy * xqy * xqy * value;
112 c21 += xpy * xpy * xqy * value;
113 c12 += xpy * xqy * xqy * value;
130 moments[4] =
static_cast<ScalarRealType>((c30 * c12 * c12 * c12).real());
131 moments[5] =
static_cast<ScalarRealType>((c20 * c12 * c12).real());
132 moments[6] =
static_cast<ScalarRealType>((c30 * c12 * c12 * c12).imag());