OTB  9.0.0
Orfeo Toolbox
otbShiftScaleVectorImageFilter.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 otbShiftScaleImageFilter_h
22 #define otbShiftScaleImageFilter_h
23 
24 #include "itkUnaryFunctorImageFilter.h"
25 #include "itkVariableLengthVector.h"
26 
27 namespace otb
28 {
29 namespace Functor
30 {
47 template <class TInput, class TOutput>
49 {
50 public:
51 public:
53  typedef typename itk::NumericTraits<typename TInput::ValueType>::RealType RealType;
54 
57  {
58  }
59 
62  {
63  }
64 
66  void SetShiftValues(TInput value)
67  {
68  m_Shift = value;
69  }
70  void SetScaleValues(TInput value)
71  {
72  m_Scale = value;
73  }
74  TInput GetShiftValues()
75  {
76  return m_Shift;
77  }
78  TInput GetScaleValues()
79  {
80  return m_Scale;
81  }
82 
83  bool operator!=(const VectorShiftScale& other) const
84  {
85  if (m_Shift.Size() == other.GetShiftValues().Size())
86  {
87  for (unsigned int i = 0; i < m_Shift.Size(); ++i)
88  {
89  if (m_Shift[i] != other.GetShiftValues()[i])
90  {
91  return true;
92  }
93  }
94  }
95  if (m_Scale.Size() == other.GetScaleValues().Size())
96  {
97  for (unsigned int i = 0; i < m_Scale.Size(); ++i)
98  {
99  if (m_Scale[i] != other.GetScaleValues()[i])
100  {
101  return true;
102  }
103  }
104  }
105  return false;
106  }
107 
108  bool operator==(const VectorShiftScale& other) const
109  {
110  return !(*this != other);
111  }
112 
113  // main computation method
114  inline TOutput operator()(const TInput& x) const
115  {
116  // output instantiation
117  TOutput result;
118  result.SetSize(x.GetSize());
119 
120  // consistency checking
121  if (result.GetSize() != m_Scale.GetSize() || result.GetSize() != m_Shift.GetSize())
122  {
123  itkGenericExceptionMacro(<< "Pixel size different from scale or shift size !");
124  }
125 
126  // transformation
127  for (unsigned int i = 0; i < x.GetSize(); ++i)
128  {
129  if (m_Scale[i] > 1e-10)
130  {
131  const RealType invertedScale = 1 / m_Scale[i];
132  result[i] = static_cast<typename TOutput::ValueType>(invertedScale * (x[i] - m_Shift[i]));
133  }
134  else
135  {
136  result[i] = static_cast<typename TOutput::ValueType>(x[i] - m_Shift[i]);
137  }
138  }
139  return result;
140  }
141 
142 private:
143  TInput m_Shift;
144  TOutput m_Scale;
145 };
146 } // End namespace Functor
147 
164 template <class TInputImage, class TOutputImage = TInputImage>
166  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
167  Functor::VectorShiftScale<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
168 {
169 public:
173  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, FunctorType> Superclass;
174  typedef itk::SmartPointer<Self> Pointer;
175  typedef itk::SmartPointer<const Self> ConstPointer;
176 
177  typedef typename TOutputImage::PixelType OutputPixelType;
178  typedef typename TInputImage::PixelType InputPixelType;
179  typedef typename InputPixelType::ValueType InputValueType;
180  typedef typename OutputPixelType::ValueType OutputValueType;
181  typedef typename itk::NumericTraits<InputValueType>::RealType InputRealType;
182  typedef typename itk::NumericTraits<OutputValueType>::RealType OutputRealType;
183 
185  itkNewMacro(Self);
186 
188  itkTypeMacro(ShiftScaleImageFilter, itk::UnaryFunctorImageFilter);
189 
190  itkGetMacro(Scale, InputPixelType);
191  itkSetMacro(Scale, InputPixelType);
192 
193  itkGetMacro(Shift, InputPixelType);
194  itkSetMacro(Shift, InputPixelType);
195 
196 protected:
198  {
199  }
201  {
202  }
203 
205  void BeforeThreadedGenerateData(void) override;
206 
208  void GenerateOutputInformation(void) override;
209 
211  void GenerateInputRequestedRegion(void) override;
212 
213 private:
214  ShiftScaleVectorImageFilter(const Self&) = delete;
215  void operator=(const Self&) = delete;
216 
219 };
220 
221 } // end namespace otb
222 
223 #ifndef OTB_MANUAL_INSTANTIATION
225 #endif
226 
227 #endif
otb::ShiftScaleVectorImageFilter
This filter performs a shift and scaling of a vector image on a per band basis.
Definition: otbShiftScaleVectorImageFilter.h:165
otbShiftScaleVectorImageFilter.hxx
otb::Functor::VectorShiftScale::operator==
bool operator==(const VectorShiftScale &other) const
Definition: otbShiftScaleVectorImageFilter.h:108
otb::ShiftScaleVectorImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbShiftScaleVectorImageFilter.h:174
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::VectorShiftScale::operator()
TOutput operator()(const TInput &x) const
Definition: otbShiftScaleVectorImageFilter.h:114
otb::ShiftScaleVectorImageFilter::ShiftScaleVectorImageFilter
ShiftScaleVectorImageFilter()
Definition: otbShiftScaleVectorImageFilter.h:197
otb::Functor::VectorShiftScale::VectorShiftScale
VectorShiftScale()
Constructor.
Definition: otbShiftScaleVectorImageFilter.h:56
otb::Functor::VectorShiftScale::GetScaleValues
TInput GetScaleValues()
Definition: otbShiftScaleVectorImageFilter.h:78
otb::Functor::VectorShiftScale::~VectorShiftScale
virtual ~VectorShiftScale()
Constructor.
Definition: otbShiftScaleVectorImageFilter.h:61
otb::ShiftScaleVectorImageFilter::Self
ShiftScaleVectorImageFilter Self
Definition: otbShiftScaleVectorImageFilter.h:171
otb::Functor::VectorShiftScale::SetScaleValues
void SetScaleValues(TInput value)
Definition: otbShiftScaleVectorImageFilter.h:70
otb::Functor::VectorShiftScale::GetShiftValues
TInput GetShiftValues()
Definition: otbShiftScaleVectorImageFilter.h:74
otb::Functor::VectorShiftScale::SetShiftValues
void SetShiftValues(TInput value)
Accessors.
Definition: otbShiftScaleVectorImageFilter.h:66
otb::ShiftScaleVectorImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbShiftScaleVectorImageFilter.h:175
otb::ShiftScaleVectorImageFilter::~ShiftScaleVectorImageFilter
~ShiftScaleVectorImageFilter() override
Definition: otbShiftScaleVectorImageFilter.h:200
otb::ShiftScaleVectorImageFilter::OutputPixelType
TOutputImage::PixelType OutputPixelType
Definition: otbShiftScaleVectorImageFilter.h:177
otb::Functor::VectorShiftScale::operator!=
bool operator!=(const VectorShiftScale &other) const
Definition: otbShiftScaleVectorImageFilter.h:83
otb::ShiftScaleVectorImageFilter::OutputRealType
itk::NumericTraits< OutputValueType >::RealType OutputRealType
Definition: otbShiftScaleVectorImageFilter.h:182
otb::ShiftScaleVectorImageFilter::OutputValueType
OutputPixelType::ValueType OutputValueType
Definition: otbShiftScaleVectorImageFilter.h:180
otb::Functor::VectorShiftScale
This functor performs a per band linear transform of its input.
Definition: otbShiftScaleVectorImageFilter.h:48
otb::ShiftScaleVectorImageFilter::m_Shift
InputPixelType m_Shift
Definition: otbShiftScaleVectorImageFilter.h:218
otb::ShiftScaleVectorImageFilter::Superclass
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, FunctorType > Superclass
Definition: otbShiftScaleVectorImageFilter.h:173
otb::ShiftScaleVectorImageFilter::m_Scale
InputPixelType m_Scale
Definition: otbShiftScaleVectorImageFilter.h:217
otb::Functor::VectorShiftScale::m_Shift
TInput m_Shift
Definition: otbShiftScaleVectorImageFilter.h:143
otb::ShiftScaleVectorImageFilter::InputPixelType
TInputImage::PixelType InputPixelType
Definition: otbShiftScaleVectorImageFilter.h:178
otb::ShiftScaleVectorImageFilter::FunctorType
Functor::VectorShiftScale< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
Definition: otbShiftScaleVectorImageFilter.h:172
otb::Functor::VectorShiftScale::m_Scale
TOutput m_Scale
Definition: otbShiftScaleVectorImageFilter.h:144
otb::Functor::VectorShiftScale::RealType
itk::NumericTraits< typename TInput::ValueType >::RealType RealType
Real type typedef.
Definition: otbShiftScaleVectorImageFilter.h:53
otb::ShiftScaleVectorImageFilter::InputRealType
itk::NumericTraits< InputValueType >::RealType InputRealType
Definition: otbShiftScaleVectorImageFilter.h:181
otb::ShiftScaleVectorImageFilter::InputValueType
InputPixelType::ValueType InputValueType
Definition: otbShiftScaleVectorImageFilter.h:179