OTB  6.1.0
Orfeo Toolbox
otbTerraSarBrightnessFunctor.txx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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 #ifndef otbTerraSarBrightnessFunctor_txx
22 #define otbTerraSarBrightnessFunctor_txx
23 
25 
26 #include "itkNumericTraits.h"
27 
28 namespace otb
29 {
30 namespace Functor
31 {
32 
33 template <class TInput, class TOutput>
36 {
37  m_CalibrationFactor = itk::NumericTraits<double>::Zero;
38  m_ResultsInDecibels = false;
39  m_DefaultValue = 0.00001; // Default value is 10^-5
40 }
41 
42 template <class TInput, class TOutput>
43 TOutput
45 ::operator() (const TInput &inPix)
46  {
47  // Formula: Beta^0 = Ks * |DN|^2
48 
49  // First, square the input pixel
50  double squareInPix = vcl_pow(static_cast<double>(inPix), 2.);
51 
52  // Then apply the calibration factor
53  double beta = m_CalibrationFactor * squareInPix;
54 
55  if (beta <= 0) beta = m_DefaultValue;
56 
57  // Results in decibels case
58  if (m_ResultsInDecibels)
59  {
60  beta = 10 * vcl_log10(beta);
61  }
62 
63  return static_cast<TOutput>(beta);
64  }
65 
66 template <class TInput, class TOutput>
67 std::complex<TOutput>
69 ::operator() (const std::complex<TInput> &inPix)
70  {
71  // First, extract modulus and phase
72  double modulus = vcl_sqrt(inPix.real() * inPix.real() + inPix.imag() * inPix.imag());
73  double phase = vcl_atan2(inPix.imag(), inPix.real());
74 
75  // Then, calibrate the modulus
76  double beta = this->operator() (modulus);
77 
78  // Last, put back the phase
79  std::complex<TOutput> out(std::polar(beta, phase));
80 
81  return out;
82  }
83 
84 } // namespace Functor
85 
86 } // namespace otb
87 #endif