OTB  9.0.0
Orfeo Toolbox
otbImageToReflectanceImageFilter.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 otbImageToReflectanceImageFilter_h
23 #define otbImageToReflectanceImageFilter_h
24 
27 
28 namespace otb
29 {
30 namespace Functor
31 {
45 template <class TInput, class TOutput>
47 {
48 public:
50  {
51  }
53  {
54  }
55 
58 
59  void SetAlpha(double alpha)
60  {
62  }
63  void SetBeta(double beta)
64  {
66  }
67  void SetSolarIllumination(double solarIllumination)
68  {
69  m_LumToReflecFunctor.SetSolarIllumination(solarIllumination);
70  }
72  {
74  }
75  void SetUseClamp(bool useClamp)
76  {
78  }
79 
80  double GetAlpha()
81  {
82  return m_ImToLumFunctor.GetAlpha();
83  }
84  double GetBeta()
85  {
86  return m_ImToLumFunctor.GetBeta();
87  }
89  {
91  }
93  {
95  }
96  bool GetUseClamp()
97  {
99  }
100 
101  inline TOutput operator()(const TInput& inPixel) const
102  {
103  TOutput outPixel;
104  TOutput tempPix;
105  tempPix = m_ImToLumFunctor(inPixel);
106  outPixel = m_LumToReflecFunctor(tempPix);
107 
108  return outPixel;
109  }
110 
111 private:
114 };
115 }
116 
137 template <class TInputImage, class TOutputImage>
140  TInputImage, TOutputImage,
141  typename Functor::ImageToReflectanceImageFunctor<typename TInputImage::InternalPixelType, typename TOutputImage::InternalPixelType>>
142 {
143 public:
145  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
146  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
148 
150  typedef TInputImage InputImageType;
151  typedef TOutputImage OutputImageType;
153 
157  typedef itk::SmartPointer<Self> Pointer;
158  typedef itk::SmartPointer<const Self> ConstPointer;
159 
161  itkNewMacro(Self);
162 
164  itkTypeMacro(ImageToReflectanceImageFilter, UnaryImageFunctorWithVectorImageFiltermageFilter);
165 
167  typedef typename InputImageType::PixelType InputPixelType;
168  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
169  typedef typename InputImageType::RegionType InputImageRegionType;
170  typedef typename OutputImageType::PixelType OutputPixelType;
171  typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
172  typedef typename OutputImageType::RegionType OutputImageRegionType;
173 
174  typedef typename itk::VariableLengthVector<double> VectorType;
175 
177  typedef typename InputImageType::SizeType SizeType;
178 
180  itkSetMacro(Alpha, VectorType);
181 
183  itkGetConstReferenceMacro(Alpha, VectorType);
184 
186  itkSetMacro(Beta, VectorType);
187 
189  itkGetConstReferenceMacro(Beta, VectorType);
190 
192  itkSetMacro(SolarIllumination, VectorType);
193 
195  itkGetConstReferenceMacro(SolarIllumination, VectorType);
196 
198  itkSetMacro(ZenithalSolarAngle, double);
199 
201  itkGetConstReferenceMacro(ZenithalSolarAngle, double);
202 
204  itkSetMacro(UseClamp, bool);
205 
207  itkGetConstReferenceMacro(UseClamp, bool);
208 
210  virtual void SetElevationSolarAngle(double elevationAngle)
211  {
212  double zenithalAngle = 90.0 - elevationAngle;
213  if (this->m_ZenithalSolarAngle != zenithalAngle)
214  {
215  this->m_ZenithalSolarAngle = zenithalAngle;
216  this->Modified();
217  }
218  }
220 
221  virtual double GetElevationSolarAngle() const
222  {
223  return 90.0 - this->m_ZenithalSolarAngle;
224  }
225 
228  {
229  m_FluxNormalizationCoefficient = coef;
230  m_IsSetFluxNormalizationCoefficient = true;
231  this->Modified();
232  }
234 
236  void SetSolarDistance(double value)
237  {
238  m_SolarDistance = value;
239  m_IsSetSolarDistance = true;
240  this->Modified();
241  }
242 
244  itkGetConstReferenceMacro(SolarDistance, double);
245 
247  itkSetMacro(IsSetSolarDistance, bool);
248 
250  itkGetConstReferenceMacro(IsSetSolarDistance, bool);
251 
253  itkSetClampMacro(Day, int, 1, 31);
254 
256  itkGetConstReferenceMacro(Day, int);
257 
259  itkSetClampMacro(Month, int, 1, 12);
260 
262  itkGetConstReferenceMacro(Month, int);
263 
264 protected:
267  : m_ZenithalSolarAngle(120.), // invalid value which will lead to negative radiometry
268  m_FluxNormalizationCoefficient(1.),
269  m_UseClamp(true),
270  m_IsSetFluxNormalizationCoefficient(false),
271  m_Day(0),
272  m_Month(0),
273  m_SolarDistance(1.0),
274  m_IsSetSolarDistance(false)
275  {
276  m_Alpha.SetSize(0);
277  m_Beta.SetSize(0);
278  m_SolarIllumination.SetSize(0);
279  };
281 
284  {
285  }
286 
288  void BeforeThreadedGenerateData(void) override
289  {
290  const auto & metadata = this->GetInput()->GetImageMetadata();
291 
292  if (m_Alpha.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalGain))
293  {
294  m_Alpha = metadata.GetAsVector(MDNum::PhysicalGain);
295  }
296 
297  if (m_Beta.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalBias))
298  {
299  m_Beta = metadata.GetAsVector(MDNum::PhysicalBias);
300  }
301 
302  if (m_Day == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
303  && metadata.Has(MDTime::AcquisitionDate))
304  {
305  m_Day = metadata[MDTime::AcquisitionDate].GetDay();
306  }
307 
308  if (m_Month == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
309  && metadata.Has(MDTime::AcquisitionDate))
310  {
311  m_Month = metadata[MDTime::AcquisitionDate].GetMonth();
312  }
313 
314  if (m_SolarIllumination.GetSize() == 0 && metadata.HasBandMetadata(MDNum::SolarIrradiance))
315  {
316  m_SolarIllumination = metadata.GetAsVector(MDNum::SolarIrradiance);
317  }
318 
319  if (m_ZenithalSolarAngle == 120.0 && metadata.Has(MDNum::SunElevation))
320  {
321  // the zenithal angle is the complementary of the elevation angle
322  m_ZenithalSolarAngle = 90.0 - metadata[MDNum::SunElevation];
323  }
324 
325  otbMsgDevMacro(<< "Using correction parameters: ");
326  otbMsgDevMacro(<< "Alpha (gain): " << m_Alpha);
327  otbMsgDevMacro(<< "Beta (bias): " << m_Beta);
328  otbMsgDevMacro(<< "Day: " << m_Day);
329  otbMsgDevMacro(<< "Month: " << m_Month);
330  otbMsgDevMacro(<< "Solar irradiance: " << m_SolarIllumination);
331  otbMsgDevMacro(<< "Zenithal angle: " << m_ZenithalSolarAngle);
332 
333  if ((m_Alpha.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()) || (m_Beta.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()) ||
334  (m_SolarIllumination.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()))
335  {
336  itkExceptionMacro(<< "Alpha, Beta and SolarIllumination parameters should have the same size as the number of bands");
337  }
338 
339  this->GetFunctorVector().clear();
340  for (unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
341  {
342  FunctorType functor;
343  double coefTemp = 0.;
344 
345  if (m_IsSetFluxNormalizationCoefficient)
346  {
347  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) * m_FluxNormalizationCoefficient * m_FluxNormalizationCoefficient;
348  }
349  else if (m_IsSetSolarDistance)
350  {
351  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) / (m_SolarDistance * m_SolarDistance);
352  }
353  else if (m_Day * m_Month != 0 && m_Day < 32 && m_Month < 13)
354  {
355  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) * VarSol::GetVarSol(m_Day, m_Month);
356  }
357  else
358  {
359  itkExceptionMacro(<< "Day has to be included between 1 and 31, Month between 1 and 12.");
360  }
361 
362  functor.SetIlluminationCorrectionCoefficient(1. / coefTemp);
363  functor.SetAlpha(m_Alpha[i]);
364  functor.SetBeta(m_Beta[i]);
365  functor.SetSolarIllumination(m_SolarIllumination[i]);
366  functor.SetUseClamp(m_UseClamp);
367  this->GetFunctorVector().push_back(functor);
368  }
369  }
370 
371 private:
375 
378 
381 
384 
387 
391 
393  int m_Day;
394 
396  int m_Month;
397 
400 
404 };
405 
406 } // end namespace otb
407 
408 #endif
otb::ImageToReflectanceImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageToReflectanceImageFilter.h:157
otb::ImageToReflectanceImageFilter::SetFluxNormalizationCoefficient
void SetFluxNormalizationCoefficient(double coef)
Definition: otbImageToReflectanceImageFilter.h:227
otb::Functor::RadianceToReflectanceImageFunctor::GetIlluminationCorrectionCoefficient
double GetIlluminationCorrectionCoefficient()
Definition: otbRadianceToReflectanceImageFilter.h:79
otb::Functor::ImageToReflectanceImageFunctor::GetUseClamp
bool GetUseClamp()
Definition: otbImageToReflectanceImageFilter.h:96
otb::ImageToReflectanceImageFilter::m_Day
int m_Day
Definition: otbImageToReflectanceImageFilter.h:393
otb::ImageToReflectanceImageFilter::SizeType
InputImageType::SizeType SizeType
Definition: otbImageToReflectanceImageFilter.h:177
otb::Functor::ImageToReflectanceImageFunctor::SetSolarIllumination
void SetSolarIllumination(double solarIllumination)
Definition: otbImageToReflectanceImageFilter.h:67
otb::Functor::ImageToReflectanceImageFunctor::m_ImToLumFunctor
ImToLumFunctorType m_ImToLumFunctor
Definition: otbImageToReflectanceImageFilter.h:112
otb::ImageToReflectanceImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData(void) override
Definition: otbImageToReflectanceImageFilter.h:288
otb::ImageToReflectanceImageFilter::OutputInternalPixelType
OutputImageType::InternalPixelType OutputInternalPixelType
Definition: otbImageToReflectanceImageFilter.h:171
otb::ImageToReflectanceImageFilter::FunctorType
Functor::ImageToReflectanceImageFunctor< typename InputImageType::InternalPixelType, typename OutputImageType::InternalPixelType > FunctorType
Definition: otbImageToReflectanceImageFilter.h:152
otb::ImageToReflectanceImageFilter::VectorType
itk::VariableLengthVector< double > VectorType
Definition: otbImageToReflectanceImageFilter.h:174
otb::ImageToReflectanceImageFilter::~ImageToReflectanceImageFilter
~ImageToReflectanceImageFilter() override
Definition: otbImageToReflectanceImageFilter.h:283
otb::ImageToReflectanceImageFilter::m_ZenithalSolarAngle
double m_ZenithalSolarAngle
Definition: otbImageToReflectanceImageFilter.h:377
otb::Functor::ImageToRadianceImageFunctor::GetAlpha
double GetAlpha()
Definition: otbImageToRadianceImageFilter.h:65
otb::Functor::ImageToRadianceImageFunctor::SetAlpha
void SetAlpha(double alpha)
Definition: otbImageToRadianceImageFilter.h:57
otb::ImageToReflectanceImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbImageToReflectanceImageFilter.h:169
otb::Functor::ImageToReflectanceImageFunctor::SetUseClamp
void SetUseClamp(bool useClamp)
Definition: otbImageToReflectanceImageFilter.h:75
otb::Functor::ImageToReflectanceImageFunctor::m_LumToReflecFunctor
LumToReflecFunctorType m_LumToReflecFunctor
Definition: otbImageToReflectanceImageFilter.h:113
otb::ImageToReflectanceImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageToReflectanceImageFilter.h:158
otb::MDTime::AcquisitionDate
@ AcquisitionDate
otb::ImageToReflectanceImageFilter::m_UseClamp
bool m_UseClamp
Definition: otbImageToReflectanceImageFilter.h:386
otb::Functor::RadianceToReflectanceImageFunctor::GetUseClamp
bool GetUseClamp()
Definition: otbRadianceToReflectanceImageFilter.h:83
otb::ImageToReflectanceImageFilter::m_IsSetSolarDistance
bool m_IsSetSolarDistance
Definition: otbImageToReflectanceImageFilter.h:403
otb::Functor::ImageToReflectanceImageFunctor::GetAlpha
double GetAlpha()
Definition: otbImageToReflectanceImageFilter.h:80
otb::Functor::ImageToReflectanceImageFunctor::SetIlluminationCorrectionCoefficient
void SetIlluminationCorrectionCoefficient(double coef)
Definition: otbImageToReflectanceImageFilter.h:71
otb::Functor::ImageToReflectanceImageFunctor::operator()
TOutput operator()(const TInput &inPixel) const
Definition: otbImageToReflectanceImageFilter.h:101
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MDNum::PhysicalBias
@ PhysicalBias
otb::ImageToReflectanceImageFilter::SetElevationSolarAngle
virtual void SetElevationSolarAngle(double elevationAngle)
Definition: otbImageToReflectanceImageFilter.h:210
otb::Functor::ImageToReflectanceImageFunctor::ImageToReflectanceImageFunctor
ImageToReflectanceImageFunctor()
Definition: otbImageToReflectanceImageFilter.h:49
otb::ImageToReflectanceImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbImageToReflectanceImageFilter.h:170
otb::ImageToReflectanceImageFilter::m_IsSetFluxNormalizationCoefficient
bool m_IsSetFluxNormalizationCoefficient
Definition: otbImageToReflectanceImageFilter.h:390
otb::ImageToReflectanceImageFilter::m_Alpha
VectorType m_Alpha
Definition: otbImageToReflectanceImageFilter.h:373
otb::ImageToReflectanceImageFilter::InputImageType
TInputImage InputImageType
Definition: otbImageToReflectanceImageFilter.h:150
otb::ImageToReflectanceImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbImageToReflectanceImageFilter.h:172
otb::Functor::ImageToReflectanceImageFunctor::SetAlpha
void SetAlpha(double alpha)
Definition: otbImageToReflectanceImageFilter.h:59
otb::ImageToReflectanceImageFilter::Superclass
UnaryImageFunctorWithVectorImageFilter< InputImageType, OutputImageType, FunctorType > Superclass
Definition: otbImageToReflectanceImageFilter.h:156
otb::ImageToReflectanceImageFilter::Self
ImageToReflectanceImageFilter Self
Definition: otbImageToReflectanceImageFilter.h:155
otb::CONST_PI_180
constexpr double CONST_PI_180
Definition: otbMath.h:56
otb::ImageToReflectanceImageFilter::m_SolarDistance
double m_SolarDistance
Definition: otbImageToReflectanceImageFilter.h:399
otb::ImageToReflectanceImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbImageToReflectanceImageFilter.h:164
otb::UnaryImageFunctorWithVectorImageFilter
Applies a functor to a VectorImage.
Definition: otbUnaryImageFunctorWithVectorImageFilter.h:46
otbImageToRadianceImageFilter.h
otb::ImageToReflectanceImageFilter::m_Beta
VectorType m_Beta
Definition: otbImageToReflectanceImageFilter.h:374
otb::ImageToReflectanceImageFilter::m_SolarIllumination
VectorType m_SolarIllumination
Definition: otbImageToReflectanceImageFilter.h:383
otb::Functor::ImageToReflectanceImageFunctor::GetIlluminationCorrectionCoefficient
double GetIlluminationCorrectionCoefficient()
Definition: otbImageToReflectanceImageFilter.h:92
otb::ImageToReflectanceImageFilter::ImageToReflectanceImageFilter
ImageToReflectanceImageFilter()
Definition: otbImageToReflectanceImageFilter.h:266
otb::Functor::RadianceToReflectanceImageFunctor::SetIlluminationCorrectionCoefficient
void SetIlluminationCorrectionCoefficient(double coef)
Definition: otbRadianceToReflectanceImageFilter.h:66
otb::Functor::ImageToReflectanceImageFunctor::GetBeta
double GetBeta()
Definition: otbImageToReflectanceImageFilter.h:84
otb::MDNum::PhysicalGain
@ PhysicalGain
otb::Functor::ImageToReflectanceImageFunctor::~ImageToReflectanceImageFunctor
virtual ~ImageToReflectanceImageFunctor()
Definition: otbImageToReflectanceImageFilter.h:52
otb::Functor::ImageToReflectanceImageFunctor::GetSolarIllumination
double GetSolarIllumination()
Definition: otbImageToReflectanceImageFilter.h:88
otb::ImageToReflectanceImageFilter::m_Month
int m_Month
Definition: otbImageToReflectanceImageFilter.h:396
otb::ImageToReflectanceImageFilter::m_FluxNormalizationCoefficient
double m_FluxNormalizationCoefficient
Definition: otbImageToReflectanceImageFilter.h:380
otb::ImageToReflectanceImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbImageToReflectanceImageFilter.h:151
otb::Functor::RadianceToReflectanceImageFunctor
Compute reflectance from the radiance value.
Definition: otbRadianceToReflectanceImageFilter.h:51
otb::Functor::RadianceToReflectanceImageFunctor::SetSolarIllumination
void SetSolarIllumination(double solarIllumination)
Definition: otbRadianceToReflectanceImageFilter.h:62
otb::Functor::RadianceToReflectanceImageFunctor::GetSolarIllumination
double GetSolarIllumination()
Definition: otbRadianceToReflectanceImageFilter.h:75
otb::Functor::ImageToRadianceImageFunctor::GetBeta
double GetBeta()
Definition: otbImageToRadianceImageFilter.h:69
otb::VarSol::GetVarSol
static double GetVarSol(const int day, const int month)
Definition: otbVarSol.h:47
otb::Functor::ImageToReflectanceImageFunctor
Call the ImageToRadianceFunctor over the input and the RadianceToReflectanceFunctor to this result.
Definition: otbImageToReflectanceImageFilter.h:46
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::ImageToReflectanceImageFilter
Convert a raw value into a reflectance value.
Definition: otbImageToReflectanceImageFilter.h:138
otb::Functor::ImageToRadianceImageFunctor
Add beta to the quotient Input over alpha.
Definition: otbImageToRadianceImageFilter.h:46
otb::Functor::ImageToReflectanceImageFunctor::LumToReflecFunctorType
Functor::RadianceToReflectanceImageFunctor< TInput, TOutput > LumToReflecFunctorType
Definition: otbImageToReflectanceImageFilter.h:57
otb::Functor::ImageToReflectanceImageFunctor::SetBeta
void SetBeta(double beta)
Definition: otbImageToReflectanceImageFilter.h:63
otb::Functor::ImageToReflectanceImageFunctor::ImToLumFunctorType
Functor::ImageToRadianceImageFunctor< TInput, TOutput > ImToLumFunctorType
Definition: otbImageToReflectanceImageFilter.h:56
otbRadianceToReflectanceImageFilter.h
otb::ImageToReflectanceImageFilter::GetElevationSolarAngle
virtual double GetElevationSolarAngle() const
Definition: otbImageToReflectanceImageFilter.h:221
otb::Functor::RadianceToReflectanceImageFunctor::SetUseClamp
void SetUseClamp(bool useClamp)
Definition: otbRadianceToReflectanceImageFilter.h:70
otb::Functor::ImageToRadianceImageFunctor::SetBeta
void SetBeta(double beta)
Definition: otbImageToRadianceImageFilter.h:61
otb::ImageToReflectanceImageFilter::InputInternalPixelType
InputImageType::InternalPixelType InputInternalPixelType
Definition: otbImageToReflectanceImageFilter.h:168
otb::ImageToReflectanceImageFilter::SetSolarDistance
void SetSolarDistance(double value)
Definition: otbImageToReflectanceImageFilter.h:236
otb::MDNum::SolarIrradiance
@ SolarIrradiance
otb::MDNum::SunElevation
@ SunElevation