OTB  9.0.0
Orfeo Toolbox
otbImageToRadianceImageFilter.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 otbImageToRadianceImageFilter_h
23 #define otbImageToRadianceImageFilter_h
24 
26 #include "itkNumericTraits.h"
27 #include "otbMacro.h"
28 
29 
30 namespace otb
31 {
32 namespace Functor
33 {
45 template <class TInput, class TOutput>
47 {
48 public:
50  {
51  }
52 
54  {
55  }
56 
57  void SetAlpha(double alpha)
58  {
59  m_Alpha = alpha;
60  }
61  void SetBeta(double beta)
62  {
63  m_Beta = beta;
64  }
65  double GetAlpha()
66  {
67  return m_Alpha;
68  }
69  double GetBeta()
70  {
71  return m_Beta;
72  }
73 
74  inline TOutput operator()(const TInput& inPixel) const
75  {
76  TOutput outPixel;
77  double temp;
78  temp = static_cast<double>(inPixel) / m_Alpha + m_Beta;
79  outPixel = static_cast<TOutput>(temp);
80  return outPixel;
81  }
82 
83 private:
84  double m_Alpha;
85  double m_Beta;
86 };
87 }
88 
106 template <class TInputImage, class TOutputImage>
109  TInputImage, TOutputImage,
110  typename Functor::ImageToRadianceImageFunctor<typename TInputImage::InternalPixelType, typename TOutputImage::InternalPixelType>>
111 {
112 public:
114  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
115  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
117 
119  typedef TInputImage InputImageType;
120  typedef TOutputImage OutputImageType;
122 
126  typedef itk::SmartPointer<Self> Pointer;
127  typedef itk::SmartPointer<const Self> ConstPointer;
128 
130  itkNewMacro(Self);
131 
133  itkTypeMacro(ImageToRadianceImageFilter, UnaryImageFunctorWithVectorImageFiltermageFilter);
134 
136  typedef typename InputImageType::PixelType InputPixelType;
137  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
138  typedef typename InputImageType::RegionType InputImageRegionType;
139  typedef typename OutputImageType::PixelType OutputPixelType;
140  typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
141  typedef typename OutputImageType::RegionType OutputImageRegionType;
142 
143  typedef typename itk::VariableLengthVector<double> VectorType;
144 
146  typedef typename InputImageType::SizeType SizeType;
147 
149  itkSetMacro(Alpha, VectorType);
150 
152  itkGetConstReferenceMacro(Alpha, VectorType);
153 
155  itkSetMacro(Beta, VectorType);
156 
158  itkGetConstReferenceMacro(Beta, VectorType);
159 
160 protected:
163  {
164  m_Alpha.SetSize(0);
165  m_Beta.SetSize(0);
166  };
168 
171  {
172  }
173 
175  void BeforeThreadedGenerateData(void) override
176  {
177  const auto & metadata = this->GetInput()->GetImageMetadata();
178 
179  if (m_Alpha.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalGain))
180  {
181  m_Alpha = metadata.GetAsVector(MDNum::PhysicalGain);
182  }
183 
184  if (m_Beta.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalBias))
185  {
186  m_Beta = metadata.GetAsVector(MDNum::PhysicalBias);
187  }
188 
189  otbMsgDevMacro(<< "Dimension: ");
190  otbMsgDevMacro(<< "m_Alpha.GetSize(): " << m_Alpha.GetSize());
191  otbMsgDevMacro(<< "m_Beta.GetSize() : " << m_Beta.GetSize());
192  otbMsgDevMacro(<< "this->GetInput()->GetNumberOfComponentsPerPixel() : " << this->GetInput()->GetNumberOfComponentsPerPixel());
193 
194  if ((m_Alpha.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()) || (m_Beta.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()))
195  {
196  itkExceptionMacro(<< "Alpha and Beta parameters should have the same size as the number of bands");
197  }
198 
199  otbMsgDevMacro(<< "Using correction parameters: ");
200  otbMsgDevMacro(<< "Alpha (gain): " << m_Alpha);
201  otbMsgDevMacro(<< "Beta (bias): " << m_Beta);
202 
203  this->GetFunctorVector().clear();
204  for (unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
205  {
206  FunctorType functor;
207  functor.SetAlpha(m_Alpha[i]);
208  functor.SetBeta(m_Beta[i]);
209  this->GetFunctorVector().push_back(functor);
210  }
211  }
212 
213 private:
217 };
218 
219 } // end namespace otb
220 
221 #endif
otb::ImageToRadianceImageFilter::OutputInternalPixelType
OutputImageType::InternalPixelType OutputInternalPixelType
Definition: otbImageToRadianceImageFilter.h:140
otb::ImageToRadianceImageFilter::~ImageToRadianceImageFilter
~ImageToRadianceImageFilter() override
Definition: otbImageToRadianceImageFilter.h:170
otb::ImageToRadianceImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbImageToRadianceImageFilter.h:138
otb::Functor::ImageToRadianceImageFunctor::GetAlpha
double GetAlpha()
Definition: otbImageToRadianceImageFilter.h:65
otb::Functor::ImageToRadianceImageFunctor::SetAlpha
void SetAlpha(double alpha)
Definition: otbImageToRadianceImageFilter.h:57
otb::ImageToRadianceImageFilter::ImageToRadianceImageFilter
ImageToRadianceImageFilter()
Definition: otbImageToRadianceImageFilter.h:162
otb::ImageToRadianceImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbImageToRadianceImageFilter.h:120
otb::ImageToRadianceImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbImageToRadianceImageFilter.h:139
otb::ImageToRadianceImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData(void) override
Definition: otbImageToRadianceImageFilter.h:175
otb::Functor::ImageToRadianceImageFunctor::~ImageToRadianceImageFunctor
virtual ~ImageToRadianceImageFunctor()
Definition: otbImageToRadianceImageFilter.h:53
otb::ImageToRadianceImageFilter::SizeType
InputImageType::SizeType SizeType
Definition: otbImageToRadianceImageFilter.h:146
otb::ImageToRadianceImageFilter::InputImageType
TInputImage InputImageType
Definition: otbImageToRadianceImageFilter.h:119
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MDNum::PhysicalBias
@ PhysicalBias
otbMacro.h
otb::ImageToRadianceImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageToRadianceImageFilter.h:126
otb::Functor::ImageToRadianceImageFunctor::operator()
TOutput operator()(const TInput &inPixel) const
Definition: otbImageToRadianceImageFilter.h:74
otb::ImageToRadianceImageFilter::m_Alpha
VectorType m_Alpha
Definition: otbImageToRadianceImageFilter.h:215
otb::ImageToRadianceImageFilter::m_Beta
VectorType m_Beta
Definition: otbImageToRadianceImageFilter.h:216
otb::ImageToRadianceImageFilter
Convert a raw value into a radiance value.
Definition: otbImageToRadianceImageFilter.h:107
otb::ImageToRadianceImageFilter::VectorType
itk::VariableLengthVector< double > VectorType
Definition: otbImageToRadianceImageFilter.h:143
otb::UnaryImageFunctorWithVectorImageFilter
Applies a functor to a VectorImage.
Definition: otbUnaryImageFunctorWithVectorImageFilter.h:46
otb::MDNum::PhysicalGain
@ PhysicalGain
otb::ImageToRadianceImageFilter::FunctorType
Functor::ImageToRadianceImageFunctor< typename InputImageType::InternalPixelType, typename OutputImageType::InternalPixelType > FunctorType
Definition: otbImageToRadianceImageFilter.h:121
otb::Functor::ImageToRadianceImageFunctor::m_Alpha
double m_Alpha
Definition: otbImageToRadianceImageFilter.h:84
otb::ImageToRadianceImageFilter::InputInternalPixelType
InputImageType::InternalPixelType InputInternalPixelType
Definition: otbImageToRadianceImageFilter.h:137
otbUnaryImageFunctorWithVectorImageFilter.h
otb::Functor::ImageToRadianceImageFunctor::GetBeta
double GetBeta()
Definition: otbImageToRadianceImageFilter.h:69
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::Functor::ImageToRadianceImageFunctor
Add beta to the quotient Input over alpha.
Definition: otbImageToRadianceImageFilter.h:46
otb::Functor::ImageToRadianceImageFunctor::ImageToRadianceImageFunctor
ImageToRadianceImageFunctor()
Definition: otbImageToRadianceImageFilter.h:49
otb::ImageToRadianceImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageToRadianceImageFilter.h:127
otb::ImageToRadianceImageFilter::Self
ImageToRadianceImageFilter Self
Definition: otbImageToRadianceImageFilter.h:124
otb::ImageToRadianceImageFilter::Superclass
UnaryImageFunctorWithVectorImageFilter< InputImageType, OutputImageType, FunctorType > Superclass
Definition: otbImageToRadianceImageFilter.h:125
otb::ImageToRadianceImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbImageToRadianceImageFilter.h:133
otb::Functor::ImageToRadianceImageFunctor::m_Beta
double m_Beta
Definition: otbImageToRadianceImageFilter.h:85
otb::Functor::ImageToRadianceImageFunctor::SetBeta
void SetBeta(double beta)
Definition: otbImageToRadianceImageFilter.h:61
otb::ImageToRadianceImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbImageToRadianceImageFilter.h:141