OTB  10.0.0
Orfeo Toolbox
otbCloudEstimatorFunctor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 otbCloudEstimatorFunctor_h
22 #define otbCloudEstimatorFunctor_h
23 
25 
26 namespace otb
27 {
28 namespace Functor
29 {
40 template <class TInput, class TOutputValue>
42 {
43 public:
45 
47  {
48  m_ReferencePixel.SetSize(4);
49  m_ReferencePixel.Fill(1);
50  m_RefNorm = 2.0;
51  m_Variance = 1.0;
52  m_Denom = 1.0;
53  }
54 
56  {
57  }
58  inline TOutputValue operator()(const TInput& inPix) const
59  {
60 
61  TOutputValue lOut;
62  double lRes = 0.0;
63  double lCurPixNorm = 0.0;
64  double lGaussianCoef = 1.0;
65 
66  // Compute the Gaussian Coef
67  for (unsigned int i = 0; i < std::min(inPix.Size(), m_ReferencePixel.Size()); ++i)
68  {
69  lCurPixNorm += inPix[i] * inPix[i];
70  }
71  lCurPixNorm = std::sqrt(static_cast<double>(lCurPixNorm));
72  lGaussianCoef = std::exp(-std::pow((lCurPixNorm - m_RefNorm), 2) / m_Denom);
73 
74  // Reverse the SpectralAngle values and set them between [0; 1]
75  lRes = lGaussianCoef * ((CONST_PI - m_SpectralAngleFunctor(inPix)) / CONST_PI);
76 
77  lOut = static_cast<TOutputValue>(lRes);
78  return lOut;
79  }
80 
81  void SetReferencePixel(TInput ref)
82  {
83  m_ReferencePixel = ref;
85  m_RefNorm = 0.0;
86  for (unsigned int i = 0; i < ref.Size(); ++i)
87  {
88  m_RefNorm += ref[i] * ref[i];
89  }
90  m_RefNorm = std::sqrt(static_cast<double>(m_RefNorm));
92  }
93 
94  void SetVariance(double variance)
95  {
96  m_Variance = variance;
97  m_Denom = 2 * variance * variance * m_RefNorm * m_RefNorm;
98  }
99 
100  TInput GetReferencePixel() const
101  {
102  return m_ReferencePixel;
103  }
104  double GetVariance() const
105  {
106  return m_Variance;
107  }
108 
109 protected:
112  double m_RefNorm;
113  double m_Variance;
114  double m_Denom;
115 };
116 
117 } // end namespace functor
118 } // end namespace otb
119 
120 #endif
Functor to help with the cloud detection.
SpectralAngleFunctor< TInput, TOutputValue > SpectralAngleFunctorType
TOutputValue operator()(const TInput &inPix) const
This functor computes the spectral angle according to a reference pixel.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
constexpr double CONST_PI
Definition: otbMath.h:49