Commit c909ecfc authored by Julien Michel's avatar Julien Michel

Merge branch 'enhance_SARConcatenateBursts' into 'develop'

Enhance SARConcatenateBursts

See merge request !355
parents d47e53b8 52d39687
......@@ -92,7 +92,9 @@ public:
/** Deburst metadata if possible and prepare the burst concatenation */
bool DeburstAndConcatenate(std::vector<std::pair<unsigned long, unsigned long> > & linesBursts,
std::vector<std::pair<unsigned long,unsigned long> > & samplesBursts);
std::vector<std::pair<unsigned long,unsigned long> > & samplesBursts,
unsigned int & linesOffset, unsigned int first_burstInd,
bool inputWithInvalidPixels=false);
/** Transform world point (lat,lon,hgt) to input image point
......
......@@ -115,11 +115,14 @@ bool SarSensorModelAdapter::BurstExtraction(const unsigned int burst_index,
bool
SarSensorModelAdapter::DeburstAndConcatenate(std::vector<std::pair<unsigned long, unsigned long> > & linesBursts,
std::vector<std::pair<unsigned long,unsigned long> >& samplesBursts)
std::vector<std::pair<unsigned long,unsigned long> >& samplesBursts,
unsigned int & linesOffset, unsigned int first_burstInd,
bool inputWithInvalidPixels)
{
if(m_SensorModel.get())
{
return m_SensorModel->deburstAndConcatenate(linesBursts, samplesBursts);
return m_SensorModel->deburstAndConcatenate(linesBursts, samplesBursts, linesOffset, first_burstInd,
inputWithInvalidPixels);
}
return false;
......
......@@ -79,6 +79,11 @@ private:
AddParameter(ParameterType_OutputImage, "out", "Output Image");
SetParameterDescription("out", "The concatenated and debursted output image.");
AddParameter(ParameterType_Int, "burstindex", "Index of the first Burst");
SetParameterDescription("burstindex", "Index for the first required Burst");
MandatoryOff("burstindex");
SetDefaultParameterInt("burstindex", 0);
AddRAMParameter();
// Doc example parameter settings
......@@ -94,6 +99,9 @@ private:
void DoExecute() override
{
// Get the first Burst index
int burst_index = GetParameterInt("burstindex");
// Instanciate filters
ExtractROIFilterListType::Pointer m_ExtractorList = ExtractROIFilterListType::New();
ImageListType::Pointer m_ImageList = ImageListType::New();
......@@ -117,7 +125,7 @@ private:
catch( ... )
{
// Throw an execption
throw std::runtime_error("Failed to retrieve bursts.number value from .geom file.");
otbAppLogFATAL(<< "Failed to retrieve bursts.number value from .geom file.");
}
nbBursts = inList->Size();
......@@ -129,7 +137,17 @@ private:
// Coniguration for fusion filter
fusionFilter->SetSLCImageKeyWorList(in->GetImageKeywordlist());
fusionFilter->getDeburstLinesAndSamples(lines, samples);
// 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";
fusionFilter->getDeburstLinesAndSamples(lines, samples, burst_index, inputWithInvalidPixels);
// Split each input burst to keep only interested region
for( unsigned int i=0; i<inList->Size(); i++ )
......@@ -137,6 +155,16 @@ private:
FloatVectorImageType::Pointer vectIm = inList->GetNthElement(i);
vectIm->UpdateOutputInformation();
// Check invalid Pixel Key
const bool inputWithInvalidPixels_loop = vectIm->GetImageKeywordlist().HasKey("support_data.invalid_pixels")
&& vectIm->GetImageKeywordlist().GetMetadataByKey("support_data.invalid_pixels") == "yes";
if (inputWithInvalidPixels_loop != inputWithInvalidPixels)
{
// Throw an execption
otbAppLogFATAL(<< "Incoherency between input images (for support_data.invalid_pixels key).");
}
unsigned long originOffset_samples = static_cast<long>(vectIm->GetOrigin()[0]-0.5);
unsigned long originOffset_lines = static_cast<long>(vectIm->GetOrigin()[1]-0.5);
......
......@@ -140,6 +140,15 @@ SarBurstExtractionImageFilter<TImage>::GenerateOutputInformation()
newKwl.AddKey("number_samples", std::to_string(burstSize[0]));
newKwl.AddKey("number_lines", std::to_string(burstSize[1]));
if (m_AllPixels)
{
newKwl.AddKey("support_data.invalid_pixels", "yes");
}
else
{
newKwl.AddKey("support_data.invalid_pixels", "no");
}
// Set new keyword list to output image
outputPtr->SetImageKeywordList(newKwl);
......
......@@ -69,6 +69,7 @@ public:
typedef typename ImageType::Pointer ImagePointerType;
typedef typename ImageType::SizeType SizeType;
typedef typename ImageType::RegionType RegionType;
typedef typename ImageType::PointType PointType;
typedef std::pair<unsigned long, unsigned long> RecordType;
typedef std::vector<RecordType> LinesRecordVectorType;
......@@ -82,7 +83,8 @@ public:
// Setter
void SetSLCImageKeyWorList(ImageKeywordlist sarImageKWL);
bool getDeburstLinesAndSamples(LinesRecordVectorType & linesRecord, LinesRecordVectorType & samplesRecord);
bool getDeburstLinesAndSamples(LinesRecordVectorType & linesRecord, LinesRecordVectorType & samplesRecord,
unsigned int first_burstInd, bool inputWithInvalidPixels);
protected:
/** Constructor */
......@@ -104,6 +106,8 @@ private:
// Deburst SLC KeywordList
ImageKeywordlist m_DeburstSLCImageKWL;
unsigned int m_Offset_OriginL;
};
} // end namespace itk
......
......@@ -38,7 +38,8 @@ SarConcatenateBurstsImageFilter<TImage>
template <class TImage>
bool
SarConcatenateBurstsImageFilter<TImage>
::getDeburstLinesAndSamples(LinesRecordVectorType & linesRecord, LinesRecordVectorType & samplesRecord)
::getDeburstLinesAndSamples(LinesRecordVectorType & linesRecord, LinesRecordVectorType & samplesRecord,
unsigned int first_burstInd, bool inputWithInvalidPixels)
{
// Try to create a SarSensorModelAdapter
SarSensorModelAdapter::Pointer sarSensorModel = SarSensorModelAdapter::New();
......@@ -47,9 +48,13 @@ SarConcatenateBurstsImageFilter<TImage>
if(!loadOk || !sarSensorModel->IsValidSensorModel())
itkExceptionMacro(<<"Input image does not contain a valid SAR sensor model.");
LinesRecordVectorType lines;
// Try to call the deburstAndConcatenate function
bool deburstAndConcatenateOk = sarSensorModel->DeburstAndConcatenate(linesRecord, samplesRecord);
bool deburstAndConcatenateOk = sarSensorModel->DeburstAndConcatenate(linesRecord, samplesRecord,
m_Offset_OriginL, first_burstInd,
inputWithInvalidPixels);
if(!deburstAndConcatenateOk)
itkExceptionMacro(<<"Could not deburst or concatenate from input bursts");
......@@ -71,9 +76,16 @@ SarConcatenateBurstsImageFilter<TImage>
// First, call superclass implementation
Superclass::GenerateOutputInformation();
// Output KeywordList
ImageType * outputPtr = this->GetOutput();
// Origin to (0.5, 0.5) : Metadata are already adjusted
PointType origin;
origin[0] = 0.5;
origin[1] = 0.5 + m_Offset_OriginL;
outputPtr->SetOrigin(origin);
// Output KeywordList
m_DeburstSLCImageKWL.AddKey("support_data.number_samples", std::to_string(this->GetOutput()->
GetLargestPossibleRegion().
GetSize()[0]));
......
......@@ -351,7 +351,9 @@ public:
* \param lines A Boolean to indicate only valids samples are required.
*/
bool deburstAndConcatenate(std::vector<std::pair<unsigned long,unsigned long> >& linesBursts,
std::vector<std::pair<unsigned long,unsigned long> >& samplesBursts);
std::vector<std::pair<unsigned long,unsigned long> >& samplesBursts,
unsigned int & linesOffset, unsigned int first_burstInd,
bool inputWithInvalidPixels=false);
/**
* Returns pointer to a new instance, copy of this.
......
......@@ -1728,7 +1728,9 @@ ossimSarSensorModel::burstExtraction(const unsigned int burst_index,
bool
ossimSarSensorModel::deburstAndConcatenate(std::vector<std::pair<unsigned long,unsigned long> >& linesBursts,
std::vector<std::pair<unsigned long,unsigned long> >& samplesBursts)
std::vector<std::pair<unsigned long,unsigned long> >& samplesBursts,
unsigned int & linesOffset, unsigned int first_burstInd,
bool inputWithInvalidPixels)
{
if(theBurstRecords.empty())
return false;
......@@ -1865,16 +1867,36 @@ ossimSarSensorModel::deburstAndConcatenate(std::vector<std::pair<unsigned long,u
for(; itBursts!= theBurstRecords.end() ;++itBursts)
{
unsigned long currentStart_L = halfLineOverlapBegin[counter];
if (inputWithInvalidPixels)
{
currentStart_L += itBursts->startLine - counter*theNumberOfLinesPerBurst;
}
unsigned long currentStop_L = itBursts->endLine - itBursts->startLine - halfLineOverlapEnd[counter];
if (inputWithInvalidPixels)
{
currentStop_L = itBursts->endLine - counter*theNumberOfLinesPerBurst - halfLineOverlapEnd[counter];
}
linesBursts.push_back(std::make_pair(currentStart_L, currentStop_L));
unsigned long currentStart_S = 0;
unsigned long currentStop_S = samples.second-samples.first;
if (itBursts->startSample < samples.first)
if (inputWithInvalidPixels)
{
currentStart_S = samples.first - itBursts->startSample;
currentStart_S = samples.first;
}
else
{
if (itBursts->startSample < samples.first)
{
currentStart_S = samples.first - itBursts->startSample;
}
}
currentStop_S += currentStart_S;
samplesBursts.push_back(std::make_pair(currentStart_S, currentStop_S));
......@@ -1882,6 +1904,9 @@ ossimSarSensorModel::deburstAndConcatenate(std::vector<std::pair<unsigned long,u
++counter;
}
// Define linesOffset
linesOffset = (theBurstRecords[first_burstInd].azimuthStartTime - theBurstRecords[0].azimuthStartTime)/theAzimuthTimeInterval;
// Clear the previous burst records
theBurstRecords.clear();
......
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