OTB  9.0.0
Orfeo Toolbox
otbWaterIndicesFunctor.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 otbWaterIndicesFunctor_h
22 #define otbWaterIndicesFunctor_h
23 
24 #include "otbMath.h"
25 #include "otbRadiometricIndex.h"
26 
27 namespace otb
28 {
29 namespace Functor
30 {
45 template <class TInput, class TOutput>
46 class NDWI : public RadiometricIndex<TInput, TOutput>
47 {
48 public:
49  NDWI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::NIR, CommonBandNames::MIR})
50  {
51  }
52 
53  TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override
54  {
55  auto mir = this->Value(CommonBandNames::MIR, input);
56  auto nir = this->Value(CommonBandNames::NIR, input);
57 
58  if (std::abs(nir + mir) < RadiometricIndex<TInput, TOutput>::Epsilon)
59  {
60  return 0.;
61  }
62 
63  return (nir - mir) / (nir + mir);
64  }
65 };
66 
77 template <class TInput, class TOutput>
78 class NDWI2 : public RadiometricIndex<TInput, TOutput>
79 {
80 public:
81  NDWI2() : RadiometricIndex<TInput, TOutput>({CommonBandNames::NIR, CommonBandNames::GREEN})
82  {
83  }
84 
85  TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override
86  {
87  auto green = this->Value(CommonBandNames::GREEN, input);
88  auto nir = this->Value(CommonBandNames::NIR, input);
89 
90  if (std::abs(nir + green) < RadiometricIndex<TInput, TOutput>::Epsilon)
91  {
92  return 0.;
93  }
94 
95  return (green - nir) / (green + nir);
96  }
97 };
98 
113 template <class TInput, class TOutput>
114 class MNDWI : public RadiometricIndex<TInput, TOutput>
115 {
116 public:
117  MNDWI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::MIR, CommonBandNames::GREEN})
118  {
119  }
120 
121  TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override
122  {
123  auto green = this->Value(CommonBandNames::GREEN, input);
124  auto mir = this->Value(CommonBandNames::MIR, input);
125 
126  if (std::abs(mir + green) < RadiometricIndex<TInput, TOutput>::Epsilon)
127  {
128  return 0.;
129  }
130 
131  return (green - mir) / (green + mir);
132  }
133 };
134 
145 template <class TInput, class TOutput>
146 class NDTI : public RadiometricIndex<TInput, TOutput>
147 {
148 public:
149  NDTI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN})
150  {
151  }
152 
153  TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override
154  {
155  auto green = this->Value(CommonBandNames::GREEN, input);
156  auto red = this->Value(CommonBandNames::RED, input);
157 
158  if (std::abs(red + green) < RadiometricIndex<TInput, TOutput>::Epsilon)
159  {
160  return 0.;
161  }
162 
163  return (red - green) / (green + red);
164  }
165 };
166 
167 } // namespace Functor
168 } // namespace otb
169 
170 #endif
otb::Functor::NDWI2::NDWI2
NDWI2()
Definition: otbWaterIndicesFunctor.h:81
otb::Functor::NDWI2
This functor computes the Normalized Difference Water Index (NDWI2)
Definition: otbWaterIndicesFunctor.h:78
otb::Functor::RadiometricIndex::Value
double Value(BandNameType band, const itk::VariableLengthVector< TInput > &input) const
Definition: otbRadiometricIndex.h:204
otb::Functor::MNDWI::operator()
TOutput operator()(const itk::VariableLengthVector< TInput > &input) const override
Definition: otbWaterIndicesFunctor.h:121
otb::Functor::MNDWI
This functor computes the Modified Normalized Difference Water Index (MNDWI)
Definition: otbWaterIndicesFunctor.h:114
otb::Functor::NDTI
This functor computes the Normalized Difference Turbidity Index (NDTI)
Definition: otbWaterIndicesFunctor.h:146
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::NDTI::operator()
TOutput operator()(const itk::VariableLengthVector< TInput > &input) const override
Definition: otbWaterIndicesFunctor.h:153
otb::Functor::NDTI::NDTI
NDTI()
Definition: otbWaterIndicesFunctor.h:149
otb::Functor::MNDWI::MNDWI
MNDWI()
Definition: otbWaterIndicesFunctor.h:117
otbRadiometricIndex.h
otb::Functor::NDWI::operator()
TOutput operator()(const itk::VariableLengthVector< TInput > &input) const override
Definition: otbWaterIndicesFunctor.h:53
otb::Functor::RadiometricIndex
Base class for all radiometric indices.
Definition: otbRadiometricIndex.h:57
otb::Functor::NDWI
This functor computes the Normalized Difference Water Index (NDWI)
Definition: otbWaterIndicesFunctor.h:46
otb::Functor::NDWI2::operator()
TOutput operator()(const itk::VariableLengthVector< TInput > &input) const override
Definition: otbWaterIndicesFunctor.h:85
otb::Functor::NDWI::NDWI
NDWI()
Definition: otbWaterIndicesFunctor.h:49