Commit 7f9b9e2d authored by Cédric Traizet's avatar Cédric Traizet

ENH: use ImageMetadata in OpticalCalibrationFilter when determining the default values

parent f65c8622
Pipeline #6249 failed with stages
in 92 minutes and 22 seconds
......@@ -10,9 +10,9 @@ SatAzimuth -74.1736
AcquisitionDate 2009-03-16T11:03:49.972847Z
ProductionDate 2009-03-26T11:56:45Z
BandName XS1
PhysicalGain 2.24793
PhysicalGain 3.04029
PhysicalBias 0
SolarIrradiance 1858
SolarIrradiance 1043
SpectralSensitivity LUT1D.DIM0.SIZE = 541
LUT1D.DIM0.ORIGIN = 0.45
LUT1D.DIM0.SPACING = 0.0025
......@@ -26,9 +26,9 @@ LUT1D.DIM0.ORIGIN = 0.45
LUT1D.DIM0.SPACING = 0.0025
LUT1D.ARRAY = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000767371 0.00153474 0.0104196 0.0193045 0.0615428 0.103781 0.200796 0.297811 0.412078 0.526345 0.620393 0.71444 0.780931 0.847421 0.886912 0.926403 0.95094 0.975478 0.985468 0.995459 0.997729 1 0.993748 0.987495 0.974977 0.962458 0.943181 0.923905 0.899244 0.874583 0.844649 0.814715 0.768634 0.722553 0.65867 0.594786 0.516931 0.439075 0.366208 0.293341 0.235793 0.178245 0.1414 0.104555 0.082136 0.0597166 0.0472382 0.0347598 0.0272426 0.0197255 0.0155478 0.01137 0.0090188 0.00666756 0.00509771 0.00352787 0.0028316 0.00213534 0.00106767 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BandName XS3
PhysicalGain 3.04029
PhysicalGain 2.24793
PhysicalBias 0
SolarIrradiance 1043
SolarIrradiance 1858
SpectralSensitivity LUT1D.DIM0.SIZE = 541
LUT1D.DIM0.ORIGIN = 0.45
LUT1D.DIM0.SPACING = 0.0025
......
......@@ -11,9 +11,9 @@ AcquisitionDate 2003-07-23T07:27:43.889716Z
ProductionDate 2003-12-05T08:21:19Z
GCP <GCPParam>
BandName XS1
PhysicalGain 1.0032
PhysicalGain 1.3812
PhysicalBias 0
SolarIrradiance 1858
SolarIrradiance 1047
SpectralSensitivity LUT1D.DIM0.SIZE = 541
LUT1D.DIM0.ORIGIN = 0.45
LUT1D.DIM0.SPACING = 0.0025
......@@ -27,9 +27,9 @@ LUT1D.DIM0.ORIGIN = 0.45
LUT1D.DIM0.SPACING = 0.0025
LUT1D.ARRAY = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000767371 0.00153474 0.0104196 0.0193045 0.0615428 0.103781 0.200796 0.297811 0.412078 0.526345 0.620393 0.71444 0.780931 0.847421 0.886912 0.926403 0.95094 0.975478 0.985468 0.995459 0.997729 1 0.993748 0.987495 0.974977 0.962458 0.943181 0.923905 0.899244 0.874583 0.844649 0.814715 0.768634 0.722553 0.65867 0.594786 0.516931 0.439075 0.366208 0.293341 0.235793 0.178245 0.1414 0.104555 0.082136 0.0597166 0.0472382 0.0347598 0.0272426 0.0197255 0.0155478 0.01137 0.0090188 0.00666756 0.00509771 0.00352787 0.0028316 0.00213534 0.00106767 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BandName XS3
PhysicalGain 1.3812
PhysicalGain 1.0032
PhysicalBias 0
SolarIrradiance 1047
SolarIrradiance 1858
SpectralSensitivity LUT1D.DIM0.SIZE = 541
LUT1D.DIM0.ORIGIN = 0.45
LUT1D.DIM0.SPACING = 0.0025
......
......@@ -305,6 +305,12 @@ public:
/** Getter for numeric keys on each band*/
itk::VariableLengthVector<double> GetAsVector(const MDNum & key) const;
/** test wether the metadata corresponding to key is present on each band */
bool HasBandMetadata(const MDNum & key) const;
/** test wether the metadata corresponding to key is present on each band */
bool HasBandMetadata(const MDL1D & key) const;
};
extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::ImageMetadataBase& imd);
......
......@@ -1461,30 +1461,31 @@ void FormosatImageMetadataInterface::Parse(const MetadataSupplierInterface & mds
solarIrradianceVec = dimapData.SolarIrradiance;
}
if (dimapData.PhysicalBias.size() == nbBands
&& dimapData.PhysicalGain.size() == nbBands
&& solarIrradianceVec.size() == nbBands)
auto setDimapBandMetadata = [this](const MDNum & key, const std::vector<double> & input)
{
auto bias = dimapData.PhysicalBias.begin();
auto gain = dimapData.PhysicalGain.begin();
auto solarIrradiance = solarIrradianceVec.begin();
for (auto & band: m_Imd.Bands)
if (input.size() == 1)
{
band.Add(MDNum::PhysicalGain, *gain);
band.Add(MDNum::PhysicalBias, *bias);
band.Add(MDNum::SolarIrradiance, *solarIrradiance);
bias++;
gain++;
solarIrradiance++;
// this is a PAN image
m_Imd.Bands[0].Add(key, input[0]);
}
}
else
{
otbGenericExceptionMacro(MissingMetadataException,
else if (input.size() == 4)
{
// MS image, note the band ordering
m_Imd.Bands[0].Add(key, input[2]);
m_Imd.Bands[1].Add(key, input[1]);
m_Imd.Bands[2].Add(key, input[0]);
m_Imd.Bands[3].Add(key, input[3]);
}
else
{
otbGenericExceptionMacro(MissingMetadataException,
<< "The number of bands in image metadatas is incoherent with the DIMAP product")
}
}
};
setDimapBandMetadata(MDNum::PhysicalBias, dimapData.PhysicalBias);
setDimapBandMetadata(MDNum::PhysicalGain, dimapData.PhysicalGain);
setDimapBandMetadata(MDNum::SolarIrradiance, solarIrradianceVec);
FetchSpectralSensitivity();
......
......@@ -645,6 +645,19 @@ itk::VariableLengthVector<double> ImageMetadata::GetAsVector(const MDNum& key) c
return output;
}
bool ImageMetadata::HasBandMetadata(const MDNum & key) const
{
return std::all_of(Bands.begin(), Bands.end(),
[key](ImageMetadataBase band){return band.Has(key);});
}
bool ImageMetadata::HasBandMetadata(const MDL1D & key) const
{
return std::all_of(Bands.begin(), Bands.end(),
[key](ImageMetadataBase band){return band.Has(key);});
}
// printing
std::ostream& operator<<(std::ostream& os, const otb::ImageMetadataBase& imd)
{
......
......@@ -1806,31 +1806,39 @@ void SpotImageMetadataInterface::Parse(const MetadataSupplierInterface & mds)
m_Imd.Add(MDNum::SatAzimuth, dimapData.SceneOrientation[0] - 90);
}
auto nbBands = m_Imd.Bands.size();
if (dimapData.PhysicalBias.size() == nbBands
&& dimapData.PhysicalGain.size() == nbBands
&& dimapData.SolarIrradiance.size() == nbBands)
auto setDimapBandMetadata = [this](const MDNum & key, const std::vector<double> & input)
{
auto bias = dimapData.PhysicalBias.begin();
auto gain = dimapData.PhysicalGain.begin();
auto solarIrradiance = dimapData.SolarIrradiance.begin();
for (auto & band: m_Imd.Bands)
if (input.size() == 1)
{
band.Add(MDNum::PhysicalGain, *gain);
band.Add(MDNum::PhysicalBias, *bias);
band.Add(MDNum::SolarIrradiance, *solarIrradiance);
bias++;
gain++;
solarIrradiance++;
// this is a PAN image
m_Imd.Bands[0].Add(key, input[0]);
}
}
else
{
otbGenericExceptionMacro(MissingMetadataException,
else if (input.size() == 4)
{
// MS image, note the band ordering
m_Imd.Bands[0].Add(key, input[2]);
m_Imd.Bands[1].Add(key, input[1]);
m_Imd.Bands[2].Add(key, input[0]);
m_Imd.Bands[3].Add(key, input[3]);
}
else if (input.size() == 3)
{
m_Imd.Bands[0].Add(key, input[2]);
m_Imd.Bands[1].Add(key, input[1]);
m_Imd.Bands[2].Add(key, input[0]);
}
else
{
otbGenericExceptionMacro(MissingMetadataException,
<< "The number of bands in image metadatas is incoherent with the DIMAP product")
}
}
};
setDimapBandMetadata(MDNum::PhysicalBias, dimapData.PhysicalBias);
setDimapBandMetadata(MDNum::PhysicalGain, dimapData.PhysicalGain);
setDimapBandMetadata(MDNum::SolarIrradiance, dimapData.SolarIrradiance);
auto nbBands = m_Imd.Bands.size();
// band IDs is not parsed in geom files. There are two possible cases: panchromatic and multispectral
if (dimapData.BandIDs.empty())
......
......@@ -2202,7 +2202,7 @@ namespace
// In previous version of OTB the effective bandwith was tabulated
// because Ossim did not read this specific metadata.
outMetadata.effectiveBandwidth[bandName] = mds.GetAs<double>(prefix + "effectiveBandwidth");
outMetadata.effectiveBandwidth[bandName] = mds.GetAs<double>(0., prefix + "effectiveBandwidth");
outMetadata.absCalFactor[bandName] = mds.GetAs<double>(prefix + "absCalFactor");
......
......@@ -172,15 +172,16 @@ protected:
/** Update the functor list and input parameters */
void BeforeThreadedGenerateData(void) override
{
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(this->GetInput()->GetMetaDataDictionary());
if (m_Alpha.GetSize() == 0)
const auto & metadata = this->GetInput()->GetImageMetadata();
if (m_Alpha.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalGain))
{
m_Alpha = imageMetadataInterface->GetPhysicalGain();
m_Alpha = metadata.GetAsVector(MDNum::PhysicalGain);
}
if (m_Beta.GetSize() == 0)
if (m_Beta.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalBias))
{
m_Beta = imageMetadataInterface->GetPhysicalBias();
m_Beta = metadata.GetAsVector(MDNum::PhysicalBias);
}
otbMsgDevMacro(<< "Dimension: ");
......
......@@ -272,37 +272,39 @@ protected:
/** Update the functor list and input parameters */
void BeforeThreadedGenerateData(void) override
{
const auto & metadata = this->GetInput()->GetImageMetadata();
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(this->GetInput()->GetMetaDataDictionary());
if (m_Alpha.GetSize() == 0)
if (m_Alpha.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalGain))
{
m_Alpha = imageMetadataInterface->GetPhysicalGain();
m_Alpha = metadata.GetAsVector(MDNum::PhysicalGain);
}
if (m_Beta.GetSize() == 0)
if (m_Beta.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalBias))
{
m_Beta = imageMetadataInterface->GetPhysicalBias();
m_Beta = metadata.GetAsVector(MDNum::PhysicalBias);
}
if ((m_Day == 0) && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance))
if (m_Day == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
&& metadata.Has(MDTime::AcquisitionDate))
{
m_Day = imageMetadataInterface->GetDay();
m_Day = metadata[MDTime::AcquisitionDate].GetDay();
}
if ((m_Month == 0) && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance))
if (m_Month == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
&& metadata.Has(MDTime::AcquisitionDate))
{
m_Month = imageMetadataInterface->GetMonth();
m_Month = metadata[MDTime::AcquisitionDate].GetMonth();
}
if (m_SolarIllumination.GetSize() == 0)
if (m_SolarIllumination.GetSize() == 0 && metadata.HasBandMetadata(MDNum::SolarIrradiance))
{
m_SolarIllumination = imageMetadataInterface->GetSolarIrradiance();
m_SolarIllumination = metadata.GetAsVector(MDNum::SolarIrradiance);
}
if (m_ZenithalSolarAngle == 120.0)
if (m_ZenithalSolarAngle == 120.0 && metadata.Has(MDNum::SunElevation))
{
// the zenithal angle is the complementary of the elevation angle
m_ZenithalSolarAngle = 90.0 - imageMetadataInterface->GetSunElevation();
m_ZenithalSolarAngle = 90.0 - metadata[MDNum::SunElevation];
}
otbMsgDevMacro(<< "Using correction parameters: ");
......
......@@ -173,15 +173,16 @@ protected:
/** Update the functor list and input parameters */
void BeforeThreadedGenerateData(void) override
{
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(this->GetInput()->GetMetaDataDictionary());
if (m_Alpha.GetSize() == 0)
const auto & metadata = this->GetInput()->GetImageMetadata();
if (m_Alpha.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalGain))
{
m_Alpha = imageMetadataInterface->GetPhysicalGain();
m_Alpha = metadata.GetAsVector(MDNum::PhysicalGain);
}
if (m_Beta.GetSize() == 0)
if (m_Beta.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalBias))
{
m_Beta = imageMetadataInterface->GetPhysicalBias();
m_Beta = metadata.GetAsVector(MDNum::PhysicalBias);
}
otbMsgDevMacro(<< "Dimension: ");
......
......@@ -261,26 +261,29 @@ protected:
/** Update the functor list and input parameters */
void BeforeThreadedGenerateData(void) override
{
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(this->GetInput()->GetMetaDataDictionary());
if ((m_Day == 0) && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance))
const auto & metadata = this->GetInput()->GetImageMetadata();
if (m_Day == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
&& metadata.Has(MDTime::AcquisitionDate))
{
m_Day = imageMetadataInterface->GetDay();
m_Day = metadata[MDTime::AcquisitionDate].GetDay();
}
if ((m_Month == 0) && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance))
if (m_Month == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
&& metadata.Has(MDTime::AcquisitionDate))
{
m_Month = imageMetadataInterface->GetMonth();
m_Month = metadata[MDTime::AcquisitionDate].GetMonth();
}
if (m_SolarIllumination.GetSize() == 0)
if (m_SolarIllumination.GetSize() == 0 && metadata.HasBandMetadata(MDNum::SolarIrradiance))
{
m_SolarIllumination = imageMetadataInterface->GetSolarIrradiance();
m_SolarIllumination = metadata.GetAsVector(MDNum::SolarIrradiance);
}
if (m_ZenithalSolarAngle == 120.0)
if (m_ZenithalSolarAngle == 120.0 && metadata.Has(MDNum::SunElevation))
{
// the zenithal angle is the complementary of the elevation angle
m_ZenithalSolarAngle = 90.0 - imageMetadataInterface->GetSunElevation();
m_ZenithalSolarAngle = 90.0 - metadata[MDNum::SunElevation];
}
otbMsgDevMacro(<< "Using correction parameters: ");
......
......@@ -258,37 +258,39 @@ protected:
/** Update the functor list and input parameters */
void BeforeThreadedGenerateData(void) override
{
const auto & metadata = this->GetInput()->GetImageMetadata();
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(this->GetInput()->GetMetaDataDictionary());
if (m_Alpha.GetSize() == 0)
if (m_Alpha.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalGain))
{
m_Alpha = imageMetadataInterface->GetPhysicalGain();
m_Alpha = metadata.GetAsVector(MDNum::PhysicalGain);
}
if (m_Beta.GetSize() == 0)
if (m_Beta.GetSize() == 0 && metadata.HasBandMetadata(MDNum::PhysicalBias))
{
m_Beta = imageMetadataInterface->GetPhysicalBias();
m_Beta = metadata.GetAsVector(MDNum::PhysicalBias);
}
if ((m_Day == 0) && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance))
if (m_Day == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
&& metadata.Has(MDTime::AcquisitionDate))
{
m_Day = imageMetadataInterface->GetDay();
m_Day = metadata[MDTime::AcquisitionDate].GetDay();
}
if ((m_Month == 0) && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance))
if (m_Month == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
&& metadata.Has(MDTime::AcquisitionDate))
{
m_Month = imageMetadataInterface->GetMonth();
m_Month = metadata[MDTime::AcquisitionDate].GetMonth();
}
if (m_SolarIllumination.GetSize() == 0)
if (m_SolarIllumination.GetSize() == 0 && metadata.HasBandMetadata(MDNum::SolarIrradiance))
{
m_SolarIllumination = imageMetadataInterface->GetSolarIrradiance();
m_SolarIllumination = metadata.GetAsVector(MDNum::SolarIrradiance);
}
if (m_ZenithalSolarAngle == 120.0)
if (m_ZenithalSolarAngle == 120.0 && metadata.Has(MDNum::SunElevation))
{
// the zenithal angle is the complementary of the elevation angle
m_ZenithalSolarAngle = 90.0 - imageMetadataInterface->GetSunElevation();
m_ZenithalSolarAngle = 90.0 - metadata[MDNum::SunElevation];
}
otbMsgDevMacro(<< "Using correction parameters: ");
......
......@@ -244,26 +244,29 @@ protected:
/** Update the functor list and input parameters */
void BeforeThreadedGenerateData(void) override
{
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(this->GetInput()->GetMetaDataDictionary());
if ((m_Day == 0) && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance))
const auto & metadata = this->GetInput()->GetImageMetadata();
if (m_Day == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
&& metadata.Has(MDTime::AcquisitionDate))
{
m_Day = imageMetadataInterface->GetDay();
m_Day = metadata[MDTime::AcquisitionDate].GetDay();
}
if ((m_Month == 0) && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance))
if (m_Month == 0 && (!m_IsSetFluxNormalizationCoefficient) && (!m_IsSetSolarDistance)
&& metadata.Has(MDTime::AcquisitionDate))
{
m_Month = imageMetadataInterface->GetMonth();
m_Month = metadata[MDTime::AcquisitionDate].GetMonth();
}
if (m_SolarIllumination.GetSize() == 0)
if (m_SolarIllumination.GetSize() == 0 && metadata.HasBandMetadata(MDNum::SolarIrradiance))
{
m_SolarIllumination = imageMetadataInterface->GetSolarIrradiance();
m_SolarIllumination = metadata.GetAsVector(MDNum::SolarIrradiance);
}
if (m_ZenithalSolarAngle == 120.0)
if (m_ZenithalSolarAngle == 120.0 && metadata.Has(MDNum::SunElevation))
{
// the zenithal angle is the complementary of the elevation angle
m_ZenithalSolarAngle = 90.0 - imageMetadataInterface->GetSunElevation();
m_ZenithalSolarAngle = 90.0 - metadata[MDNum::SunElevation];
}
otbMsgDevMacro(<< "Using correction parameters: ");
......
......@@ -96,34 +96,49 @@ void ReflectanceToSurfaceReflectanceImageFilter<TInputImage, TOutputImage>::Upda
SetFilterFunctionValuesFileName = true;
}
MetaDataDictionaryType dict = this->GetInput()->GetMetaDataDictionary();
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(dict);
const auto & metadata = this->GetInput()->GetImageMetadata();
if (m_AtmoCorrectionParameters->GetAeronetFileName() != "")
m_AtmoCorrectionParameters->UpdateAeronetData(imageMetadataInterface->GetYear(), imageMetadataInterface->GetHour(), imageMetadataInterface->GetMinute());
{
m_AtmoCorrectionParameters->UpdateAeronetData(metadata[MDTime::AcquisitionDate].GetYear(),
metadata[MDTime::AcquisitionDate].GetHour(),
metadata[MDTime::AcquisitionDate].GetMinute());
}
// Acquisition parameters
if (!m_IsSetAcquiCorrectionParameters) // Get info from image metadata interface
if (!m_IsSetAcquiCorrectionParameters) // Get info from image metadata
{
m_AcquiCorrectionParameters = AcquiCorrectionParametersType::New();
m_AcquiCorrectionParameters->SetSolarZenithalAngle(90. - imageMetadataInterface->GetSunElevation());
m_AcquiCorrectionParameters->SetSolarAzimutalAngle(imageMetadataInterface->GetSunAzimuth());
m_AcquiCorrectionParameters->SetViewingZenithalAngle(90. - imageMetadataInterface->GetSatElevation());
m_AcquiCorrectionParameters->SetViewingAzimutalAngle(imageMetadataInterface->GetSatAzimuth());
m_AcquiCorrectionParameters->SetSolarZenithalAngle(90. - metadata[MDNum::SunElevation]);
m_AcquiCorrectionParameters->SetSolarAzimutalAngle(metadata[MDNum::SunAzimuth]);
m_AcquiCorrectionParameters->SetViewingZenithalAngle(90. - metadata[MDNum::SatElevation]);
m_AcquiCorrectionParameters->SetViewingAzimutalAngle(metadata[MDNum::SatAzimuth]);
m_AcquiCorrectionParameters->SetDay(imageMetadataInterface->GetDay());
m_AcquiCorrectionParameters->SetMonth(imageMetadataInterface->GetMonth());
m_AcquiCorrectionParameters->SetDay(metadata[MDTime::AcquisitionDate].GetDay());
m_AcquiCorrectionParameters->SetMonth(metadata[MDTime::AcquisitionDate].GetMonth());
if (!SetFilterFunctionValuesFileName)
{
if (imageMetadataInterface->GetSpectralSensitivity()->Capacity() > 0)
if (metadata.HasBandMetadata(MDL1D::SpectralSensitivity))
{
m_AcquiCorrectionParameters->SetWavelengthSpectralBand(imageMetadataInterface->GetSpectralSensitivity());
auto spectralSensitivity = AcquiCorrectionParametersType::InternalWavelengthSpectralBandVectorType::New();
for (const auto & band : metadata.Bands)
{
const auto & spectralSensitivityLUT = band[MDL1D::SpectralSensitivity];
const auto & axis = spectralSensitivityLUT.Axis[0];
auto filterFunction = FilterFunctionValues::New();
// LUT1D stores a double vector whereas FilterFunctionValues stores a float vector
std::vector<float> vec(spectralSensitivityLUT.Array.begin(), spectralSensitivityLUT.Array.end());
filterFunction->SetFilterFunctionValues(vec);
filterFunction->SetMinSpectralValue(axis.Origin);
filterFunction->SetMaxSpectralValue(axis.Origin + axis.Spacing * axis.Size);
filterFunction->SetUserStep(axis.Spacing);
spectralSensitivity->PushBack(filterFunction);
}
m_AcquiCorrectionParameters->SetWavelengthSpectralBand(spectralSensitivity);
}
else
{
......@@ -152,9 +167,6 @@ void ReflectanceToSurfaceReflectanceImageFilter<TInputImage, TOutputImage>::Upda
itkExceptionMacro(<< "Input must be set before updating the functors");
}
MetaDataDictionaryType dict = this->GetInput()->GetMetaDataDictionary();
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(dict);
this->GetFunctorVector().clear();
for (unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
......
......@@ -83,25 +83,41 @@ void SurfaceAdjacencyEffectCorrectionSchemeFilter<TInputImage, TOutputImage>::Up
}
// Acquisition parameters
if (!m_IsSetAcquiCorrectionParameters) // Get info from image metadata interface
if (!m_IsSetAcquiCorrectionParameters) // Get info from image metadata
{
MetaDataDictionaryType dict = this->GetInput()->GetMetaDataDictionary();
OpticalImageMetadataInterface::Pointer imageMetadataInterface = OpticalImageMetadataInterfaceFactory::CreateIMI(dict);
const auto & metadata = this->GetInput()->GetImageMetadata();
m_AcquiCorrectionParameters = AcquiCorrectionParametersType::New();
m_AcquiCorrectionParameters->SetSolarZenithalAngle(90. - imageMetadataInterface->GetSunElevation());
m_AcquiCorrectionParameters->SetSolarAzimutalAngle(imageMetadataInterface->GetSunAzimuth());
m_AcquiCorrectionParameters->SetViewingZenithalAngle(90. - imageMetadataInterface->GetSatElevation());
m_AcquiCorrectionParameters->SetViewingAzimutalAngle(imageMetadataInterface->GetSatAzimuth());
m_AcquiCorrectionParameters->SetSolarZenithalAngle(90. - metadata[MDNum::SunElevation]);
m_AcquiCorrectionParameters->SetSolarAzimutalAngle(metadata[MDNum::SunAzimuth]);
m_AcquiCorrectionParameters->SetViewingZenithalAngle(90. - metadata[MDNum::SatElevation]);
m_AcquiCorrectionParameters->SetViewingAzimutalAngle(metadata[MDNum::SatAzimuth]);
m_AcquiCorrectionParameters->SetDay(metadata[MDTime::AcquisitionDate].GetDay());
m_AcquiCorrectionParameters->SetMonth(metadata[MDTime::AcquisitionDate].GetMonth());
m_AcquiCorrectionParameters->SetDay(imageMetadataInterface->GetDay());
m_AcquiCorrectionParameters->SetMonth(imageMetadataInterface->GetMonth());
if (imageMetadataInterface->GetSpectralSensitivity()->Capacity() > 0)
if (metadata.HasBandMetadata(MDL1D::SpectralSensitivity))
{
m_AcquiCorrectionParameters->SetWavelengthSpectralBand(imageMetadataInterface->GetSpectralSensitivity());
auto spectralSensitivity = AcquiCorrectionParametersType::InternalWavelengthSpectralBandVectorType::New();
for (const auto & band : metadata.Bands)
{
const auto & spectralSensitivityLUT = band[MDL1D::SpectralSensitivity];
const auto & axis = spectralSensitivityLUT.Axis[0];
auto filterFunction = FilterFunctionValues::New();
// LUT1D stores a double vector whereas FilterFunctionValues stores a float vector
std::vector<float> vec(spectralSensitivityLUT.Array.begin(), spectralSensitivityLUT.Array.end());
filterFunction->SetFilterFunctionValues(vec);
filterFunction->SetMinSpectralValue(axis.Origin);
filterFunction->SetMaxSpectralValue(axis.Origin + axis.Spacing * axis.Size);
filterFunction->SetUserStep(axis.Spacing);
spectralSensitivity->PushBack(filterFunction);
}
m_AcquiCorrectionParameters->SetWavelengthSpectralBand(spectralSensitivity);
}