Commit 90a8c462 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

REFAC: use SarSensorModel instead of SarSensorModelAdapter (ossim) in Deburst,...

REFAC: use SarSensorModel instead of SarSensorModelAdapter (ossim) in Deburst, BurstExtraction and ConcatenateBursts filters and applications
parent ec40606b
Pipeline #8068 failed with stages
in 82 minutes and 50 seconds
......@@ -137,15 +137,13 @@ private:
}*/
// Coniguration for fusion filter
fusionFilter->SetSLCImageKeyWorList(in->GetImageKeywordlist());
fusionFilter->SetSLCImageMetadata(in->GetImageMetadata());
// Get Invalid pixel Key (from Image 0)
FloatVectorImageType::Pointer Im0 = inList->GetNthElement(0);
Im0->UpdateOutputInformation();
auto const& kwl = Im0->GetImageKeywordlist();
const bool inputWithInvalidPixels = kwl.HasKey("support_data.invalid_pixels") && kwl.GetMetadataByKey("support_data.invalid_pixels") == "yes";
auto const & imd = Im0->GetImageMetadata();
const bool inputWithInvalidPixels = imd.Has("invalid_pixels") && imd["invalid_pixels"] == "yes";
fusionFilter->getDeburstLinesAndSamples(lines, samples, burst_index, inputWithInvalidPixels);
......
......@@ -109,20 +109,19 @@ private:
FloatVectorImageType* in = GetParameterImage("in");
// Set the filer input
m_DeburstFilter = DeburstFilterType::New();
m_DeburstFilter->SetInput(in);
auto deburstFilter = DeburstFilterType::New();
deburstFilter->SetInput(in);
if (IsParameterEnabled("onlyvalidsamples"))
{
m_DeburstFilter->SetOnlyValidSample(true);
deburstFilter->SetOnlyValidSample(true);
}
// Set the output image
SetParameterOutputImage("out", m_DeburstFilter->GetOutput());
SetParameterOutputImage("out", deburstFilter->GetOutput());
RegisterPipeline();
}
DeburstFilterType::Pointer m_DeburstFilter;
};
}
}
......
......@@ -323,8 +323,9 @@ std::vector<SARNoise> SarImageMetadataInterface::GetNoiseVectorGeom() const
std::istringstream(m_MetadataSupplierInterface->GetAs<std::string>(path_root + ".azimuthTime")) >> noiseVect.azimuthTime;
MetaData::LUT1D noiseLut;
MetaData::LUTAxis ax1;
ax1.Size = m_MetadataSupplierInterface->GetAs<int>(path_root + ".pixel_count");
ax1.Values = m_MetadataSupplierInterface->GetAsVector<double>(path_root + ".pixel", ' ', ax1.Size);
// note: in some geom products pixel_count does not match the vector size in noiseVector.
ax1.Values = m_MetadataSupplierInterface->GetAsVector<double>(path_root + ".pixel", ' ');
ax1.Size = ax1.Values.size();
noiseLut.Axis[0] = ax1;
noiseLut.Array = m_MetadataSupplierInterface->GetAsVector<double>(path_root + ".noiseLut", ' ', ax1.Size);
noiseVect.noiseLut = std::move(noiseLut);
......@@ -356,10 +357,10 @@ bool SarImageMetadataInterface::GetSAR(SARParam & sarParam) const
sarParam.rangeResolution = m_MetadataSupplierInterface->GetAs<double>(
supportDataPrefix + "range_spacing");
sarParam.azimuthTimeInterval = MetaData::DurationType(m_MetadataSupplierInterface->GetAs<double>(
sarParam.azimuthTimeInterval = MetaData::DurationType::Seconds(m_MetadataSupplierInterface->GetAs<double>(
supportDataPrefix + "line_time_interval") );
if (sarParam.burstRecords.size() > 1)
if (sarParam.burstRecords.size() > 1 && m_MetadataSupplierInterface->GetAs<int>("header.version") > 2)
{
sarParam.numberOfLinesPerBurst = m_MetadataSupplierInterface->GetAs<unsigned long>(
supportDataPrefix + "geom.bursts.number_lines_per_burst");
......@@ -367,7 +368,6 @@ bool SarImageMetadataInterface::GetSAR(SARParam & sarParam) const
sarParam.numberOfSamplesPerBurst = m_MetadataSupplierInterface->GetAs<unsigned long>(
supportDataPrefix + "geom.bursts.number_samples_per_burst");
}
return true;
}
......
......@@ -854,10 +854,13 @@ void Sentinel1ImageMetadataInterface::ParseGeom(ImageMetadata & imd)
LoadRadiometricCalibrationData(sarCalib, *m_MetadataSupplierInterface, imd);
CreateCalibrationLookupData(sarCalib, imd, *m_MetadataSupplierInterface, true);
imd.Add(MDGeom::SARCalib, sarCalib);
Projection::GCPParam gcp;
imd.Add(MDGeom::GCP, gcp);
}
void Sentinel1ImageMetadataInterface::Parse(ImageMetadata & imd)
{
{
// Try to fetch the metadata from GDAL Metadata Supplier
if (m_MetadataSupplierInterface->GetAs<std::string>("", "MISSION_ID").substr(0, 2) == "S1"
|| m_MetadataSupplierInterface->GetAs<std::string>("", "TIFFTAG_IMAGEDESCRIPTION").substr(0, 10) == "Sentinel-1")
......
......@@ -106,6 +106,11 @@ public:
unsigned int & linesOffset, unsigned int first_burstInd,
bool inputWithInvalidPixels=false);
/** Update a ImageMetadata object with the sotred SarParam and GCPs, possibly modified from the
* original metadata by the SarSensorModel
* \param imd The ImageMetadata to be updated
*/
void UpdateImageMetadata(ImageMetadata & imd);
/**
* This is a helper function to convert deburst line to input image
......@@ -114,7 +119,7 @@ public:
* \param imageLine The input deburst line
* \param deburstLine The output original image line
*/
void DeburstLineToImageLine(const std::vector<std::pair<unsigned long,unsigned long> >& lines,
static void DeburstLineToImageLine(const std::vector<std::pair<unsigned long,unsigned long> >& lines,
unsigned long deburstLine,
unsigned long & imageLine);
......@@ -126,9 +131,9 @@ public:
* \param deburstLine The output deburst line
* \return True if imageLine is within a preserved range, false otherwise
*/
bool ImageLineToDeburstLine(const std::vector<std::pair<unsigned long,unsigned long> >& lines,
static bool ImageLineToDeburstLine(const std::vector<std::pair<unsigned long,unsigned long> >& lines,
unsigned long imageLine,
unsigned long & deburstLine) const;
unsigned long & deburstLine);
protected:
......
......@@ -1102,9 +1102,15 @@ bool SarSensorModel::DeburstAndConcatenate(std::vector<std::pair<unsigned long,u
return true;
}
void SarSensorModel::UpdateImageMetadata(ImageMetadata & imd)
{
imd.Add(MDGeom::SAR, m_SarParam);
imd.Add(MDGeom::GCP, m_GCP);
}
bool SarSensorModel::ImageLineToDeburstLine(const std::vector<std::pair<unsigned long,unsigned long> >& lines,
unsigned long imageLine,
unsigned long & deburstLine) const
unsigned long & deburstLine)
{
auto vit = lines.cbegin();
auto nit = vit + 1;
......
......@@ -23,7 +23,7 @@
#include "otbSarBurstExtractionImageFilter.h"
#include "otbSarSensorModelAdapter.h"
#include "otbSarSensorModel.h"
#include "otbImageKeywordlist.h"
#include "itkImageScanlineIterator.h"
#include "itkImageScanlineConstIterator.h"
......@@ -57,34 +57,24 @@ void SarBurstExtractionImageFilter<TImage>::GenerateOutputInformation()
if (std::abs(inputPtr->GetOrigin()[1] - static_cast<long>(inputPtr->GetOrigin()[1]) - 0.5) >= std::numeric_limits<double>::epsilon())
itkExceptionMacro("Can not perform burst extraction if input image azimuth origin is not N.5");
// Retrieve input image keywordlist
ImageKeywordlist inputKwl = inputPtr->GetImageKeywordlist();
// Retrieve input image metadata
auto imd = inputPtr->GetImageMetadata();
// Try to create a SarSensorModelAdapter
SarSensorModelAdapter::Pointer sarSensorModel = SarSensorModelAdapter::New();
bool loadOk = sarSensorModel->LoadState(inputKwl);
if (!loadOk || !sarSensorModel->IsValidSensorModel())
itkExceptionMacro(<< "Input image does not contain a valid SAR sensor model.");
SarSensorModel sarSensorModel(imd);
// Try to call the burst extraction function
bool burstExtractionOk = sarSensorModel->BurstExtraction(m_BurstIndex, m_LinesRecord, m_SamplesRecord, m_AllPixels);
bool burstExtractionOk = sarSensorModel.BurstExtraction(m_BurstIndex, m_LinesRecord, m_SamplesRecord, m_AllPixels);
if (!burstExtractionOk)
itkExceptionMacro(<< "Could not etract Burst from input image");
itkExceptionMacro(<< "Could not extract Burst from input image");
sarSensorModel.UpdateImageMetadata(imd);
// Compute the actual lines to remove
typename ImageType::RegionType largestPossibleRegion = this->GetInput()->GetLargestPossibleRegion();
typename ImageType::PointType origin = this->GetInput()->GetOrigin();
// Export the new keywordlist
ImageKeywordlist newKwl;
bool saveOk = sarSensorModel->SaveState(newKwl);
if (!saveOk)
itkExceptionMacro(<< "Could not export deburst SAR sensor model to keyword list");
// Move origin and size (if necessary)
long originOffset_samples = static_cast<long>(this->GetInput()->GetOrigin()[0] - 0.5);
long originOffset_lines = static_cast<long>(this->GetInput()->GetOrigin()[1] - 0.5);
......@@ -132,23 +122,20 @@ void SarBurstExtractionImageFilter<TImage>::GenerateOutputInformation()
largestPossibleRegion.SetSize(burstSize);
outputPtr->SetLargestPossibleRegion(largestPossibleRegion);
newKwl.AddKey("support_data.number_samples", std::to_string(burstSize[0]));
newKwl.AddKey("support_data.number_lines", std::to_string(burstSize[1]));
newKwl.AddKey("number_samples", std::to_string(burstSize[0]));
newKwl.AddKey("number_lines", std::to_string(burstSize[1]));
imd.Add(MDNum::NumberOfLines, burstSize[0]);
imd.Add(MDNum::NumberOfColumns, burstSize[1]);
if (m_AllPixels)
{
newKwl.AddKey("support_data.invalid_pixels", "yes");
imd.Add("invalid_pixels", "yes");
}
else
{
newKwl.AddKey("support_data.invalid_pixels", "no");
imd.Add("invalid_pixels", "no");
}
// Set new keyword list to output image
outputPtr->SetImageKeywordList(newKwl);
outputPtr->SetImageMetadata(imd);
}
template <class TImage>
......
......@@ -80,7 +80,7 @@ public:
itkTypeMacro(SarConcatenateBurstsImageFilter, TileImageFilter);
// Setter
void SetSLCImageKeyWorList(ImageKeywordlist sarImageKWL);
void SetSLCImageMetadata(ImageMetadata sarImd);
bool getDeburstLinesAndSamples(LinesRecordVectorType& linesRecord, LinesRecordVectorType& samplesRecord, unsigned int first_burstInd,
bool inputWithInvalidPixels);
......@@ -101,10 +101,7 @@ private:
void operator=(const Self&) = delete;
// SLC KeywordList
ImageKeywordlist m_SLCImageKWL;
// Deburst SLC KeywordList
ImageKeywordlist m_DeburstSLCImageKWL;
ImageMetadata m_SLCImd;
unsigned int m_Offset_OriginL;
};
......
......@@ -23,14 +23,14 @@
#include "otbSarConcatenateBurstsImageFilter.h"
#include "itkImageRegionIterator.h"
#include "otbSarSensorModelAdapter.h"
#include "otbSarSensorModel.h"
namespace otb
{
template <class TImage>
void SarConcatenateBurstsImageFilter<TImage>::SetSLCImageKeyWorList(ImageKeywordlist sarImageKWL)
void SarConcatenateBurstsImageFilter<TImage>::SetSLCImageMetadata(ImageMetadata sarImd)
{
m_SLCImageKWL = sarImageKWL;
m_SLCImd = sarImd;
}
template <class TImage>
......@@ -38,26 +38,17 @@ bool SarConcatenateBurstsImageFilter<TImage>::getDeburstLinesAndSamples(LinesRec
unsigned int first_burstInd, bool inputWithInvalidPixels)
{
// Try to create a SarSensorModelAdapter
SarSensorModelAdapter::Pointer sarSensorModel = SarSensorModelAdapter::New();
bool loadOk = sarSensorModel->LoadState(m_SLCImageKWL);
if (!loadOk || !sarSensorModel->IsValidSensorModel())
itkExceptionMacro(<< "Input image does not contain a valid SAR sensor model.");
SarSensorModel sarSensorModel(m_SLCImd);
LinesRecordVectorType lines;
// Try to call the deburstAndConcatenate function
bool deburstAndConcatenateOk = sarSensorModel->DeburstAndConcatenate(linesRecord, samplesRecord, m_Offset_OriginL, first_burstInd, inputWithInvalidPixels);
bool deburstAndConcatenateOk = sarSensorModel.DeburstAndConcatenate(linesRecord, samplesRecord, m_Offset_OriginL, first_burstInd, inputWithInvalidPixels);
if (!deburstAndConcatenateOk)
itkExceptionMacro(<< "Could not deburst or concatenate from input bursts");
// Export the new keywordlist
bool saveOk = sarSensorModel->SaveState(m_DeburstSLCImageKWL);
if (!saveOk)
itkExceptionMacro(<< "Could not export deburst SAR sensor model to keyword list");
sarSensorModel.UpdateImageMetadata(m_SLCImd);
return true;
}
......@@ -68,7 +59,7 @@ void SarConcatenateBurstsImageFilter<TImage>::GenerateOutputInformation()
// First, call superclass implementation
Superclass::GenerateOutputInformation();
ImageType* outputPtr = this->GetOutput();
auto outputPtr = this->GetOutput();
// Origin to (0.5, 0.5) : Metadata are already adjusted
PointType origin;
......@@ -77,15 +68,10 @@ void SarConcatenateBurstsImageFilter<TImage>::GenerateOutputInformation()
outputPtr->SetOrigin(origin);
// Output KeywordList
m_DeburstSLCImageKWL.AddKey("support_data.number_samples", std::to_string(this->GetOutput()->GetLargestPossibleRegion().GetSize()[0]));
m_DeburstSLCImageKWL.AddKey("support_data.number_lines", std::to_string(this->GetOutput()->GetLargestPossibleRegion().GetSize()[1]));
m_DeburstSLCImageKWL.AddKey("number_samples", std::to_string(this->GetOutput()->GetLargestPossibleRegion().GetSize()[0]));
m_DeburstSLCImageKWL.AddKey("number_lines", std::to_string(this->GetOutput()->GetLargestPossibleRegion().GetSize()[1]));
m_SLCImd.Add(MDNum::NumberOfLines, this->GetOutput()->GetLargestPossibleRegion().GetSize()[0]);
m_SLCImd.Add(MDNum::NumberOfColumns, this->GetOutput()->GetLargestPossibleRegion().GetSize()[1]);
// Set new keyword list to output image
outputPtr->SetImageKeywordList(m_DeburstSLCImageKWL);
outputPtr->SetImageMetadata(m_SLCImd);
}
......
......@@ -23,7 +23,7 @@
#include "otbSarDeburstImageFilter.h"
#include "otbSarSensorModelAdapter.h"
#include "otbSarSensorModel.h"
#include "otbImageKeywordlist.h"
#include "itkImageScanlineIterator.h"
#include "itkImageScanlineConstIterator.h"
......@@ -57,18 +57,13 @@ void SarDeburstImageFilter<TImage>::GenerateOutputInformation()
if (std::abs(inputPtr->GetOrigin()[1] - static_cast<long>(inputPtr->GetOrigin()[1]) - 0.5) >= std::numeric_limits<double>::epsilon())
itkExceptionMacro("Can not perform deburst if input image azimuth origin is not N.5");
// Retrieve input image keywordlist
ImageKeywordlist inputKwl = inputPtr->GetImageKeywordlist();
// Retrieve input image metadata
auto imd = inputPtr->GetImageMetadata();
// Try to create a SarSensorModelAdapter
SarSensorModelAdapter::Pointer sarSensorModel = SarSensorModelAdapter::New();
bool loadOk = sarSensorModel->LoadState(inputKwl);
if (!loadOk || !sarSensorModel->IsValidSensorModel())
itkExceptionMacro(<< "Input image does not contain a valid SAR sensor model.");
SarSensorModel sarSensorModel(imd);
// Try to call the deburst function
bool deburstOk = sarSensorModel->Deburst(m_LinesRecord, m_SamplesRecord, m_OnlyValidSample);
bool deburstOk = sarSensorModel.Deburst(m_LinesRecord, m_SamplesRecord, m_OnlyValidSample);
if (!deburstOk || m_LinesRecord.empty())
itkExceptionMacro(<< "Could not deburst SAR sensor model from input image");
......@@ -77,14 +72,6 @@ void SarDeburstImageFilter<TImage>::GenerateOutputInformation()
typename ImageType::RegionType largestPossibleRegion = this->GetInput()->GetLargestPossibleRegion();
typename ImageType::PointType origin = this->GetInput()->GetOrigin();
// Export the new keywordlist
ImageKeywordlist newKwl;
bool saveOk = sarSensorModel->SaveState(newKwl);
if (!saveOk)
itkExceptionMacro(<< "Could not export deburst SAR sensor model to keyword list");
// Now, filter the LinesRecord so as to account for possible
// extracts on input image
long firstInputLine = static_cast<long>(origin[1] - 0.5);
......@@ -94,7 +81,7 @@ void SarDeburstImageFilter<TImage>::GenerateOutputInformation()
// Move origin
unsigned long outputOriginLine = 0;
SarSensorModelAdapter::ImageLineToDeburstLine(m_LinesRecord, firstInputLine, outputOriginLine);
SarSensorModel::ImageLineToDeburstLine(m_LinesRecord, firstInputLine, outputOriginLine);
long originOffset_samples = static_cast<long>(this->GetInput()->GetOrigin()[0] - 0.5);
unsigned long outputOriginSample = 0;
......@@ -158,14 +145,10 @@ void SarDeburstImageFilter<TImage>::GenerateOutputInformation()
largestPossibleRegion.SetSize(deburstSize);
outputPtr->SetLargestPossibleRegion(largestPossibleRegion);
newKwl.AddKey("support_data.number_samples", std::to_string(deburstSize[0]));
newKwl.AddKey("support_data.number_lines", std::to_string(deburstSize[1]));
newKwl.AddKey("number_samples", std::to_string(deburstSize[0]));
newKwl.AddKey("number_lines", std::to_string(deburstSize[1]));
imd.Add(MDNum::NumberOfLines, deburstSize[0]);
imd.Add(MDNum::NumberOfColumns, deburstSize[1]);
// Set new keyword list to output image
outputPtr->SetImageKeywordList(newKwl);
outputPtr->SetImageMetadata(imd);
}
template <class TImage>
......@@ -186,8 +169,8 @@ typename SarDeburstImageFilter<TImage>::RegionType SarDeburstImageFilter<TImage>
unsigned long inputUpperLeftLine, inputLowerLeftLine;
SarSensorModelAdapter::DeburstLineToImageLine(m_LinesRecord, upperLeftLine, inputUpperLeftLine);
SarSensorModelAdapter::DeburstLineToImageLine(m_LinesRecord, lowerLeftLine, inputLowerLeftLine);
SarSensorModel::DeburstLineToImageLine(m_LinesRecord, upperLeftLine, inputUpperLeftLine);
SarSensorModel::DeburstLineToImageLine(m_LinesRecord, lowerLeftLine, inputLowerLeftLine);
long originOffset = static_cast<long>(this->GetInput()->GetOrigin()[1] - 0.5);
long originOffset_samples = static_cast<long>(this->GetInput()->GetOrigin()[0] - 0.5);
......
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