Commit 3f9cc7e6 authored by Cédric Traizet's avatar Cédric Traizet

ENH: test optical image metadata interface and various bug fixes

parent 24b0532b
Pipeline #6035 failed with stages
in 106 minutes and 5 seconds
......@@ -160,6 +160,9 @@ public:
ParseVector(mds, prefix + "Radiometric_Data.Radiometric_Calibration.Instrument_Calibration.Band_Measurement_List.Band_Solar_Irradiance",
"VALUE" , m_Data.SolarIrradiance, defaultValue);
ParseVector(mds, prefix + "Data_Strip.Sensor_Calibration.Solar_Irradiance.Band_Solar_Irradiance",
"SOLAR_IRRADIANCE_VALUE" , m_Data.SolarIrradiance, defaultValue);
ParseVector(mds, prefix + "Dataset_Frame",
"SCENE_ORIENTATION" , m_Data.SceneOrientation);
......
......@@ -308,6 +308,8 @@ extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::
extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::ImageMetadata& imd);
OTBMetadata_EXPORT bool HasOpticalSensorMetadata(const ImageMetadata & imd);
} // end namespace otb
#endif
......@@ -1349,7 +1349,7 @@ void FormosatImageMetadataInterface::Parse(const MetadataSupplierInterface *mds)
XMLMetadataSupplier xmlMds(metadataFile);
DimapMetadataHelper helper;
helper.ParseDimapV1(xmlMds, "Dimap_Document.");
const auto & dimapData = helper.GetDimapData();
......
......@@ -653,4 +653,30 @@ std::ostream& operator<<(std::ostream& os, const otb::ImageMetadata& imd)
return os;
}
bool HasOpticalSensorMetadata(const ImageMetadata & imd)
{
auto hasBandMetadataNum = [&imd](MDNum key)
{return std::all_of(imd.Bands.begin(),
imd.Bands.end(),
[key](ImageMetadataBase band){return band.Has(key);});};
auto hasBandMetadataLut = [&imd](MDL1D key)
{return std::all_of(imd.Bands.begin(),
imd.Bands.end(),
[key](ImageMetadataBase band){return band.Has(key);});};
return imd.Has(MDStr::SensorID)
&& imd.Has(MDNum::SunElevation)
&& imd.Has(MDNum::SunAzimuth)
&& imd.Has(MDNum::SatElevation)
&& imd.Has(MDNum::SatAzimuth)
&& imd.Has(MDTime::AcquisitionDate)
&& imd.Has(MDTime::ProductionDate)
&& hasBandMetadataNum(MDNum::PhysicalBias)
&& hasBandMetadataNum(MDNum::PhysicalGain)
&& hasBandMetadataNum(MDNum::SolarIrradiance)
&& hasBandMetadataLut(MDL1D::SpectralSensitivity);
}
}
......@@ -26,6 +26,8 @@
#include "itkMetaDataObject.h"
#include "otbImageKeywordlist.h"
#include "otbXMLMetadataSupplier.h"
#include "otbDimapMetadataHelper.h"
namespace otb
......@@ -1759,30 +1761,54 @@ void SpotImageMetadataInterface::Parse(const MetadataSupplierInterface *mds)
otbGenericExceptionMacro(MissingMetadataException,<<"Not a spot 5 product")
}
DimapMetadataHelper helper;
//Find the METADATA.DIM file (Dimap V1 metadata file)
auto resourceFiles = mds->GetResourceFiles();
std::string metadataFile;
for (const auto & file: resourceFiles)
{
if (file.find("METADATA.DIM")!=std::string::npos)
{
metadataFile = file;
break;
}
}
if (metadataFile.empty())
{
otbGenericExceptionMacro(MissingMetadataException,<<"Cannot find the METADATA.DIM file")
}
helper.ParseDimapV1(*mds, "IMD/");
XMLMetadataSupplier xmlMds(metadataFile);
const auto & dimapData = helper.GetDimapData();
DimapMetadataHelper helper;
helper.ParseDimapV1(xmlMds, "Dimap_Document.");
const auto & dimapData = helper.GetDimapData();
auto nbBands = m_Imd.Bands.size();
if (dimapData.PhysicalBias.size() == nbBands
&& dimapData.PhysicalGain.size() == nbBands
&& dimapData.SolarIrradiance.size() == nbBands
&& dimapData.BandIDs.size() == nbBands)
{
auto bias = dimapData.PhysicalBias.begin();
auto gain = dimapData.PhysicalGain.begin();
auto bandId = dimapData.BandIDs.begin();
auto solarIrradiance = dimapData.SolarIrradiance.begin();
for (auto & band: m_Imd.Bands)
{
band.Add(MDNum::PhysicalGain, *gain);
band.Add(MDNum::PhysicalBias, *bias);
band.Add(MDStr::BandName, *bandId);
band.Add(MDNum::SolarIrradiance, *solarIrradiance);
bias++;
gain++;
bandId++;
solarIrradiance++;
}
}
else
......@@ -1796,8 +1822,7 @@ void SpotImageMetadataInterface::Parse(const MetadataSupplierInterface *mds)
FetchSpectralSensitivity();
}
//FetchRPC(*mds);
FetchRPC(*mds);
}
} // end namespace otb
......@@ -536,7 +536,12 @@ WorldView2ImageMetadataInterface::VariableLengthVectorType WorldView2ImageMetada
}
else if (keywordStringBId == multi || keywordStringBId == ms1)
{
outputValuesVariableLengthVector.SetSize(m_Imd.Bands.size());
std::string keywordStringBandNameList = imageKeywordlist.GetMetadataByKey("support_data.band_name_list");
std::vector<std::string> bandNameList;
boost::trim(keywordStringBandNameList);
boost::split(bandNameList, keywordStringBandNameList, boost::is_any_of(" "));
outputValuesVariableLengthVector.SetSize(bandNameList.size());
outputValuesVariableLengthVector.Fill(0.0);
}
else
......
......@@ -429,3 +429,11 @@ otb_add_test(NAME ioTuotbXMLMetadataSupplierTest COMMAND otbMetadataTestDriver
${INPUTDATA}/ioTuotbXMLMetadataSupplierTest.xml
${TEMP}/ioTuotbXMLMetadataSupplierTest.txt
)
otb_add_test(NAME ioTvImageMetadataInterfaceTest_Pleiades COMMAND otbMetadataTestDriver
--compare-ascii 0 ${BASELINE_FILES}/ioTvImageMetadataInterfaceTest_Pleiades.txt
${TEMP}/ioTvImageMetadataInterfaceTest_TerraSar.txt
otbImageMetadataInterfaceTest
LARGEINPUT{PLEIADES/MAIDO_JP2_DIMAPv2_PRIMARY_MS_lossy_12bits/IMG_PHR1A_MS_002/IMG_PHR1A_MS_201206050630064_SEN_559102101-002_R1C1.JP2}
${TEMP}/ioTvImageMetadataInterfaceTest_Pleiades.txt
)
......@@ -29,7 +29,7 @@
#include "otbGDALImageIO.h"
#include "otbMetaDataKey.h"
#include "otbTestTools.h"
#include "otbOpticalImageMetadataInterface.h"
int otbImageMetadataInterfaceTest(int itkNotUsed(argc), char* argv[])
{
......@@ -44,13 +44,10 @@ int otbImageMetadataInterfaceTest(int itkNotUsed(argc), char* argv[])
reader->SetFileName(inputFilename);
reader->UpdateOutputInformation();
otb::ImageMetadata imd = reader->GetImageIO()->GetImageMetadata();
otb::MetadataSupplierInterface* mds = dynamic_cast<otb::MetadataSupplierInterface*>(reader->GetImageIO());
auto imd = reader->GetImageIO()->GetImageMetadata();
auto mds = dynamic_cast<otb::MetadataSupplierInterface*>(reader->GetImageIO());
otb::ImageMetadataInterfaceBase::Pointer imi = otb::ImageMetadataInterfaceFactory::CreateIMI(imd, mds);
// Test the image interface
otb::GDALImageIO* mds2 = dynamic_cast<otb::GDALImageIO*>(mds);
imi->Parse(mds);
const otb::ImageMetadata& imd2 = imi->GetImageMetadata();
std::ofstream file;
file.open(outputFilename);
......@@ -59,5 +56,14 @@ int otbImageMetadataInterfaceTest(int itkNotUsed(argc), char* argv[])
file << boost::any_cast<otb::Projection::GCPParam>(imd2[otb::MDGeom::GCP]).ToJSON(true);
file.close();
if (dynamic_cast<otb::OpticalImageMetadataInterface*>(imi.GetPointer()))
{
if (!otb::HasOpticalSensorMetadata(imi->GetImageMetadata()))
{
std::cout << "Input image does not contains all required optical image metadata" << std::endl;
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment