Commit 5009e64c authored by Cyrille Valladeau's avatar Cyrille Valladeau

ENH : TSX calib evolution

parent a5da175f
......@@ -29,6 +29,7 @@
#include "itkMetaDataObject.h"
#include "otbVectorDataKeywordlist.h"
#include "base/ossimDate.h"
namespace otb
{
......@@ -48,9 +49,10 @@ TerraSarImageMetadataInterface::GetSensorID( const MetaDataDictionaryType & dict
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist);
}
ossimKeywordlist kwl;
ImageKeywordlist.convertToOSSIMKeywordlist(kwl);
kwl.print(std::cout);
std::string key= "sensor";
ossimString keywordString = kwl.find(key.c_str());
std::string output(keywordString.chars());
......@@ -351,7 +353,7 @@ TerraSarImageMetadataInterface::GetCalibrationFactor( const MetaDataDictionaryTy
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image");
itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image");
}
ImageKeywordlistType imageKeywordlist;
......@@ -371,4 +373,311 @@ TerraSarImageMetadataInterface::GetCalibrationFactor( const MetaDataDictionaryTy
}
ossimplugins::Noise *
TerraSarImageMetadataInterface::GetNoise( const MetaDataDictionaryType & dict ) const
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image");
}
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
ossimplugins::Noise * noise = new ossimplugins::Noise();
noise->loadState( kwl, "");
return noise;
}
unsigned int
TerraSarImageMetadataInterface::GetNumberOfNoiseRecords( const MetaDataDictionaryType & dict ) const
{
ossimplugins::Noise * noise = this->GetNoise( dict );
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key = "noise.numberOfNoiseRecords";
ossimString nbRec = kwl.find(key.c_str());
delete noise;
return static_cast<unsigned int>(nbRec.toInt());
}
TerraSarImageMetadataInterface::UIntVectorType
TerraSarImageMetadataInterface::GetNoisePolynomialDegrees( const MetaDataDictionaryType & dict ) const
{
ossimplugins::Noise * noise = this->GetNoise( dict );
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
UIntVectorType polDeg;
itk::OStringStream oss;
unsigned int nbRec = this->GetNumberOfNoiseRecords(dict);
for(unsigned int i=0; i<nbRec; i++)
{
oss.str("");
oss << "noise[" << i << "]imageNoise.noiseEstimate.polynomialDegree";
ossimString tempVal = kwl.find(oss.str().c_str());
polDeg.push_back( static_cast<unsigned int>(tempVal.toInt()) );
}
delete noise;
return polDeg;
}
TerraSarImageMetadataInterface::DoubleVectorVectorType
TerraSarImageMetadataInterface::GetNoisePolynomialCoefficientsList( const MetaDataDictionaryType & dict ) const
{
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
ossimplugins::Noise * noise = this->GetNoise( dict );
unsigned int nbRec = this->GetNumberOfNoiseRecords(dict);
UIntVectorType polDegs = this->GetNoisePolynomialDegrees(dict);
DoubleVectorVectorType polCoefList;
DoubleVectorType polCoef;
itk::OStringStream oss;
for(unsigned int i=0; i<nbRec; i++)
{
polCoef.clear();
// set <= condition because degree N means N+1 coeff
for(unsigned int j=0; j<=polDegs.size(); j++)
{
oss.str("");
oss << "noise[" << i << "]imageNoise.noiseEstimate.coefficient[" << j <<"]";
ossimString tempVal = kwl.find(oss.str().c_str());
polCoef.push_back( static_cast<double>(tempVal.toDouble()) );
}
polCoefList.push_back(polCoef);
}
delete noise;
return polCoefList;
}
TerraSarImageMetadataInterface::DoubleVectorType
TerraSarImageMetadataInterface::GetNoiseTimeUTCList( const MetaDataDictionaryType & dict ) const
{
ossimplugins::Noise * noise = this->GetNoise( dict );
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
DoubleVectorType timeList;
itk::OStringStream oss;
ossimString separatorList = "-T:Z";
std::vector<ossimString> splittedDate;
int year, month, day, hour, minu, sec;
double secDec, julianDay;
unsigned int nbRec = this->GetNumberOfNoiseRecords(dict);
for(unsigned int i=0; i<nbRec; i++)
{
oss.str("");
oss << "noise[" << i << "]imageNoise.timeUTC";
ossimString tempVal = kwl.find(oss.str().c_str());
splittedDate = tempVal.split(separatorList);
year = splittedDate[0].toInt();
month = splittedDate[1].toInt();
day = splittedDate[2].toInt();
hour = splittedDate[3].toInt();
minu = splittedDate[4].toInt();
double secFull = splittedDate[5].toDouble();
sec = static_cast<int>(vcl_floor(secFull));
// store the decimal second value
secDec = secFull - vcl_floor(secFull);
ossimDate myDate(month, day, year);
myDate.setHour(hour);
myDate.setMin(minu);
myDate.setSec(sec);
std::cout<<secDec*1e-5/0.864<<std::endl;
julianDay = myDate.getJulian();
// add the decimal second to the julian day (0.00001 <-> 0.864s)
julianDay += secDec*1e-5/0.864;
timeList.push_back( julianDay );
}
delete noise;
return timeList;
}
TerraSarImageMetadataInterface::DoubleVectorType
TerraSarImageMetadataInterface::GetNoiseValidityRangeMaxList( const MetaDataDictionaryType & dict ) const
{
ossimplugins::Noise * noise = this->GetNoise( dict );
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
DoubleVectorType maxList;
itk::OStringStream oss;
unsigned int nbRec = this->GetNumberOfNoiseRecords(dict);
for(unsigned int i=0; i<nbRec; i++)
{
oss.str("");
oss << "noise[" << i << "]imageNoise.noiseEstimate.validityRangeMax";
ossimString tempVal = kwl.find(oss.str().c_str());
maxList.push_back( tempVal.toDouble() );
}
delete noise;
return maxList;
}
TerraSarImageMetadataInterface::DoubleVectorType
TerraSarImageMetadataInterface::GetNoiseValidityRangeMinList( const MetaDataDictionaryType & dict ) const
{
ossimplugins::Noise * noise = this->GetNoise( dict );
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
DoubleVectorType minList;
itk::OStringStream oss;
unsigned int nbRec = this->GetNumberOfNoiseRecords(dict);
for(unsigned int i=0; i<nbRec; i++)
{
oss.str("");
oss << "noise[" << i << "]imageNoise.noiseEstimate.validityRangeMin";
ossimString tempVal = kwl.find(oss.str().c_str());
minList.push_back( tempVal.toDouble() );
}
delete noise;
return minList;
}
TerraSarImageMetadataInterface::DoubleVectorType
TerraSarImageMetadataInterface::GetNoiseReferencePointList( const MetaDataDictionaryType & dict ) const
{
ossimplugins::Noise * noise = this->GetNoise( dict );
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
DoubleVectorType refPointList;
itk::OStringStream oss;
unsigned int nbRec = this->GetNumberOfNoiseRecords(dict);
for(unsigned int i=0; i<nbRec; i++)
{
oss.str("");
oss << "noise[" << i << "]imageNoise.noiseEstimate.referencePoint";
ossimString tempVal = kwl.find(oss.str().c_str());
refPointList.push_back( tempVal.toDouble() );
}
delete noise;
return refPointList;
}
double
TerraSarImageMetadataInterface::GetRadarFrequency( const MetaDataDictionaryType & dict ) const
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image");
}
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
ossimString tempVal = kwl.find("radarFrequency");
double freq = tempVal.toDouble();
return freq;
}
} // end namespace otb
......@@ -29,6 +29,7 @@
#include "otbMetaDataKey.h"
#include "otbImageKeywordlist.h"
#include "itkImageBase.h"
#include <otb/Noise.h>
#include <string>
namespace otb
......@@ -59,6 +60,9 @@ public:
typedef MetaDataKey::VectorType VectorType;
typedef MetaDataKey::VariableLengthVectorType VariableLengthVectorType;
typedef ImageKeywordlist ImageKeywordlistType;
typedef std::vector<double> DoubleVectorType;
typedef std::vector<DoubleVectorType> DoubleVectorVectorType;
typedef std::vector<unsigned int> UIntVectorType;
/** Set the image used to get the metadata */
itkSetObjectMacro(Image,ImageType);
......@@ -93,7 +97,34 @@ public:
/** Get the calibration.calFactor : generationTime variable */
double GetCalibrationFactor( const MetaDataDictionaryType & ) const;
bool CanRead( const MetaDataDictionaryType & ) const;
/** Get the noise structure */
ossimplugins::Noise * GetNoise( const MetaDataDictionaryType & ) const;
/** Get the number of noise records */
unsigned int GetNumberOfNoiseRecords( const MetaDataDictionaryType & ) const;
/** Get the polynomial degree list */
UIntVectorType GetNoisePolynomialDegrees( const MetaDataDictionaryType & ) const;
/** Get the polynomial coefficient list */
DoubleVectorVectorType GetNoisePolynomialCoefficientsList( const MetaDataDictionaryType & ) const;
/** Get timeUTC noise acquisition list in Julian day */
DoubleVectorType GetNoiseTimeUTCList( const MetaDataDictionaryType & ) const;
/** Get noise minimum validity range list */
DoubleVectorType GetNoiseValidityRangeMinList( const MetaDataDictionaryType & ) const;
/** Get noise maximum validity range list */
DoubleVectorType GetNoiseValidityRangeMaxList( const MetaDataDictionaryType & ) const;
/** Get noise reference point list */
DoubleVectorType GetNoiseReferencePointList( const MetaDataDictionaryType & ) const;
/** Get the radar frequency */
double GetRadarFrequency( const MetaDataDictionaryType & ) const;
bool CanRead( const MetaDataDictionaryType & ) const;
protected:
TerraSarImageMetadataInterface();
......
......@@ -74,17 +74,18 @@ public:
typedef std::vector<DoubleVectorType> DoubleVectorVectorType;
/** Accessors */
void SetCalFactor(double pCalFactor){
this->GetFunctor().SetCalFactor( pCalFactor );
this->Modified();
}
void SetCalFactor(double pCalFactor)
{
this->GetFunctor().SetCalFactor( pCalFactor );
this->Modified();
}
double GetCalFactor(){
return this->GetFunctor().GetCalFactor();
}
protected:
/** Constructor */
TerraSarBrightnessImageFilter();
TerraSarBrightnessImageFilter(){};
/** Destructor */
virtual ~TerraSarBrightnessImageFilter() {};
......
......@@ -19,29 +19,32 @@
#define __otbTerraSarBrightnessImageFilter_txx
#include "otbTerraSarBrightnessImageFilter.h"
#include "otbImageMetadataInterfaceFactory.h"
#include "otbImageMetadataInterfaceBase.h"
//#include "otbImageMetadataInterfaceFactory.h"
//#include "otbImageMetadataInterfaceBase.h"
#include "otbTerraSarImageMetadataInterface.h"
namespace otb
{
/**
* Constructor
*/
template <class TInputImage, class TOutputImage>
TerraSarBrightnessImageFilter<TInputImage,TOutputImage>
::TerraSarBrightnessImageFilter()
{
// m_CalFactor = 1.;
}
template <class TInputImage, class TOutputImage>
void
TerraSarBrightnessImageFilter<TInputImage,TOutputImage>
::BeforeThreadedGenerateData()
{
Superclass::BeforeThreadedGenerateData();
// If the user doesn't set it AND the metadata is available, set calFactor using image metadata
std::cout<<this->GetCalFactor()<<std::endl;
if (this->GetCalFactor() == itk::NumericTraits<double>::min())
{
/** TODO : use a factory for RADAR image metadata interface */
TerraSarImageMetadataInterface::Pointer lImageMetadata = otb::TerraSarImageMetadataInterface::New();
if( !lImageMetadata->CanRead(this->GetInput()->GetMetaDataDictionary()) )
{
itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted");
}
this->SetCalFactor( lImageMetadata->GetCalibrationFactor(this->GetInput()->GetMetaDataDictionary()) );
}
}
}
......
......@@ -33,7 +33,7 @@ template <class TInput, class TOutput>
TerraSarBrightnessImageFunctor<TInput, TOutput>
::TerraSarBrightnessImageFunctor()
{
m_CalFactor = 1.;
m_CalFactor = itk::NumericTraits<double>::min();
}
......
......@@ -37,12 +37,42 @@ int otbTerraSarImageMetadataInterface (int argc, char* argv[])
typedef otb::VectorImage< double, 2 > InputImageType;
typedef otb::ImageFileReader< InputImageType > ImageReaderType;
typedef std::vector<double> DoubleVectorType;
typedef std::vector<DoubleVectorType> DoubleVectorVectorType;
typedef std::vector<unsigned int> UIntVectorType;
ImageReaderType::Pointer reader = ImageReaderType::New();
reader->SetFileName( inputFilename );
reader->UpdateOutputInformation();
otb::TerraSarImageMetadataInterface::Pointer lImageMetadata = otb::TerraSarImageMetadataInterface::New();
lImageMetadata->GetNoise(reader->GetOutput()->GetMetaDataDictionary())->print(std::cout);
std::cout<<lImageMetadata->GetNumberOfNoiseRecords(reader->GetOutput()->GetMetaDataDictionary())<<std::endl;
UIntVectorType deg = lImageMetadata->GetNoisePolynomialDegrees(reader->GetOutput()->GetMetaDataDictionary());
DoubleVectorVectorType coeffs = lImageMetadata->GetNoisePolynomialCoefficientsList(reader->GetOutput()->GetMetaDataDictionary());
DoubleVectorType mins = lImageMetadata->GetNoiseValidityRangeMinList(reader->GetOutput()->GetMetaDataDictionary());
DoubleVectorType maxs = lImageMetadata->GetNoiseValidityRangeMaxList(reader->GetOutput()->GetMetaDataDictionary());
DoubleVectorType ref = lImageMetadata->GetNoiseReferencePointList(reader->GetOutput()->GetMetaDataDictionary());
DoubleVectorType time = lImageMetadata->GetNoiseTimeUTCList(reader->GetOutput()->GetMetaDataDictionary());
for( unsigned int i=0; i<deg.size(); i++ )
{
std::cout<<"~~~~~~~ Polynome "<<i<<" ( degree: "<<deg[i]<<")"<<std::endl;
for( unsigned int j=0; j<coeffs[i].size(); j++ )
{
std::cout<<coeffs[i][j]<<" ";
}
std::cout<<std::endl;
std::cout<<mins[i]<<std::endl;
std::cout<<maxs[i]<<std::endl;
std::cout<<ref[i]<<std::endl;
std::cout<<time[i]<<std::endl;
}
std::cout<<lImageMetadata->GetRadarFrequency(reader->GetOutput()->GetMetaDataDictionary())<<std::endl;
std::ofstream file;
file.open(outputFilename);
file<<"GetSensorID: "<<lImageMetadata->GetSensorID(reader->GetOutput()->GetMetaDataDictionary())<<std::endl;
......
......@@ -1076,8 +1076,20 @@ ADD_TEST(raTvTerraSarBrightnessImageFilterTest ${RADIOMETRY_TESTS9}
otbTerraSarBrightnessImageFilterTest
${INPUTDATA}/ExtractIMAGE_HH_SRA_strip_012.tif
${TEMP}/raTvTerraSarBrightnessImageFilterTest.tif
1 # set calfactor
)
IF(OTB_DATA_USE_LARGEINPUT)
ADD_TEST(raTvTerraSarBrightnessImageFilterUPSALA ${RADIOMETRY_TESTS9}
--compare-image ${EPSILON}
${BASELINE}//raTvTerraSarBrightnessImageFilter_UPSALA.tif
${TEMP}//raTvTerraSarBrightnessImageFilter_UPSALA.tif
otbTerraSarBrightnessImageFilterTest
${LARGEINPUT}/TERRASARX/UPSALA_GLACIER/TSX1_SAR__MGD/IMAGEDATA/IMAGE_HH_SRA_strip_012.tif
${TEMP}/raTvTerraSarBrightnessImageFilter_UPSALA.tif
0 # don't set calfactor
)
ENDIF(OTB_DATA_USE_LARGEINPUT)
# A enrichir
......
......@@ -44,15 +44,14 @@ int otbTerraSarBrightnessImageFilterTest(int argc, char * argv[])
reader->UpdateOutputInformation();
std::cout<<reader->GetOutput()->GetNumberOfComponentsPerPixel()<<std::endl;
filter->SetCalFactor( 10 );
//std::cout<<reader->GetOutput()->GetNumberOfComponentsPerPixel()<<std::endl;
if( atoi(argv[3]) == 1 )
filter->SetCalFactor( 10 );
filter->SetInput(reader->GetOutput());
writer->SetInput(filter->GetOutput());
writer->SetNumberOfStreamDivisions(1);
writer->Update();
return EXIT_SUCCESS;
......
......@@ -239,6 +239,11 @@ namespace ossimplugins
*/
double _calFactor;
/**
* @brief centerFrequency (instrument node).
*/
double _radarFrequency;
/**
* @brief Azimuthal Start Time (Start acquisition time).
*/
......
......@@ -718,8 +718,8 @@ bool ossimplugins::ossimTerraSarProductDoc::getRadiometricCorrection(
}
bool ossimplugins::ossimTerraSarProductDoc::getReferencePoint(
const ossimXmlDocument* xdoc, ossimString& s) const
bool ossimplugins::ossimTerraSarProductDoc::getReferencePoint(
const ossimXmlDocument* xdoc, ossimString& s) const
{
ossimString path = "/level1Product/productSpecific/projectedImageInfo/slantToGroundRangeProjection/referencePoint";
return ossim::getPath(path, xdoc, s);
......@@ -869,7 +869,6 @@ bool ossimplugins::ossimTerraSarProductDoc::getAzimuthStartTime(
bool ossimplugins::ossimTerraSarProductDoc::getAzimuthStopTime(
const ossimXmlDocument* xdoc, ossimString& s) const
{
std::cout<<"getAzimuthStopTimegetAzimuthStopTimegetAzimuthStopTimegetAzimuthStopTimegetAzimuthStopTimeres"<<std::endl;
ossimString path =
"/level1Product/productInfo/sceneInfo/stop/timeUTC";
......@@ -881,9 +880,8 @@ bool ossimplugins::ossimTerraSarProductDoc::getAzimuthStopTime(
{
ossimNotify(ossimNotifyLevel_DEBUG)<< "Node \"/level1Product/productInfo/sceneInfo/stop/timeUTC\" invalid, trying \"/level1Product/instrument/settings/rxGainSetting/stopTimeUTC\"...\n";
}
path = "/level1Product/instrument/settings/settingRecord/dataSegment segmentID/stopTimeUTC";// rxGainSetting/stopTimeUTC";
path = "/level1Product/instrument/settings/settingRecord/dataSegment segmentID/stopTimeUTC";
res = ossim::getPath(path, xdoc, s);
std::cout<<res<<std::endl;
}
return res;
......@@ -1057,7 +1055,13 @@ bool ossimplugins::ossimTerraSarProductDoc::getCalFactor(
"/level1Product/calibration/calibrationConstant/calFactor";
return ossim::getPath(path, xdoc, s);
}
bool ossimplugins::ossimTerraSarProductDoc::getRadarFrequency(
const ossimXmlDocument* xdoc, ossimString& s) const
{
ossimString path =
"/level1Product/instrument/radarParameters/centerFrequency";
return ossim::getPath(path, xdoc, s);
}
bool ossimplugins::ossimTerraSarProductDoc::initNoise(
const ossimXmlDocument* xdoc, ossimplugins::Noise* noise) const
{
......
......@@ -218,6 +218,9 @@ namespace ossimplugins
ossimString& s) const;
bool getCalFactor(const ossimXmlDocument* xdoc,
ossimString& s) const;
bool getRadarFrequency(const ossimXmlDocument* xdoc,