Failed to fetch fork details. Try again later.
-
Guillaume Blanchy authored36812934
Forked from
reversaal / OhmPi
Source project has a limited visibility.
/*=========================================================================
Copyright (c) 2018-2019 IRSTEA
Copyright (c) 2020-2021 INRAE
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"
// Filter
#include "otbTensorflowSampler.h"
// Stack
#include "otbTensorflowSource.h"
namespace otb
{
namespace Wrapper
{
class PatchesExtraction : public Application
{
public:
/** Standard class typedefs. */
typedef PatchesExtraction Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(PatchesExtraction, Application);
/** Filter typedef */
typedef otb::TensorflowSampler<FloatVectorImageType, VectorDataType> SamplerType;
/** Typedefs for image concatenation */
typedef TensorflowSource<FloatVectorImageType> TFSourceType;
//
// Store stuff related to one source
//
struct SourceBundle
{
TFSourceType m_ImageSource; // Image source
FloatVectorImageType::SizeType m_PatchSize; // Patch size
std::string m_KeyIn; // Key of input image list
std::string m_KeyOut; // Key of output samples image
std::string m_KeyPszX; // Key for samples sizes X
std::string m_KeyPszY; // Key for samples sizes Y
std::string m_KeyNoData; // Key for no-data value
FloatVectorImageType::InternalPixelType m_NoDataValue; // No data value
};
//
// Add an input source, which includes:
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
// -an input image list
// -an output image (samples)
// -an input patchsize (dimensions of samples)
//
void AddAnInputImage()
{
// Number of source
unsigned int inputNumber = m_Bundles.size() + 1;
// Create keys and descriptions
std::stringstream ss_group_key, ss_desc_group, ss_key_in, ss_key_out, ss_desc_in,
ss_desc_out, ss_key_dims_x, ss_desc_dims_x, ss_key_dims_y, ss_desc_dims_y, ss_key_nodata, ss_desc_nodata;
ss_group_key << "source" << inputNumber;
ss_desc_group << "Parameters for source " << inputNumber;
ss_key_out << ss_group_key.str() << ".out";
ss_desc_out << "Output patches for image " << inputNumber;
ss_key_in << ss_group_key.str() << ".il";
ss_desc_in << "Input image(s) " << inputNumber;
ss_key_dims_x << ss_group_key.str() << ".patchsizex";
ss_desc_dims_x << "X patch size for image " << inputNumber;
ss_key_dims_y << ss_group_key.str() << ".patchsizey";
ss_desc_dims_y << "Y patch size for image " << inputNumber;
ss_key_nodata << ss_group_key.str() << ".nodata";
ss_desc_nodata << "No-data value for image " << inputNumber;
// Populate group
AddParameter(ParameterType_Group, ss_group_key.str(), ss_desc_group.str());
AddParameter(ParameterType_InputImageList, ss_key_in.str(), ss_desc_in.str() );
AddParameter(ParameterType_OutputImage, ss_key_out.str(), ss_desc_out.str());
AddParameter(ParameterType_Int, ss_key_dims_x.str(), ss_desc_dims_x.str());
SetMinimumParameterIntValue (ss_key_dims_x.str(), 1);
AddParameter(ParameterType_Int, ss_key_dims_y.str(), ss_desc_dims_y.str());
SetMinimumParameterIntValue (ss_key_dims_y.str(), 1);
AddParameter(ParameterType_Float, ss_key_nodata.str(), ss_desc_nodata.str());
MandatoryOff (ss_key_nodata.str());
// Add a new bundle
SourceBundle bundle;
bundle.m_KeyIn = ss_key_in.str();
bundle.m_KeyOut = ss_key_out.str();
bundle.m_KeyPszX = ss_key_dims_x.str();
bundle.m_KeyPszY = ss_key_dims_y.str();
bundle.m_KeyNoData = ss_key_nodata.str();
m_Bundles.push_back(bundle);
}
//
// Prepare bundles from the number of points
//
void PrepareInputs()
{
for (auto& bundle: m_Bundles)
{
// Create a stack of input images
FloatVectorImageListType::Pointer list = GetParameterImageList(bundle.m_KeyIn);
bundle.m_ImageSource.Set(list);
// Patch size
bundle.m_PatchSize[0] = GetParameterInt(bundle.m_KeyPszX);
bundle.m_PatchSize[1] = GetParameterInt(bundle.m_KeyPszY);
// No data value
if (HasValue(bundle.m_KeyNoData))
{
bundle.m_NoDataValue = GetParameterFloat(bundle.m_KeyNoData);
}
}