Skip to content
Snippets Groups Projects
Commit dacdf102 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: automatic retrieval of radiometric parameters from ossim metadata

parent b902f0e5
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@
#endif
#include <typeinfo>
#include <cassert>
#include "itkMetaDataObject.h"
......@@ -298,6 +299,107 @@ const ImageMetadataInterface::ImageKeywordlistType ImageMetadataInterface::GetIm
return ( ImageKeywordlist );
}
ImageMetadataInterface::VariableLengthVectorType
ImageMetadataInterface::GetPhysicalBias( const MetaDataDictionaryType & dict ) const
{
ImageKeywordlistType ImageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist);
}
ossimKeywordlist kwl;
ImageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "physical_bias";
ossimString keywordString = kwl.find(key.c_str());
ossimString separatorList = " ";
std::vector<ossimString> keywordStrings = keywordString.split(separatorList);
VariableLengthVectorType outputValues;
outputValues.SetSize(keywordStrings.size());
for (int i=0; i < keywordStrings.size(); ++i)
{
outputValues[i]=keywordStrings[i].toDouble();
}
//In the case of SPOT, the bands are in a different order:
// XS3, XS2. XS1, SWIR in the tif file.
if(IsSpot(dict))
{
assert(outputValues.GetSize() == 4);//Valid for Spot 4 and 5
VariableLengthVectorType::ValueType tmp;
tmp = outputValues[0];
outputValues[0]=outputValues[2];
outputValues[2]=tmp;
}
return outputValues;
}
ImageMetadataInterface::VariableLengthVectorType
ImageMetadataInterface::GetPhysicalGain( const MetaDataDictionaryType & dict ) const
{
ImageKeywordlistType ImageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist);
}
ossimKeywordlist kwl;
ImageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "physical_gain";
ossimString keywordString = kwl.find(key.c_str());
ossimString separatorList = " ";
std::vector<ossimString> keywordStrings = keywordString.split(separatorList);
VariableLengthVectorType outputValues;
outputValues.SetSize(keywordStrings.size());
for (int i=0; i < keywordStrings.size(); ++i)
{
outputValues[i]=keywordStrings[i].toDouble();
}
//In the case of SPOT, the bands are in a different order:
// XS3, XS2. XS1, SWIR in the tif file.
if(IsSpot(dict))
{
assert(outputValues.GetSize() == 4);//Valid for Spot 4 and 5
VariableLengthVectorType::ValueType tmp;
tmp = outputValues[0];
outputValues[0]=outputValues[2];
outputValues[2]=tmp;
}
return outputValues;
}
std::string ImageMetadataInterface::GetSensorID( const MetaDataDictionaryType & dict ) const
{
ImageKeywordlistType ImageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist);
}
ossimKeywordlist kwl;
ImageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "sensor";
ossimString keywordString = kwl.find(key.c_str());
std::string output(keywordString.chars());
return output;
}
bool ImageMetadataInterface::IsSpot( const MetaDataDictionaryType & dict ) const
{
std::string sensorID = GetSensorID(dict);
if (sensorID.find("Spot") != std::string::npos)
return true;
else
return false;
}
void
ImageMetadataInterface::PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType & dict) const
{
......
......@@ -55,6 +55,7 @@ public:
typedef itk::MetaDataDictionary MetaDataDictionaryType;
typedef MetaDataKey::VectorType VectorType;
typedef MetaDataKey::VariableLengthVectorType VariableLengthVectorType;
typedef ImageKeywordlist ImageKeywordlistType;
......@@ -101,6 +102,16 @@ public:
ImageKeywordlistType GetImageKeywordlist( MetaDataDictionaryType & dict );
const ImageKeywordlistType GetImageKeywordlist(const MetaDataDictionaryType & dict ) const;
/** Get the radiometric bias from the ossim metadata */
VariableLengthVectorType GetPhysicalBias( const MetaDataDictionaryType & dict ) const;
/** Get the radiometric gain from the ossim metadata */
VariableLengthVectorType GetPhysicalGain( const MetaDataDictionaryType & dict ) const;
/** Get the sensor ID from the ossim metadata */
std::string GetSensorID(const MetaDataDictionaryType & dict ) const;
void PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType & dict) const;
......@@ -108,6 +119,8 @@ protected:
ImageMetadataInterface();
virtual ~ImageMetadataInterface() {};
bool IsSpot( const MetaDataDictionaryType & dict) const;
private:
ImageMetadataInterface(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
......
......@@ -26,6 +26,8 @@
#include <vector>
#include "itkDataObject.h"
#include "itkVariableLengthVector.h"
#include "gdal.h"
......@@ -106,6 +108,7 @@ public:
KeyType GetKeyType(std::string name);
typedef std::vector<double> VectorType;
typedef itk::VariableLengthVector<double> VariableLengthVectorType;
private:
MetaDataKey(const Self&); //purposely not implemented
......
......@@ -27,6 +27,7 @@
#include "otbVectorImage.h"
#include "itkNumericTraits.h"
#include "itkVariableLengthVector.h"
#include "otbMacro.h"
#include <fstream>
......@@ -139,6 +140,7 @@ public:
/** Set the absolute calibration gains. */
itkSetMacro(Alpha, VectorType);
/** Give the absolute calibration gains. */
itkGetConstReferenceMacro(Alpha, VectorType);
......@@ -152,15 +154,40 @@ protected:
ImageToLuminanceImageFilter()
{
m_Alpha.SetSize(1);
m_Beta.SetSize(1);
m_Alpha.Fill(1);
m_Beta.Fill(0);
// m_Alpha.SetSize(1);
// m_Beta.SetSize(1);
// m_Alpha.Fill(1);
// m_Beta.Fill(0);
m_Alpha.SetSize(0);
m_Beta.SetSize(0);
};
virtual ~ImageToLuminanceImageFilter() {};
virtual void BeforeThreadedGenerateData(void)
{
if(m_Alpha.GetSize() == 0)
{
ImageMetadataInterface::Pointer imageMetadataInterface= ImageMetadataInterface::New();
m_Alpha = imageMetadataInterface->GetPhysicalGain(this->GetInput()->GetMetaDataDictionary());
}
if(m_Beta.GetSize() == 0)
{
ImageMetadataInterface::Pointer imageMetadataInterface= ImageMetadataInterface::New();
m_Beta = imageMetadataInterface->GetPhysicalBias(this->GetInput()->GetMetaDataDictionary());
}
if ((m_Alpha.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel())
|| (m_Beta.GetSize() != this->GetInput()->GetNumberOfComponentsPerPixel()))
{
itkExceptionMacro(<<"Alpha and Beta parameters should have the same size as the number of bands");
}
otbMsgDevMacro( << "Using correction parameters: ");
otbMsgDevMacro( << "Alpha (gain): " << m_Alpha);
otbMsgDevMacro( << "Beta (bias): " << m_Beta);
this->GetFunctorVector().clear();
for (unsigned int i = 0;i<this->GetInput()->GetNumberOfComponentsPerPixel();++i)
{
......@@ -176,6 +203,7 @@ private:
/** Ponderation declaration*/
VectorType m_Alpha;
VectorType m_Beta;
typename ImageMetadataInterface::Pointer m_ImageMetadataInterface;
};
} // end namespace otb
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment