OTB  9.0.0
Orfeo Toolbox
otbReflectanceToRadianceImageFilter.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 otbReflectanceToRadianceImageFilter_h
23 #define otbReflectanceToRadianceImageFilter_h
24 
25 #include "otbVarSol.h"
27 #include "otbMacro.h"
28 #include <iomanip>
29 
30 namespace otb
31 {
32 namespace Functor
33 {
50 template <class TInput, class TOutput>
52 {
53 public:
55  {
56  }
57 
59  {
60  }
61 
62  void SetSolarIllumination(double solarIllumination)
63  {
64  m_SolarIllumination = solarIllumination;
65  }
67  {
69  }
70 
72  {
73  return m_SolarIllumination;
74  }
76  {
78  }
79 
80  inline TOutput operator()(const TInput& inPixel) const
81  {
82  TOutput outPixel;
83  double temp;
84  temp = static_cast<double>(inPixel) / static_cast<double>(CONST_PI) * m_IlluminationCorrectionCoefficient * m_SolarIllumination;
85 
86  outPixel = static_cast<TOutput>(temp);
87  return outPixel;
88  }
89 
90 private:
93 };
94 }
95 
113 template <class TInputImage, class TOutputImage>
116  TInputImage, TOutputImage,
117  typename Functor::ReflectanceToRadianceImageFunctor<typename TInputImage::InternalPixelType, typename TOutputImage::InternalPixelType>>
118 {
119 public:
121  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
122  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
124 
126  typedef TInputImage InputImageType;
127  typedef TOutputImage OutputImageType;
130 
134  typedef itk::SmartPointer<Self> Pointer;
135  typedef itk::SmartPointer<const Self> ConstPointer;
136 
138  itkNewMacro(Self);
139 
141  itkTypeMacro(ReflectanceToRadianceImageFilter, UnaryImageFunctorWithVectorImageFiltermageFilter);
142 
144  typedef typename InputImageType::PixelType InputPixelType;
145  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
146  typedef typename InputImageType::RegionType InputImageRegionType;
147  typedef typename OutputImageType::PixelType OutputPixelType;
148  typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
149  typedef typename OutputImageType::RegionType OutputImageRegionType;
150 
151  typedef typename itk::VariableLengthVector<double> VectorType;
152 
154  typedef typename InputImageType::SizeType SizeType;
155 
157  itkSetMacro(SolarIllumination, VectorType);
158 
160  itkGetConstReferenceMacro(SolarIllumination, VectorType);
161 
163  itkSetMacro(ZenithalSolarAngle, double);
164 
166  itkGetConstReferenceMacro(ZenithalSolarAngle, double);
167 
169  virtual void SetElevationSolarAngle(double elevationAngle)
170  {
171  double zenithalAngle = 90.0 - elevationAngle;
172  if (this->m_ZenithalSolarAngle != zenithalAngle)
173  {
174  this->m_ZenithalSolarAngle = zenithalAngle;
175  this->Modified();
176  }
177  }
179 
180  virtual double GetElevationSolarAngle() const
181  {
182  return 90.0 - this->m_ZenithalSolarAngle;
183  }
184 
186  itkSetClampMacro(Day, int, 1, 31);
187 
189  itkGetConstReferenceMacro(Day, int);
190 
192  itkSetClampMacro(Month, int, 1, 12);
193 
195  itkGetConstReferenceMacro(Month, int);
196 
199  {
200  m_FluxNormalizationCoefficient = coef;
201  m_IsSetFluxNormalizationCoefficient = true;
202  this->Modified();
203  }
204 
206  itkGetConstReferenceMacro(FluxNormalizationCoefficient, double);
207 
209  itkSetMacro(IsSetFluxNormalizationCoefficient, bool);
210 
212  itkGetConstReferenceMacro(IsSetFluxNormalizationCoefficient, bool);
213 
215  void SetSolarDistance(double value)
216  {
217  m_SolarDistance = value;
218  m_IsSetSolarDistance = true;
219  this->Modified();
220  }
221 
223  itkGetConstReferenceMacro(SolarDistance, double);
224 
226  itkSetMacro(IsSetSolarDistance, bool);
227 
229  itkGetConstReferenceMacro(IsSetSolarDistance, bool);
230 
232  itkSetMacro(UseClamp, bool);
233 
235  itkGetConstReferenceMacro(UseClamp, bool);
236 
237 protected:
240  : m_ZenithalSolarAngle(120.0), // invalid value which will lead to negative radiometry
241  m_FluxNormalizationCoefficient(1.),
242  m_Day(0),
243  m_Month(0),
244  m_SolarDistance(1.0),
245  m_IsSetFluxNormalizationCoefficient(false),
246  m_IsSetSolarDistance(false)
247  {
248  m_SolarIllumination.SetSize(0);
249  };
251 
254  {
255  }
256 
258  void BeforeThreadedGenerateData(void) override
259  {
260  const auto & metadata = this->GetInput()->GetImageMetadata();
261 
262  if (m_Day == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
263  && metadata.Has(MDTime::AcquisitionDate))
264  {
265  m_Day = metadata[MDTime::AcquisitionDate].GetDay();
266  }
267 
268  if (m_Month == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
269  && metadata.Has(MDTime::AcquisitionDate))
270  {
271  m_Month = metadata[MDTime::AcquisitionDate].GetMonth();
272  }
273 
274  if (m_SolarIllumination.GetSize() == 0 && metadata.HasBandMetadata(MDNum::SolarIrradiance))
275  {
276  m_SolarIllumination = metadata.GetAsVector(MDNum::SolarIrradiance);
277  }
278 
279  if (m_ZenithalSolarAngle == 120.0 && metadata.Has(MDNum::SunElevation))
280  {
281  // the zenithal angle is the complementary of the elevation angle
282  m_ZenithalSolarAngle = 90.0 - metadata[MDNum::SunElevation];
283  }
284 
285  otbMsgDevMacro(<< "Using correction parameters: ");
286  otbMsgDevMacro(<< "Day: " << m_Day);
287  otbMsgDevMacro(<< "Month: " << m_Month);
288  otbMsgDevMacro(<< "Solar irradiance: " << m_SolarIllumination);
289  otbMsgDevMacro(<< "Zenithal angle: " << m_ZenithalSolarAngle);
290 
291  if ((m_SolarIllumination.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()))
292  {
293  itkExceptionMacro(<< "SolarIllumination parameter should have the same size as the number of bands");
294  }
295 
296  this->GetFunctorVector().clear();
297 
298  for (unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
299  {
300  FunctorType functor;
301  double coefTemp = 0.;
302 
303  if (m_IsSetFluxNormalizationCoefficient)
304  {
305  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) * m_FluxNormalizationCoefficient * m_FluxNormalizationCoefficient;
306  }
307  else if (m_IsSetSolarDistance)
308  {
309  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) / (m_SolarDistance * m_SolarDistance);
310  }
311  else if (m_Day * m_Month != 0 && m_Day < 32 && m_Month < 13)
312  {
313  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) * VarSol::GetVarSol(m_Day, m_Month);
314  }
315  else
316  {
317  itkExceptionMacro(<< "Day has to be included between 1 and 31, Month between 1 and 12.");
318  }
319 
320  functor.SetIlluminationCorrectionCoefficient(coefTemp);
321  functor.SetSolarIllumination(static_cast<double>(m_SolarIllumination[i]));
322 
323  this->GetFunctorVector().push_back(functor);
324  }
325  }
326 
327 private:
330 
333 
335  int m_Day;
336 
338  int m_Month;
339 
342 
345 
349 
353 
356 };
357 
358 } // end namespace otb
359 #endif
otb::ReflectanceToRadianceImageFilter::FunctorType
Functor::ReflectanceToRadianceImageFunctor< typename InputImageType::InternalPixelType, typename OutputImageType::InternalPixelType > FunctorType
Definition: otbReflectanceToRadianceImageFilter.h:129
otb::ReflectanceToRadianceImageFilter::SetElevationSolarAngle
virtual void SetElevationSolarAngle(double elevationAngle)
Definition: otbReflectanceToRadianceImageFilter.h:169
otb::CONST_PI
constexpr double CONST_PI
Definition: otbMath.h:49
otb::Functor::ReflectanceToRadianceImageFunctor::m_SolarIllumination
double m_SolarIllumination
Definition: otbReflectanceToRadianceImageFilter.h:91
otb::Functor::ReflectanceToRadianceImageFunctor::operator()
TOutput operator()(const TInput &inPixel) const
Definition: otbReflectanceToRadianceImageFilter.h:80
otb::ReflectanceToRadianceImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbReflectanceToRadianceImageFilter.h:134
otb::ReflectanceToRadianceImageFilter::m_IsSetSolarDistance
bool m_IsSetSolarDistance
Definition: otbReflectanceToRadianceImageFilter.h:352
otb::ReflectanceToRadianceImageFilter::VectorType
itk::VariableLengthVector< double > VectorType
Definition: otbReflectanceToRadianceImageFilter.h:151
otb::ReflectanceToRadianceImageFilter::Superclass
UnaryImageFunctorWithVectorImageFilter< InputImageType, OutputImageType, FunctorType > Superclass
Definition: otbReflectanceToRadianceImageFilter.h:133
otb::MDTime::AcquisitionDate
@ AcquisitionDate
otb::ReflectanceToRadianceImageFilter::m_UseClamp
bool m_UseClamp
Definition: otbReflectanceToRadianceImageFilter.h:355
otbVarSol.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ReflectanceToRadianceImageFilter::Self
ReflectanceToRadianceImageFilter Self
Definition: otbReflectanceToRadianceImageFilter.h:132
otb::Functor::ReflectanceToRadianceImageFunctor::SetIlluminationCorrectionCoefficient
void SetIlluminationCorrectionCoefficient(double coef)
Definition: otbReflectanceToRadianceImageFilter.h:66
otb::ReflectanceToRadianceImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbReflectanceToRadianceImageFilter.h:146
otb::ReflectanceToRadianceImageFilter::m_SolarDistance
double m_SolarDistance
Definition: otbReflectanceToRadianceImageFilter.h:341
otbMacro.h
otb::ReflectanceToRadianceImageFilter::ReflectanceToRadianceImageFilter
ReflectanceToRadianceImageFilter()
Definition: otbReflectanceToRadianceImageFilter.h:239
otb::ReflectanceToRadianceImageFilter::m_IsSetFluxNormalizationCoefficient
bool m_IsSetFluxNormalizationCoefficient
Definition: otbReflectanceToRadianceImageFilter.h:348
otb::ReflectanceToRadianceImageFilter::SetSolarDistance
void SetSolarDistance(double value)
Definition: otbReflectanceToRadianceImageFilter.h:215
otb::Functor::ReflectanceToRadianceImageFunctor::~ReflectanceToRadianceImageFunctor
virtual ~ReflectanceToRadianceImageFunctor()
Definition: otbReflectanceToRadianceImageFilter.h:58
otb::CONST_PI_180
constexpr double CONST_PI_180
Definition: otbMath.h:56
otb::UnaryImageFunctorWithVectorImageFilter
Applies a functor to a VectorImage.
Definition: otbUnaryImageFunctorWithVectorImageFilter.h:46
otb::ReflectanceToRadianceImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbReflectanceToRadianceImageFilter.h:127
otb::ReflectanceToRadianceImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbReflectanceToRadianceImageFilter.h:149
otb::ReflectanceToRadianceImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData(void) override
Definition: otbReflectanceToRadianceImageFilter.h:258
otb::Functor::ReflectanceToRadianceImageFunctor::ReflectanceToRadianceImageFunctor
ReflectanceToRadianceImageFunctor()
Definition: otbReflectanceToRadianceImageFilter.h:54
otb::Functor::ReflectanceToRadianceImageFunctor::GetSolarIllumination
double GetSolarIllumination()
Definition: otbReflectanceToRadianceImageFilter.h:71
otb::ReflectanceToRadianceImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbReflectanceToRadianceImageFilter.h:141
otb::ReflectanceToRadianceImageFilter::m_FluxNormalizationCoefficient
double m_FluxNormalizationCoefficient
Definition: otbReflectanceToRadianceImageFilter.h:332
otb::ReflectanceToRadianceImageFilter::InputImageType
TInputImage InputImageType
Definition: otbReflectanceToRadianceImageFilter.h:126
otb::Functor::ReflectanceToRadianceImageFunctor::SetSolarIllumination
void SetSolarIllumination(double solarIllumination)
Definition: otbReflectanceToRadianceImageFilter.h:62
otb::ReflectanceToRadianceImageFilter::OutputInternalPixelType
OutputImageType::InternalPixelType OutputInternalPixelType
Definition: otbReflectanceToRadianceImageFilter.h:148
otb::ReflectanceToRadianceImageFilter::SizeType
InputImageType::SizeType SizeType
Definition: otbReflectanceToRadianceImageFilter.h:154
otb::ReflectanceToRadianceImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbReflectanceToRadianceImageFilter.h:135
otbUnaryImageFunctorWithVectorImageFilter.h
otb::ReflectanceToRadianceImageFilter::SetFluxNormalizationCoefficient
void SetFluxNormalizationCoefficient(double coef)
Definition: otbReflectanceToRadianceImageFilter.h:198
otb::ReflectanceToRadianceImageFilter::m_ZenithalSolarAngle
double m_ZenithalSolarAngle
Definition: otbReflectanceToRadianceImageFilter.h:329
otb::Functor::ReflectanceToRadianceImageFunctor::m_IlluminationCorrectionCoefficient
double m_IlluminationCorrectionCoefficient
Definition: otbReflectanceToRadianceImageFilter.h:92
otb::VarSol::GetVarSol
static double GetVarSol(const int day, const int month)
Definition: otbVarSol.h:47
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::ReflectanceToRadianceImageFilter::GetElevationSolarAngle
virtual double GetElevationSolarAngle() const
Definition: otbReflectanceToRadianceImageFilter.h:180
otb::ReflectanceToRadianceImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbReflectanceToRadianceImageFilter.h:147
otb::ReflectanceToRadianceImageFilter::m_SolarIllumination
VectorType m_SolarIllumination
Definition: otbReflectanceToRadianceImageFilter.h:344
otb::ReflectanceToRadianceImageFilter::m_Month
int m_Month
Definition: otbReflectanceToRadianceImageFilter.h:338
otb::Functor::ReflectanceToRadianceImageFunctor::GetIlluminationCorrectionCoefficient
double GetIlluminationCorrectionCoefficient()
Definition: otbReflectanceToRadianceImageFilter.h:75
otb::ReflectanceToRadianceImageFilter::~ReflectanceToRadianceImageFilter
~ReflectanceToRadianceImageFilter() override
Definition: otbReflectanceToRadianceImageFilter.h:253
otb::ReflectanceToRadianceImageFilter::InputInternalPixelType
InputImageType::InternalPixelType InputInternalPixelType
Definition: otbReflectanceToRadianceImageFilter.h:145
otb::ReflectanceToRadianceImageFilter::m_Day
int m_Day
Definition: otbReflectanceToRadianceImageFilter.h:335
otb::MDNum::SolarIrradiance
@ SolarIrradiance
otb::Functor::ReflectanceToRadianceImageFunctor
Compute radiance from the reflectance value.
Definition: otbReflectanceToRadianceImageFilter.h:51
otb::ReflectanceToRadianceImageFilter
Convert reflectance value into radiance value.
Definition: otbReflectanceToRadianceImageFilter.h:114
otb::MDNum::SunElevation
@ SunElevation