OTB  9.0.0
Orfeo Toolbox
otbReflectanceToImageImageFilter.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 otbReflectanceToImageImageFilter_h
23 #define otbReflectanceToImageImageFilter_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_ReflecToLumFunctor.SetSolarIllumination(solarIllumination);
70  }
72  {
74  }
75 
76  double GetAlpha()
77  {
78  return m_LumToImFunctor.GetAlpha();
79  }
80  double GetBeta()
81  {
82  return m_LumToImFunctor.GetBeta();
83  }
85  {
87  }
89  {
91  }
92 
93  inline TOutput operator()(const TInput& inPixel) const
94  {
95  TOutput outPixel;
96  TOutput tempPix;
97  tempPix = m_ReflecToLumFunctor(inPixel);
98  outPixel = m_LumToImFunctor(tempPix);
99 
100  return outPixel;
101  }
102 
103 private:
106 };
107 }
108 
129 template <class TInputImage, class TOutputImage>
132  TInputImage, TOutputImage,
133  typename Functor::ReflectanceToImageImageFunctor<typename TInputImage::InternalPixelType, typename TOutputImage::InternalPixelType>>
134 {
135 public:
137  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
138  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
140 
142  typedef TInputImage InputImageType;
143  typedef TOutputImage OutputImageType;
145 
149  typedef itk::SmartPointer<Self> Pointer;
150  typedef itk::SmartPointer<const Self> ConstPointer;
151 
153  itkNewMacro(Self);
154 
156  itkTypeMacro(ReflectanceToImageImageFilter, UnaryImageFunctorWithVectorImageFiltermageFilter);
157 
159  typedef typename InputImageType::PixelType InputPixelType;
160  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
161  typedef typename InputImageType::RegionType InputImageRegionType;
162  typedef typename OutputImageType::PixelType OutputPixelType;
163  typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
164  typedef typename OutputImageType::RegionType OutputImageRegionType;
165 
166  typedef typename itk::VariableLengthVector<double> VectorType;
167 
169  typedef typename InputImageType::SizeType SizeType;
170 
172  itkSetMacro(Alpha, VectorType);
173 
175  itkGetConstReferenceMacro(Alpha, VectorType);
176 
178  itkSetMacro(Beta, VectorType);
179 
181  itkGetConstReferenceMacro(Beta, VectorType);
182 
184  itkSetMacro(SolarIllumination, VectorType);
185 
187  itkGetConstReferenceMacro(SolarIllumination, VectorType);
188 
190  itkSetMacro(ZenithalSolarAngle, double);
191 
193  itkGetConstReferenceMacro(ZenithalSolarAngle, double);
194 
196  virtual void SetElevationSolarAngle(double elevationAngle)
197  {
198  double zenithalAngle = 90.0 - elevationAngle;
199  if (this->m_ZenithalSolarAngle != zenithalAngle)
200  {
201  this->m_ZenithalSolarAngle = zenithalAngle;
202  this->Modified();
203  }
204  }
206 
207  virtual double GetElevationSolarAngle() const
208  {
209  return 90.0 - this->m_ZenithalSolarAngle;
210  }
211 
214  {
215  m_FluxNormalizationCoefficient = coef;
216  m_IsSetFluxNormalizationCoefficient = true;
217  this->Modified();
218  }
220 
222  void SetSolarDistance(double value)
223  {
224  m_SolarDistance = value;
225  m_IsSetSolarDistance = true;
226  this->Modified();
227  }
228 
230  itkGetConstReferenceMacro(SolarDistance, double);
231 
233  itkSetMacro(IsSetSolarDistance, bool);
234 
236  itkGetConstReferenceMacro(IsSetSolarDistance, bool);
237 
239  itkSetClampMacro(Day, int, 1, 31);
240 
242  itkGetConstReferenceMacro(Day, int);
243 
245  itkSetClampMacro(Month, int, 1, 12);
246 
248  itkGetConstReferenceMacro(Month, int);
249 
250 protected:
253  : m_ZenithalSolarAngle(120.), // invalid value which will lead to negative radiometry
254  m_FluxNormalizationCoefficient(1.),
255  m_IsSetFluxNormalizationCoefficient(false),
256  m_Day(0),
257  m_Month(0),
258  m_SolarDistance(1.0),
259  m_IsSetSolarDistance(false)
260  {
261  m_Alpha.SetSize(0);
262  m_Beta.SetSize(0);
263  m_SolarIllumination.SetSize(0);
264  };
266 
269  {
270  }
271 
273  void BeforeThreadedGenerateData(void) override
274  {
275  const auto & metadata = this->GetInput()->GetImageMetadata();
276 
277  if (m_Alpha.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalGain))
278  {
279  m_Alpha = metadata.GetAsVector(MDNum::PhysicalGain);
280  }
281 
282  if (m_Beta.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalBias))
283  {
284  m_Beta = metadata.GetAsVector(MDNum::PhysicalBias);
285  }
286 
287  if (m_Day == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
288  && metadata.Has(MDTime::AcquisitionDate))
289  {
290  m_Day = metadata[MDTime::AcquisitionDate].GetDay();
291  }
292 
293  if (m_Month == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
294  && metadata.Has(MDTime::AcquisitionDate))
295  {
296  m_Month = metadata[MDTime::AcquisitionDate].GetMonth();
297  }
298 
299  if (m_SolarIllumination.GetSize() == 0 && metadata.HasBandMetadata(MDNum::SolarIrradiance))
300  {
301  m_SolarIllumination = metadata.GetAsVector(MDNum::SolarIrradiance);
302  }
303 
304  if (m_ZenithalSolarAngle == 120.0 && metadata.Has(MDNum::SunElevation))
305  {
306  // the zenithal angle is the complementary of the elevation angle
307  m_ZenithalSolarAngle = 90.0 - metadata[MDNum::SunElevation];
308  }
309 
310  otbMsgDevMacro(<< "Using correction parameters: ");
311  otbMsgDevMacro(<< "Alpha (gain): " << m_Alpha);
312  otbMsgDevMacro(<< "Beta (bias): " << m_Beta);
313  otbMsgDevMacro(<< "Day: " << m_Day);
314  otbMsgDevMacro(<< "Month: " << m_Month);
315  otbMsgDevMacro(<< "Solar irradiance: " << m_SolarIllumination);
316  otbMsgDevMacro(<< "Zenithal angle: " << m_ZenithalSolarAngle);
317 
318  if ((m_Alpha.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()) || (m_Beta.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()) ||
319  (m_SolarIllumination.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()))
320  {
321  itkExceptionMacro(<< "Alpha, Beta and SolarIllumination parameters should have the same size as the number of bands");
322  }
323 
324  this->GetFunctorVector().clear();
325  for (unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
326  {
327  FunctorType functor;
328  double coefTemp = 0.;
329 
330  if (m_IsSetFluxNormalizationCoefficient)
331  {
332  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) * m_FluxNormalizationCoefficient * m_FluxNormalizationCoefficient;
333  }
334  else if (m_IsSetSolarDistance)
335  {
336  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) / (m_SolarDistance * m_SolarDistance);
337  }
338  else if (m_Day * m_Month != 0 && m_Day < 32 && m_Month < 13)
339  {
340  coefTemp = std::cos(m_ZenithalSolarAngle * CONST_PI_180) * VarSol::GetVarSol(m_Day, m_Month);
341  }
342  else
343  {
344  itkExceptionMacro(<< "Day has to be included between 1 and 31, Month between 1 and 12.");
345  }
346 
347  functor.SetIlluminationCorrectionCoefficient(coefTemp);
348  functor.SetAlpha(m_Alpha[i]);
349  functor.SetBeta(m_Beta[i]);
350  functor.SetSolarIllumination(m_SolarIllumination[i]);
351  this->GetFunctorVector().push_back(functor);
352  }
353  }
354 
355 private:
359 
362 
365 
368 
372 
374  int m_Day;
375 
377  int m_Month;
378 
381 
385 };
386 
387 } // end namespace otb
388 
389 #endif
otb::ReflectanceToImageImageFilter::ReflectanceToImageImageFilter
ReflectanceToImageImageFilter()
Definition: otbReflectanceToImageImageFilter.h:252
otb::Functor::RadianceToImageImageFunctor
Subtract beta to the Input and multiply by alpha.
Definition: otbRadianceToImageImageFilter.h:47
otb::Functor::ReflectanceToImageImageFunctor::GetBeta
double GetBeta()
Definition: otbReflectanceToImageImageFilter.h:80
otb::ReflectanceToImageImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbReflectanceToImageImageFilter.h:150
otb::ReflectanceToImageImageFilter::VectorType
itk::VariableLengthVector< double > VectorType
Definition: otbReflectanceToImageImageFilter.h:166
otb::Functor::ReflectanceToImageImageFunctor::operator()
TOutput operator()(const TInput &inPixel) const
Definition: otbReflectanceToImageImageFilter.h:93
otb::ReflectanceToImageImageFilter::m_Day
int m_Day
Definition: otbReflectanceToImageImageFilter.h:374
otb::Functor::ReflectanceToImageImageFunctor::ReflecToLumFunctorType
Functor::ReflectanceToRadianceImageFunctor< TInput, TOutput > ReflecToLumFunctorType
Definition: otbReflectanceToImageImageFilter.h:57
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::ReflectanceToImageImageFilter::m_SolarDistance
double m_SolarDistance
Definition: otbReflectanceToImageImageFilter.h:380
otb::Functor::ReflectanceToImageImageFunctor::ReflectanceToImageImageFunctor
ReflectanceToImageImageFunctor()
Definition: otbReflectanceToImageImageFilter.h:49
otb::ReflectanceToImageImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbReflectanceToImageImageFilter.h:149
otb::MDTime::AcquisitionDate
@ AcquisitionDate
otb::ReflectanceToImageImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbReflectanceToImageImageFilter.h:164
otb::Functor::ReflectanceToImageImageFunctor::SetIlluminationCorrectionCoefficient
void SetIlluminationCorrectionCoefficient(double coef)
Definition: otbReflectanceToImageImageFilter.h:71
otb::Functor::ReflectanceToImageImageFunctor::LumToImFunctorType
Functor::RadianceToImageImageFunctor< TInput, TOutput > LumToImFunctorType
Definition: otbReflectanceToImageImageFilter.h:56
otb::ReflectanceToImageImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbReflectanceToImageImageFilter.h:162
otb::ReflectanceToImageImageFilter::m_Beta
VectorType m_Beta
Definition: otbReflectanceToImageImageFilter.h:358
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::ReflectanceToRadianceImageFunctor::SetIlluminationCorrectionCoefficient
void SetIlluminationCorrectionCoefficient(double coef)
Definition: otbReflectanceToRadianceImageFilter.h:66
otb::ReflectanceToImageImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbReflectanceToImageImageFilter.h:156
otb::MDNum::PhysicalBias
@ PhysicalBias
otb::Functor::ReflectanceToImageImageFunctor::SetAlpha
void SetAlpha(double alpha)
Definition: otbReflectanceToImageImageFilter.h:59
otb::Functor::ReflectanceToImageImageFunctor::SetBeta
void SetBeta(double beta)
Definition: otbReflectanceToImageImageFilter.h:63
otb::Functor::RadianceToImageImageFunctor::GetBeta
double GetBeta()
Definition: otbRadianceToImageImageFilter.h:70
otb::ReflectanceToImageImageFilter::FunctorType
Functor::ReflectanceToImageImageFunctor< typename InputImageType::InternalPixelType, typename OutputImageType::InternalPixelType > FunctorType
Definition: otbReflectanceToImageImageFilter.h:144
otb::ReflectanceToImageImageFilter::Self
ReflectanceToImageImageFilter Self
Definition: otbReflectanceToImageImageFilter.h:147
otb::CONST_PI_180
constexpr double CONST_PI_180
Definition: otbMath.h:56
otb::ReflectanceToImageImageFilter::Superclass
UnaryImageFunctorWithVectorImageFilter< InputImageType, OutputImageType, FunctorType > Superclass
Definition: otbReflectanceToImageImageFilter.h:148
otb::UnaryImageFunctorWithVectorImageFilter
Applies a functor to a VectorImage.
Definition: otbUnaryImageFunctorWithVectorImageFilter.h:46
otb::Functor::ReflectanceToImageImageFunctor::GetAlpha
double GetAlpha()
Definition: otbReflectanceToImageImageFilter.h:76
otb::ReflectanceToImageImageFilter::GetElevationSolarAngle
virtual double GetElevationSolarAngle() const
Definition: otbReflectanceToImageImageFilter.h:207
otb::ReflectanceToImageImageFilter::SizeType
InputImageType::SizeType SizeType
Definition: otbReflectanceToImageImageFilter.h:169
otb::ReflectanceToImageImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData(void) override
Definition: otbReflectanceToImageImageFilter.h:273
otbRadianceToImageImageFilter.h
otb::ReflectanceToImageImageFilter::m_Alpha
VectorType m_Alpha
Definition: otbReflectanceToImageImageFilter.h:357
otb::ReflectanceToImageImageFilter::m_IsSetSolarDistance
bool m_IsSetSolarDistance
Definition: otbReflectanceToImageImageFilter.h:384
otb::Functor::ReflectanceToImageImageFunctor::GetIlluminationCorrectionCoefficient
double GetIlluminationCorrectionCoefficient()
Definition: otbReflectanceToImageImageFilter.h:88
otb::ReflectanceToImageImageFilter::m_IsSetFluxNormalizationCoefficient
bool m_IsSetFluxNormalizationCoefficient
Definition: otbReflectanceToImageImageFilter.h:371
otb::ReflectanceToImageImageFilter::m_Month
int m_Month
Definition: otbReflectanceToImageImageFilter.h:377
otb::Functor::ReflectanceToRadianceImageFunctor::GetSolarIllumination
double GetSolarIllumination()
Definition: otbReflectanceToRadianceImageFilter.h:71
otb::MDNum::PhysicalGain
@ PhysicalGain
otb::ReflectanceToImageImageFilter::SetFluxNormalizationCoefficient
void SetFluxNormalizationCoefficient(double coef)
Definition: otbReflectanceToImageImageFilter.h:213
otb::ReflectanceToImageImageFilter::m_FluxNormalizationCoefficient
double m_FluxNormalizationCoefficient
Definition: otbReflectanceToImageImageFilter.h:364
otb::ReflectanceToImageImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbReflectanceToImageImageFilter.h:143
otb::ReflectanceToImageImageFilter::InputInternalPixelType
InputImageType::InternalPixelType InputInternalPixelType
Definition: otbReflectanceToImageImageFilter.h:160
otb::Functor::ReflectanceToRadianceImageFunctor::SetSolarIllumination
void SetSolarIllumination(double solarIllumination)
Definition: otbReflectanceToRadianceImageFilter.h:62
otb::ReflectanceToImageImageFilter::InputImageType
TInputImage InputImageType
Definition: otbReflectanceToImageImageFilter.h:142
otb::Functor::ReflectanceToImageImageFunctor::m_ReflecToLumFunctor
ReflecToLumFunctorType m_ReflecToLumFunctor
Definition: otbReflectanceToImageImageFilter.h:105
otbReflectanceToRadianceImageFilter.h
otb::ReflectanceToImageImageFilter::SetSolarDistance
void SetSolarDistance(double value)
Definition: otbReflectanceToImageImageFilter.h:222
otb::Functor::ReflectanceToImageImageFunctor::m_LumToImFunctor
LumToImFunctorType m_LumToImFunctor
Definition: otbReflectanceToImageImageFilter.h:104
otb::Functor::RadianceToImageImageFunctor::GetAlpha
double GetAlpha()
Definition: otbRadianceToImageImageFilter.h:66
otb::VarSol::GetVarSol
static double GetVarSol(const int day, const int month)
Definition: otbVarSol.h:47
otb::ReflectanceToImageImageFilter::m_ZenithalSolarAngle
double m_ZenithalSolarAngle
Definition: otbReflectanceToImageImageFilter.h:361
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::Functor::ReflectanceToImageImageFunctor
Call the ReflectanceToRadianceFunctor over the input and the RadianceToImageFunctor to this result.
Definition: otbReflectanceToImageImageFilter.h:46
otb::ReflectanceToImageImageFilter::m_SolarIllumination
VectorType m_SolarIllumination
Definition: otbReflectanceToImageImageFilter.h:367
otb::Functor::ReflectanceToImageImageFunctor::SetSolarIllumination
void SetSolarIllumination(double solarIllumination)
Definition: otbReflectanceToImageImageFilter.h:67
otb::ReflectanceToImageImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbReflectanceToImageImageFilter.h:161
otb::ReflectanceToImageImageFilter::OutputInternalPixelType
OutputImageType::InternalPixelType OutputInternalPixelType
Definition: otbReflectanceToImageImageFilter.h:163
otb::Functor::ReflectanceToRadianceImageFunctor::GetIlluminationCorrectionCoefficient
double GetIlluminationCorrectionCoefficient()
Definition: otbReflectanceToRadianceImageFilter.h:75
otb::Functor::ReflectanceToImageImageFunctor::GetSolarIllumination
double GetSolarIllumination()
Definition: otbReflectanceToImageImageFilter.h:84
otb::ReflectanceToImageImageFilter::~ReflectanceToImageImageFilter
~ReflectanceToImageImageFilter() override
Definition: otbReflectanceToImageImageFilter.h:268
otb::ReflectanceToImageImageFilter::SetElevationSolarAngle
virtual void SetElevationSolarAngle(double elevationAngle)
Definition: otbReflectanceToImageImageFilter.h:196
otb::Functor::ReflectanceToImageImageFunctor::~ReflectanceToImageImageFunctor
virtual ~ReflectanceToImageImageFunctor()
Definition: otbReflectanceToImageImageFilter.h:52
otb::MDNum::SolarIrradiance
@ SolarIrradiance
otb::Functor::ReflectanceToRadianceImageFunctor
Compute radiance from the reflectance value.
Definition: otbReflectanceToRadianceImageFilter.h:51
otb::ReflectanceToImageImageFilter
Convert a reflectance into a raw value value.
Definition: otbReflectanceToImageImageFilter.h:130
otb::MDNum::SunElevation
@ SunElevation