OTB  10.0.0
Orfeo Toolbox
otbSurfaceReflectanceToReflectanceFilter.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 otbSurfaceReflectanceToReflectanceFilter_h
23 #define otbSurfaceReflectanceToReflectanceFilter_h
24 
25 
27 
29 #include "itkMetaDataDictionary.h"
30 // #include "itkFactory.h"
31 namespace otb
32 {
33 namespace Functor
34 {
44 template <class TInput, class TOutput>
45 class ReflectanceToSurfaceReflectanceImageFunctor
46 {
47 public:
48 
51 
53  {
54  m_Coefficient = 1.;
55  m_Residu = 1.;
56  m_SphericalAlbedo = 1.;
57  };
59 
63  void SetSphericalAlbedo(double albedo)
64  {
65  m_SphericalAlbedo = albedo;
66  };
68  {
69  return m_SphericalAlbedo;
70  };
72 
76  void SetCoefficient(double coef)
77  {
78  m_Coefficient = coef;
79  };
80  double GetCoefficient()
81  {
82  return m_Coefficient;
83  };
85 
89  void SetResidu(double res)
90  {
91  m_Residu = res;
92  };
93  double GetResidu()
94  {
95  return m_Residu;
96  };
98 
99  inline TOutput operator()(const TInput& inPixel)
100  {
101  // std::cout << "m_Coefficient "<< m_Coefficient << std::endl;
102  // std::cout << "m_Residu "<< m_Residu << std::endl;
103 
104  TOutput outPixel;
105  // outPixel.first = inPixel.first;
106  double temp, temp1, temp2;
107  // temp = static_cast<double>(inPixel)*m_Coefficient + m_Residu;
108  // temp2 = temp / (1. + m_SphericalAlbedo * temp);
109 
110  temp = 1. - (static_cast<double>(inPixel) * m_SphericalAlbedo);
111  // temp1 = 1/temp;
112 
113  // std::cout << "------------------------------" << std::endl;
114  // std::cout << "B "<< temp << std::endl;
115  // std::cout << "B*residu "<< temp*m_Residu << std::endl;
116  // std::cout << "m_Coefficient*static_cast<double>(inPixel) "<< m_Coefficient*static_cast<double>(inPixel) << std::endl;
117  // std::cout << "albedo "<< m_SphericalAlbedo << std::endl;
118  // std::cout << "all gaz "<< m_Coefficient << std::endl;
119  // std::cout << "residu "<< m_Residu << std::endl;
120  // std::cout << "temp2 "<< temp2 << std::endl;
121  temp2 = m_Residu;
122  // std::cout << "temp2 "<< temp2 << std::endl;
123  temp1 = 1. / temp;
124  // std::cout << "temp1 "<< temp1 << std::endl;
125  temp2 += temp1 * m_Coefficient * static_cast<double>(inPixel);
126  // std::cout << "1-row*S "<< temp << std::endl;
127  // outPixel = std::fabs (static_cast<TOutput>(temp2));
128  outPixel = static_cast<TOutput>(temp2);
129 
130  // std::cout << "in out "<< static_cast<double>(inPixel) << "; " << static_cast<double>(outPixel)<< std::endl;
131  // std::cout <<"plot " << m_Residu << "+" << m_Coefficient << "*(x/(1-x*" << m_SphericalAlbedo << "))" << std::endl;
132  // std::cout << "------------------------------" << std::endl;
133  return outPixel;
134  }
136  bool operator==(const Self& func) const
137  {
138  return ((m_SphericalAlbedo == func.m_SphericalAlbedo) && (m_Coefficient == func.m_Coefficient) && (m_Residu == func.m_Residu));
139  }
140 
142  bool operator!=(const Self& func) const
143  {
144  return ((m_SphericalAlbedo != func.m_SphericalAlbedo) && (m_Coefficient != func.m_Coefficient) && (m_Residu != func.m_Residu));
145  }
146 
147 private:
148  double m_SphericalAlbedo;
149  double m_Coefficient;
150  double m_Residu;
151 };
152 }
165 template <class TInputImage, class TOutputImage>
168  TInputImage, TOutputImage,
169  typename Functor::ReflectanceToSurfaceReflectanceImageFunctor<typename TInputImage::InternalPixelType, typename TOutputImage::InternalPixelType>>
170 {
171 public:
173  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
174  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
176 
178  typedef TInputImage InputImageType;
179  typedef TOutputImage OutputImageType;
182 
186  typedef itk::SmartPointer<Self> Pointer;
187  typedef itk::SmartPointer<const Self> ConstPointer;
188 
190  itkNewMacro(Self);
191 
194 
196  typedef typename InputImageType::PixelType InputPixelType;
197  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
198  typedef typename InputImageType::RegionType InputImageRegionType;
199  typedef typename OutputImageType::PixelType OutputPixelType;
200  typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
201  typedef typename OutputImageType::RegionType OutputImageRegionType;
202 
204 
207 
210 
213 
214 
218 
220 
221  typedef itk::MetaDataDictionary MetaDataDictionaryType;
222 
223 
226  {
227  m_AtmosphericRadiativeTerms = atmoRadTerms;
228  this->SetNthInput(1, m_AtmosphericRadiativeTerms);
229  m_IsSetAtmosphericRadiativeTerms = true;
230  this->Modified();
231  }
234 
237  {
238  m_AtmoCorrectionParameters = atmoCorrTerms;
239  this->SetNthInput(2, m_AtmoCorrectionParameters);
240  m_IsSetAtmoCorrectionParameters = true;
241  this->Modified();
242  }
245 
248  {
249  m_AcquiCorrectionParameters = acquiCorrTerms;
250  this->SetNthInput(3, m_AcquiCorrectionParameters);
251  m_IsSetAcquiCorrectionParameters = true;
252  this->Modified();
253  }
255 
256 
258  void GenerateParameters();
259 
261  itkSetMacro(UseGenerateParameters, bool);
262  itkGetMacro(UseGenerateParameters, bool);
264 
266  itkSetMacro(IsSetAtmosphericRadiativeTerms, bool);
267  itkGetMacro(IsSetAtmosphericRadiativeTerms, bool);
269 
270 
271 protected:
274 
277 
278 
280  void BeforeThreadedGenerateData() override;
281 
283  void UpdateAtmosphericRadiativeTerms();
284 
286  void UpdateFunctors();
287 
289  void Modified() const override;
290 
291 private:
295 
300 
302 
305 };
306 
307 } // end namespace otb
308 
309 #ifndef OTB_MANUAL_INSTANTIATION
311 #endif
312 
313 #endif
This class contains all atmospheric correction parameters.
This class is a vector of AtmosphericRadiativeTermsSingleChannel, it contains all atmospheric radiati...
This class contains the values of the filter function for the processed spectral band.
std::vector< WavelengthSpectralBandType > ValuesVectorType
Compute the surface reflectance pixel from a TOA reflectance.
This class contains all atmospheric correction parameters.
InternalWavelengthSpectralBandVectorType::Pointer WavelengthSpectralBandVectorType
Calculates the slope, the orientation incidence and exitance radius values for each pixel.
void SetAcquiCorrectionParameters(AcquiCorrectionParametersPointerType acquiCorrTerms)
UnaryImageFunctorWithVectorImageFilter< InputImageType, OutputImageType, FunctorType > Superclass
otb::RadiometryCorrectionParametersToAtmosphericRadiativeTerms CorrectionParametersToRadiativeTermsType
AcquiCorrectionParametersType::Pointer AcquiCorrectionParametersPointerType
otb::ImageMetadataCorrectionParameters AcquiCorrectionParametersType
itkGetObjectMacro(AtmosphericRadiativeTerms, AtmosphericRadiativeTermsType)
AtmoCorrectionParametersType::Pointer AtmoCorrectionParametersPointerType
itkGetObjectMacro(AtmoCorrectionParameters, AtmoCorrectionParametersType)
AcquiCorrectionParametersType::WavelengthSpectralBandVectorType WavelengthSpectralBandVectorType
Functor::ReflectanceToSurfaceReflectanceImageFunctor< typename InputImageType::InternalPixelType, typename OutputImageType::InternalPixelType > FunctorType
AtmosphericRadiativeTermsType::Pointer AtmosphericRadiativeTermsPointerType
FilterFunctionValuesType::WavelengthSpectralBandType ValueType
void SetAtmosphericRadiativeTerms(AtmosphericRadiativeTermsPointerType atmoRadTerms)
FilterFunctionValuesType::ValuesVectorType ValuesVectorType
void SetAtmoCorrectionParameters(AtmoCorrectionParametersPointerType atmoCorrTerms)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.