OTB  9.0.0
Orfeo Toolbox
otbWaterSqrtSpectralAngleImageFilter.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 otbWaterSqrtSpectralAngleImageFilter_h
22 #define otbWaterSqrtSpectralAngleImageFilter_h
23 
25 #include "itkUnaryFunctorImageFilter.h"
26 #include "otbRadiometricIndex.h"
27 
28 namespace otb
29 {
30 
31 namespace Functor
32 {
42 template <class TInput, class TOutput>
43 class WaterSqrtSpectralAngleFunctor : public RadiometricIndex<TInput, TOutput>
44 {
45 public:
47 
49  : RadiometricIndex<TInput, TOutput>({CommonBandNames::BLUE, CommonBandNames::GREEN, CommonBandNames::RED, CommonBandNames::NIR} )
50  {
51  // Set default reference water value
52  m_ReferencePixel.SetSize(4);
53  m_ReferencePixel[0] = 136.0;
54  m_ReferencePixel[1] = 132.0;
55  m_ReferencePixel[2] = 47.0;
56  m_ReferencePixel[3] = 24.0;
57  m_RefNorm = m_ReferencePixel.GetNorm();
58  }
59 
60  virtual ~WaterSqrtSpectralAngleFunctor() = default;
61 
66  {
67  assert(m_ReferencePixel.Size() == 4);
68  m_ReferencePixel[0] = this->Value(CommonBandNames::BLUE, ref);
69  m_ReferencePixel[1] = this->Value(CommonBandNames::GREEN, ref);
70  m_ReferencePixel[2] = this->Value(CommonBandNames::RED, ref);
71  m_ReferencePixel[3] = this->Value(CommonBandNames::NIR, ref);
72  m_RefNorm = m_ReferencePixel.GetNorm();
73  }
75 
76  // Binary operator
77  inline TOutput operator()(PixelType const & inPix) const override
78  {
79  PixelType pix(4);
80  pix[0] = this->Value(CommonBandNames::BLUE, inPix);
81  pix[1] = this->Value(CommonBandNames::GREEN, inPix);
82  pix[2] = this->Value(CommonBandNames::RED, inPix);
83  pix[3] = this->Value(CommonBandNames::NIR, inPix);
84 
85  return std::sqrt(SpectralAngleDetails::ComputeSpectralAngle<PixelType, PixelType, TOutput>
86  (pix, pix.GetNorm(),
88  }
89 
95  void SetBlueChannel(unsigned int channel)
96  {
97  this->SetBandIndex(CommonBandNames::BLUE, channel + 1);
98  }
99  unsigned int GetBlueChannel() const
100  {
101  return this->GetBandIndex(CommonBandNames::BLUE) - 1;
102  }
103  void SetGreenChannel(unsigned int channel)
104  {
105  this->SetBandIndex(CommonBandNames::GREEN, channel + 1);
106  }
107  unsigned int GetGreenChannel() const
108  {
109  return this->GetBandIndex(CommonBandNames::GREEN) - 1;
110  }
111  void SetRedChannel(unsigned int channel)
112  {
113  this->SetBandIndex(CommonBandNames::RED, channel + 1);
114  }
115  unsigned int GetRedChannel() const
116  {
117  return this->GetBandIndex(CommonBandNames::RED) - 1;
118  }
119  void SetNIRChannel(unsigned int channel)
120  {
121  this->SetBandIndex(CommonBandNames::NIR, channel + 1);
122  }
123  unsigned int GetNIRChannel() const
124  {
125  return this->GetBandIndex(CommonBandNames::NIR) - 1;
126  }
127 
131 private:
132 
134  double m_RefNorm;
135 };
136 } // End namespace Functor
137 
138 
159 template <class TInputVectorImage, class TOutputImage,
161 class ITK_EXPORT WaterSqrtSpectralAngleImageFilter : public itk::UnaryFunctorImageFilter<TInputVectorImage, TOutputImage, TFunction>
162 {
163 public:
166  typedef itk::UnaryFunctorImageFilter<TInputVectorImage, TOutputImage, TFunction> Superclass;
167  typedef itk::SmartPointer<Self> Pointer;
168  typedef itk::SmartPointer<const Self> ConstPointer;
169 
171  itkNewMacro(Self);
172 
174  itkTypeMacro(WaterSqrtSpectralAngleImageFilter, itk::UnaryFunctorImageFilter);
175 
177  typedef TInputVectorImage InputVectorImageType;
178  typedef typename InputVectorImageType::PixelType InputVectorPixelType;
179  typedef TOutputImage OutputImageType;
180 
181 protected:
183  {
184  }
186  {
187  }
188 
189 private:
190  WaterSqrtSpectralAngleImageFilter(Self&) = delete;
191  void operator=(const Self&) = delete;
192 };
193 } // end namespace otb
194 
195 #ifndef OTB_MANUAL_INSTANTIATION
196 #endif
197 
198 #endif
otb::Functor::WaterSqrtSpectralAngleFunctor
This functor uses a spectral angle with a particular reference pixel.
Definition: otbWaterSqrtSpectralAngleImageFilter.h:43
otb::WaterSqrtSpectralAngleImageFilter::~WaterSqrtSpectralAngleImageFilter
~WaterSqrtSpectralAngleImageFilter() override
Definition: otbWaterSqrtSpectralAngleImageFilter.h:185
otb::Functor::WaterSqrtSpectralAngleFunctor::SetGreenChannel
void SetGreenChannel(unsigned int channel)
Definition: otbWaterSqrtSpectralAngleImageFilter.h:103
otb::WaterSqrtSpectralAngleImageFilter::Self
WaterSqrtSpectralAngleImageFilter Self
Definition: otbWaterSqrtSpectralAngleImageFilter.h:165
otb::Functor::WaterSqrtSpectralAngleFunctor::operator()
TOutput operator()(PixelType const &inPix) const override
Definition: otbWaterSqrtSpectralAngleImageFilter.h:77
otb::Functor::RadiometricIndex::Value
double Value(BandNameType band, const itk::VariableLengthVector< TInput > &input) const
Definition: otbRadiometricIndex.h:204
otb::Functor::WaterSqrtSpectralAngleFunctor::m_RefNorm
double m_RefNorm
Definition: otbWaterSqrtSpectralAngleImageFilter.h:134
otb::WaterSqrtSpectralAngleImageFilter::Superclass
itk::UnaryFunctorImageFilter< TInputVectorImage, TOutputImage, TFunction > Superclass
Definition: otbWaterSqrtSpectralAngleImageFilter.h:166
otb::Functor::WaterSqrtSpectralAngleFunctor::WaterSqrtSpectralAngleFunctor
WaterSqrtSpectralAngleFunctor()
Definition: otbWaterSqrtSpectralAngleImageFilter.h:48
otb::Functor::WaterSqrtSpectralAngleFunctor::SetBlueChannel
void SetBlueChannel(unsigned int channel)
Definition: otbWaterSqrtSpectralAngleImageFilter.h:95
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::WaterSqrtSpectralAngleImageFilter::WaterSqrtSpectralAngleImageFilter
WaterSqrtSpectralAngleImageFilter()
Definition: otbWaterSqrtSpectralAngleImageFilter.h:182
otb::WaterSqrtSpectralAngleImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbWaterSqrtSpectralAngleImageFilter.h:168
otb::Functor::WaterSqrtSpectralAngleFunctor::~WaterSqrtSpectralAngleFunctor
virtual ~WaterSqrtSpectralAngleFunctor()=default
otb::WaterSqrtSpectralAngleImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbWaterSqrtSpectralAngleImageFilter.h:167
otbSqrtSpectralAngleFunctor.h
otb::WaterSqrtSpectralAngleImageFilter::InputVectorPixelType
InputVectorImageType::PixelType InputVectorPixelType
Definition: otbWaterSqrtSpectralAngleImageFilter.h:178
otb::Functor::RadiometricIndex::PixelType
itk::VariableLengthVector< InputType > PixelType
Definition: otbRadiometricIndex.h:62
otb::Functor::WaterSqrtSpectralAngleFunctor::GetGreenChannel
unsigned int GetGreenChannel() const
Definition: otbWaterSqrtSpectralAngleImageFilter.h:107
otbRadiometricIndex.h
otb::Functor::WaterSqrtSpectralAngleFunctor::SetReferenceWaterPixel
void SetReferenceWaterPixel(PixelType ref)
Definition: otbWaterSqrtSpectralAngleImageFilter.h:65
otb::WaterSqrtSpectralAngleImageFilter
Compute a radiometric water indice.
Definition: otbWaterSqrtSpectralAngleImageFilter.h:161
otb::Functor::WaterSqrtSpectralAngleFunctor::SetNIRChannel
void SetNIRChannel(unsigned int channel)
Definition: otbWaterSqrtSpectralAngleImageFilter.h:119
otb::WaterSqrtSpectralAngleImageFilter::InputVectorImageType
TInputVectorImage InputVectorImageType
Definition: otbWaterSqrtSpectralAngleImageFilter.h:174
otb::WaterSqrtSpectralAngleImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbWaterSqrtSpectralAngleImageFilter.h:179
otb::Functor::WaterSqrtSpectralAngleFunctor::GetBlueChannel
unsigned int GetBlueChannel() const
Definition: otbWaterSqrtSpectralAngleImageFilter.h:99
otb::Functor::RadiometricIndex::GetBandIndex
vcl_size_t GetBandIndex(BandNameType band) const
Definition: otbRadiometricIndex.h:151
otb::Functor::WaterSqrtSpectralAngleFunctor::GetNIRChannel
unsigned int GetNIRChannel() const
Definition: otbWaterSqrtSpectralAngleImageFilter.h:123
otb::Functor::RadiometricIndex
Base class for all radiometric indices.
Definition: otbRadiometricIndex.h:57
otb::Functor::WaterSqrtSpectralAngleFunctor::m_ReferencePixel
PixelType m_ReferencePixel
Definition: otbWaterSqrtSpectralAngleImageFilter.h:133
otb::Functor::WaterSqrtSpectralAngleFunctor::SetRedChannel
void SetRedChannel(unsigned int channel)
Definition: otbWaterSqrtSpectralAngleImageFilter.h:111
otb::Functor::RadiometricIndex::SetBandIndex
void SetBandIndex(BandNameType band, vcl_size_t index)
Definition: otbRadiometricIndex.h:122
otb::Functor::WaterSqrtSpectralAngleFunctor::GetRedChannel
unsigned int GetRedChannel() const
Definition: otbWaterSqrtSpectralAngleImageFilter.h:115