22 #ifndef otbReciprocalHAlphaImageFilter_h
23 #define otbReciprocalHAlphaImageFilter_h
26 #include "vnl/algo/vnl_complex_eigensystem.h"
64 template <
class TInput,
class TOutput>
76 inline void operator()(TOutput& result,
const TInput& Coherency)
const
78 const double T0 =
static_cast<double>(Coherency[0].real());
79 const double T1 =
static_cast<double>(Coherency[3].real());
80 const double T2 =
static_cast<double>(Coherency[5].real());
86 vnlMat[1][0] = std::conj(
ComplexType(Coherency[1]));
89 vnlMat[2][0] = std::conj(
ComplexType(Coherency[2]));
90 vnlMat[2][1] = std::conj(
ComplexType(Coherency[4]));
94 vnl_complex_eigensystem syst(vnlMat,
false,
true);
99 double totalEigenValues(0.0);
107 VectorType sortedRealEigenValues(3, eigenValues[0].real());
108 sortedRealEigenValues[1] = eigenValues[1].real();
109 sortedRealEigenValues[2] = eigenValues[2].real();
110 std::sort(sortedRealEigenValues.begin(), sortedRealEigenValues.end());
111 std::reverse(sortedRealEigenValues.begin(), sortedRealEigenValues.end());
114 VNLVectorType sortedGreaterEigenVector(3, eigenVectors[0][0]);
115 for (
unsigned int i = 0; i < 3; ++i)
117 if (std::abs(eigenValues[1].real() - sortedRealEigenValues[i]) <
m_Epsilon)
119 sortedGreaterEigenVector[i] = eigenVectors[1][0];
121 else if (std::abs(eigenValues[2].real() - sortedRealEigenValues[i]) <
m_Epsilon)
123 sortedGreaterEigenVector[i] = eigenVectors[2][0];
127 totalEigenValues = 0.0;
128 for (
unsigned int k = 0; k < 3; ++k)
130 sortedRealEigenValues[k] = std::max(sortedRealEigenValues[k], 0.);
131 totalEigenValues += sortedRealEigenValues[k];
135 for (
unsigned int k = 0; k < 3; ++k)
137 p[k] = sortedRealEigenValues[k] / totalEigenValues;
142 plog[k] = -p[k] * log(p[k]) / log(3.0);
146 for (
unsigned int k = 0; k < 3; ++k)
150 double val0, val1, val2;
153 val0 = std::abs(sortedGreaterEigenVector[0]);
156 val1 = std::abs(sortedGreaterEigenVector[1]);
159 val2 = std::abs(sortedGreaterEigenVector[2]);
162 alpha = p[0] * a0 + p[1] * a1 + p[2] * a2;
165 anisotropy = (sortedRealEigenValues[1] - sortedRealEigenValues[2]) / (sortedRealEigenValues[1] + sortedRealEigenValues[2] +
m_Epsilon);
195 template <
typename TInputImage,
typename TOutputImage>