OTB  6.7.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-2019 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 
27 
28 namespace otb
29 {
30 namespace Functor
31 {
43 template<typename TInput, typename TOutput>
45 {
46 public:
49 
54 
56  void SetOutputMaximum(TOutput a)
57  {
58  m_OutputMaximum = a;
59  }
60  void SetOutputMinimum(TOutput a)
61  {
62  m_OutputMinimum = a;
63  }
64  void SetInputMinimum(TInput a)
65  {
66  m_InputMinimum = a;
67  }
68  void SetInputMaximum(TInput a)
69  {
70  m_InputMaximum = a;
71  }
72  void SetGamma(const double& gamma)
73  {
74  m_Gamma = gamma;
75  }
76  TOutput GetOutputMaximum()
77  {
78  return m_OutputMaximum;
79  }
80  TOutput GetOutputMinimum()
81  {
82  return m_OutputMinimum;
83  }
84  TInput GetInputMinimum()
85  {
86  return m_InputMinimum;
87  }
88  TInput GetInputMaximum()
89  {
90  return m_InputMaximum;
91  }
92  double GetGamma()
93  {
94  return m_Gamma;
95  }
96 
97 
98  bool operator !=(const VectorAffineTransform& other) const
99  {
100  if (m_OutputMinimum.Size() == other.GetOutputMinimum().Size())
101  {
102  for (unsigned int i = 0; i < m_OutputMinimum.Size(); ++i)
103  {
104  if (m_OutputMinimum[i] != other.GetOutputMinimum()[i])
105  {
106  return true;
107  }
108  }
109  }
110  if (m_OutputMaximum.Size() == other.GetOutputMaximum().Size())
111  {
112  for (unsigned int i = 0; i < m_OutputMaximum.Size(); ++i)
113  {
114  if (m_OutputMaximum[i] != other.GetOutputMaximum()[i])
115  {
116  return true;
117  }
118  }
119  }
120  if (m_InputMinimum.Size() == other.GetInputMinimum().Size())
121  {
122  for (unsigned int i = 0; i < m_InputMinimum.Size(); ++i)
123  {
124  if (m_InputMinimum[i] != other.GetInputMinimum()[i])
125  {
126  return true;
127  }
128  }
129  }
130  if (m_InputMaximum.Size() == other.GetInputMaximum().Size())
131  {
132  for (unsigned int i = 0; i < m_InputMaximum.Size(); ++i)
133  {
134  if (m_InputMaximum[i] != other.GetInputMaximum()[i])
135  {
136  return true;
137  }
138  }
139  }
140  return false;
141  }
142  bool operator ==(const VectorAffineTransform& other) const
143  {
144  return !(*this != other);
145  }
146 
147  // main computation method
148  inline TOutput operator ()(const TInput& x)
149  {
150  // output instantiation
151  TOutput result;
152  result.SetSize(x.GetSize());
153 
154  // consistency checking
155  if (result.GetSize() != m_OutputMinimum.GetSize()
156  || result.GetSize() != m_OutputMaximum.GetSize()
157  || result.GetSize() != m_InputMinimum.GetSize()
158  || result.GetSize() != m_InputMaximum.GetSize())
159  {
160  itkGenericExceptionMacro(<< "Pixel size different from scale or shift size !");
161  }
162 
163  // transformation
164  for (unsigned int i = 0; i < x.GetSize(); ++i)
165  {
166  if (x[i] < m_InputMinimum[i])
167  {
168  result[i] = m_OutputMinimum[i];
169  }
170  else if (x[i] > m_InputMaximum[i])
171  {
172  result[i] = m_OutputMaximum[i];
173  }
174  else if (m_InputMaximum[i] == m_InputMinimum[i])
175  {
176  result[i] = m_OutputMinimum[i];
177  }
178  else
179  {
180  RealType scaledComponent = static_cast<RealType>(x[i] - m_InputMinimum[i])/ static_cast<RealType> (m_InputMaximum[i] - m_InputMinimum[i]);
181  scaledComponent = std::pow(scaledComponent,1./m_Gamma);
182  scaledComponent *= static_cast<RealType> (m_OutputMaximum[i] - m_OutputMinimum[i]);
183  result[i] = static_cast<typename TOutput::ValueType>(scaledComponent + m_OutputMinimum[i]);
184  }
185  }
186  return result;
187  }
188 private:
193  double m_Gamma;
194 };
195 } // end namespace functor
196 
216 template <class TInputImage, class TOutputImage = TInputImage>
218  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
219  Functor::VectorAffineTransform<
220  typename TInputImage::PixelType,
221  typename TOutputImage::PixelType> >
222 {
223 public:
226  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
227  Functor::VectorAffineTransform<typename TInputImage::PixelType,
228  typename TOutputImage::PixelType> > Superclass;
231 
232  typedef TInputImage InputImageType;
233  typedef typename InputImageType::ConstPointer InputImagePointer;
234  typedef typename TOutputImage::PixelType OutputPixelType;
235  typedef typename InputImageType::PixelType InputPixelType;
236  typedef typename InputPixelType::ValueType InputValueType;
237  typedef typename OutputPixelType::ValueType OutputValueType;
240 
242  itkNewMacro(Self);
243 
244  itkSetMacro(OutputMaximum, OutputPixelType);
245  itkGetConstReferenceMacro(OutputMaximum, OutputPixelType);
246  itkSetMacro(OutputMinimum, OutputPixelType);
247  itkGetConstReferenceMacro(OutputMinimum, OutputPixelType);
248  itkSetMacro(AutomaticInputMinMaxComputation, bool);
249  itkGetMacro(AutomaticInputMinMaxComputation, bool);
250  itkBooleanMacro(AutomaticInputMinMaxComputation);
251 
252  itkGetMacro(ClampThreshold, double);
253  itkSetMacro(ClampThreshold, double);
254 
255  itkGetMacro(InputMinimum, InputPixelType);
256  itkSetMacro(InputMinimum, InputPixelType);
257 
258  itkGetMacro(InputMaximum, InputPixelType);
259  itkSetMacro(InputMaximum, InputPixelType);
260 
261  itkSetMacro(Gamma,double);
262  itkGetConstReferenceMacro(Gamma,double);
263 
265  void BeforeThreadedGenerateData(void) override;
266 
268  void GenerateOutputInformation(void) override;
269 
271  void GenerateInputRequestedRegion(void) override;
272 
274  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
275 
276 protected:
279 
280 private:
281  VectorRescaleIntensityImageFilter(const Self &) = delete;
282  void operator =(const Self&) = delete;
283 
290  double m_Gamma;
291 
292 };
293 
294 } // end namespace otb
295 
296 #ifndef OTB_MANUAL_INSTANTIATION
298 #endif
299 
300 #endif
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::VectorAffineTransform< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
itk::NumericTraits< typename TInput::ValueType >::RealType RealType
Real type typedef.
itk::NumericTraits< InputValueType >::RealType InputRealType
bool operator!=(const VectorAffineTransform &other) const
This filter performs a rescaling of a vector image on a per band basis.
itk::NumericTraits< OutputValueType >::RealType OutputRealType
bool operator==(const VectorAffineTransform &other) const
This functor performs a per band linear transform of its input.