OTB  10.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-2024 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
Subtract beta to the Input and multiply by alpha.
Call the ReflectanceToRadianceFunctor over the input and the RadianceToImageFunctor to this result.
Functor::ReflectanceToRadianceImageFunctor< TInput, TOutput > ReflecToLumFunctorType
Functor::RadianceToImageImageFunctor< TInput, TOutput > LumToImFunctorType
Convert a reflectance into a raw value value.
InputImageType::InternalPixelType InputInternalPixelType
virtual void SetElevationSolarAngle(double elevationAngle)
itk::VariableLengthVector< double > VectorType
OutputImageType::InternalPixelType OutputInternalPixelType
Functor::ReflectanceToImageImageFunctor< typename InputImageType::InternalPixelType, typename OutputImageType::InternalPixelType > FunctorType
UnaryImageFunctorWithVectorImageFilter< InputImageType, OutputImageType, FunctorType > Superclass
static double GetVarSol(const int day, const int month)
Definition: otbVarSol.h:47
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
constexpr double CONST_PI_180
Definition: otbMath.h:56
#define otbMsgDevMacro(x)
Definition: otbMacro.h:116