OTB  9.0.0
Orfeo Toolbox
otbPhaseFunctor.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 otbPhaseFunctor_h
22 #define otbPhaseFunctor_h
23 
25 
26 namespace otb
27 {
28 namespace Function
29 {
39 template <class TInputPixel>
40 class PhaseFunctor : public ChannelSelectorFunctor<TInputPixel>
41 {
42 public:
44  typedef PhaseFunctor Self;
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(PhaseFunctor, 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  ~PhaseFunctor() override
75  {
76  }
77 
78  const char* GetDescription() const
79  {
80  return "Phase";
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] = ComputePhase(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
96  return outPixel;
97  }
98 
99  OutputPixelType operator()(ScalarType /*inPixel*/) const override
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())[0] < 3);
111  assert((this->GetChannelList())[1] < 3);
112 
113  outPixel[0] = ComputePhase(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
114  return outPixel;
115  }
116 
117  OutputPixelType operator()(const RGBAPixelType& inPixel) const override
118  {
119  OutputPixelType outPixel;
120  outPixel.SetSize(1);
121 
122  assert((this->GetChannelList())[0] < 4);
123  assert((this->GetChannelList())[1] < 4);
124 
125  outPixel[0] = ComputePhase(inPixel[(this->GetChannelList())[0]], inPixel[(this->GetChannelList())[1]]);
126  return outPixel;
127  }
128 
129 private:
131  {
132  return std::atan2(b, a);
133  }
134 };
135 }
136 }
137 
138 #endif
otb::Function::PhaseFunctor::Superclass
itk::Object Superclass
Definition: otbPhaseFunctor.h:45
otb::Function::PhaseFunctor::operator()
OutputPixelType operator()(const RGBPixelType &inPixel) const override
Definition: otbPhaseFunctor.h:105
otb::Function::PhaseFunctor::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbPhaseFunctor.h:46
otb::Function::PhaseFunctor
Compute the module from the selected channel in the input.
Definition: otbPhaseFunctor.h:40
otb::Function::PhaseFunctor::Self
PhaseFunctor Self
Definition: otbPhaseFunctor.h:44
otb::Function::PhaseFunctor::PixelType
TInputPixel PixelType
Definition: otbPhaseFunctor.h:53
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Function::PhaseFunctor::~PhaseFunctor
~PhaseFunctor() override
Definition: otbPhaseFunctor.h:74
otb::Function::ChannelSelectorFunctor::RGBAPixelType
itk::RGBAPixel< ScalarType > RGBAPixelType
Definition: otbChannelSelectorFunctor.h:64
otb::Function::PhaseFunctor::RGBAPixelType
itk::RGBAPixel< ScalarType > RGBAPixelType
Definition: otbPhaseFunctor.h:59
otb::Function::PhaseFunctor::ComputePhase
ScalarType ComputePhase(ScalarType a, ScalarType b) const
Definition: otbPhaseFunctor.h:130
otbChannelSelectorFunctor.h
otb::Function::PhaseFunctor::OutputPixelType
VectorPixelType OutputPixelType
Definition: otbPhaseFunctor.h:61
otb::Function::PhaseFunctor::GetDescription
const char * GetDescription() const
Definition: otbPhaseFunctor.h:78
otb::Function::ChannelSelectorFunctor::RGBPixelType
itk::RGBPixel< ScalarType > RGBPixelType
Definition: otbChannelSelectorFunctor.h:63
otb::Function::ChannelSelectorFunctor::SetChannelList
virtual void SetChannelList(std::vector< unsigned int > channels)
Definition: otbChannelSelectorFunctor.h:137
otb::Function::ChannelSelectorFunctor::OutputPixelType
VectorPixelType OutputPixelType
Definition: otbChannelSelectorFunctor.h:66
otb::Function::PhaseFunctor::operator()
OutputPixelType operator()(ScalarType) const override
Definition: otbPhaseFunctor.h:99
otb::Function::PhaseFunctor::VectorPixelType
itk::VariableLengthVector< ScalarType > VectorPixelType
Definition: otbPhaseFunctor.h:57
otb::Function::PhaseFunctor::ScalarType
itk::NumericTraits< PixelType >::ValueType ScalarType
Definition: otbPhaseFunctor.h:56
otb::Function::ChannelSelectorFunctor::GetChannelList
virtual std::vector< unsigned int > GetChannelList() const
Definition: otbChannelSelectorFunctor.h:132
otb::Function::PhaseFunctor::GetOutputSize
unsigned int GetOutputSize() const override
Definition: otbPhaseFunctor.h:83
otb::Function::PhaseFunctor::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbPhaseFunctor.h:47
otb::Function::ChannelSelectorFunctor::VectorPixelType
itk::VariableLengthVector< ScalarType > VectorPixelType
Definition: otbChannelSelectorFunctor.h:62
otb::Function::PhaseFunctor::operator()
OutputPixelType operator()(const VectorPixelType &inPixel) const override
Definition: otbPhaseFunctor.h:88
otb::Function::ChannelSelectorFunctor::ScalarType
itk::NumericTraits< PixelType >::ValueType ScalarType
Definition: otbChannelSelectorFunctor.h:61
otb::Function::PhaseFunctor::PhaseFunctor
PhaseFunctor()
Definition: otbPhaseFunctor.h:64
otb::Function::ChannelSelectorFunctor
Base class for pixel representation functions.
Definition: otbChannelSelectorFunctor.h:45
otb::Function::PhaseFunctor::operator()
OutputPixelType operator()(const RGBAPixelType &inPixel) const override
Definition: otbPhaseFunctor.h:117
otb::Function::PhaseFunctor::RGBPixelType
itk::RGBPixel< ScalarType > RGBPixelType
Definition: otbPhaseFunctor.h:58