OTB  9.0.0
Orfeo Toolbox
otbVectorRescaleIntensityImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbVectorRescaleIntensityImageFilter_h
23 #define otbVectorRescaleIntensityImageFilter_h
24 
25 #include "itkUnaryFunctorImageFilter.h"
26 #include "itkVariableLengthVector.h"
27 
28 namespace otb
29 {
30 namespace Functor
31 {
43 template <typename TInput, typename TOutput>
45 {
46 public:
48  typedef typename itk::NumericTraits<typename TInput::ValueType>::RealType RealType;
49 
52  {
53  }
56  {
57  }
58 
60  void SetOutputMaximum(TOutput a)
61  {
62  m_OutputMaximum = a;
63  }
64  void SetOutputMinimum(TOutput a)
65  {
66  m_OutputMinimum = a;
67  }
68  void SetInputMinimum(TInput a)
69  {
70  m_InputMinimum = a;
71  }
72  void SetInputMaximum(TInput a)
73  {
74  m_InputMaximum = a;
75  }
76  void SetGamma(const double& gamma)
77  {
78  m_Gamma = gamma;
79  }
80  TOutput GetOutputMaximum()
81  {
82  return m_OutputMaximum;
83  }
84  TOutput GetOutputMinimum()
85  {
86  return m_OutputMinimum;
87  }
88  TInput GetInputMinimum()
89  {
90  return m_InputMinimum;
91  }
92  TInput GetInputMaximum()
93  {
94  return m_InputMaximum;
95  }
96  double GetGamma()
97  {
98  return m_Gamma;
99  }
100 
101 
102  bool operator!=(const VectorAffineTransform& other) const
103  {
104  if (m_OutputMinimum.Size() == other.GetOutputMinimum().Size())
105  {
106  for (unsigned int i = 0; i < m_OutputMinimum.Size(); ++i)
107  {
108  if (m_OutputMinimum[i] != other.GetOutputMinimum()[i])
109  {
110  return true;
111  }
112  }
113  }
114  if (m_OutputMaximum.Size() == other.GetOutputMaximum().Size())
115  {
116  for (unsigned int i = 0; i < m_OutputMaximum.Size(); ++i)
117  {
118  if (m_OutputMaximum[i] != other.GetOutputMaximum()[i])
119  {
120  return true;
121  }
122  }
123  }
124  if (m_InputMinimum.Size() == other.GetInputMinimum().Size())
125  {
126  for (unsigned int i = 0; i < m_InputMinimum.Size(); ++i)
127  {
128  if (m_InputMinimum[i] != other.GetInputMinimum()[i])
129  {
130  return true;
131  }
132  }
133  }
134  if (m_InputMaximum.Size() == other.GetInputMaximum().Size())
135  {
136  for (unsigned int i = 0; i < m_InputMaximum.Size(); ++i)
137  {
138  if (m_InputMaximum[i] != other.GetInputMaximum()[i])
139  {
140  return true;
141  }
142  }
143  }
144  return false;
145  }
146  bool operator==(const VectorAffineTransform& other) const
147  {
148  return !(*this != other);
149  }
150 
151  // main computation method
152  inline TOutput operator()(const TInput& x)
153  {
154  // output instantiation
155  TOutput result;
156  result.SetSize(x.GetSize());
157 
158  // consistency checking
159  if (result.GetSize() != m_OutputMinimum.GetSize() || result.GetSize() != m_OutputMaximum.GetSize() || result.GetSize() != m_InputMinimum.GetSize() ||
160  result.GetSize() != m_InputMaximum.GetSize())
161  {
162  itkGenericExceptionMacro(<< "Pixel size different from scale or shift size !");
163  }
164 
165  // transformation
166  for (unsigned int i = 0; i < x.GetSize(); ++i)
167  {
168  if (x[i] < m_InputMinimum[i])
169  {
170  result[i] = m_OutputMinimum[i];
171  }
172  else if (x[i] > m_InputMaximum[i])
173  {
174  result[i] = m_OutputMaximum[i];
175  }
176  else if (m_InputMaximum[i] == m_InputMinimum[i])
177  {
178  result[i] = m_OutputMinimum[i];
179  }
180  else
181  {
182  RealType scaledComponent = static_cast<RealType>(x[i] - m_InputMinimum[i]) / static_cast<RealType>(m_InputMaximum[i] - m_InputMinimum[i]);
183  scaledComponent = std::pow(scaledComponent, 1. / m_Gamma);
184  scaledComponent *= static_cast<RealType>(m_OutputMaximum[i] - m_OutputMinimum[i]);
185  result[i] = static_cast<typename TOutput::ValueType>(scaledComponent + m_OutputMinimum[i]);
186  }
187  }
188  return result;
189  }
190 
191 private:
196  double m_Gamma;
197 };
198 } // end namespace functor
199 
219 template <class TInputImage, class TOutputImage = TInputImage>
221  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
222  Functor::VectorAffineTransform<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
223 {
224 public:
227  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
230  typedef itk::SmartPointer<Self> Pointer;
231  typedef itk::SmartPointer<const Self> ConstPointer;
232 
233  typedef TInputImage InputImageType;
234  typedef typename InputImageType::ConstPointer InputImagePointer;
235  typedef typename TOutputImage::PixelType OutputPixelType;
236  typedef typename InputImageType::PixelType InputPixelType;
237  typedef typename InputPixelType::ValueType InputValueType;
238  typedef typename OutputPixelType::ValueType OutputValueType;
239  typedef typename itk::NumericTraits<InputValueType>::RealType InputRealType;
240  typedef typename itk::NumericTraits<OutputValueType>::RealType OutputRealType;
241 
243  itkNewMacro(Self);
244 
245  itkSetMacro(OutputMaximum, OutputPixelType);
246  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
247  itkSetMacro(OutputMinimum, OutputPixelType);
248  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
249  itkSetMacro(AutomaticInputMinMaxComputation, bool);
250  itkGetMacro(AutomaticInputMinMaxComputation, bool);
251  itkBooleanMacro(AutomaticInputMinMaxComputation);
252 
253  itkGetMacro(ClampThreshold, double);
254  itkSetMacro(ClampThreshold, double);
255 
256  itkGetMacro(InputMinimum, InputPixelType);
257  itkSetMacro(InputMinimum, InputPixelType);
258 
259  itkGetMacro(InputMaximum, InputPixelType);
260  itkSetMacro(InputMaximum, InputPixelType);
261 
262  itkSetMacro(Gamma, double);
263  itkGetConstReferenceMacro(Gamma, double);
264 
266  void BeforeThreadedGenerateData(void) override;
267 
269  void GenerateOutputInformation(void) override;
270 
272  void GenerateInputRequestedRegion(void) override;
273 
275  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
276 
277 protected:
280  {
281  }
282 
283 private:
284  VectorRescaleIntensityImageFilter(const Self&) = delete;
285  void operator=(const Self&) = delete;
286 
293  double m_Gamma;
294 };
295 
296 } // end namespace otb
297 
298 #ifndef OTB_MANUAL_INSTANTIATION
300 #endif
301 
302 #endif
otbVectorRescaleIntensityImageFilter.hxx
otb::Functor::VectorAffineTransform::GetGamma
double GetGamma()
Definition: otbVectorRescaleIntensityImageFilter.h:96
otb::VectorRescaleIntensityImageFilter::m_InputMinimum
InputPixelType m_InputMinimum
Definition: otbVectorRescaleIntensityImageFilter.h:289
otb::VectorRescaleIntensityImageFilter::OutputRealType
itk::NumericTraits< OutputValueType >::RealType OutputRealType
Definition: otbVectorRescaleIntensityImageFilter.h:240
otb::Functor::VectorAffineTransform::VectorAffineTransform
VectorAffineTransform()
Constructor.
Definition: otbVectorRescaleIntensityImageFilter.h:51
otb::VectorRescaleIntensityImageFilter
This filter performs a rescaling of a vector image on a per band basis.
Definition: otbVectorRescaleIntensityImageFilter.h:220
otb::Functor::VectorAffineTransform::operator!=
bool operator!=(const VectorAffineTransform &other) const
Definition: otbVectorRescaleIntensityImageFilter.h:102
otb::VectorRescaleIntensityImageFilter::~VectorRescaleIntensityImageFilter
~VectorRescaleIntensityImageFilter() override
Definition: otbVectorRescaleIntensityImageFilter.h:279
otb::Functor::VectorAffineTransform::~VectorAffineTransform
virtual ~VectorAffineTransform()
Destructor.
Definition: otbVectorRescaleIntensityImageFilter.h:55
otb::VectorRescaleIntensityImageFilter::OutputPixelType
TOutputImage::PixelType OutputPixelType
Definition: otbVectorRescaleIntensityImageFilter.h:235
otb::Functor::VectorAffineTransform::m_InputMinimum
TInput m_InputMinimum
Definition: otbVectorRescaleIntensityImageFilter.h:194
otb::VectorRescaleIntensityImageFilter::m_OutputMaximum
OutputPixelType m_OutputMaximum
Definition: otbVectorRescaleIntensityImageFilter.h:288
otb::Functor::VectorAffineTransform::m_OutputMinimum
TOutput m_OutputMinimum
Definition: otbVectorRescaleIntensityImageFilter.h:193
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::VectorRescaleIntensityImageFilter::InputImagePointer
InputImageType::ConstPointer InputImagePointer
Definition: otbVectorRescaleIntensityImageFilter.h:234
otb::Functor::VectorAffineTransform::m_InputMaximum
TInput m_InputMaximum
Definition: otbVectorRescaleIntensityImageFilter.h:195
otb::Functor::VectorAffineTransform::SetInputMinimum
void SetInputMinimum(TInput a)
Definition: otbVectorRescaleIntensityImageFilter.h:68
otb::VectorRescaleIntensityImageFilter::m_ClampThreshold
double m_ClampThreshold
Definition: otbVectorRescaleIntensityImageFilter.h:291
otb::Functor::VectorAffineTransform::RealType
itk::NumericTraits< typename TInput::ValueType >::RealType RealType
Real type typedef.
Definition: otbVectorRescaleIntensityImageFilter.h:48
otb::Functor::VectorAffineTransform::SetInputMaximum
void SetInputMaximum(TInput a)
Definition: otbVectorRescaleIntensityImageFilter.h:72
otb::VectorRescaleIntensityImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbVectorRescaleIntensityImageFilter.h:231
otb::VectorRescaleIntensityImageFilter::InputImageType
TInputImage InputImageType
Definition: otbVectorRescaleIntensityImageFilter.h:233
otb::VectorRescaleIntensityImageFilter::m_Gamma
double m_Gamma
Definition: otbVectorRescaleIntensityImageFilter.h:293
otb::Functor::VectorAffineTransform::m_Gamma
double m_Gamma
Definition: otbVectorRescaleIntensityImageFilter.h:196
otb::Functor::VectorAffineTransform
This functor performs a per band linear transform of its input.
Definition: otbVectorRescaleIntensityImageFilter.h:44
otb::Functor::VectorAffineTransform::SetOutputMaximum
void SetOutputMaximum(TOutput a)
Accessors.
Definition: otbVectorRescaleIntensityImageFilter.h:60
otb::VectorRescaleIntensityImageFilter::m_OutputMinimum
OutputPixelType m_OutputMinimum
Definition: otbVectorRescaleIntensityImageFilter.h:287
otb::Functor::VectorAffineTransform::SetGamma
void SetGamma(const double &gamma)
Definition: otbVectorRescaleIntensityImageFilter.h:76
otb::Functor::VectorAffineTransform::GetOutputMaximum
TOutput GetOutputMaximum()
Definition: otbVectorRescaleIntensityImageFilter.h:80
otb::VectorRescaleIntensityImageFilter::Superclass
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::VectorAffineTransform< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
Definition: otbVectorRescaleIntensityImageFilter.h:229
otb::Functor::VectorAffineTransform::m_OutputMaximum
TOutput m_OutputMaximum
Definition: otbVectorRescaleIntensityImageFilter.h:192
otb::VectorRescaleIntensityImageFilter::OutputValueType
OutputPixelType::ValueType OutputValueType
Definition: otbVectorRescaleIntensityImageFilter.h:238
otb::Functor::VectorAffineTransform::SetOutputMinimum
void SetOutputMinimum(TOutput a)
Definition: otbVectorRescaleIntensityImageFilter.h:64
otb::Functor::VectorAffineTransform::GetInputMaximum
TInput GetInputMaximum()
Definition: otbVectorRescaleIntensityImageFilter.h:92
otb::Functor::VectorAffineTransform::GetInputMinimum
TInput GetInputMinimum()
Definition: otbVectorRescaleIntensityImageFilter.h:88
otb::VectorRescaleIntensityImageFilter::m_InputMaximum
InputPixelType m_InputMaximum
Definition: otbVectorRescaleIntensityImageFilter.h:290
otb::VectorRescaleIntensityImageFilter::InputValueType
InputPixelType::ValueType InputValueType
Definition: otbVectorRescaleIntensityImageFilter.h:237
otb::VectorRescaleIntensityImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbVectorRescaleIntensityImageFilter.h:230
otb::Functor::VectorAffineTransform::operator()
TOutput operator()(const TInput &x)
Definition: otbVectorRescaleIntensityImageFilter.h:152
otb::VectorRescaleIntensityImageFilter::InputRealType
itk::NumericTraits< InputValueType >::RealType InputRealType
Definition: otbVectorRescaleIntensityImageFilter.h:239
otb::VectorRescaleIntensityImageFilter::Self
VectorRescaleIntensityImageFilter Self
Definition: otbVectorRescaleIntensityImageFilter.h:226
otb::VectorRescaleIntensityImageFilter::m_AutomaticInputMinMaxComputation
bool m_AutomaticInputMinMaxComputation
Definition: otbVectorRescaleIntensityImageFilter.h:292
otb::Functor::VectorAffineTransform::GetOutputMinimum
TOutput GetOutputMinimum()
Definition: otbVectorRescaleIntensityImageFilter.h:84
otb::VectorRescaleIntensityImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbVectorRescaleIntensityImageFilter.h:236
otb::Functor::VectorAffineTransform::operator==
bool operator==(const VectorAffineTransform &other) const
Definition: otbVectorRescaleIntensityImageFilter.h:146