OTB  9.0.0
Orfeo Toolbox
otbCloudEstimatorFunctor.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 #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
otb::Functor::CloudEstimatorFunctor::GetReferencePixel
TInput GetReferencePixel() const
Definition: otbCloudEstimatorFunctor.h:100
otb::Functor::CloudEstimatorFunctor::~CloudEstimatorFunctor
virtual ~CloudEstimatorFunctor()
Definition: otbCloudEstimatorFunctor.h:55
otb::Functor::CloudEstimatorFunctor::m_Denom
double m_Denom
Definition: otbCloudEstimatorFunctor.h:114
otb::CONST_PI
constexpr double CONST_PI
Definition: otbMath.h:49
otb::Functor::SpectralAngleFunctor
This functor computes the spectral angle according to a reference pixel.
Definition: otbSpectralAngleFunctor.h:67
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::CloudEstimatorFunctor::m_RefNorm
double m_RefNorm
Definition: otbCloudEstimatorFunctor.h:112
otb::Functor::CloudEstimatorFunctor::m_ReferencePixel
TInput m_ReferencePixel
Definition: otbCloudEstimatorFunctor.h:111
otb::Functor::CloudEstimatorFunctor::operator()
TOutputValue operator()(const TInput &inPix) const
Definition: otbCloudEstimatorFunctor.h:58
otb::Functor::SpectralAngleFunctor::SetReferencePixel
void SetReferencePixel(TInput const &ref)
Definition: otbSpectralAngleFunctor.h:84
otb::Functor::CloudEstimatorFunctor
Functor to help with the cloud detection.
Definition: otbCloudEstimatorFunctor.h:41
otbSpectralAngleFunctor.h
otb::Functor::CloudEstimatorFunctor::SetReferencePixel
void SetReferencePixel(TInput ref)
Definition: otbCloudEstimatorFunctor.h:81
otb::Functor::CloudEstimatorFunctor::SetVariance
void SetVariance(double variance)
Definition: otbCloudEstimatorFunctor.h:94
otb::Functor::CloudEstimatorFunctor::GetVariance
double GetVariance() const
Definition: otbCloudEstimatorFunctor.h:104
otb::Functor::CloudEstimatorFunctor::m_Variance
double m_Variance
Definition: otbCloudEstimatorFunctor.h:113
otb::Functor::CloudEstimatorFunctor::CloudEstimatorFunctor
CloudEstimatorFunctor()
Definition: otbCloudEstimatorFunctor.h:46
otb::Functor::CloudEstimatorFunctor::SpectralAngleFunctorType
SpectralAngleFunctor< TInput, TOutputValue > SpectralAngleFunctorType
Definition: otbCloudEstimatorFunctor.h:44
otb::Functor::CloudEstimatorFunctor::m_SpectralAngleFunctor
SpectralAngleFunctorType m_SpectralAngleFunctor
Definition: otbCloudEstimatorFunctor.h:110