21 #ifndef otbReflectanceToSurfaceReflectanceImageFilter_hxx
22 #define otbReflectanceToSurfaceReflectanceImageFilter_hxx
32 template <
class TInputImage,
class TOutputImage>
34 : m_IsSetAtmosphericRadiativeTerms(false), m_IsSetAtmoCorrectionParameters(false), m_IsSetAcquiCorrectionParameters(false), m_UseGenerateParameters(true)
42 template <
class TInputImage,
class TOutputImage>
45 Superclass::BeforeThreadedGenerateData();
46 if (m_UseGenerateParameters)
47 this->GenerateParameters();
51 template <
class TInputImage,
class TOutputImage>
54 Superclass::Modified();
55 m_FunctorParametersHaveBeenComputed =
false;
59 template <
class TInputImage,
class TOutputImage>
62 if (!m_IsSetAtmosphericRadiativeTerms)
64 this->UpdateAtmosphericRadiativeTerms();
65 m_IsSetAtmosphericRadiativeTerms =
true;
68 if (!m_FunctorParametersHaveBeenComputed)
70 this->UpdateFunctors();
71 m_FunctorParametersHaveBeenComputed =
true;
76 template <
class TInputImage,
class TOutputImage>
79 if (this->GetInput() ==
nullptr)
81 itkExceptionMacro(<<
"Input must be set before updating the atmospheric radiative terms");
85 if (!m_IsSetAtmoCorrectionParameters)
87 itkExceptionMacro(<<
"Atmospheric correction parameters must be provided before updating the atmospheric radiative terms");
92 bool SetFilterFunctionValuesFileName =
false;
93 if (m_AcquiCorrectionParameters->GetFilterFunctionValuesFileName() !=
"")
95 m_AcquiCorrectionParameters->LoadFilterFunctionValue();
96 SetFilterFunctionValuesFileName =
true;
99 const auto & metadata = this->GetInput()->GetImageMetadata();
101 if (m_AtmoCorrectionParameters->GetAeronetFileName() !=
"")
109 if (!m_IsSetAcquiCorrectionParameters)
111 m_AcquiCorrectionParameters = AcquiCorrectionParametersType::New();
116 m_AcquiCorrectionParameters->SetViewingAzimutalAngle(metadata[
MDNum::SatAzimuth]);
122 if (!SetFilterFunctionValuesFileName)
126 auto spectralSensitivity = AcquiCorrectionParametersType::InternalWavelengthSpectralBandVectorType::New();
127 for (
const auto & band : metadata.Bands)
130 const auto & axis = spectralSensitivityLUT.Axis[0];
133 std::vector<float> vec(spectralSensitivityLUT.Array.begin(), spectralSensitivityLUT.Array.end());
134 filterFunction->SetFilterFunctionValues(vec);
135 filterFunction->SetMinSpectralValue(axis.Origin);
136 filterFunction->SetMaxSpectralValue(axis.Origin + axis.Spacing * (axis.Size-1));
137 filterFunction->SetUserStep(axis.Spacing);
138 spectralSensitivity->PushBack(filterFunction);
141 m_AcquiCorrectionParameters->SetWavelengthSpectralBand(spectralSensitivity);
147 spectralDummy->Clear();
148 for (
unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
150 spectralDummy->PushBack(FilterFunctionValuesType::New());
152 m_AcquiCorrectionParameters->SetWavelengthSpectralBand(spectralDummy);
158 m_AtmosphericRadiativeTerms = CorrectionParametersToRadiativeTermsType::Compute(m_AtmoCorrectionParameters, m_AcquiCorrectionParameters);
161 template <
class TInputImage,
class TOutputImage>
165 if (this->GetInput() ==
nullptr)
167 itkExceptionMacro(<<
"Input must be set before updating the functors");
170 this->GetFunctorVector().clear();
172 for (
unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
179 unsigned int wavelengthPosition = i;
181 coef =
static_cast<double>(m_AtmosphericRadiativeTerms->GetTotalGaseousTransmission(wavelengthPosition) *
182 m_AtmosphericRadiativeTerms->GetDownwardTransmittance(wavelengthPosition) *
183 m_AtmosphericRadiativeTerms->GetUpwardTransmittance(wavelengthPosition));
185 res = -m_AtmosphericRadiativeTerms->GetIntrinsicAtmosphericReflectance(wavelengthPosition);
189 functor.
SetSphericalAlbedo(
static_cast<double>(m_AtmosphericRadiativeTerms->GetSphericalAlbedo(wavelengthPosition)));
191 this->GetFunctorVector().push_back(functor);
195 otbMsgDevMacro(<<
"Band wavelengh position: " << wavelengthPosition);
204 template <
class TInputImage,
class TOutputImage>
207 os << indent <<
"Atmospheric radiative terms : " << m_AtmosphericRadiativeTerms << std::endl;
208 os << indent <<
"Atmospheric correction terms : " << m_AtmoCorrectionParameters << std::endl;
209 os << indent <<
"Acquisition correction terms : " << m_AcquiCorrectionParameters << std::endl;