OTB  6.7.0
Orfeo Toolbox
otbShiftScaleVectorImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 
26 
27 namespace otb
28 {
29 namespace Functor
30 {
47 template<class TInput, class TOutput>
49 {
50 public:
51 public:
54 
57 
59  virtual ~VectorShiftScale() {}
60 
62  void SetShiftValues(TInput value)
63  {
64  m_Shift = value;
65  }
66  void SetScaleValues(TInput value)
67  {
68  m_Scale = value;
69  }
70  TInput GetShiftValues()
71  {
72  return m_Shift;
73  }
74  TInput GetScaleValues()
75  {
76  return m_Scale;
77  }
78 
79  bool operator !=(const VectorShiftScale& other) const
80  {
81  if (m_Shift.Size() == other.GetShiftValues().Size())
82  {
83  for (unsigned int i = 0; i < m_Shift.Size(); ++i)
84  {
85  if (m_Shift[i] != other.GetShiftValues()[i])
86  {
87  return true;
88  }
89  }
90  }
91  if (m_Scale.Size() == other.GetScaleValues().Size())
92  {
93  for (unsigned int i = 0; i < m_Scale.Size(); ++i)
94  {
95  if (m_Scale[i] != other.GetScaleValues()[i])
96  {
97  return true;
98  }
99  }
100  }
101  return false;
102  }
103 
104  bool operator==(const VectorShiftScale & other) const
105  {
106  return !(*this != other);
107  }
108 
109  // main computation method
110  inline TOutput operator()(const TInput & x) const
111  {
112  // output instantiation
113  TOutput result;
114  result.SetSize(x.GetSize());
115 
116  // consistency checking
117  if (result.GetSize() != m_Scale.GetSize()
118  || result.GetSize() != m_Shift.GetSize())
119  {
120  itkGenericExceptionMacro(<< "Pixel size different from scale or shift size !");
121  }
122 
123  // transformation
124  for (unsigned int i = 0; i < x.GetSize(); ++i)
125  {
126  if ( m_Scale[i] > 1e-10)
127  {
128  const RealType invertedScale = 1 / m_Scale[i];
129  result[i] = static_cast<typename TOutput::ValueType> (invertedScale * (x[i] - m_Shift[i]) );
130  }
131  else
132  {
133  result[i] = static_cast<typename TOutput::ValueType> (x[i] - m_Shift[i]);
134  }
135  }
136  return result;
137  }
138 
139 private:
140  TInput m_Shift;
141  TOutput m_Scale;
142 };
143 } // End namespace Functor
144 
161 template <class TInputImage, class TOutputImage = TInputImage>
162 class ITK_EXPORT ShiftScaleVectorImageFilter :
163  public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
164  Functor::VectorShiftScale<typename TInputImage::PixelType,
165  typename TOutputImage::PixelType> >
166 {
167 public:
170  typedef Functor::VectorShiftScale< typename TInputImage::PixelType,
171  typename TOutputImage::PixelType>
173  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
177 
178  typedef typename TOutputImage::PixelType OutputPixelType;
179  typedef typename TInputImage::PixelType InputPixelType;
180  typedef typename InputPixelType::ValueType InputValueType;
181  typedef typename OutputPixelType::ValueType OutputValueType;
184 
186  itkNewMacro(Self);
187 
189  itkTypeMacro(ShiftScaleImageFilter,
191 
192  itkGetMacro(Scale, InputPixelType);
193  itkSetMacro(Scale, InputPixelType);
194 
195  itkGetMacro(Shift, InputPixelType);
196  itkSetMacro(Shift, InputPixelType);
197 
198 protected:
201 
203  void BeforeThreadedGenerateData(void) override;
204 
206  void GenerateOutputInformation(void) override;
207 
209  void GenerateInputRequestedRegion(void) override;
210 
211 private:
212  ShiftScaleVectorImageFilter(const Self&) = delete;
213  void operator=(const Self&) = delete;
214 
217 
218 };
219 
220 } // end namespace otb
221 
222 #ifndef OTB_MANUAL_INSTANTIATION
224 #endif
225 
226 #endif
bool operator!=(const VectorShiftScale &other) const
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, FunctorType > Superclass
This functor performs a per band linear transform of its input.
void SetShiftValues(TInput value)
Accessors.
itk::SmartPointer< const Self > ConstPointer
Functor::VectorShiftScale< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
bool operator==(const VectorShiftScale &other) const
itk::NumericTraits< typename TInput::ValueType >::RealType RealType
Real type typedef.
itk::NumericTraits< InputValueType >::RealType InputRealType
TOutput operator()(const TInput &x) const
itk::NumericTraits< OutputValueType >::RealType OutputRealType
This filter performs a shift and scaling of a vector image on a per band basis.