OTB  10.0.0
Orfeo Toolbox
otbAmplitudeFunctor.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 otbAmplitudeFunctor_h
22 #define otbAmplitudeFunctor_h
23 
25 
26 namespace otb
27 {
28 namespace Function
29 {
39 template <class TInputPixel>
40 class AmplitudeFunctor : public ChannelSelectorFunctor<TInputPixel>
41 {
42 public:
45  typedef itk::Object Superclass;
46  typedef itk::SmartPointer<Self> Pointer;
47  typedef itk::SmartPointer<const Self> ConstPointer;
48 
50  itkNewMacro(Self);
51 
53  itkTypeMacro(AmplitudeFunctor, itk::Object);
54 
55  typedef TInputPixel PixelType;
56  typedef typename itk::NumericTraits<PixelType>::ValueType ScalarType;
57  typedef itk::VariableLengthVector<ScalarType> VectorPixelType;
58  typedef itk::RGBPixel<ScalarType> RGBPixelType;
59  typedef itk::RGBAPixel<ScalarType> RGBAPixelType;
60 
62 
65  {
66  std::vector<unsigned int> channels;
67  channels.push_back(0);
68  channels.push_back(1);
69  this->SetChannelList(channels);
70  }
72 
74  ~AmplitudeFunctor() override
75  {
76  }
77 
78  const char* GetDescription() const
79  {
80  return "Amplitude";
81  }
82 
83  unsigned int GetOutputSize() const override
84  {
85  return 1;
86  }
87 
88  OutputPixelType operator()(const VectorPixelType& inPixel) const override
89  {
90  OutputPixelType outPixel;
91  outPixel.SetSize(1);
92  assert((this->GetChannelList()).size() == 2);
93  assert((this->GetChannelList())[0] < inPixel.Size());
94  assert((this->GetChannelList())[1] < inPixel.Size());
95  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
96  return outPixel;
97  }
98 
100  {
101  // FIXME we don't handle the std::complex<> yet
102  itkExceptionMacro(<< "Can't compute amplitude from a scalar value");
103  }
104 
105  OutputPixelType operator()(const RGBPixelType& inPixel) const override
106  {
107  OutputPixelType outPixel;
108  outPixel.SetSize(1);
109 
110  assert((this->GetChannelList()).size() == 2);
111  assert((this->GetChannelList())[0] < 3);
112  assert((this->GetChannelList())[1] < 3);
113 
114  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
115  return outPixel;
116  }
117 
118  OutputPixelType operator()(const RGBAPixelType& inPixel) const override
119  {
120  OutputPixelType outPixel;
121  outPixel.SetSize(1);
122 
123  assert((this->GetChannelList()).size() == 2);
124  assert((this->GetChannelList())[0] < 4);
125  assert((this->GetChannelList())[1] < 4);
126 
127  outPixel[0] = ComputeAmplitude(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
128  return outPixel;
129  }
130 
131 private:
133  {
134  return std::sqrt(a * a + b * b);
135  }
136 };
137 }
138 }
139 
140 #endif
Compute the module from the selected channel in the input.
ScalarType ComputeAmplitude(ScalarType a, ScalarType b) const
OutputPixelType operator()(const RGBPixelType &inPixel) const override
itk::RGBPixel< ScalarType > RGBPixelType
itk::VariableLengthVector< ScalarType > VectorPixelType
itk::NumericTraits< PixelType >::ValueType ScalarType
OutputPixelType operator()(const RGBAPixelType &inPixel) const override
itk::SmartPointer< Self > Pointer
itk::SmartPointer< const Self > ConstPointer
unsigned int GetOutputSize() const override
OutputPixelType operator()(ScalarType) const override
OutputPixelType operator()(const VectorPixelType &inPixel) const override
itk::RGBAPixel< ScalarType > RGBAPixelType
Base class for pixel representation functions.
virtual std::vector< unsigned int > GetChannelList() const
typename itk::NumericTraits< PixelType >::ValueType ScalarType
itk::VariableLengthVector< ScalarType > VectorPixelType
virtual void SetChannelList(std::vector< unsigned int > channels)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.