Commit 918ef4e8 authored by Jordi Inglada's avatar Jordi Inglada
Browse files

STYLE: rename new DimensionalityReduction applications

No related merge requests found
Showing with 179 additions and 179 deletions
+179 -179
......@@ -31,20 +31,20 @@ otb_create_application(
LINK_LIBRARIES ${${otb-module}_LIBRARIES})
OTB_CREATE_APPLICATION(
NAME CbDimensionalityReductionTrainer
SOURCES cbDimensionalityReductionTrainer.cxx
NAME TrainDimensionalityReduction
SOURCES otbTrainDimensionalityReduction.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES} ${OTBCommon_LIBRARIES} ${OTBITK_LIBRARIES} ${OTBBoost_LIBRARIES} ${OTBShark_LIBRARIES}
)
OTB_CREATE_APPLICATION(
NAME CbDimensionalityReduction
SOURCES cbDimensionalityReduction.cxx
NAME ImageDimensionalityReduction
SOURCES otbImageDimensionalityReduction.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES} ${OTBCommon_LIBRARIES} ${OTBITK_LIBRARIES} ${OTBBoost_LIBRARIES} ${OTBShark_LIBRARIES}
)
OTB_CREATE_APPLICATION(
NAME CbDimensionalityReductionVector
SOURCES cbDimensionalityReductionVector.cxx
NAME VectorDimensionalityReduction
SOURCES otbVectorDimensionalityReduction.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES} ${OTBCommon_LIBRARIES} ${OTBITK_LIBRARIES} ${OTBBoost_LIBRARIES} ${OTBShark_LIBRARIES}
)
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbOGRDataSourceWrapper.h"
#include "otbOGRFeatureWrapper.h"
#include "itkVariableLengthVector.h"
#include "otbShiftScaleSampleListFilter.h"
#include "otbStatisticsXMLFileReader.h"
//#include "otbSharkUtils.h"
#include <fstream> // write the model file
#include "DimensionalityReductionModelFactory.h"
#include "cbLearningApplicationBaseDR.h"
namespace otb
{
namespace Wrapper
{
class CbDimensionalityReductionTrainer : public cbLearningApplicationBaseDR<float,float>
{
public:
typedef CbDimensionalityReductionTrainer Self;
typedef cbLearningApplicationBaseDR<float, float> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkNewMacro(Self);
itkTypeMacro(CbDimensionalityReductionTrainer, otb::Application);
typedef Superclass::SampleType SampleType;
typedef Superclass::ListSampleType ListSampleType;
typedef Superclass::SampleImageType SampleImageType;
typedef float ValueType;
typedef itk::VariableLengthVector<ValueType> MeasurementType;
typedef otb::StatisticsXMLFileReader<SampleType> StatisticsReader;
typedef otb::Statistics::ShiftScaleSampleListFilter<ListSampleType, ListSampleType> ShiftScaleFilterType;
typedef otb::DimensionalityReductionModelFactory<ValueType, ValueType> ModelFactoryType;
private:
void DoInit()
{
SetName("CbDimensionalityReductionTrainer");
SetDescription("Trainer for the dimensionality reduction algorithms used in the cbDimensionalityReduction application.");
AddParameter(ParameterType_Group, "io", "Input and output data");
SetParameterDescription("io", "This group of parameters allows setting input and output data.");
AddParameter(ParameterType_InputVectorData, "io.vd", "Input Vector Data");
SetParameterDescription("io.vd", "Input geometries used for training (note : all geometries from the layer will be used)");
AddParameter(ParameterType_OutputFilename, "io.out", "Output model");
SetParameterDescription("io.out", "Output file containing the model estimated (.txt format).");
AddParameter(ParameterType_InputFilename, "io.stats", "Input XML image statistics file");
MandatoryOff("io.stats");
SetParameterDescription("io.stats", "XML file containing mean and variance of each feature.");
AddParameter(ParameterType_StringList, "feat", "Field names to be calculated."); //
SetParameterDescription("feat","List of field names in the input vector data used as features for training."); //
Superclass::DoInit();
AddRAMParameter();
}
void DoUpdateParameters()
{
}
void DoExecute()
{
std::string shapefile = GetParameterString("io.vd");
otb::ogr::DataSource::Pointer source = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Read);
otb::ogr::Layer layer = source->GetLayer(0);
ListSampleType::Pointer input = ListSampleType::New();
const int nbFeatures = GetParameterStringList("feat").size();
input->SetMeasurementVectorSize(nbFeatures);
otb::ogr::Layer::const_iterator it = layer.cbegin();
otb::ogr::Layer::const_iterator itEnd = layer.cend();
for( ; it!=itEnd ; ++it)
{
MeasurementType mv;
mv.SetSize(nbFeatures);
for(int idx=0; idx < nbFeatures; ++idx)
{
mv[idx] = (*it)[GetParameterStringList("feat")[idx]].GetValue<double>();
}
input->PushBack(mv);
}
MeasurementType meanMeasurementVector;
MeasurementType stddevMeasurementVector;
if (HasValue("io.stats") && IsParameterEnabled("io.stats"))
{
StatisticsReader::Pointer statisticsReader = StatisticsReader::New();
std::string XMLfile = GetParameterString("io.stats");
statisticsReader->SetFileName(XMLfile);
meanMeasurementVector = statisticsReader->GetStatisticVectorByName("mean");
stddevMeasurementVector = statisticsReader->GetStatisticVectorByName("stddev");
}
else
{
meanMeasurementVector.SetSize(nbFeatures);
meanMeasurementVector.Fill(0.);
stddevMeasurementVector.SetSize(nbFeatures);
stddevMeasurementVector.Fill(1.);
}
ShiftScaleFilterType::Pointer trainingShiftScaleFilter = ShiftScaleFilterType::New();
trainingShiftScaleFilter->SetInput(input);
trainingShiftScaleFilter->SetShifts(meanMeasurementVector);
trainingShiftScaleFilter->SetScales(stddevMeasurementVector);
trainingShiftScaleFilter->Update();
ListSampleType::Pointer trainingListSample= trainingShiftScaleFilter->GetOutput();
this->Train(trainingListSample,GetParameterString("io.out"));
}
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::CbDimensionalityReductionTrainer)
......@@ -71,11 +71,11 @@ private:
namespace Wrapper
{
class CbDimensionalityReduction : public Application
class ImageDimensionalityReduction : public Application
{
public:
/** Standard class typedefs. */
typedef CbDimensionalityReduction Self;
typedef ImageDimensionalityReduction Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......@@ -83,7 +83,7 @@ public:
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(CbDimensionalityReduction, otb::Application);
itkTypeMacro(ImageDimensionalityReduction, otb::Application);
/** Filters typedef */
typedef UInt8ImageType MaskImageType;
......@@ -104,10 +104,10 @@ public:
protected:
~CbDimensionalityReduction() ITK_OVERRIDE
{
~ImageDimensionalityReduction() ITK_OVERRIDE
{
DimensionalityReductionModelFactoryType::CleanFactories();
}
}
private:
void DoInit() ITK_OVERRIDE
......@@ -119,7 +119,7 @@ private:
SetDocName("DimensionalityReduction");
SetDocLongDescription("This application reduces the dimension of an input"
" image, based on a machine learning model file produced by"
" the DimensionalityReductionTrainer application. Pixels of the "
" the TrainDimensionalityReduction application. Pixels of the "
"output image will contain the reduced values from"
"the model. The input pixels"
" can be optionally centered and reduced according "
......@@ -132,7 +132,7 @@ private:
"Training application, it is mandatory to use the same "
"statistics file for reduction.");
SetDocAuthors("OTB-Team");
SetDocSeeAlso("DimensionalityReductionTrainer, ComputeImagesStatistics");
SetDocSeeAlso("TrainDimensionalityReduction, ComputeImagesStatistics");
AddDocTag(Tags::Learning);
......@@ -146,27 +146,27 @@ private:
MandatoryOff("mask");
AddParameter(ParameterType_InputFilename, "model", "Model file");
SetParameterDescription("model", "A regression model file (produced by "
"TrainRegression application).");
SetParameterDescription("model", "A dimensionality reduction model file (produced by "
"TrainRegression application).");
AddParameter(ParameterType_InputFilename, "imstat", "Statistics file");
SetParameterDescription("imstat", "A XML file containing mean and standard"
" deviation to center and reduce samples before prediction "
"(produced by ComputeImagesStatistics application). If this file contains"
"one more band than the sample size, the last stat of last band will be"
"applied to expand the output predicted value");
"one more bands than the sample size, the last stat of last band will be"
"applied to expand the output predicted value");
MandatoryOff("imstat");
AddParameter(ParameterType_OutputImage, "out", "Output Image");
SetParameterDescription( "out", "Output image containing predicted values");
SetParameterDescription( "out", "Output image containing reduced values");
AddRAMParameter();
// Doc example parameter settings
SetDocExampleParameterValue("in", "QB_1_ortho.tif");
SetDocExampleParameterValue("imstat", "EstimateImageStatisticsQB1.xml");
SetDocExampleParameterValue("model", "clsvmModelQB1.svm");
SetDocExampleParameterValue("out", "clLabeledImageQB1.tif");
SetDocExampleParameterValue("model", "clsvmModelQB1.model");
SetDocExampleParameterValue("out", "ReducedImageQB1.tif");
}
void DoUpdateParameters() ITK_OVERRIDE
......@@ -258,4 +258,4 @@ private:
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::CbDimensionalityReduction)
OTB_APPLICATION_EXPORT(otb::Wrapper::ImageDimensionalityReduction)
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbOGRDataSourceWrapper.h"
#include "otbOGRFeatureWrapper.h"
#include "itkVariableLengthVector.h"
#include "otbShiftScaleSampleListFilter.h"
#include "otbStatisticsXMLFileReader.h"
//#include "otbSharkUtils.h"
#include <fstream> // write the model file
#include "DimensionalityReductionModelFactory.h"
#include "cbLearningApplicationBaseDR.h"
namespace otb
{
namespace Wrapper
{
class TrainDimensionalityReduction : public cbLearningApplicationBaseDR<float,float>
{
public:
typedef TrainDimensionalityReduction Self;
typedef cbLearningApplicationBaseDR<float, float> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkNewMacro(Self);
itkTypeMacro(TrainDimensionalityReduction, otb::Application);
typedef Superclass::SampleType SampleType;
typedef Superclass::ListSampleType ListSampleType;
typedef Superclass::SampleImageType SampleImageType;
typedef float ValueType;
typedef itk::VariableLengthVector<ValueType> MeasurementType;
typedef otb::StatisticsXMLFileReader<SampleType> StatisticsReader;
typedef otb::Statistics::ShiftScaleSampleListFilter<ListSampleType, ListSampleType> ShiftScaleFilterType;
typedef otb::DimensionalityReductionModelFactory<ValueType, ValueType> ModelFactoryType;
private:
void DoInit()
{
SetName("TrainDimensionalityReduction");
SetDescription("Trainer for the dimensionality reduction algorithms used in the ImageDimensionalityReduction and VectorDimensionalityReduction applications.");
AddParameter(ParameterType_Group, "io", "Input and output data");
SetParameterDescription("io", "This group of parameters allows setting input and output data.");
AddParameter(ParameterType_InputVectorData, "io.vd", "Input Vector Data");
SetParameterDescription("io.vd", "Input geometries used for training (note : all geometries from the layer will be used)");
AddParameter(ParameterType_OutputFilename, "io.out", "Output model");
SetParameterDescription("io.out", "Output file containing the model estimated (.txt format).");
AddParameter(ParameterType_InputFilename, "io.stats", "Input XML image statistics file");
MandatoryOff("io.stats");
SetParameterDescription("io.stats", "XML file containing mean and variance of each feature.");
AddParameter(ParameterType_StringList, "feat", "Field names to be calculated."); //
SetParameterDescription("feat","List of field names in the input vector data used as features for training."); //
Superclass::DoInit();
AddRAMParameter();
}
void DoUpdateParameters()
{
}
void DoExecute()
{
std::string shapefile = GetParameterString("io.vd");
otb::ogr::DataSource::Pointer source = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Read);
otb::ogr::Layer layer = source->GetLayer(0);
ListSampleType::Pointer input = ListSampleType::New();
const int nbFeatures = GetParameterStringList("feat").size();
input->SetMeasurementVectorSize(nbFeatures);
otb::ogr::Layer::const_iterator it = layer.cbegin();
otb::ogr::Layer::const_iterator itEnd = layer.cend();
for( ; it!=itEnd ; ++it)
{
MeasurementType mv;
mv.SetSize(nbFeatures);
for(int idx=0; idx < nbFeatures; ++idx)
{
mv[idx] = (*it)[GetParameterStringList("feat")[idx]].GetValue<double>();
}
input->PushBack(mv);
}
MeasurementType meanMeasurementVector;
MeasurementType stddevMeasurementVector;
if (HasValue("io.stats") && IsParameterEnabled("io.stats"))
{
StatisticsReader::Pointer statisticsReader = StatisticsReader::New();
std::string XMLfile = GetParameterString("io.stats");
statisticsReader->SetFileName(XMLfile);
meanMeasurementVector = statisticsReader->GetStatisticVectorByName("mean");
stddevMeasurementVector = statisticsReader->GetStatisticVectorByName("stddev");
}
else
{
meanMeasurementVector.SetSize(nbFeatures);
meanMeasurementVector.Fill(0.);
stddevMeasurementVector.SetSize(nbFeatures);
stddevMeasurementVector.Fill(1.);
}
ShiftScaleFilterType::Pointer trainingShiftScaleFilter = ShiftScaleFilterType::New();
trainingShiftScaleFilter->SetInput(input);
trainingShiftScaleFilter->SetShifts(meanMeasurementVector);
trainingShiftScaleFilter->SetScales(stddevMeasurementVector);
trainingShiftScaleFilter->Update();
ListSampleType::Pointer trainingListSample= trainingShiftScaleFilter->GetOutput();
this->Train(trainingListSample,GetParameterString("io.out"));
}
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::TrainDimensionalityReduction)
......@@ -41,13 +41,13 @@ bool IsNotAlphaNum(char c)
return !std::isalnum(c);
}
class CbDimensionalityReductionVector : public Application
class VectorDimensionalityReduction : public Application
{
public:
/** Standard class typedefs. */
typedef CbDimensionalityReductionVector Self;
typedef Application Superclass;
typedef VectorDimensionalityReduction Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......@@ -68,8 +68,8 @@ class CbDimensionalityReductionVector : public Application
typedef itk::VariableLengthVector<ValueType> MeasurementType;
typedef otb::StatisticsXMLFileReader<MeasurementType> StatisticsReader;
typedef otb::Statistics::ShiftScaleSampleListFilter<ListSampleType, ListSampleType> ShiftScaleFilterType;
~CbDimensionalityReductionVector() ITK_OVERRIDE
{
~VectorDimensionalityReduction() ITK_OVERRIDE
{
DimensionalityReductionModelFactoryType::CleanFactories();
}
......@@ -81,8 +81,8 @@ class CbDimensionalityReductionVector : public Application
SetDescription("Performs dimensionality reduction of the input vector data according to a model file.");
SetDocName("Vector Dimensionality Reduction");
SetDocAuthors("OTB-Team");
SetDocLongDescription("This application performs a vector data dimensionality reduction based on a model file produced by the cbDimensionalityReductionTrainer application.");
SetDocSeeAlso("cbDimensionalityReductionTrainer");
SetDocLongDescription("This application performs a vector data dimensionality reduction based on a model file produced by the TrainDimensionalityReduction application.");
SetDocSeeAlso("TrainDimensionalityReduction");
AddDocTag(Tags::Learning);
AddParameter(ParameterType_InputVectorData, "in", "Name of the input vector data");
......@@ -94,13 +94,13 @@ class CbDimensionalityReductionVector : public Application
MandatoryOff("instat");
AddParameter(ParameterType_InputFilename, "model", "Model file");
SetParameterDescription("model", "A model file (produced by cbDimensionalityReduction application,");
SetParameterDescription("model", "A model file (produced by the TrainDimensionalityReduction application,");
AddParameter(ParameterType_ListView, "feat", "Field names to be calculated."); //
SetParameterDescription("feat","List of field names in the input vector data used as features for training."); //
SetParameterDescription("feat","List of field names in the input vector data used as features for reduction."); //
AddParameter(ParameterType_StringList, "featout", "Field names to be calculated."); //
SetParameterDescription("featout","List of field names in the input vector data used as features for training."); //
SetParameterDescription("featout","List of field names in the input vector data used as features for reduction."); //
AddParameter(ParameterType_OutputFilename, "out", "Output vector data file containing the reduced vector");
SetParameterDescription("out","Output vector data file storing sample values (OGR format)."
......@@ -388,4 +388,4 @@ class CbDimensionalityReductionVector : public Application
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::CbDimensionalityReductionVector)
OTB_APPLICATION_EXPORT(otb::Wrapper::VectorDimensionalityReduction)
Supports Markdown
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