otbDecloudTimeSeriesPreProcessor.cxx 23.39 KiB
/*=========================================================================
     Copyright (c) INRAE 2020-2022. All rights reserved.
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.
=========================================================================*/
#include "itkFixedArray.h"
#include "itkObjectFactory.h"
#include "otbWrapperApplicationFactory.h"
// Application engine
#include "otbStandardFilterWatcher.h"
#include "itkFixedArray.h"
// Stack
#include "otbTensorflowSource.h"
#include "otbTensorflowCommon.h"
#include <vector>
#include <algorithm>
#include <numeric>
// Functor
#include "otbFunctorImageFilter.h"
// Channels slices
#include "otbMultiChannelExtractROI.h"
namespace otb
namespace Wrapper
// Name of the environment variable for the number of outputs
const std::string ENV_VAR_NOUTPUTS = "DECLOUD_PREPROCESSING_NOUTPUTS";
// Structure to store one timestamp and one index
template <class TimestampType>
struct TimestampWithIndex
  TimestampType timestamp;
  unsigned int  index;
// Sorting modes
enum SortMode
  ASC, // Ascending order
  DES, // Descending order
  ABS  // Ascending order computed from the abs(t-tref)
 * \class PixelFunction
 * \brief Computes the output pixel from
 * - SAR pixels (stacked in channels)
 * - Optical pixels (stacked in channels)
 * - pairs (list of pair of SAR and Optical input images indices)
 * - Nodata (of SAR, and Optical)
 * - Number of channels (in SAR, and Optical)
 * The function that computes the output pixel, outputs the stacked [SAR, Optical] pixels in channels
 * \ingroup OTBDecloud
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
template <class TPixel, class TPairList> class PixelFunction { public: PixelFunction() {} ~PixelFunction() {} bool operator!=(const PixelFunction &) const { return false; } bool operator==(const PixelFunction & other) const { return !(*this != other); } // Returns the output pixel size std::size_t OutputSize(std::array<size_t, 2ul> Inputs) const { return m_NbOutputImages * (m_SARNbBands + m_OptNbBands); } // Set parameters void SetParameters(TPairList pairs, unsigned int sarNbBands, unsigned int optNbBands, float sarNdVal, float optNdVal, unsigned int nbOutputImages) { m_Pairs = pairs; m_SARNbBands = sarNbBands; m_OptNbBands = optNbBands; m_SARNoDataValue = sarNdVal; m_OptNoDataValue = optNdVal; m_NbOutputImages = nbOutputImages; } /* * Get the pixel of n input image */ TPixel GetPixel(const TPixel & inPix, unsigned int idx, unsigned int nbBands) const { TPixel pix; pix.SetSize(nbBands); unsigned int outBand = 0; unsigned int start = idx * nbBands; for (unsigned int i = start; i < start + nbBands; i++) { pix[outBand] = inPix[i]; outBand++; } return pix; } /* * Tell if the pixel is full on no-data values */ bool IsNoData(const TPixel & pix, const float noDataValue) const { for (unsigned int i = 0; i < pix.GetSize(); i++) if (pix[i] != noDataValue) return false;