Commit 77f2c141 authored by Guillaume Pasero's avatar Guillaume Pasero

REFAC: clean old tests of SVMLearning

parent 4f474c69
#
# Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
otb_module_test()
set(OTBSVMLearningTests
otbSVMLearningTestDriver.cxx
otbSVMImageClassificationWithRuleFilter.cxx
otbLabelMapSVMClassifier.cxx
otbSVMPointSetModelEstimatorTrain.cxx
otbExhaustiveExponentialOptimizerNew.cxx
otbSVMImageModelEstimatorModelAccessor.cxx
otbSVMImageClassificationFilter.cxx
otbSVMModelNew.cxx
otbSVMImageModelEstimatorNew.cxx
otbSVMImageModelEstimatorTrainOneClass.cxx
otbSVMCrossValidationCostFunctionNew.cxx
otbSVMModelLoadSave.cxx
otbSVMClassifierPointSet.cxx
otbSVMImageClassificationWithRuleFilterNew.cxx
otbSVMImageModelEstimatorTrain.cxx
otbObjectDetectionClassifier.cxx
otbSVMClassifierNew.cxx
otbSVMSampleListModelEstimatorTest.cxx
otbSVMModelAccessor.cxx
otbSVMModelLoad.cxx
otbSVMImageClassificationFilterNew.cxx
otbSVMPointSetModelEstimatorNew.cxx
otbSVMMarginSampler.cxx
otbExhaustiveExponentialOptimizerTest.cxx
)
add_executable(otbSVMLearningTestDriver ${OTBSVMLearningTests})
target_link_libraries(otbSVMLearningTestDriver ${OTBSVMLearning-Test_LIBRARIES})
otb_module_target_label(otbSVMLearningTestDriver)
# Tests Declaration
otb_add_test(NAME leTvSVMImageClassificationWithRuleFilter COMMAND otbSVMLearningTestDriver
--compare-image ${NOTOL}
${BASELINE}/leSVMImageClassificationWithRuleFilterOutput.tif
${TEMP}/leSVMImageClassificationWithRuleFilterOutput.tif
otbSVMImageClassificationWithRuleFilter
${INPUTDATA}/ROI_QB_MUL_4.tif
${INPUTDATA}/svm_model_image
${TEMP}/leSVMImageClassificationWithRuleFilterOutput.tif)
#otb_add_test(NAME obTvLabelMapSVMClassifier COMMAND otbSVMLearningTestDriver
#otbLabelMapSVMClassifier
#${INPUTDATA}/maur.tif
#${INPUTDATA}/maur_labelled.tif
#${TEMP}/obTvLabelMapSVMClassifierLabeledOutput.tif)
otb_add_test(NAME obTuLabelMapSVMClassifierNew COMMAND otbSVMLearningTestDriver
otbLabelMapSVMClassifierNew)
otb_add_test(NAME leTvSVMPointSetModelEstimatorTrain COMMAND otbSVMLearningTestDriver
--compare-ascii ${EPSILON_3} ${BASELINE_FILES}/leTvsvm_model_pointset
${TEMP}/leTvsvm_model_pointset
otbSVMPointSetModelEstimatorTrain
${TEMP}/leTvsvm_model_pointset)
otb_add_test(NAME leTuExhaustiveExponentialOptimizerNew COMMAND otbSVMLearningTestDriver
otbExhaustiveExponentialOptimizerNew)
otb_add_test(NAME leTvSVMImageModelEstimatorModelAccessor COMMAND otbSVMLearningTestDriver
--compare-ascii ${EPSILON_3} ${BASELINE_FILES}/leSVMModelEstimatorModelAccessor.txt
${TEMP}/leSVMModelEstimatorModelAccessor.txt
otbSVMImageModelEstimatorModelAccessor
${INPUTDATA}/ROI_QB_MUL_4.tif
${INPUTDATA}/ROI_QB_MUL_4_train.c1.hdr
${TEMP}/leSVMModelEstimatorModelAccessor.txt)
otb_add_test(NAME leTvSVMImageClassificationFilter COMMAND otbSVMLearningTestDriver
--compare-image ${NOTOL}
${BASELINE}/leSVMImageClassificationFilterOutput.tif
${TEMP}/leSVMImageClassificationFilterOutput.tif
otbSVMImageClassificationFilter
${INPUTDATA}/ROI_QB_MUL_4.tif
${INPUTDATA}/svm_model_image
${TEMP}/leSVMImageClassificationFilterOutput.tif)
otb_add_test(NAME leTuSVMModelNew COMMAND otbSVMLearningTestDriver
otbSVMModelNew)
otb_add_test(NAME leTuSVMImageModelEstimatorNew COMMAND otbSVMLearningTestDriver
otbSVMImageModelEstimatorNew)
otb_add_test(NAME leTvSVMImageModelEstimatorTrainOneClass COMMAND otbSVMLearningTestDriver
--compare-ascii ${EPSILON_3} ${BASELINE_FILES}/leTvsvm_model_image_one_class
${TEMP}/leTvsvm_model_image_one_class
otbSVMImageModelEstimatorTrainOneClass
${INPUTDATA}/ROI_QB_MUL_4.tif
${INPUTDATA}/ROI_QB_MUL_4_train_one_class.tif
${TEMP}/leTvsvm_model_image_one_class)
otb_add_test(NAME leTuSVMCrossValidationCostFunctionNew COMMAND otbSVMLearningTestDriver
otbSVMCrossValidationCostFunctionNew)
otb_add_test(NAME leTvSVMModelLoadSave COMMAND otbSVMLearningTestDriver
--compare-ascii ${NOTOL} ${INPUTDATA}/svm_model
${TEMP}/svmmodel_test
otbSVMModelLoadSave
${INPUTDATA}/svm_model
${TEMP}/svmmodel_test)
otb_add_test(NAME leTvSVMClassifierPointSet COMMAND otbSVMLearningTestDriver
otbSVMClassifierPointSet
${INPUTDATA}/svm_model_pointset)
otb_add_test(NAME leTuSVMImageClassificationWithRuleFilterNew COMMAND otbSVMLearningTestDriver
otbSVMImageClassificationWithRuleFilterNew)
otb_add_test(NAME leTvSVMImageModelEstimatorTrain COMMAND otbSVMLearningTestDriver
--compare-ascii ${EPSILON_3} ${BASELINE_FILES}/leTvsvm_model_image
${TEMP}/leTvsvm_model_image
otbSVMImageModelEstimatorTrain
${INPUTDATA}/ROI_QB_MUL_4.tif
${INPUTDATA}/ROI_QB_MUL_4_train.c1.hdr
${TEMP}/leTvsvm_model_image
0 )
# RK: 09/2016. LibSVM has serious issues in the code. Fixing this third party code is the right fix
# which requires some time and communication with upstream developer. But in the mean-time this failing test
# cannot be attributed to way OTB or OTB dashboard. For this reason, I am skipping 'baseline' comparison of output
# results. From this day onwards test results are not validated and can have bad results.
# If and When libsvm code is fixed, we put back test validation. Until then, we are extremely sorry for this action.
# Twisting the test to check only some parameters while skipping always problematic ones does not seems a right choice.
# After all, test has problem which is clear, a fix is needed for sure and that fix must be applied upstream
# --compare-ascii ${EPSILON_3} ${BASELINE_FILES}/leTvsvm_model_image_opt
# ${TEMP}/leTvsvm_model_image_opt
otb_add_test(NAME leTvSVMImageModelEstimatorTrainWithOptimization COMMAND otbSVMLearningTestDriver
otbSVMImageModelEstimatorTrain
${INPUTDATA}/ROI_QB_MUL_4.tif
${INPUTDATA}/ROI_QB_MUL_4_train.c1.hdr
${TEMP}/leTvsvm_model_image_opt
1)
otb_add_test(NAME odTuObjectDetectionClassifierNew COMMAND otbSVMLearningTestDriver
otbObjectDetectionClassifierNew
)
otb_add_test(NAME odTvObjectDetectionClassifierStreaming COMMAND otbSVMLearningTestDriver
--compare-ascii ${NOTOL}
${BASELINE_FILES}/TvObjectDetectionClassifierOutput.txt
${TEMP}/TvObjectDetectionClassifierOutputStreaming.txt
otbObjectDetectionClassifier
${INPUTDATA}/ObjectReco/Boats/maur_B010202_01_extract_amplitude.tif
${INPUTDATA}/ObjectReco/Boats/FeatureStats_RadiometricMoments_amplitude.xml
${BASELINE_FILES}/TvDescriptorsSVMModelCreation.svm
${TEMP}/TvObjectDetectionClassifierOutputStreaming.txt
50 # streaming
5 # neighborhood radius
)
otb_add_test(NAME odTvObjectDetectionClassifier COMMAND otbSVMLearningTestDriver
--compare-ascii ${NOTOL}
${BASELINE_FILES}/TvObjectDetectionClassifierOutput.txt
${TEMP}/TvObjectDetectionClassifierOutput.txt
otbObjectDetectionClassifier
${INPUTDATA}/ObjectReco/Boats/maur_B010202_01_extract_amplitude.tif
${INPUTDATA}/ObjectReco/Boats/FeatureStats_RadiometricMoments_amplitude.xml
${BASELINE_FILES}/TvDescriptorsSVMModelCreation.svm
${TEMP}/TvObjectDetectionClassifierOutput.txt
0 # streaming
5 # neighborhood radius
)
otb_add_test(NAME leTuSVMClassifierNew COMMAND otbSVMLearningTestDriver
otbSVMClassifierNew)
otb_add_test(NAME leTvSVMSampleListModelEstimatorTest COMMAND otbSVMLearningTestDriver
--compare-ascii ${EPSILON_4}
${BASELINE_FILES}/leTvSVMSampleListModelEstimatorModel.txt
${TEMP}/leTvSVMSampleListModelEstimatorModel.txt
otbSVMSampleListModelEstimatorTest
${EXAMPLEDATA}/qb_RoadExtract.tif
${EXAMPLEDATA}/qb_RoadExtract_easyClassification.shp
${TEMP}/leTvSVMSampleListModelEstimatorModel.txt
)
otb_add_test(NAME leTuSVMSampleListModelEstimatorNew COMMAND otbSVMLearningTestDriver
otbSVMSampleListModelEstimatorNew)
otb_add_test(NAME leTvSVMModelAccessor COMMAND otbSVMLearningTestDriver
--compare-ascii ${EPSILON_5} ${BASELINE_FILES}/leSVMModelAccessor.txt
${TEMP}/leSVMModelAccessor.txt
otbSVMModelAccessor
${INPUTDATA}/svm_model
${TEMP}/leSVMModelAccessor.txt)
otb_add_test(NAME leTuSVMModelLoad COMMAND otbSVMLearningTestDriver
otbSVMModelLoad
${INPUTDATA}/svm_model)
otb_add_test(NAME leTuSVMImageClassificationFilterNew COMMAND otbSVMLearningTestDriver
otbSVMImageClassificationFilterNew)
otb_add_test(NAME leTuSVMPointSetModelEstimatorNew COMMAND otbSVMLearningTestDriver
otbSVMPointSetModelEstimatorNew)
otb_add_test(NAME leTuSVMMarginSamplerNew COMMAND otbSVMLearningTestDriver
otbSVMMarginSamplerNew)
otb_add_test(NAME leTvExhaustiveExponentialOptimizerTest COMMAND otbSVMLearningTestDriver
--compare-ascii ${NOTOL}
${BASELINE_FILES}/leTvExhaustiveExponentialOptimizerOutput.txt
${TEMP}/leTvExhaustiveExponentialOptimizerTestOutput.txt
otbExhaustiveExponentialOptimizerTest
${TEMP}/leTvExhaustiveExponentialOptimizerTestOutput.txt)
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "itkPointSetToListSampleAdaptor.h"
#include "itkSubsample.h"
#include "otbSVMClassifier.h"
int otbSVMClassifierNew(int itkNotUsed(argc), char * itkNotUsed(argv) [])
{
typedef double InputPixelType;
typedef int LabelPixelType;
typedef itk::PointSet<InputPixelType, 2> PointSetType;
typedef itk::Statistics::PointSetToListSampleAdaptor<PointSetType>
DataSampleType;
typedef otb::SVMClassifier<DataSampleType, LabelPixelType> ClassifierType;
ClassifierType::Pointer classifier = ClassifierType::New();
std::cout << classifier << std::endl;
return EXIT_SUCCESS;
}
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <fstream>
#include "itkPoint.h"
#include "itkPointSetToListSampleAdaptor.h"
#include "itkSubsample.h"
#include "otbSVMClassifier.h"
int otbSVMClassifierPointSet(int argc, char* argv[])
{
if (argc != 2)
{
std::cout << "Usage : " << argv[0] << " modelFile"
<< std::endl;
return EXIT_FAILURE;
}
const char * modelFilename = argv[1];
std::cout << "Building the pointset" << std::endl;
typedef double InputPixelType;
typedef int LabelPixelType;
typedef std::vector<InputPixelType> InputVectorType;
const unsigned int Dimension = 2;
typedef itk::PointSet<InputVectorType, Dimension>
MeasurePointSetType;
MeasurePointSetType::Pointer mPSet = MeasurePointSetType::New();
typedef MeasurePointSetType::PointType MeasurePointType;
typedef MeasurePointSetType::PointsContainer MeasurePointsContainer;
MeasurePointsContainer::Pointer mCont = MeasurePointsContainer::New();
unsigned int pointId;
for (pointId = 0; pointId < 20; pointId++)
{
MeasurePointType mP;
mP[0] = pointId;
mP[1] = pointId;
InputVectorType measure;
//measure.push_back(vcl_pow(pointId, 2.0));
measure.push_back(double(2.0 * pointId));
measure.push_back(double(-10));
mCont->InsertElement(pointId, mP);
mPSet->SetPointData(pointId, measure);
}
mPSet->SetPoints(mCont);
std::cout << "PointSet built" << std::endl;
typedef itk::Statistics::PointSetToListSampleAdaptor<MeasurePointSetType>
SampleType;
SampleType::Pointer sample = SampleType::New();
sample->SetPointSet(mPSet);
std::cout << "Sample set to Adaptor" << std::endl;
/** preparing classifier and decision rule object */
typedef otb::SVMModel<SampleType::MeasurementVectorType::ValueType, LabelPixelType> ModelType;
ModelType::Pointer model = ModelType::New();
model->LoadModel(modelFilename);
std::cout << "Model loaded" << std::endl;
int numberOfClasses = model->GetNumberOfClasses();
typedef otb::SVMClassifier<SampleType, LabelPixelType> ClassifierType;
ClassifierType::Pointer classifier = ClassifierType::New();
classifier->SetNumberOfClasses(numberOfClasses);
classifier->SetModel(model);
classifier->SetInput(sample.GetPointer());
classifier->Update();
/* Build the class map */
std::cout << "classifier get output" << std::endl;
ClassifierType::OutputType* membershipSample =
classifier->GetOutput();
std::cout << "Sample iterators" << std::endl;
ClassifierType::OutputType::ConstIterator m_iter =
membershipSample->Begin();
ClassifierType::OutputType::ConstIterator m_last =
membershipSample->End();
double error = 0.0;
pointId = 0;
while (m_iter != m_last)
{
ClassifierType::ClassLabelType label = m_iter.GetClassLabel();
InputVectorType measure;
mPSet->GetPointData(pointId, &measure);
if (label != ((measure[0] + measure[1]) > 0)) error++;
std::cout << label << "/" <<
((measure[0] + measure[1]) > 0) << std::endl;
++pointId;
++m_iter;
}
std::cout << "Error = " << error / pointId << std::endl;
return EXIT_SUCCESS;
}
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbSVMImageClassificationFilter.h"
#include "otbVectorImage.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
int otbSVMImageClassificationFilter(int itkNotUsed(argc), char * argv[])
{
const char * infname = argv[1];
const char * modelfname = argv[2];
const char * outfname = argv[3];
const unsigned int Dimension = 2;
typedef double PixelType;
typedef unsigned short LabeledPixelType;
typedef otb::VectorImage<PixelType, Dimension> ImageType;
typedef otb::Image<LabeledPixelType, Dimension> LabeledImageType;
typedef otb::SVMImageClassificationFilter<ImageType, LabeledImageType> ClassificationFilterType;
typedef ClassificationFilterType::ModelType ModelType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageFileWriter<LabeledImageType> WriterType;
// Instantiating object
ClassificationFilterType::Pointer filter = ClassificationFilterType::New();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(infname);
ModelType::Pointer model = ModelType::New();
model->LoadModel(modelfname);
filter->SetModel(model);
filter->SetInput(reader->GetOutput());
WriterType::Pointer writer = WriterType::New();
writer->SetInput(filter->GetOutput());
writer->SetFileName(outfname);
writer->Update();
return EXIT_SUCCESS;
}
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbSVMImageClassificationFilter.h"
#include "otbVectorImage.h"
#include "otbImage.h"
int otbSVMImageClassificationFilterNew(int itkNotUsed(argc), char * itkNotUsed(argv) [])
{
const unsigned int Dimension = 2;
typedef double PixelType;
typedef unsigned short LabeledPixelType;
typedef otb::VectorImage<PixelType, Dimension> ImageType;
typedef otb::Image<LabeledPixelType, Dimension> LabeledImageType;
typedef otb::SVMImageClassificationFilter<ImageType, LabeledImageType> ClassificationFilterType;
// Instantiating object
ClassificationFilterType::Pointer filter = ClassificationFilterType::New();
std::cout << filter << std::endl;
return EXIT_SUCCESS;
}
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbSVMImageClassificationWithRuleFilter.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
int otbSVMImageClassificationWithRuleFilter(int itkNotUsed(argc), char * argv[])
{
const char * infname = argv[1];
const char * modelfname = argv[2];
const char * outfname = argv[3];
const unsigned int Dimension = 2;
typedef double PixelType;
typedef unsigned short LabeledPixelType;
typedef otb::VectorImage<PixelType, Dimension> ImageType;
typedef otb::Image<LabeledPixelType, Dimension> LabeledImageType;
typedef otb::SVMImageClassificationWithRuleFilter<ImageType, LabeledImageType> ClassificationFilterType;
typedef ClassificationFilterType::ModelType ModelType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageFileWriter<LabeledImageType> WriterType;
// Instantiating object
ClassificationFilterType::Pointer filter = ClassificationFilterType::New();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(infname);
ModelType::Pointer model = ModelType::New();
model->LoadModel(modelfname);
filter->SetModel(model);
filter->SetInput(reader->GetOutput());
WriterType::Pointer writer = WriterType::New();
writer->SetInput(filter->GetOutput());
writer->SetFileName(outfname);
writer->Update();
return EXIT_SUCCESS;
}
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbSVMImageClassificationWithRuleFilter.h"
#include "otbImage.h"
int otbSVMImageClassificationWithRuleFilterNew(int itkNotUsed(argc), char * itkNotUsed(argv) [])
{
const unsigned int Dimension = 2;
typedef double PixelType;
typedef unsigned short LabeledPixelType;
typedef otb::VectorImage<PixelType, Dimension> ImageType;
typedef otb::Image<LabeledPixelType, Dimension> LabeledImageType;
typedef otb::SVMImageClassificationWithRuleFilter<ImageType, LabeledImageType> ClassificationWithRuleFilterType;
// Instantiating object
ClassificationWithRuleFilterType::Pointer filter = ClassificationWithRuleFilterType::New();
std::cout << filter << std::endl;
return EXIT_SUCCESS;
}
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iomanip>
#include <iostream>
#include <fstream>
#include "itkMacro.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbSVMModel.h"
#include "otbSVMImageModelEstimator.h"
#include "otbImageFileReader.h"
int otbSVMImageModelEstimatorModelAccessor(int itkNotUsed(argc), char* argv[])
{
const char* inputImageFileName = argv[1];
const char* trainingImageFileName = argv[2];
const char* outputModelFileName = argv[3];
typedef double InputPixelType;
const unsigned int Dimension = 2;
typedef otb::VectorImage<InputPixelType, Dimension> InputImageType;
typedef otb::Image<int, Dimension> TrainingImageType;
typedef otb::SVMImageModelEstimator<InputImageType,
TrainingImageType> EstimatorType;
typedef otb::ImageFileReader<InputImageType> InputReaderType;
typedef otb::ImageFileReader<TrainingImageType> TrainingReaderType;
InputReaderType::Pointer inputReader = InputReaderType::New();
TrainingReaderType::Pointer trainingReader = TrainingReaderType::New();
inputReader->SetFileName(inputImageFileName);
trainingReader->SetFileName(trainingImageFileName);
inputReader->Update();
trainingReader->Update();
EstimatorType::Pointer svmEstimator = EstimatorType::New();
svmEstimator->SetInputImage(inputReader->GetOutput());
svmEstimator->SetTrainingImage(trainingReader->GetOutput());
svmEstimator