OTB  9.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-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 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
otb::Functor::RadianceToImageImageFunctor
Subtract beta to the Input and multiply by alpha.
Definition: otbRadianceToImageImageFilter.h:47
otb::RadianceToImageImageFilter::SizeType
InputImageType::SizeType SizeType
Definition: otbRadianceToImageImageFilter.h:147
otb::RadianceToImageImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbRadianceToImageImageFilter.h:142
otb::RadianceToImageImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData(void) override
Definition: otbRadianceToImageImageFilter.h:176
otb::Functor::RadianceToImageImageFunctor::SetAlpha
void SetAlpha(double alpha)
Definition: otbRadianceToImageImageFilter.h:58
otb::Functor::RadianceToImageImageFunctor::SetBeta
void SetBeta(double beta)
Definition: otbRadianceToImageImageFilter.h:62
otb::RadianceToImageImageFilter::~RadianceToImageImageFilter
~RadianceToImageImageFilter() override
Definition: otbRadianceToImageImageFilter.h:171
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::RadianceToImageImageFilter
Convert a radiance value into raw image value.
Definition: otbRadianceToImageImageFilter.h:108
otb::MDNum::PhysicalBias
@ PhysicalBias
otb::RadianceToImageImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbRadianceToImageImageFilter.h:127
otbMacro.h
otb::Functor::RadianceToImageImageFunctor::GetBeta
double GetBeta()
Definition: otbRadianceToImageImageFilter.h:70
otb::RadianceToImageImageFilter::InputImageType
TInputImage InputImageType
Definition: otbRadianceToImageImageFilter.h:120
otb::RadianceToImageImageFilter::OutputInternalPixelType
OutputImageType::InternalPixelType OutputInternalPixelType
Definition: otbRadianceToImageImageFilter.h:141
otb::UnaryImageFunctorWithVectorImageFilter
Applies a functor to a VectorImage.
Definition: otbUnaryImageFunctorWithVectorImageFilter.h:46
otb::RadianceToImageImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbRadianceToImageImageFilter.h:128
otb::RadianceToImageImageFilter::RadianceToImageImageFilter
RadianceToImageImageFilter()
Definition: otbRadianceToImageImageFilter.h:163
otb::Functor::RadianceToImageImageFunctor::m_Beta
double m_Beta
Definition: otbRadianceToImageImageFilter.h:86
otb::RadianceToImageImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbRadianceToImageImageFilter.h:134
otb::RadianceToImageImageFilter::InputInternalPixelType
InputImageType::InternalPixelType InputInternalPixelType
Definition: otbRadianceToImageImageFilter.h:138
otb::MDNum::PhysicalGain
@ PhysicalGain
otb::RadianceToImageImageFilter::Superclass
UnaryImageFunctorWithVectorImageFilter< InputImageType, OutputImageType, FunctorType > Superclass
Definition: otbRadianceToImageImageFilter.h:126
otb::Functor::RadianceToImageImageFunctor::m_Alpha
double m_Alpha
Definition: otbRadianceToImageImageFilter.h:85
otb::Functor::RadianceToImageImageFunctor::operator()
TOutput operator()(const TInput &inPixel) const
Definition: otbRadianceToImageImageFilter.h:75
otbUnaryImageFunctorWithVectorImageFilter.h
otb::RadianceToImageImageFilter::m_Beta
VectorType m_Beta
Definition: otbRadianceToImageImageFilter.h:217
otb::RadianceToImageImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbRadianceToImageImageFilter.h:121
otb::RadianceToImageImageFilter::m_Alpha
VectorType m_Alpha
Definition: otbRadianceToImageImageFilter.h:216
otb::RadianceToImageImageFilter::FunctorType
Functor::RadianceToImageImageFunctor< typename InputImageType::InternalPixelType, typename OutputImageType::InternalPixelType > FunctorType
Definition: otbRadianceToImageImageFilter.h:122
otb::Functor::RadianceToImageImageFunctor::GetAlpha
double GetAlpha()
Definition: otbRadianceToImageImageFilter.h:66
otb::RadianceToImageImageFilter::VectorType
itk::VariableLengthVector< double > VectorType
Definition: otbRadianceToImageImageFilter.h:144
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::RadianceToImageImageFilter::Self
RadianceToImageImageFilter Self
Definition: otbRadianceToImageImageFilter.h:125
otb::RadianceToImageImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbRadianceToImageImageFilter.h:140
otb::RadianceToImageImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbRadianceToImageImageFilter.h:139
otb::Functor::RadianceToImageImageFunctor::~RadianceToImageImageFunctor
virtual ~RadianceToImageImageFunctor()
Definition: otbRadianceToImageImageFilter.h:54
otb::Functor::RadianceToImageImageFunctor::RadianceToImageImageFunctor
RadianceToImageImageFunctor()
Definition: otbRadianceToImageImageFilter.h:50