OTB  9.0.0
Orfeo Toolbox
otbReciprocalBarnesDecompImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 
22 #ifndef otbReciprocalBarnesDecompImageFilter_h
23 #define otbReciprocalBarnesDecompImageFilter_h
24 
25 #include "otbMath.h"
26 #include "vnl/algo/vnl_complex_eigensystem.h"
27 #include <algorithm>
28 
29 #include "otbFunctorImageFilter.h"
30 
31 namespace otb
32 {
33 
34 namespace Functor
35 {
36 
45 template <class TInput, class TOutput>
47 {
48 public:
49  typedef typename std::complex<double> ComplexType;
50  typedef vnl_matrix<ComplexType> VNLMatrixType;
51  typedef vnl_vector<ComplexType> VNLVectorType;
52  typedef vnl_vector<double> VNLDoubleVectorType;
53  typedef std::vector<double> VectorType;
54  typedef typename TOutput::ValueType OutputValueType;
55 
56  inline void operator()(TOutput& result, const TInput& Covariance) const
57  {
58 
59  VNLMatrixType qi(3, 1);
60 
61 
62  VNLMatrixType cov(3, 3);
63  cov[0][0] = ComplexType(Covariance[0]);
64  cov[0][1] = ComplexType(Covariance[1]);
65  cov[0][2] = ComplexType(Covariance[2]);
66  cov[1][0] = std::conj(ComplexType(Covariance[1]));
67  cov[1][1] = ComplexType(Covariance[3]);
68  cov[1][2] = ComplexType(Covariance[4]);
69  cov[2][0] = std::conj(ComplexType(Covariance[2]));
70  cov[2][1] = std::conj(ComplexType(Covariance[4]));
71  cov[2][2] = ComplexType(Covariance[5]);
72 
73 
74  qi[0][0] = ComplexType(1., 0.);
75  qi[1][0] = ComplexType(0., 0.);
76  qi[2][0] = ComplexType(0., 0.);
77  ComplexType norm = (qi.conjugate_transpose() * cov * qi)[0][0];
78  VNLMatrixType ki = cov * qi / std::sqrt(norm);
79  result[0] = static_cast<OutputValueType>(ki[0][0]);
80  result[1] = static_cast<OutputValueType>(ki[1][0]);
81  result[2] = static_cast<OutputValueType>(ki[2][0]);
82 
83 
84  qi[0][0] = ComplexType(0., 0.);
85  qi[1][0] = ComplexType(1. / std::sqrt(2.), 0.);
86  qi[2][0] = ComplexType(0., 1. / std::sqrt(2.));
87  norm = (qi.conjugate_transpose() * cov * qi)[0][0];
88  ki = cov * qi / std::sqrt(norm);
89  result[3] = static_cast<OutputValueType>(ki[0][0]);
90  result[4] = static_cast<OutputValueType>(ki[1][0]);
91  result[5] = static_cast<OutputValueType>(ki[2][0]);
92 
93 
94  qi[0][0] = ComplexType(0., 0.);
95  qi[1][0] = ComplexType(0., 1. / std::sqrt(2.));
96  qi[2][0] = ComplexType(1. / std::sqrt(2.), 0.);
97  norm = (qi.conjugate_transpose() * cov * qi)[0][0];
98  ki = cov * qi / std::sqrt(norm);
99  result[6] = static_cast<OutputValueType>(ki[0][0]);
100  result[7] = static_cast<OutputValueType>(ki[1][0]);
101  result[8] = static_cast<OutputValueType>(ki[2][0]);
102  }
103 
104  constexpr size_t OutputSize(...) const
105  {
106  // Size of the result
107  return 9;
108  }
109 
110 private:
111  static constexpr double m_Epsilon = 1e-6;
112 };
113 } // namespace Functor
114 
127 template <typename TInputImage, typename TOutputImage>
130 } // end namespace otb
131 
132 #endif
otbFunctorImageFilter.h
otb::Functor::ReciprocalBarnesDecompFunctor::operator()
void operator()(TOutput &result, const TInput &Covariance) const
Definition: otbReciprocalBarnesDecompImageFilter.h:56
otb::Functor::ReciprocalBarnesDecompFunctor::OutputValueType
TOutput::ValueType OutputValueType
Definition: otbReciprocalBarnesDecompImageFilter.h:54
otb::Functor::ReciprocalBarnesDecompFunctor::VNLVectorType
vnl_vector< ComplexType > VNLVectorType
Definition: otbReciprocalBarnesDecompImageFilter.h:51
otb::FunctorImageFilter
A generic functor filter templated by its functor.
Definition: otbFunctorImageFilter.h:322
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::ReciprocalBarnesDecompFunctor::VNLDoubleVectorType
vnl_vector< double > VNLDoubleVectorType
Definition: otbReciprocalBarnesDecompImageFilter.h:52
otb::Functor::ReciprocalBarnesDecompFunctor::OutputSize
constexpr vcl_size_t OutputSize(...) const
Definition: otbReciprocalBarnesDecompImageFilter.h:104
otb::Functor::ReciprocalBarnesDecompFunctor
Definition: otbReciprocalBarnesDecompImageFilter.h:46
otb::Functor::ReciprocalBarnesDecompFunctor::VNLMatrixType
vnl_matrix< ComplexType > VNLMatrixType
Definition: otbReciprocalBarnesDecompImageFilter.h:50
otb::Functor::ReciprocalBarnesDecompFunctor::m_Epsilon
static constexpr double m_Epsilon
Definition: otbReciprocalBarnesDecompImageFilter.h:111
otb::Functor::ReciprocalBarnesDecompFunctor::ComplexType
std::complex< double > ComplexType
Definition: otbReciprocalBarnesDecompImageFilter.h:49
otb::Functor::ReciprocalBarnesDecompFunctor::VectorType
std::vector< double > VectorType
Definition: otbReciprocalBarnesDecompImageFilter.h:53