OTB  10.0.0
Orfeo Toolbox
otbRadianceToImageImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2024 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 otbRadianceToImageImageFilter_h
23 #define otbRadianceToImageImageFilter_h
24 
25 #include "otb_6S.h"
27 #include "itkNumericTraits.h"
28 #include "otbMacro.h"
29 
30 
31 namespace otb
32 {
33 namespace Functor
34 {
46 template <class TInput, class TOutput>
48 {
49 public:
51  {
52  }
53 
55  {
56  }
57 
58  void SetAlpha(double alpha)
59  {
60  m_Alpha = alpha;
61  }
62  void SetBeta(double beta)
63  {
64  m_Beta = beta;
65  }
66  double GetAlpha()
67  {
68  return m_Alpha;
69  }
70  double GetBeta()
71  {
72  return m_Beta;
73  }
74 
75  inline TOutput operator()(const TInput& inPixel) const
76  {
77  TOutput outPixel;
78  double temp;
79  temp = (static_cast<double>(inPixel) - m_Beta) * m_Alpha;
80  outPixel = static_cast<TOutput>(temp);
81  return outPixel;
82  }
83 
84 private:
85  double m_Alpha;
86  double m_Beta;
87 };
88 }
89 
107 template <class TInputImage, class TOutputImage>
110  TInputImage, TOutputImage,
111  typename Functor::RadianceToImageImageFunctor<typename TInputImage::InternalPixelType, typename TOutputImage::InternalPixelType>>
112 {
113 public:
115  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
116  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
118 
120  typedef TInputImage InputImageType;
121  typedef TOutputImage OutputImageType;
123 
127  typedef itk::SmartPointer<Self> Pointer;
128  typedef itk::SmartPointer<const Self> ConstPointer;
129 
131  itkNewMacro(Self);
132 
134  itkTypeMacro(RadianceToImageImageFilter, UnaryImageFunctorWithVectorImageFiltermageFilter);
135 
137  typedef typename InputImageType::PixelType InputPixelType;
138  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
139  typedef typename InputImageType::RegionType InputImageRegionType;
140  typedef typename OutputImageType::PixelType OutputPixelType;
141  typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
142  typedef typename OutputImageType::RegionType OutputImageRegionType;
143 
144  typedef typename itk::VariableLengthVector<double> VectorType;
145 
147  typedef typename InputImageType::SizeType SizeType;
148 
150  itkSetMacro(Alpha, VectorType);
151 
153  itkGetConstReferenceMacro(Alpha, VectorType);
154 
156  itkSetMacro(Beta, VectorType);
157 
159  itkGetConstReferenceMacro(Beta, VectorType);
160 
161 protected:
164  {
165  m_Alpha.SetSize(0);
166  m_Beta.SetSize(0);
167  };
169 
172  {
173  }
174 
176  void BeforeThreadedGenerateData(void) override
177  {
178  const auto & metadata = this->GetInput()->GetImageMetadata();
179 
180  if (m_Alpha.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalGain))
181  {
182  m_Alpha = metadata.GetAsVector(MDNum::PhysicalGain);
183  }
184 
185  if (m_Beta.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalBias))
186  {
187  m_Beta = metadata.GetAsVector(MDNum::PhysicalBias);
188  }
189 
190  otbMsgDevMacro(<< "Dimension: ");
191  otbMsgDevMacro(<< "m_Alpha.GetSize(): " << m_Alpha.GetSize());
192  otbMsgDevMacro(<< "m_Beta.GetSize() : " << m_Beta.GetSize());
193  otbMsgDevMacro(<< "this->GetInput()->GetNumberOfComponentsPerPixel() : " << this->GetInput()->GetNumberOfComponentsPerPixel());
194 
195  if ((m_Alpha.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()) || (m_Beta.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()))
196  {
197  itkExceptionMacro(<< "Alpha and Beta parameters should have the same size as the number of bands");
198  }
199 
200  otbMsgDevMacro(<< "Using correction parameters: ");
201  otbMsgDevMacro(<< "Alpha (gain): " << m_Alpha);
202  otbMsgDevMacro(<< "Beta (bias): " << m_Beta);
203 
204  this->GetFunctorVector().clear();
205  for (unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
206  {
207  FunctorType functor;
208  functor.SetAlpha(m_Alpha[i]);
209  functor.SetBeta(m_Beta[i]);
210  this->GetFunctorVector().push_back(functor);
211  }
212  }
213 
214 private:
218 };
219 
220 } // end namespace otb
221 
222 #endif
Subtract beta to the Input and multiply by alpha.
TOutput operator()(const TInput &inPixel) const
Convert a radiance value into raw image value.
Functor::RadianceToImageImageFunctor< typename InputImageType::InternalPixelType, typename OutputImageType::InternalPixelType > FunctorType
itk::SmartPointer< const Self > ConstPointer
InputImageType::RegionType InputImageRegionType
InputImageType::InternalPixelType InputInternalPixelType
UnaryImageFunctorWithVectorImageFilter< InputImageType, OutputImageType, FunctorType > Superclass
itk::VariableLengthVector< double > VectorType
OutputImageType::InternalPixelType OutputInternalPixelType
OutputImageType::RegionType OutputImageRegionType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbMsgDevMacro(x)
Definition: otbMacro.h:116