OTB  9.0.0
Orfeo Toolbox
otbMuellerToPolarisationDegreeAndPowerImageFilter.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 otbMuellerToPolarisationDegreeAndPowerImageFilter_h
23 #define otbMuellerToPolarisationDegreeAndPowerImageFilter_h
24 
25 #include "itkNumericTraits.h"
26 #include "itkMatrix.h"
27 #include "itkVector.h"
28 #include "otbMath.h"
29 
30 #include "otbFunctorImageFilter.h"
31 
32 namespace otb
33 {
34 
35 namespace Functor
36 {
37 
83 template <class TInput, class TOutput>
85 {
86 public:
87  typedef typename TOutput::ValueType OutputValueType;
88  typedef itk::Matrix<double, 4, 4> MuellerMatrixType;
89  typedef itk::Vector<double, 4> StokesVectorType;
90 
91  inline void operator()(TOutput& result, const TInput& Mueller) const
92  {
93  double P;
94  double deg_pol;
95  double tau;
96  double psi;
99 
100  double l_PowerMin(itk::NumericTraits<double>::max());
101  double l_PowerMax(itk::NumericTraits<double>::min());
102  double l_PolarisationDegreeMin(itk::NumericTraits<double>::max());
103  double l_PolarisationDegreeMax(itk::NumericTraits<double>::min());
104 
105  MuellerMatrixType muellerMatrix;
106  muellerMatrix[0][0] = Mueller[0];
107  muellerMatrix[0][1] = Mueller[1];
108  muellerMatrix[0][2] = Mueller[2];
109  muellerMatrix[0][3] = Mueller[3];
110  muellerMatrix[1][0] = Mueller[4];
111  muellerMatrix[1][1] = Mueller[5];
112  muellerMatrix[1][2] = Mueller[6];
113  muellerMatrix[1][3] = Mueller[7];
114  muellerMatrix[2][0] = Mueller[8];
115  muellerMatrix[2][1] = Mueller[9];
116  muellerMatrix[2][2] = Mueller[10];
117  muellerMatrix[2][3] = Mueller[11];
118  muellerMatrix[3][0] = Mueller[12];
119  muellerMatrix[3][1] = Mueller[13];
120  muellerMatrix[3][2] = Mueller[14];
121  muellerMatrix[3][3] = Mueller[15];
122 
123  tau = -45.0;
124  while (tau < 46.0)
125  {
126  psi = -90.0;
127  while (psi < 91.0)
128  {
129  // Define the incident Stokes vector
130  Si[0] = 1.0;
131  Si[1] = cos(psi * m_PI_90) * cos(tau * m_PI_90);
132  Si[2] = sin(psi * m_PI_90) * cos(tau * m_PI_90);
133  Si[3] = sin(tau * m_PI_90);
134 
135  // Evaluate the received Stokes vector
136  Sr = muellerMatrix * Si;
137 
138  // Evaluate Power and Polarisation degree
139  P = Sr[0];
140 
141  if (P < m_Epsilon)
142  {
143  deg_pol = 0.;
144  }
145  else
146  {
147  deg_pol = std::sqrt(Sr[1] * Sr[1] + Sr[2] * Sr[2] + Sr[3] * Sr[3]) / Sr[0];
148  }
149 
150  if (P > l_PowerMax)
151  {
152  l_PowerMax = P;
153  }
154  else
155  {
156  l_PowerMin = P;
157  }
158 
159  if (deg_pol > l_PolarisationDegreeMax)
160  {
161  l_PolarisationDegreeMax = deg_pol;
162  }
163  else
164  {
165  l_PolarisationDegreeMin = deg_pol;
166  }
167  psi += 5.0;
168  }
169  tau += 5.0;
170  }
171 
172  result[0] = l_PowerMin;
173  result[1] = l_PowerMax;
174  result[2] = l_PolarisationDegreeMin;
175  result[3] = l_PolarisationDegreeMax;
176  }
177 
178  constexpr size_t OutputSize(...) const
179  {
180  // Size of the result
181  return 4;
182  }
183 
184 private:
185  static constexpr double m_Epsilon = 1e-6;
186  static constexpr double m_PI_90 = 2 * CONST_PI_180;
187 };
188 } // namespace Functor
189 
202 template <typename TInputImage, typename TOutputImage>
205 
206 
207 } // end namespace otb
208 
209 #endif
otb::Functor::MuellerToPolarisationDegreeAndPowerFunctor::OutputValueType
TOutput::ValueType OutputValueType
Definition: otbMuellerToPolarisationDegreeAndPowerImageFilter.h:87
otbFunctorImageFilter.h
otb::FunctorImageFilter
A generic functor filter templated by its functor.
Definition: otbFunctorImageFilter.h:322
otb::Functor::MuellerToPolarisationDegreeAndPowerFunctor::operator()
void operator()(TOutput &result, const TInput &Mueller) const
Definition: otbMuellerToPolarisationDegreeAndPowerImageFilter.h:91
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::MuellerToPolarisationDegreeAndPowerFunctor
Evaluate the min and max polarisation degree and min and max power from the Mueller image.
Definition: otbMuellerToPolarisationDegreeAndPowerImageFilter.h:84
otb::Functor::MuellerToPolarisationDegreeAndPowerFunctor::OutputSize
constexpr vcl_size_t OutputSize(...) const
Definition: otbMuellerToPolarisationDegreeAndPowerImageFilter.h:178
otb::Functor::MuellerToPolarisationDegreeAndPowerFunctor::StokesVectorType
itk::Vector< double, 4 > StokesVectorType
Definition: otbMuellerToPolarisationDegreeAndPowerImageFilter.h:89
otb::CONST_PI_180
constexpr double CONST_PI_180
Definition: otbMath.h:56
otb::Functor::MuellerToPolarisationDegreeAndPowerFunctor::MuellerMatrixType
itk::Matrix< double, 4, 4 > MuellerMatrixType
Definition: otbMuellerToPolarisationDegreeAndPowerImageFilter.h:88
otb::Functor::MuellerToPolarisationDegreeAndPowerFunctor::m_Epsilon
static constexpr double m_Epsilon
Definition: otbMuellerToPolarisationDegreeAndPowerImageFilter.h:185
otb::Functor::MuellerToPolarisationDegreeAndPowerFunctor::m_PI_90
static constexpr double m_PI_90
Definition: otbMuellerToPolarisationDegreeAndPowerImageFilter.h:186