OTB  9.0.0
Orfeo Toolbox
otbSoilIndicesFunctor.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 otbSoilIndicesFunctor_h
22 #define otbSoilIndicesFunctor_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 RI : public RadiometricIndex<TInput, TOutput>
47 {
48 public:
49  RI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN})
50  {
51  }
52 
53  TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override
54  {
55  auto green = this->Value(CommonBandNames::GREEN, input);
56  auto red = this->Value(CommonBandNames::RED, input);
57 
58  if (std::abs(green) < RadiometricIndex<TInput, TOutput>::Epsilon)
59  {
60  return static_cast<TOutput>(0.);
61  }
62 
63  return static_cast<TOutput>(red * red / (green * green * green));
64  }
65 };
66 
81 template <class TInput, class TOutput>
82 class CI : public RadiometricIndex<TInput, TOutput>
83 {
84 public:
85  CI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN})
86  {
87  }
88 
89  TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override
90  {
91  auto green = this->Value(CommonBandNames::GREEN, input);
92  auto red = this->Value(CommonBandNames::RED, input);
93 
94  if (std::abs(green + red) < RadiometricIndex<TInput, TOutput>::Epsilon)
95  {
96  return static_cast<TOutput>(0.);
97  }
98 
99  return (static_cast<TOutput>((red - green) / (red + green)));
100  }
101 };
102 
113 template <class TInput, class TOutput>
114 class BI : public RadiometricIndex<TInput, TOutput>
115 {
116 public:
117  BI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, 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 red = this->Value(CommonBandNames::RED, input);
125 
126  return (static_cast<TOutput>(std::sqrt((red * red + green * green) / 2.)));
127  }
128 };
129 
140 template <class TInput, class TOutput>
141 class BI2 : public RadiometricIndex<TInput, TOutput>
142 {
143 public:
144  BI2() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN, CommonBandNames::NIR})
145  {
146  }
147 
148  TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override
149  {
150  auto green = this->Value(CommonBandNames::GREEN, input);
151  auto red = this->Value(CommonBandNames::RED, input);
152  auto nir = this->Value(CommonBandNames::NIR, input);
153 
154  return (static_cast<TOutput>(std::sqrt((red * red + green * green + nir * nir) / 3.)));
155  }
156 };
157 
158 } // namespace Functor
159 } // namespace otb
160 
161 #endif
otb::Functor::RadiometricIndex::Value
double Value(BandNameType band, const itk::VariableLengthVector< TInput > &input) const
Definition: otbRadiometricIndex.h:204
otb::Functor::CI
This functor computes the Color Index (IC)
Definition: otbSoilIndicesFunctor.h:82
otb::Functor::BI::BI
BI()
Definition: otbSoilIndicesFunctor.h:117
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::BI::operator()
TOutput operator()(const itk::VariableLengthVector< TInput > &input) const override
Definition: otbSoilIndicesFunctor.h:121
otb::Functor::BI2::BI2
BI2()
Definition: otbSoilIndicesFunctor.h:144
otb::Functor::RI::operator()
TOutput operator()(const itk::VariableLengthVector< TInput > &input) const override
Definition: otbSoilIndicesFunctor.h:53
otbRadiometricIndex.h
otb::Functor::CI::operator()
TOutput operator()(const itk::VariableLengthVector< TInput > &input) const override
Definition: otbSoilIndicesFunctor.h:89
otb::Functor::RI
This functor computes the Redness Index (RI)
Definition: otbSoilIndicesFunctor.h:46
otb::Functor::BI
This functor computes the Brilliance Index (BI)
Definition: otbSoilIndicesFunctor.h:114
otb::Functor::BI2
This functor computes the Brilliance Index (BI2)
Definition: otbSoilIndicesFunctor.h:141
otb::Functor::CI::CI
CI()
Definition: otbSoilIndicesFunctor.h:85
otb::Functor::RI::RI
RI()
Definition: otbSoilIndicesFunctor.h:49
otb::Functor::RadiometricIndex
Base class for all radiometric indices.
Definition: otbRadiometricIndex.h:57
otb::Functor::BI2::operator()
TOutput operator()(const itk::VariableLengthVector< TInput > &input) const override
Definition: otbSoilIndicesFunctor.h:148