diff --git a/Applications/Classification/CMakeLists.txt b/Applications/Classification/CMakeLists.txt index e9783817f39252c50149c1d8ad44e12feb4ebb2d..bb31d9cc5f2efd1f31404681ae6b01d35ed35070 100644 --- a/Applications/Classification/CMakeLists.txt +++ b/Applications/Classification/CMakeLists.txt @@ -2,22 +2,10 @@ OTB_CREATE_APPLICATION(NAME ComputeImagesStatistics SOURCES otbComputeImagesStatistics.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) -OTB_CREATE_APPLICATION(NAME ImageSVMClassifier - SOURCES otbImageSVMClassifier.cxx - LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning) - OTB_CREATE_APPLICATION(NAME KMeansClassification SOURCES otbKMeansClassification.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning) -OTB_CREATE_APPLICATION(NAME TrainSVMImagesClassifier - SOURCES otbTrainSVMImagesClassifier.cxx - LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning) - -OTB_CREATE_APPLICATION(NAME ValidateSVMImagesClassifier - SOURCES otbValidateSVMImagesClassifier.cxx - LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning) - OTB_CREATE_APPLICATION(NAME SOMClassification SOURCES otbSOMClassification.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning) @@ -35,17 +23,17 @@ OTB_CREATE_APPLICATION(NAME ClassificationMapRegularization LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) IF(OTB_USE_OPENCV) - OTB_CREATE_APPLICATION(NAME TrainImagesClassifier - SOURCES otbTrainImagesClassifier.cxx otbTrainSVM.cxx otbTrainLibSVM.cxx otbTrainBoost.cxx - otbTrainDecisionTree.cxx otbTrainGradientBoostedTree.cxx otbTrainNeuralNetwork.cxx otbTrainNormalBayes.cxx - otbTrainRandomForests.cxx otbTrainKNN.cxx - LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning;OTBMachineLearning) - - OTB_CREATE_APPLICATION(NAME ImageClassifier - SOURCES otbImageClassifier.cxx - LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning;OTBMachineLearning) - - OTB_CREATE_APPLICATION(NAME ValidateImagesClassifier - SOURCES otbValidateImagesClassifier.cxx - LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning;OTBMachineLearning) + OTB_CREATE_APPLICATION(NAME TrainImagesClassifier + SOURCES otbTrainImagesClassifier.cxx otbTrainSVM.cxx otbTrainLibSVM.cxx otbTrainBoost.cxx + otbTrainDecisionTree.cxx otbTrainGradientBoostedTree.cxx otbTrainNeuralNetwork.cxx otbTrainNormalBayes.cxx + otbTrainRandomForests.cxx otbTrainKNN.cxx + LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning;OTBMachineLearning) + + OTB_CREATE_APPLICATION(NAME ImageClassifier + SOURCES otbImageClassifier.cxx + LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning;OTBMachineLearning) + + OTB_CREATE_APPLICATION(NAME ValidateImagesClassifier + SOURCES otbValidateImagesClassifier.cxx + LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction;OTBLearning;OTBMachineLearning) ENDIF() diff --git a/Applications/Classification/otbComputeImagesStatistics.cxx b/Applications/Classification/otbComputeImagesStatistics.cxx index a4b798436533f6d5ba71f1b8a7ad4c764b526989..184b6affac219d8b130dff39e7046daddca5a5ce 100644 --- a/Applications/Classification/otbComputeImagesStatistics.cxx +++ b/Applications/Classification/otbComputeImagesStatistics.cxx @@ -46,10 +46,10 @@ private: SetName("ComputeImagesStatistics"); SetDescription("Computes global mean and standard deviation for each band from a set of images and optionally saves the results in an XML file."); SetDocName("Compute Images second order statistics"); - SetDocLongDescription("This application computes a global mean and standard deviation for each band of a set of images and optionally saves the results in an XML file. The output XML is intended to be used an input for the TrainImagesSVMClassifier application to normalize samples before learning."); + SetDocLongDescription("This application computes a global mean and standard deviation for each band of a set of images and optionally saves the results in an XML file. The output XML is intended to be used an input for the TrainImagesClassifier application to normalize samples before learning."); SetDocLimitations("Each image of the set must contain the same bands as the others (i.e. same types, in the same order)."); SetDocAuthors("OTB-Team"); - SetDocSeeAlso("Documentation of the TrainImagesSVMClassifier application."); + SetDocSeeAlso("Documentation of the TrainImagesClassifier application."); AddDocTag(Tags::Learning); AddDocTag(Tags::Analysis); diff --git a/Applications/Classification/otbFusionOfClassifications.cxx b/Applications/Classification/otbFusionOfClassifications.cxx index df8c795f80dfc477c313f904c2e7eda3a1b4247f..0ca0f9c3c9138ace6e1a4682fbe9631001d78f64 100644 --- a/Applications/Classification/otbFusionOfClassifications.cxx +++ b/Applications/Classification/otbFusionOfClassifications.cxx @@ -110,7 +110,7 @@ private: "-In case of number of votes equality, the UNDECIDED label is attributed to the pixel."); SetDocLimitations("None"); SetDocAuthors("OTB-Team"); - SetDocSeeAlso("SVMImagesClassifier application"); + SetDocSeeAlso("ImageClassifier application"); AddDocTag(Tags::Learning); AddDocTag(Tags::Analysis); diff --git a/Applications/Classification/otbImageClassifier.cxx b/Applications/Classification/otbImageClassifier.cxx index 504579e04d5f03a6ce29be0b7a386c81f1310322..c9d9463652c3a2e5721d853289c5cfb8cc58b1fc 100644 --- a/Applications/Classification/otbImageClassifier.cxx +++ b/Applications/Classification/otbImageClassifier.cxx @@ -69,7 +69,7 @@ private: SetDocName("Image Classification"); SetDocLongDescription("This application performs an image classification based on a model file (*.txt extension) produced by the TrainImagesClassifier application. Pixels of the output image will contain the class label decided by the classifier. The input pixels can be optionnaly centered and reduced according to the statistics file produced by the ComputeImagesStatistics application. An optional input mask can be provided, in which case only input image pixels whose corresponding mask value is greater than 0 will be classified. The remaining of pixels will be given the label 0 in the output image."); - SetDocLimitations("The input image must have the same type, order and number of bands than the images used to produce the statistics file and the SVM model file. If a statistics file was used during training by the TrainSVMImagesClassifier, it is mandatory to use the same statistics file for classification. If an input mask is used, its size must match the input image size."); + SetDocLimitations("The input image must have the same type, order and number of bands than the images used to produce the statistics file and the SVM model file. If a statistics file was used during training by the TrainImagesClassifier, it is mandatory to use the same statistics file for classification. If an input mask is used, its size must match the input image size."); SetDocAuthors("OTB-Team"); SetDocSeeAlso("TrainImagesClassifier, ValidateImagesClassifier, ComputeImagesStatistics"); diff --git a/Applications/Classification/otbImageSVMClassifier.cxx b/Applications/Classification/otbImageSVMClassifier.cxx deleted file mode 100644 index c3dd964e7e647ed76969be429c8efad09875aa54..0000000000000000000000000000000000000000 --- a/Applications/Classification/otbImageSVMClassifier.cxx +++ /dev/null @@ -1,173 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - 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 "otbWrapperApplication.h" -#include "otbWrapperApplicationFactory.h" - -#include "itkVariableLengthVector.h" -#include "otbChangeLabelImageFilter.h" -#include "otbStandardWriterWatcher.h" -#include "otbStatisticsXMLFileReader.h" -#include "otbShiftScaleVectorImageFilter.h" -#include "otbSVMImageClassificationFilter.h" -#include "otbMultiToMonoChannelExtractROI.h" -#include "otbImageToVectorImageCastFilter.h" - -namespace otb -{ -namespace Wrapper -{ - -class ImageSVMClassifier : public Application -{ -public: - /** Standard class typedefs. */ - typedef ImageSVMClassifier Self; - typedef Application Superclass; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - /** Standard macro */ - itkNewMacro(Self); - - itkTypeMacro(ImageSVMClassifier, otb::Application); - - /** Filters typedef */ - typedef itk::VariableLengthVector MeasurementType; - typedef otb::StatisticsXMLFileReader StatisticsReader; - typedef otb::ShiftScaleVectorImageFilter RescalerType; - typedef otb::SVMImageClassificationFilter ClassificationFilterType; - typedef ClassificationFilterType::Pointer ClassificationFilterPointerType; - typedef ClassificationFilterType::ModelType ModelType; - typedef ModelType::Pointer ModelPointerType; - -private: - void DoInit() - { - SetName("ImageSVMClassifier"); - SetDescription("Performs a SVM classification of the input image according to a SVM model file."); - - // Documentation - SetDocName("Image SVM Classification"); - SetDocLongDescription("This application performs a SVM image classification based on a SVM model file (*.svm extension) produced by the TrainSVMImagesClassifier application. Pixels of the output image will contain the class label decided by the SVM classifier. The input pixels can be optionnaly centered and reduced according to the statistics file produced by the ComputeImagesStatistics application. An optional input mask can be provided, in which case only input image pixels whose corresponding mask value is greater than 0 will be classified. The remaining of pixels will be given the label 0 in the output image."); - - SetDocLimitations("The input image must have the same type, order and number of bands than the images used to produce the statistics file and the SVM model file. If a statistics file was used during training by the TrainSVMImagesClassifier, it is mandatory to use the same statistics file for classification. If an input mask is used, its size must match the input image size."); - SetDocAuthors("OTB-Team"); - SetDocSeeAlso("TrainSVMImagesClassifier, ValidateSVMImagesClassifier, ComputeImagesStatistics"); - - AddDocTag(Tags::Learning); - - AddParameter(ParameterType_InputImage, "in", "Input Image"); - SetParameterDescription( "in", "The input image to classify."); - - AddParameter(ParameterType_InputImage, "mask", "Input Mask"); - SetParameterDescription( "mask", "The mask allows to restrict classification of the input image to the area where mask pixel values are greater than 0."); - MandatoryOff("mask"); - - AddParameter(ParameterType_InputFilename, "svm", "SVM Model file"); - SetParameterDescription("svm", "A SVM model file (*.svm extension, produced by TrainSVMImagesClassifier application)."); - - AddParameter(ParameterType_InputFilename, "imstat", "Statistics file"); - SetParameterDescription("imstat", "A XML file containing mean and standard deviation to center and reduce samples before classification (produced by ComputeImagesStatistics application)."); - MandatoryOff("imstat"); - - AddParameter(ParameterType_OutputImage, "out", "Output Image"); - SetParameterDescription( "out", "Output image containing class labels"); - SetParameterOutputImagePixelType( "out", ImagePixelType_uint8); - - AddRAMParameter(); - - // Doc example parameter settings - SetDocExampleParameterValue("in", "QB_1_ortho.tif"); - SetDocExampleParameterValue("imstat", "EstimateImageStatisticsQB1.xml"); - SetDocExampleParameterValue("svm", "clsvmModelQB1.svm"); - SetDocExampleParameterValue("out", "clLabeledImageQB1.tif"); - } - - void DoUpdateParameters() - { - // Nothing to do here : all parameters are independent - } - - void DoExecute() - { - // Load input image - FloatVectorImageType::Pointer inImage = GetParameterImage("in"); - inImage->UpdateOutputInformation(); - - // Load svm model - otbAppLogINFO("Loading SVM model"); - m_ModelSVM = ModelType::New(); - m_ModelSVM->LoadModel(GetParameterString("svm").c_str()); - otbAppLogINFO("SVM model loaded"); - - // Normalize input image (optional) - StatisticsReader::Pointer statisticsReader = StatisticsReader::New(); - MeasurementType meanMeasurementVector; - MeasurementType stddevMeasurementVector; - m_Rescaler = RescalerType::New(); - - // Classify - m_ClassificationFilter = ClassificationFilterType::New(); - m_ClassificationFilter->SetModel(m_ModelSVM); - - // Normalize input image if asked - if(IsParameterEnabled("imstat") ) - { - otbAppLogINFO("Input image normalization activated."); - // Load input image statistics - statisticsReader->SetFileName(GetParameterString("imstat")); - meanMeasurementVector = statisticsReader->GetStatisticVectorByName("mean"); - stddevMeasurementVector = statisticsReader->GetStatisticVectorByName("stddev"); - otbAppLogINFO( "mean used: " << meanMeasurementVector ); - otbAppLogINFO( "standard deviation used: " << stddevMeasurementVector ); - // Rescale vector image - m_Rescaler->SetScale(stddevMeasurementVector); - m_Rescaler->SetShift(meanMeasurementVector); - m_Rescaler->SetInput(inImage); - - m_ClassificationFilter->SetInput(m_Rescaler->GetOutput()); - } - else - { - otbAppLogINFO("Input image normalization deactivated."); - m_ClassificationFilter->SetInput(inImage); - } - - - if(IsParameterEnabled("mask")) - { - otbAppLogINFO("Using input mask"); - // Load mask image and cast into LabeledImageType - UInt8ImageType::Pointer inMask = GetParameterUInt8Image("mask"); - - m_ClassificationFilter->SetInputMask(inMask); - } - - SetParameterOutputImage("out", m_ClassificationFilter->GetOutput()); - } - - ClassificationFilterType::Pointer m_ClassificationFilter; - ModelPointerType m_ModelSVM; - RescalerType::Pointer m_Rescaler; -}; - - -} -} - -OTB_APPLICATION_EXPORT(otb::Wrapper::ImageSVMClassifier) diff --git a/Applications/Classification/otbTrainSVMImagesClassifier.cxx b/Applications/Classification/otbTrainSVMImagesClassifier.cxx deleted file mode 100644 index f5339b2949747179a72250c79174400b1eae025b..0000000000000000000000000000000000000000 --- a/Applications/Classification/otbTrainSVMImagesClassifier.cxx +++ /dev/null @@ -1,538 +0,0 @@ -/*========================================================================= - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - 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 "otbWrapperApplication.h" -#include "otbWrapperApplicationFactory.h" - - -#include -#include "otbConfigurationFile.h" - -//Image -#include "otbImage.h" -#include "otbVectorImage.h" -#include "otbVectorData.h" -#include "otbListSampleGenerator.h" - -// ListSample -#include "itkListSample.h" -#include "itkVariableLengthVector.h" -#include "itkFixedArray.h" - -// SVM estimator -#include "otbSVMSampleListModelEstimator.h" - -// Statistic XML Reader -#include "otbStatisticsXMLFileReader.h" - -// Validation -#include "otbSVMClassifier.h" -#include "otbConfusionMatrixCalculator.h" - -#include "itkTimeProbe.h" -#include "otbStandardFilterWatcher.h" - -// Normalize the samples -#include "otbShiftScaleSampleListFilter.h" - -// List sample concatenation -#include "otbConcatenateSampleListFilter.h" - -// Balancing ListSample -#include "otbListSampleToBalancedListSampleFilter.h" - -// VectorData projection filter -#include "otbVectorDataProjectionFilter.h" - -// Extract a ROI of the vectordata -#include "otbVectorDataIntoImageProjectionFilter.h" - -// Elevation handler -#include "otbWrapperElevationParametersHandler.h" - -namespace otb -{ -namespace Wrapper -{ - -class TrainSVMImagesClassifier: public Application -{ -public: - /** Standard class typedefs. */ - typedef TrainSVMImagesClassifier Self; - typedef Application Superclass; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - /** Standard macro */ - itkNewMacro(Self); - - itkTypeMacro(TrainSVMImagesClassifier, otb::Application); - - typedef otb::Image ImageReaderType; - - typedef FloatVectorImageType::PixelType PixelType; - typedef FloatVectorImageType VectorImageType; - typedef FloatImageType ImageType; - - // Training vectordata - typedef itk::VariableLengthVector MeasurementType; - - // SampleList manipulation - typedef otb::ListSampleGenerator ListSampleGeneratorType; - - typedef ListSampleGeneratorType::ListSampleType ListSampleType; - typedef ListSampleGeneratorType::LabelType LabelType; - typedef ListSampleGeneratorType::ListLabelType LabelListSampleType; - typedef otb::Statistics::ConcatenateSampleListFilter ConcatenateListSampleFilterType; - typedef otb::Statistics::ConcatenateSampleListFilter ConcatenateLabelListSampleFilterType; - - // Statistic XML file Reader - typedef otb::StatisticsXMLFileReader StatisticsReader; - - // Enhance List Sample typedef otb::Statistics::ListSampleToBalancedListSampleFilter BalancingListSampleFilterType; - typedef otb::Statistics::ShiftScaleSampleListFilter ShiftScaleFilterType; - - // SVM Estimator - typedef otb::Functor::VariableLengthVectorToMeasurementVectorFunctor MeasurementVectorFunctorType; - typedef otb::SVMSampleListModelEstimator - SVMEstimatorType; - - typedef otb::SVMClassifier ClassifierType; - - // Estimate performance on validation sample - typedef otb::ConfusionMatrixCalculator ConfusionMatrixCalculatorType; - typedef ClassifierType::OutputType ClassifierOutputType; - - // VectorData projection filter - typedef otb::VectorDataProjectionFilter VectorDataProjectionFilterType; - - // Extract ROI - typedef otb::VectorDataIntoImageProjectionFilter VectorDataReprojectionType; - -private: - void DoInit() - { - SetName("TrainSVMImagesClassifier"); - SetDescription("Train a SVM classifier from multiple pairs of images and training vector data."); - - // Documentation - SetDocName("Train SVM classifier from multiple images"); - SetDocLongDescription("This application performs SVM classifier training from multiple pairs of input images and training vector data. Samples are composed of pixel values in each band optionally centered and reduced using XML statistics file produced by the ComputeImagesStatistics application.\n The training vector data must contain polygons with a positive integer field representing the class label. Name of the field can be set using the \"Class label field\" parameter. Training and validation sample lists are built such that each class is equally represented in both lists. One parameter allows to control the ratio between the number of samples in training and validation sets. Two parameters allow to manage the size of the training and validation sets per class and per image.\n Several SVM classifier parameters can be set, such as the kernel function which defines the feature space (for example if the kernel is a Gaussian radial basis function, the corresponding feature space is an infinite-dimensional space). To allow some flexibility in the classification, SVM models have a cost parameter, C, that controls the trade-off between allowing training errors and forcing rigid margins. It creates a soft margin that permits some misclassifications. Increasing the value of C increases the cost of misclassifying points and forces the creation of a more accurate model that may not generalize well. Classifier parameters can also be optimized. In the validation process, the confusion matrix is organized the following way: rows = reference labels, columns = produced labels."); - SetDocLimitations("None"); - SetDocAuthors("OTB-Team"); - SetDocSeeAlso(" "); - - AddDocTag(Tags::Learning); - - //Group IO - AddParameter(ParameterType_Group,"io","Input and output data"); - SetParameterDescription("io","This group of parameters allows to set input and output data."); - AddParameter(ParameterType_InputImageList, "io.il", "Input Image List"); - SetParameterDescription("io.il", "A list of input images."); - AddParameter(ParameterType_InputVectorDataList, "io.vd", "Vector Data List"); - SetParameterDescription("io.vd", "A list of vector data to select the training samples."); - AddParameter(ParameterType_InputFilename, "io.imstat", "XML image statistics file"); - MandatoryOff("io.imstat"); - SetParameterDescription("io.imstat", "Filename of an XML file containing mean and standard deviation of input images."); - AddParameter(ParameterType_OutputFilename, "io.out", "Output SVM model"); - SetParameterDescription("io.out", "Output file containing the SVM model estimated"); - - // Elevation - ElevationParametersHandler::AddElevationParameters(this, "elev"); - - //Group Sample list - AddParameter(ParameterType_Group,"sample","Training and validation samples parameters"); - SetParameterDescription("sample","This group of parameters allows to set training and validation sample lists parameters."); - - AddParameter(ParameterType_Int, "sample.mt", "Maximum training sample size"); - //MandatoryOff("mt"); - SetDefaultParameterInt("sample.mt", 1000); - SetParameterDescription("sample.mt", "Maximum size of the training sample list (default = 1000)."); - AddParameter(ParameterType_Int, "sample.mv", "Maximum validation sample size"); - // MandatoryOff("mv"); - SetDefaultParameterInt("sample.mv", 1000); - SetParameterDescription("sample.mv", "Maximum size of the validation sample list (default = 1000)"); - - AddParameter(ParameterType_Empty, "sample.edg", "On edge pixel inclusion"); - SetParameterDescription("sample.edg", "Take pixels on polygon edge into consideration when building training and validation samples."); - MandatoryOff("sample.edg"); - - AddParameter(ParameterType_Float, "sample.vtr", "training and validation sample ratio"); - SetParameterDescription("sample.vtr", - "Ratio between training and validation samples (0.0 = all training, 1.0 = all validation) default = 0.5."); - SetParameterFloat("sample.vtr", 0.5); - - AddParameter(ParameterType_String, "sample.vfn", "Name of the discrimination field"); - SetParameterDescription("sample.vfn", "Name of the field used to discriminate class in the vector data files."); - SetParameterString("sample.vfn", "Class"); - - //Group SVM - AddParameter(ParameterType_Group,"svm","SVM classifier parameters"); - SetParameterDescription("svm","This group of parameters allows to set SVM classifier parameters."); - AddParameter(ParameterType_Choice, "svm.k", "SVM Kernel Type"); - AddChoice("svm.k.linear", "Linear"); - AddChoice("svm.k.rbf", "Gaussian radial basis function"); - AddChoice("svm.k.poly", "Polynomial"); - AddChoice("svm.k.sigmoid", "Sigmoid"); - SetParameterString("svm.k", "linear"); - SetParameterDescription("svm.k", "SVM Kernel Type."); - AddParameter(ParameterType_Float, "svm.c", "Cost parameter C."); - SetParameterFloat("svm.c", 1.0); - SetParameterDescription("svm.c", "SVM models have a cost parameter C (1 by default) to control the trade-off between training errors and forcing rigid margins."); - AddParameter(ParameterType_Empty, "svm.opt", "parameters optimization"); - MandatoryOff("svm.opt"); - SetParameterDescription("svm.opt", "SVM optimization flag"); - - AddRANDParameter(); - // Doc example parameter settings - SetDocExampleParameterValue("io.il", "QB_1_ortho.tif"); - SetDocExampleParameterValue("io.vd", "VectorData_QB1.shp"); - SetDocExampleParameterValue("io.imstat", "EstimateImageStatisticsQB1.xml"); - SetDocExampleParameterValue("sample.mv", "100"); - SetDocExampleParameterValue("sample.mt", "100"); - SetDocExampleParameterValue("sample.vtr", "0.5"); - SetDocExampleParameterValue("svm.opt", "true"); - SetDocExampleParameterValue("io.out", "svmModelQB1.svm"); - } - - void DoUpdateParameters() - { - // Nothing to do here : all parameters are independent - } - - void LogConfusionMatrix(ConfusionMatrixCalculatorType* confMatCalc) - { - ConfusionMatrixCalculatorType::ConfusionMatrixType matrix = confMatCalc->GetConfusionMatrix(); - - // Compute minimal width - size_t minwidth = 0; - - for (unsigned int i = 0; i < matrix.Rows(); i++) - { - for (unsigned int j = 0; j < matrix.Cols(); j++) - { - std::ostringstream os; - os << matrix(i,j); - size_t size = os.str().size(); - - if (size > minwidth) - { - minwidth = size; - } - } - } - - typedef std::map MapOfIndicesType; - MapOfIndicesType mapOfIndices = confMatCalc->GetMapOfIndices(); - - MapOfIndicesType::const_iterator it = mapOfIndices.begin(); - MapOfIndicesType::const_iterator end = mapOfIndices.end(); - - for(; it != end; ++it) - { - std::ostringstream os; - os << "[" << it->second << "]"; - - size_t size = os.str().size(); - if (size > minwidth) - { - minwidth = size; - } - } - - - // Generate matrix string, with 'minwidth' as size specifier - std::ostringstream os; - - // Header line - for (size_t i = 0; i < minwidth; ++i) - os << " "; - os << " "; - - it = mapOfIndices.begin(); - end = mapOfIndices.end(); - for(; it != end; ++it) - { - os << "[" << it->second << "]" << " "; - } - - os << std::endl; - - // Each line of confusion matrix - for (unsigned int i = 0; i < matrix.Rows(); i++) - { - ConfusionMatrixCalculatorType::ClassLabelType label = mapOfIndices[i]; - os << "[" << std::setw(minwidth - 2) << label << "]" << " "; - for (unsigned int j = 0; j < matrix.Cols(); j++) - { - os << std::setw(minwidth) << matrix(i,j) << " "; - } - os << std::endl; - } - - otbAppLogINFO("Confusion matrix (rows = reference labels, columns = produced labels):\n" << os.str()); - } - - void DoExecute() - { - GetLogger()->Debug("Entering DoExecute\n"); - //Create training and validation for list samples and label list samples - ConcatenateLabelListSampleFilterType::Pointer - concatenateTrainingLabels = ConcatenateLabelListSampleFilterType::New(); - ConcatenateListSampleFilterType::Pointer concatenateTrainingSamples = ConcatenateListSampleFilterType::New(); - ConcatenateLabelListSampleFilterType::Pointer - concatenateValidationLabels = ConcatenateLabelListSampleFilterType::New(); - ConcatenateListSampleFilterType::Pointer concatenateValidationSamples = ConcatenateListSampleFilterType::New(); - - MeasurementType meanMeasurementVector; - MeasurementType stddevMeasurementVector; - - //-------------------------- - // Load measurements from images - unsigned int nbBands = 0; - //Iterate over all input images - - FloatVectorImageListType* imageList = GetParameterImageList("io.il"); - VectorDataListType* vectorDataList = GetParameterVectorDataList("io.vd"); - - vdreproj = VectorDataReprojectionType::New(); - - //Iterate over all input images - for (unsigned int imgIndex = 0; imgIndex < imageList->Size(); ++imgIndex) - { - FloatVectorImageType::Pointer image = imageList->GetNthElement(imgIndex); - image->UpdateOutputInformation(); - - if (imgIndex == 0) - { - nbBands = image->GetNumberOfComponentsPerPixel(); - } - - // read the Vectordata - VectorDataType::Pointer vectorData = vectorDataList->GetNthElement(imgIndex); - vectorData->Update(); - - vdreproj->SetInputImage(image); - vdreproj->SetInput(vectorData); - vdreproj->SetUseOutputSpacingAndOriginFromImage(false); - - // Setup the DEM Handler - otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev"); - - vdreproj->Update(); - - //Sample list generator - ListSampleGeneratorType::Pointer sampleGenerator = ListSampleGeneratorType::New(); - - - sampleGenerator->SetInput(image); - sampleGenerator->SetInputVectorData(vdreproj->GetOutput()); - - sampleGenerator->SetClassKey(GetParameterString("sample.vfn")); - sampleGenerator->SetMaxTrainingSize(GetParameterInt("sample.mt")); - sampleGenerator->SetMaxValidationSize(GetParameterInt("sample.mv")); - sampleGenerator->SetValidationTrainingProportion(GetParameterFloat("sample.vtr")); - - // take pixel located on polygon edge into consideration - if (IsParameterEnabled("sample.edg")) - { - sampleGenerator->SetPolygonEdgeInclusion(true); - } - - sampleGenerator->Update(); - - //Concatenate training and validation samples from the image - concatenateTrainingLabels->AddInput(sampleGenerator->GetTrainingListLabel()); - concatenateTrainingSamples->AddInput(sampleGenerator->GetTrainingListSample()); - concatenateValidationLabels->AddInput(sampleGenerator->GetValidationListLabel()); - concatenateValidationSamples->AddInput(sampleGenerator->GetValidationListSample()); - } - // Update - concatenateTrainingSamples->Update(); - concatenateTrainingLabels->Update(); - concatenateValidationSamples->Update(); - concatenateValidationLabels->Update(); - - if (concatenateTrainingSamples->GetOutputSampleList()->Size() == 0) - { - otbAppLogFATAL("No training samples, cannot perform SVM training."); - } - - if (concatenateValidationSamples->GetOutputSampleList()->Size() == 0) - { - otbAppLogWARNING("No validation samples."); - } - - if (IsParameterEnabled("io.imstat")) - { - StatisticsReader::Pointer statisticsReader = StatisticsReader::New(); - statisticsReader->SetFileName(GetParameterString("io.imstat")); - meanMeasurementVector = statisticsReader->GetStatisticVectorByName("mean"); - stddevMeasurementVector = statisticsReader->GetStatisticVectorByName("stddev"); - } - else - { - meanMeasurementVector.SetSize(nbBands); - meanMeasurementVector.Fill(0.); - stddevMeasurementVector.SetSize(nbBands); - stddevMeasurementVector.Fill(1.); - } - - // Shift scale the samples - ShiftScaleFilterType::Pointer trainingShiftScaleFilter = ShiftScaleFilterType::New(); - trainingShiftScaleFilter->SetInput(concatenateTrainingSamples->GetOutput()); - trainingShiftScaleFilter->SetShifts(meanMeasurementVector); - trainingShiftScaleFilter->SetScales(stddevMeasurementVector); - trainingShiftScaleFilter->Update(); - - ShiftScaleFilterType::Pointer validationShiftScaleFilter = ShiftScaleFilterType::New(); - validationShiftScaleFilter->SetInput(concatenateValidationSamples->GetOutput()); - validationShiftScaleFilter->SetShifts(meanMeasurementVector); - validationShiftScaleFilter->SetScales(stddevMeasurementVector); - validationShiftScaleFilter->Update(); - - ListSampleType::Pointer listSample; - LabelListSampleType::Pointer labelListSample; - //-------------------------- - // Balancing training sample (if needed) - // if (IsParameterEnabled("sample.b")) - // { - // // Balance the list sample. - // otbAppLogINFO("Number of training samples before balancing: " << concatenateTrainingSamples->GetOutputSampleList()->Size()) - // BalancingListSampleFilterType::Pointer balancingFilter = BalancingListSampleFilterType::New(); - // balancingFilter->SetInput(trainingShiftScaleFilter->GetOutput()/*GetOutputSampleList()*/); - // balancingFilter->SetInputLabel(concatenateTrainingLabels->GetOutput()/*GetOutputSampleList()*/); - // balancingFilter->SetBalancingFactor(GetParameterInt("sample.b")); - // balancingFilter->Update(); - // listSample = balancingFilter->GetOutputSampleList(); - // labelListSample = balancingFilter->GetOutputLabelSampleList(); - // otbAppLogINFO("Number of samples after balancing: " << balancingFilter->GetOutputSampleList()->Size()); - - // } - // else - // { - listSample = trainingShiftScaleFilter->GetOutputSampleList(); - labelListSample = concatenateTrainingLabels->GetOutputSampleList(); - otbAppLogINFO("Number of training samples: " << concatenateTrainingSamples->GetOutputSampleList()->Size()); - // } - //-------------------------- - // Split the data set into training/validation set - ListSampleType::Pointer trainingListSample = listSample; - ListSampleType::Pointer validationListSample = validationShiftScaleFilter->GetOutputSampleList(); - LabelListSampleType::Pointer trainingLabeledListSample = labelListSample; - LabelListSampleType::Pointer validationLabeledListSample = concatenateValidationLabels->GetOutputSampleList(); - otbAppLogINFO("Size of training set: " << trainingListSample->Size()); - otbAppLogINFO("Size of validation set: " << validationListSample->Size()); - otbAppLogINFO("Size of labeled training set: " << trainingLabeledListSample->Size()); - otbAppLogINFO("Size of labeled validation set: " << validationLabeledListSample->Size()); - - //-------------------------- - // Estimate SVM model - SVMEstimatorType::Pointer svmestimator = SVMEstimatorType::New(); - svmestimator->SetInputSampleList(trainingListSample); - svmestimator->SetTrainingSampleList(trainingLabeledListSample); - //SVM Option - //TODO : Add other options ? - if (IsParameterEnabled("svm.opt")) - { - svmestimator->SetParametersOptimization(true); - } - - - svmestimator->SetC(GetParameterFloat("svm.c")); - - - switch (GetParameterInt("svm.k")) - { - case 0: // LINEAR - svmestimator->SetKernelType(LINEAR); - break; - case 1: // RBF - svmestimator->SetKernelType(RBF); - break; - case 2: // POLY - svmestimator->SetKernelType(POLY); - break; - case 3: // SIGMOID - svmestimator->SetKernelType(SIGMOID); - break; - default: // DEFAULT = LINEAR - svmestimator->SetKernelType(LINEAR); - break; - } - - svmestimator->Update(); - svmestimator->GetModel()->SaveModel(GetParameterString("io.out")); - - otbAppLogINFO( "Learning done -> Final SVM accuracy: " << svmestimator->GetFinalCrossValidationAccuracy() << std::endl); - - //-------------------------- - // Performances estimation - ClassifierType::Pointer validationClassifier = ClassifierType::New(); - validationClassifier->SetSample(validationListSample); - validationClassifier->SetNumberOfClasses(svmestimator->GetModel()->GetNumberOfClasses()); - validationClassifier->SetModel(svmestimator->GetModel()); - validationClassifier->Update(); - - // Estimate performances - ClassifierOutputType::ConstIterator it = validationClassifier->GetOutput()->Begin(); - ClassifierOutputType::ConstIterator itEnd = validationClassifier->GetOutput()->End(); - - LabelListSampleType::Pointer classifierListLabel = LabelListSampleType::New(); - - while (it != itEnd) - { - // Due to a bug in SVMClassifier, outlier in one-class SVM are labeled with unsigned int max - classifierListLabel->PushBack( - it.GetClassLabel() == itk::NumericTraits::max() ? 2 - : it.GetClassLabel()); - ++it; - } - - ConfusionMatrixCalculatorType::Pointer confMatCalc = ConfusionMatrixCalculatorType::New(); - - confMatCalc->SetReferenceLabels(validationLabeledListSample); - confMatCalc->SetProducedLabels(classifierListLabel); - - confMatCalc->Compute(); - - otbAppLogINFO("SVM training performances"); - LogConfusionMatrix(confMatCalc); - - for (unsigned int itClasses = 0; itClasses < svmestimator->GetModel()->GetNumberOfClasses(); itClasses++) - { - ConfusionMatrixCalculatorType::ClassLabelType classLabel = confMatCalc->GetMapOfIndices()[itClasses]; - - otbAppLogINFO("Precision of class [" << classLabel << "] vs all: " << confMatCalc->GetPrecisions()[itClasses]); - otbAppLogINFO("Recall of class [" << classLabel << "] vs all: " << confMatCalc->GetRecalls()[itClasses]); - otbAppLogINFO("F-score of class [" << classLabel << "] vs all: " << confMatCalc->GetFScores()[itClasses] << "\n"); - } - otbAppLogINFO("Global performance, Kappa index: " << confMatCalc->GetKappaIndex()); - // TODO: implement hyperplan distance classifier and performance validation (cf. object detection) ? - - - } - - VectorDataReprojectionType::Pointer vdreproj; -}; - -} -} - -OTB_APPLICATION_EXPORT(otb::Wrapper::TrainSVMImagesClassifier) - diff --git a/Applications/Classification/otbValidateSVMImagesClassifier.cxx b/Applications/Classification/otbValidateSVMImagesClassifier.cxx deleted file mode 100644 index e334704fc7f4aafd8dc4eebfb53b46c853f58402..0000000000000000000000000000000000000000 --- a/Applications/Classification/otbValidateSVMImagesClassifier.cxx +++ /dev/null @@ -1,409 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - 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 "otbWrapperApplication.h" -#include "otbWrapperApplicationFactory.h" - -#include - -//Image -#include "otbListSampleGenerator.h" - - -// ListSample -#include "itkListSample.h" -#include "itkVariableLengthVector.h" -#include "itkFixedArray.h" - -// SVM estimator -#include "otbSVMSampleListModelEstimator.h" - -// Statistic XML Reader -#include "otbStatisticsXMLFileReader.h" - -// Validation -#include "otbSVMClassifier.h" -#include "otbConfusionMatrixCalculator.h" - -// Normalize the samples -#include "otbShiftScaleSampleListFilter.h" - -// List sample concatenation -#include "otbConcatenateSampleListFilter.h" - -// Classification filter -#include "otbSVMImageClassificationFilter.h" - -// Extract a ROI of the vectordata -#include "otbVectorDataIntoImageProjectionFilter.h" - -// Elevation handler -#include "otbWrapperElevationParametersHandler.h" - -namespace otb -{ -namespace Wrapper -{ - -class ValidateSVMImagesClassifier: public Application -{ - -public: - /** Standard class typedefs. */ - typedef ValidateSVMImagesClassifier Self; - typedef Application Superclass; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - /** Standard macro */ - itkNewMacro(Self); - - itkTypeMacro(ValidateSVMImagesClassifier, otb::Application); - - typedef otb::Image ImageReaderType; - - typedef FloatVectorImageType::PixelType PixelType; - typedef FloatVectorImageType VectorImageType; - typedef FloatImageType ImageType; - typedef Int32ImageType LabeledImageType; - - // Training vectordata - typedef itk::VariableLengthVector MeasurementType; - - // SampleList manipulation - typedef otb::ListSampleGenerator ListSampleGeneratorType; - - typedef ListSampleGeneratorType::ListSampleType ListSampleType; - typedef ListSampleGeneratorType::LabelType LabelType; - typedef ListSampleGeneratorType::ListLabelType LabelListSampleType; - typedef otb::Statistics::ConcatenateSampleListFilter ConcatenateListSampleFilterType; - typedef otb::Statistics::ConcatenateSampleListFilter ConcatenateLabelListSampleFilterType; - - // Statistic XML file Reader - typedef otb::StatisticsXMLFileReader StatisticsReader; - // Enhance List Sample - typedef otb::Statistics::ShiftScaleSampleListFilter ShiftScaleFilterType; - - /// Classification typedefs - typedef otb::SVMImageClassificationFilter ClassificationFilterType; - typedef ClassificationFilterType::Pointer ClassificationFilterPointerType; - typedef ClassificationFilterType::ModelType ModelType; - typedef ModelType::Pointer ModelPointerType; - - typedef otb::Functor::VariableLengthVectorToMeasurementVectorFunctor MeasurementVectorFunctorType; - typedef otb::SVMSampleListModelEstimator - SVMEstimatorType; - // Estimate performance on validation sample - typedef otb::SVMClassifier ClassifierType; - typedef otb::ConfusionMatrixCalculator ConfusionMatrixCalculatorType; - typedef ClassifierType::OutputType ClassifierOutputType; - - // Extract ROI and Project vectorData - typedef otb::VectorDataIntoImageProjectionFilter VectorDataReprojectionType; - -private: - void DoInit() - { - SetName("ValidateSVMImagesClassifier"); - SetDescription("Estimate the performance of the SVM model with a set of images and validation samples."); - - SetDocName("Validate SVM Images Classifier"); - SetDocLongDescription("Estimate the performance of the SVM model obtained by the TrainSVMImagesClassifier with a new set of images and validation samples.\n The application asks for images statistics as input (XML file generated with the ComputeImagesStatistics application) and a SVM model (text file) generated with the TrainSVMImagesClassifier application.\n It will compute the global confusion matrix, kappa index and also the precision, recall and F-score of each class. In the validation process, the confusion matrix is organized the following way: rows = reference labels, columns = produced labels."); - SetDocLimitations("None"); - SetDocAuthors("OTB-Team"); - SetDocSeeAlso(" "); - - AddDocTag(Tags::Learning); - - AddParameter(ParameterType_InputImageList, "il", "Input Image List"); - SetParameterDescription("il", "Input image list filename."); - AddParameter(ParameterType_InputVectorDataList, "vd", "Vector Data List"); - SetParameterDescription("vd", "List of vector data to select validation samples."); - AddParameter(ParameterType_String, "vfn", "Name of the discrimination field"); - SetParameterDescription("vfn", "Name of the field used to discriminate class in the vector data files."); - SetParameterString("vfn", "Class"); - MandatoryOff("vfn"); - - AddParameter(ParameterType_InputFilename, "imstat", "XML image statistics file"); - MandatoryOff("imstat"); - SetParameterDescription("imstat", "Filename of an XML file containing mean and standard deviation of input images."); - - // Elevation - ElevationParametersHandler::AddElevationParameters(this, "elev"); - - AddParameter(ParameterType_OutputFilename, "out", "Output filename"); - SetParameterDescription("out", "Output file, which contains the performances of the SVM model."); - MandatoryOff("out"); - AddParameter(ParameterType_InputFilename, "svm", "SVM validation filename"); - SetParameterDescription("svm", - "Input SVM model to validate (given by TrainSVMImagesClassification for instance)."); - - AddRANDParameter(); - // Doc example parameter settings - SetDocExampleParameterValue("il", "QB_1_ortho.tif"); - SetDocExampleParameterValue("vd", "VectorData_QB1.shp"); - SetDocExampleParameterValue("imstat", "EstimateImageStatisticsQB1.xml"); - SetDocExampleParameterValue("svm", "clsvmModelQB1.svm"); - SetDocExampleParameterValue("out", "PerformanceEstimationQB1.txt"); - } - - void DoUpdateParameters() - { - // Nothing to do here : all parameters are independent - } - - std::string LogConfusionMatrix(ConfusionMatrixCalculatorType* confMatCalc) - { - ConfusionMatrixCalculatorType::ConfusionMatrixType matrix = confMatCalc->GetConfusionMatrix(); - - // Compute minimal width - size_t minwidth = 0; - - for (unsigned int i = 0; i < matrix.Rows(); i++) - { - for (unsigned int j = 0; j < matrix.Cols(); j++) - { - std::ostringstream os; - os << matrix(i,j); - size_t size = os.str().size(); - - if (size > minwidth) - { - minwidth = size; - } - } - } - - typedef std::map MapOfIndicesType; - MapOfIndicesType mapOfIndices = confMatCalc->GetMapOfIndices(); - - MapOfIndicesType::const_iterator it = mapOfIndices.begin(); - MapOfIndicesType::const_iterator end = mapOfIndices.end(); - - for(; it != end; ++it) - { - std::ostringstream os; - os << "[" << it->second << "]"; - - size_t size = os.str().size(); - if (size > minwidth) - { - minwidth = size; - } - } - - - // Generate matrix string, with 'minwidth' as size specifier - std::ostringstream os; - - // Header line - for (size_t i = 0; i < minwidth; ++i) - os << " "; - os << " "; - - it = mapOfIndices.begin(); - end = mapOfIndices.end(); - for(; it != end; ++it) - { - os << "[" << it->second << "]" << " "; - } - - os << std::endl; - - // Each line of confusion matrix - for (unsigned int i = 0; i < matrix.Rows(); i++) - { - ConfusionMatrixCalculatorType::ClassLabelType label = mapOfIndices[i]; - os << "[" << std::setw(minwidth - 2) << label << "]" << " "; - for (unsigned int j = 0; j < matrix.Cols(); j++) - { - os << std::setw(minwidth) << matrix(i,j) << " "; - } - os << std::endl; - } - - otbAppLogINFO("Confusion matrix (rows = reference labels, columns = produced labels):\n" << os.str()); - return os.str(); - } - - void DoExecute() - { - GetLogger()->Debug("Entering DoExecute\n"); - //Create training and validation for list samples and label list samples - ConcatenateLabelListSampleFilterType::Pointer - concatenateTrainingLabels = ConcatenateLabelListSampleFilterType::New(); - ConcatenateListSampleFilterType::Pointer concatenateTrainingSamples = ConcatenateListSampleFilterType::New(); - ConcatenateLabelListSampleFilterType::Pointer - concatenateValidationLabels = ConcatenateLabelListSampleFilterType::New(); - ConcatenateListSampleFilterType::Pointer concatenateValidationSamples = ConcatenateListSampleFilterType::New(); - - MeasurementType meanMeasurementVector; - MeasurementType stddevMeasurementVector; - - //-------------------------- - // Load measurements from images - unsigned int nbBands = 0; - //Iterate over all input images - - FloatVectorImageListType* imageList = GetParameterImageList("il"); - VectorDataListType* vectorDataList = GetParameterVectorDataList("vd"); - - //Iterate over all input images - for (unsigned int imgIndex = 0; imgIndex < imageList->Size(); ++imgIndex) - { - FloatVectorImageType::Pointer image = imageList->GetNthElement(imgIndex); - image->UpdateOutputInformation(); - - if (imgIndex == 0) - { - nbBands = image->GetNumberOfComponentsPerPixel(); - } - - // read the Vectordata - VectorDataType::Pointer vectorData = vectorDataList->GetNthElement(imgIndex); - vectorData->Update(); - - VectorDataReprojectionType::Pointer vdreproj = VectorDataReprojectionType::New(); - vdreproj->SetInputImage(image); - vdreproj->SetInput(vectorData); - vdreproj->SetUseOutputSpacingAndOriginFromImage(false); - - // Setup the DEM Handler - otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev"); - vdreproj->Update(); - - //Sample list generator - ListSampleGeneratorType::Pointer sampleGenerator = ListSampleGeneratorType::New(); - - //Set inputs of the sample generator - //TODO the ListSampleGenerator perform UpdateOutputData over the input image (need a persistent implementation) - sampleGenerator->SetInput(image); - sampleGenerator->SetInputVectorData(vdreproj->GetOutput()); - sampleGenerator->SetValidationTrainingProportion(1.0); // All in validation - - sampleGenerator->SetClassKey(GetParameterString("vfn")); - - sampleGenerator->Update(); - - //Concatenate training and validation samples from the image - concatenateValidationLabels->AddInput(sampleGenerator->GetValidationListLabel()); - concatenateValidationSamples->AddInput(sampleGenerator->GetValidationListSample()); - } - - // Update - concatenateValidationSamples->Update(); - concatenateValidationLabels->Update(); - - if (IsParameterEnabled("imstat")) - { - StatisticsReader::Pointer statisticsReader = StatisticsReader::New(); - statisticsReader->SetFileName(GetParameterString("imstat")); - meanMeasurementVector = statisticsReader->GetStatisticVectorByName("mean"); - stddevMeasurementVector = statisticsReader->GetStatisticVectorByName("stddev"); - } - else - { - meanMeasurementVector.SetSize(nbBands); - meanMeasurementVector.Fill(0.); - stddevMeasurementVector.SetSize(nbBands); - stddevMeasurementVector.Fill(1.); - } - - ShiftScaleFilterType::Pointer validationShiftScaleFilter = ShiftScaleFilterType::New(); - validationShiftScaleFilter->SetInput(concatenateValidationSamples->GetOutput()); - validationShiftScaleFilter->SetShifts(meanMeasurementVector); - validationShiftScaleFilter->SetScales(stddevMeasurementVector); - validationShiftScaleFilter->Update(); - //-------------------------- - // split the data set into training/validation set - ListSampleType::Pointer validationListSample = validationShiftScaleFilter->GetOutputSampleList(); - LabelListSampleType::Pointer validationLabeledListSample = concatenateValidationLabels->GetOutputSampleList(); - - otbAppLogINFO("Size of validation set: " << validationListSample->Size()); - otbAppLogINFO("Size of labeled validation set: " << validationLabeledListSample->Size()); - - //-------------------------- - // Load svm model - ModelPointerType modelSVM = ModelType::New(); - modelSVM->LoadModel(GetParameterString("svm").c_str()); - - //-------------------------- - // Performances estimation - ClassifierType::Pointer validationClassifier = ClassifierType::New(); - validationClassifier->SetSample(validationListSample); - validationClassifier->SetNumberOfClasses(modelSVM->GetNumberOfClasses()); - validationClassifier->SetModel(modelSVM); - validationClassifier->Update(); - - // Estimate performances - ClassifierOutputType::ConstIterator it = validationClassifier->GetOutput()->Begin(); - ClassifierOutputType::ConstIterator itEnd = validationClassifier->GetOutput()->End(); - - LabelListSampleType::Pointer classifierListLabel = LabelListSampleType::New(); - - while (it != itEnd) - { - // Due to a bug in SVMClassifier, outlier in one-class SVM are labeled with unsigned int max - classifierListLabel->PushBack( - it.GetClassLabel() == itk::NumericTraits::max() ? 2 - : it.GetClassLabel()); - ++it; - } - - ConfusionMatrixCalculatorType::Pointer confMatCalc = ConfusionMatrixCalculatorType::New(); - - confMatCalc->SetReferenceLabels(validationLabeledListSample); - confMatCalc->SetProducedLabels(classifierListLabel); - - confMatCalc->Compute(); - - otbAppLogINFO("SVM training performances"); - std::string confMatString; - confMatString = LogConfusionMatrix(confMatCalc); - - for (unsigned int itClasses = 0; itClasses < modelSVM->GetNumberOfClasses(); itClasses++) - { - otbAppLogINFO("Precision of class [" << itClasses << "] vs all: " << confMatCalc->GetPrecisions()[itClasses] << std::endl); - otbAppLogINFO("Recall of class [" << itClasses << "] vs all: " << confMatCalc->GetRecalls()[itClasses] << std::endl); - otbAppLogINFO("F-score of class [" << itClasses << "] vs all: " << confMatCalc->GetFScores()[itClasses] << "\n" << std::endl); - } - otbAppLogINFO("Global performance, Kappa index: " << confMatCalc->GetKappaIndex() << std::endl); - otbAppLogINFO("Global performance, Overall accuracy: " << confMatCalc->GetOverallAccuracy() << std::endl); - //-------------------------- - // Save output in a ascii file (if needed) - if (IsParameterEnabled("out")) - { - std::ofstream file; - file.open(GetParameterString("out").c_str()); - file << "Confusion matrix (rows = reference labels, columns = produced labels):\n" << std::endl; - file << confMatString << std::endl; - file << "Precision of the different class: " << confMatCalc->GetPrecisions() << std::endl; - file << "Recall of the different class: " << confMatCalc->GetRecalls() << std::endl; - file << "F-score of the different class: " << confMatCalc->GetFScores() << std::endl; - file << "Kappa index: " << confMatCalc->GetKappaIndex() << std::endl; - file << "Overall accuracy index: " << confMatCalc->GetOverallAccuracy() << std::endl; - file.close(); - } - } -}; - -} // end of namespace Wrapper -} // end of namespace otb - -OTB_APPLICATION_EXPORT(otb::Wrapper::ValidateSVMImagesClassifier) - - diff --git a/Testing/Applications/Classification/CMakeLists.txt b/Testing/Applications/Classification/CMakeLists.txt index 8318546415a48af4a40d0cc04652bac3416a5faf..8df9fd60900b2b88aada1bb1cc14110601cd1f5d 100644 --- a/Testing/Applications/Classification/CMakeLists.txt +++ b/Testing/Applications/Classification/CMakeLists.txt @@ -5,91 +5,94 @@ OTB_TEST_APPLICATION(NAME apTvClComputeImagesStatisticsQB1 APP ComputeImagesStatistics OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho.tif - -out ${TEMP}/apTvClEstimateImageStatisticsQB1.xml + -out ${TEMP}/apTvClEstimateImageStatisticsQB1.xml VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clImageStatisticsQB1.xml - ${TEMP}/apTvClEstimateImageStatisticsQB1.xml ) - - -OTB_TEST_APPLICATION(NAME apTvClTrainSVMImagesClassifierQB1 - APP TrainSVMImagesClassifier + ${TEMP}/apTvClEstimateImageStatisticsQB1.xml) + + +OTB_TEST_APPLICATION(NAME apTvClTrainSVMImagesClassifierQB1 + APP TrainImagesClassifier OPTIONS -io.il ${INPUTDATA}/Classification/QB_1_ortho.tif - -io.vd ${INPUTDATA}/Classification/VectorData_QB1.shp - -io.imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml - ##-sample.b 2 - -svm.opt true - -io.out ${TEMP}/clsvmModelQB1.svm - -rand 121212 + -io.vd ${INPUTDATA}/Classification/VectorData_QB1.shp + -io.imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml + -classifier libsvm + -classifier.libsvm.opt true + -io.out ${TEMP}/clsvmModelQB1.svm + -rand 121212 VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clsvmModelQB1.svm - ${TEMP}/clsvmModelQB1.svm) - + ${TEMP}/clsvmModelQB1.svm) + SET_TESTS_PROPERTIES(apTvClTrainSVMImagesClassifierQB1 PROPERTIES DEPENDS apTvClComputeImagesStatisticsQB1) -OTB_TEST_APPLICATION(NAME apTvClTrainSVMImagesClassifierQB1_allOpt - APP TrainSVMImagesClassifier + +OTB_TEST_APPLICATION(NAME apTvClTrainSVMImagesClassifierQB1_allOpt + APP TrainImagesClassifier OPTIONS -io.il ${INPUTDATA}/Classification/QB_1_ortho.tif - -io.vd ${INPUTDATA}/Classification/VectorData_QB1.shp - -io.imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml - ##-sample.b 2 - -sample.mv 100 - -sample.mt 100 - -sample.vtr 0.5 - -svm.opt true - -rand 121212 - -io.out ${TEMP}/clsvmModelQB1_allOpt.svm + -io.vd ${INPUTDATA}/Classification/VectorData_QB1.shp + -io.imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml + -classifier libsvm + -sample.mv 100 + -sample.mt 100 + -sample.vtr 0.5 + -classifier.libsvm.opt true + -rand 121212 + -io.out ${TEMP}/clsvmModelQB1_allOpt.svm VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clsvmModelQB1.svm - ${TEMP}/clsvmModelQB1_allOpt.svm) + ${TEMP}/clsvmModelQB1_allOpt.svm) SET_TESTS_PROPERTIES(apTvClTrainSVMImagesClassifierQB1_allOpt PROPERTIES DEPENDS apTvClComputeImagesStatisticsQB1) -OTB_TEST_APPLICATION(NAME apTvClValidateSVMImagesClassifierQB1 - APP ValidateSVMImagesClassifier +OTB_TEST_APPLICATION(NAME apTvClValidateSVMImagesClassifierQB1 + APP ValidateImagesClassifier OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho.tif -vd ${INPUTDATA}/Classification/VectorData_QB1_bis.shp - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml - -svm ${TEMP}/clsvmModelQB1.svm - -out ${TEMP}/clsvmPerformanceEstimationQB1.txt - -rand 121212 + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml + -model ${TEMP}/clsvmModelQB1.svm + -out ${TEMP}/clsvmPerformanceEstimationQB1.txt + -rand 121212 VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clsvmPerformanceEstimationQB1.txt - ${TEMP}/clsvmPerformanceEstimationQB1.txt) + ${TEMP}/clsvmPerformanceEstimationQB1.txt) SET_TESTS_PROPERTIES(apTvClValidateSVMImagesClassifierQB1 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB1) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB1 - APP ImageSVMClassifier +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB1 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_1_ortho.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml - -svm ${TEMP}/clsvmModelQB1.svm - -out ${TEMP}/clLabeledImageQB1.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml + -model ${TEMP}/clsvmModelQB1.svm + -out ${TEMP}/clLabeledImageQB1.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB1.tif ${TEMP}/clLabeledImageQB1.tif) - + SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB1 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB1) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB2 - APP ImageSVMClassifier + +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB2 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_2_ortho.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml - -svm ${TEMP}/clsvmModelQB1.svm - -out ${TEMP}/clLabeledImageQB2.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml + -model ${TEMP}/clsvmModelQB1.svm + -out ${TEMP}/clLabeledImageQB2.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB2.tif ${TEMP}/clLabeledImageQB2.tif) SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB2 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB1) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB3 - APP ImageSVMClassifier + +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB3 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_3_ortho.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml - -svm ${TEMP}/clsvmModelQB1.svm - -out ${TEMP}/clLabeledImageQB3.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB1.xml + -model ${TEMP}/clsvmModelQB1.svm + -out ${TEMP}/clLabeledImageQB3.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB3.tif ${TEMP}/clLabeledImageQB3.tif) @@ -102,56 +105,55 @@ SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB3 PROPERTIES DEPENDS apTvClTrainS OTB_TEST_APPLICATION(NAME apTvClComputeImagesStatisticsQB123 APP ComputeImagesStatistics OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho.tif - ${INPUTDATA}/Classification/QB_2_ortho.tif - ${INPUTDATA}/Classification/QB_3_ortho.tif - -out ${TEMP}/apTvClEstimateImageStatisticsQB123.xml + ${INPUTDATA}/Classification/QB_2_ortho.tif + ${INPUTDATA}/Classification/QB_3_ortho.tif + -out ${TEMP}/apTvClEstimateImageStatisticsQB123.xml VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clImageStatisticsQB123.xml ${TEMP}/apTvClEstimateImageStatisticsQB123.xml) - -OTB_TEST_APPLICATION(NAME apTvClTrainSVMImagesClassifierQB123 - APP TrainSVMImagesClassifier + +OTB_TEST_APPLICATION(NAME apTvClTrainSVMImagesClassifierQB123 + APP TrainImagesClassifier OPTIONS -io.il ${INPUTDATA}/Classification/QB_1_ortho.tif - ${INPUTDATA}/Classification/QB_2_ortho.tif - ${INPUTDATA}/Classification/QB_3_ortho.tif - -io.vd ${INPUTDATA}/Classification/VectorData_QB1.shp - ${INPUTDATA}/Classification/VectorData_QB2.shp - ${INPUTDATA}/Classification/VectorData_QB3.shp - -io.imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml - #-sample.b 2 - -svm.opt true - -io.out ${TEMP}/clsvmModelQB123.svm - -rand 121212 + ${INPUTDATA}/Classification/QB_2_ortho.tif + ${INPUTDATA}/Classification/QB_3_ortho.tif + -io.vd ${INPUTDATA}/Classification/VectorData_QB1.shp + ${INPUTDATA}/Classification/VectorData_QB2.shp + ${INPUTDATA}/Classification/VectorData_QB3.shp + -io.imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml + -classifier libsvm + -classifier.libsvm.opt true + -io.out ${TEMP}/clsvmModelQB123.svm + -rand 121212 VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clsvmModelQB123.svm - ${TEMP}/clsvmModelQB123.svm) - + ${TEMP}/clsvmModelQB123.svm) SET_TESTS_PROPERTIES(apTvClTrainSVMImagesClassifierQB123 PROPERTIES DEPENDS apTvClComputeImagesStatisticsQB123) -OTB_TEST_APPLICATION(NAME apTvClValidateSVMImagesClassifierQB123 - APP ValidateSVMImagesClassifier +OTB_TEST_APPLICATION(NAME apTvClValidateSVMImagesClassifierQB123 + APP ValidateImagesClassifier OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho.tif -vd ${INPUTDATA}/Classification/VectorData_QB1_bis.shp - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml - -svm ${TEMP}/clsvmModelQB123.svm - -out ${TEMP}/clsvmPerformanceEstimationQB123.txt - -rand 121212 + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml + -model ${TEMP}/clsvmModelQB123.svm + -out ${TEMP}/clsvmPerformanceEstimationQB123.txt + -rand 121212 VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clsvmPerformanceEstimationQB123.txt - ${TEMP}/clsvmPerformanceEstimationQB123.txt) + ${TEMP}/clsvmPerformanceEstimationQB123.txt) - SET_TESTS_PROPERTIES(apTvClValidateSVMImagesClassifierQB123 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB123) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_1 - APP ImageSVMClassifier + +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_1 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_1_ortho.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml - -svm ${TEMP}/clsvmModelQB123.svm - -out ${TEMP}/clLabeledImageQB123_1.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml + -model ${TEMP}/clsvmModelQB123.svm + -out ${TEMP}/clLabeledImageQB123_1.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif ${TEMP}/clLabeledImageQB123_1.tif) @@ -159,120 +161,123 @@ OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_1 SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB123_1 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB123) -OTB_TEST_APPLICATION(NAME apTvClLabeledImageColorMappingQB123_1 - APP ColorMapping +OTB_TEST_APPLICATION(NAME apTvClLabeledImageColorMappingQB123_1 + APP ColorMapping OPTIONS -in ${TEMP}/clLabeledImageQB123_1.tif -method custom -method.custom.lut ${INPUTDATA}/Classification/ColorTable.txt -out ${TEMP}/clLabeledFancyImageQB123_1.tif - VALID --compare-image ${NOTOL} + VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledFancyImageQB123_1.tif - ${TEMP}/clLabeledFancyImageQB123_1.tif) - + ${TEMP}/clLabeledFancyImageQB123_1.tif) SET_TESTS_PROPERTIES(apTvClLabeledImageColorMappingQB123_1 PROPERTIES DEPENDS apTvClImageSVMClassifierQB123_1) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_2 - APP ImageSVMClassifier + +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_2 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_2_ortho.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml - -svm ${TEMP}/clsvmModelQB123.svm - -out ${TEMP}/clLabeledImageQB123_2.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml + -model ${TEMP}/clsvmModelQB123.svm + -out ${TEMP}/clLabeledImageQB123_2.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB123_2.tif ${TEMP}/clLabeledImageQB123_2.tif) SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB123_2 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB123) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_3 - APP ImageSVMClassifier + +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_3 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_3_ortho.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml - -svm ${TEMP}/clsvmModelQB123.svm - -out ${TEMP}/clLabeledImageQB123_3.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml + -model ${TEMP}/clsvmModelQB123.svm + -out ${TEMP}/clLabeledImageQB123_3.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB123_3.tif ${TEMP}/clLabeledImageQB123_3.tif) SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB123_3 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB123) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_6 - APP ImageSVMClassifier + +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB123_6 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_6_extract.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml - -svm ${TEMP}/clsvmModelQB123.svm - -out ${TEMP}/clLabeledImageQB123_6.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB123.xml + -model ${TEMP}/clsvmModelQB123.svm + -out ${TEMP}/clLabeledImageQB123_6.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB123_6.tif - ${TEMP}/clLabeledImageQB123_6.tif) + ${TEMP}/clLabeledImageQB123_6.tif) SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB123_6 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB123) + OTB_TEST_APPLICATION(NAME apTvClComputeImagesStatisticsQB456 APP ComputeImagesStatistics OPTIONS -il ${INPUTDATA}/Classification/QB_4_extract.tif - ${INPUTDATA}/Classification/QB_5_extract.tif - ${INPUTDATA}/Classification/QB_6_extract.tif - -out ${TEMP}/apTvClEstimateImageStatisticsQB456.xml + ${INPUTDATA}/Classification/QB_5_extract.tif + ${INPUTDATA}/Classification/QB_6_extract.tif + -out ${TEMP}/apTvClEstimateImageStatisticsQB456.xml VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clImageStatisticsQB456.xml ${TEMP}/apTvClEstimateImageStatisticsQB456.xml) - -OTB_TEST_APPLICATION(NAME apTvClTrainSVMImagesClassifierQB456 - APP TrainSVMImagesClassifier + + +OTB_TEST_APPLICATION(NAME apTvClTrainSVMImagesClassifierQB456 + APP TrainImagesClassifier OPTIONS -io.il ${INPUTDATA}/Classification/QB_4_extract.tif - ${INPUTDATA}/Classification/QB_5_extract.tif - ${INPUTDATA}/Classification/QB_6_extract.tif - -io.vd ${INPUTDATA}/Classification/VectorData_QB4.shp - ${INPUTDATA}/Classification/VectorData_QB5.shp - ${INPUTDATA}/Classification/VectorData_QB6.shp - -io.imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml - #-sample.b 2 - -svm.opt true - -io.out ${TEMP}/clsvmModelQB456.svm - -rand 121212 + ${INPUTDATA}/Classification/QB_5_extract.tif + ${INPUTDATA}/Classification/QB_6_extract.tif + -io.vd ${INPUTDATA}/Classification/VectorData_QB4.shp + ${INPUTDATA}/Classification/VectorData_QB5.shp + ${INPUTDATA}/Classification/VectorData_QB6.shp + -io.imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml + -classifier libsvm + -classifier.libsvm.opt true + -io.out ${TEMP}/clsvmModelQB456.svm + -rand 121212 VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clsvmModelQB456.svm - ${TEMP}/clsvmModelQB456.svm) - - + ${TEMP}/clsvmModelQB456.svm) SET_TESTS_PROPERTIES(apTvClTrainSVMImagesClassifierQB456 PROPERTIES DEPENDS apTvClComputeImagesStatisticsQB456) -OTB_TEST_APPLICATION(NAME apTvClValidateSVMImagesClassifierQB456 - APP ValidateSVMImagesClassifier + +OTB_TEST_APPLICATION(NAME apTvClValidateSVMImagesClassifierQB456 + APP ValidateImagesClassifier OPTIONS -il ${INPUTDATA}/Classification/QB_5_extract.tif -vd ${INPUTDATA}/Classification/VectorData_QB5_bis.shp - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml - -svm ${TEMP}/clsvmModelQB456.svm - -rand 121212 - -out ${TEMP}/clsvmPerformanceEstimationQB456.txt + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml + -model ${TEMP}/clsvmModelQB456.svm + -rand 121212 + -out ${TEMP}/clsvmPerformanceEstimationQB456.txt VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/clsvmPerformanceEstimationQB456.txt - ${TEMP}/clsvmPerformanceEstimationQB456.txt) - + ${TEMP}/clsvmPerformanceEstimationQB456.txt) SET_TESTS_PROPERTIES(apTvClValidateSVMImagesClassifierQB456 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB456) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB456_4 - APP ImageSVMClassifier +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB456_4 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_4_extract.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml - -svm ${TEMP}/clsvmModelQB456.svm - -out ${TEMP}/clLabeledImageQB456_4.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml + -model ${TEMP}/clsvmModelQB456.svm + -out ${TEMP}/clLabeledImageQB456_4.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB456_4.tif ${TEMP}/clLabeledImageQB456_4.tif) SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB456_4 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB456) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB456_5 - APP ImageSVMClassifier + +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB456_5 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_5_extract.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml - -svm ${TEMP}/clsvmModelQB456.svm - -out ${TEMP}/clLabeledImageQB456_5.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml + -model ${TEMP}/clsvmModelQB456.svm + -out ${TEMP}/clLabeledImageQB456_5.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB456_5.tif ${TEMP}/clLabeledImageQB456_5.tif) @@ -280,13 +285,13 @@ OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB456_5 SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB456_5 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB456) -OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB456_6 - APP ImageSVMClassifier +OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB456_6 + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_6_extract.tif - -mask ${INPUTDATA}/Classification/QB_6_mask.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml - -svm ${TEMP}/clsvmModelQB456.svm - -out ${TEMP}/clLabeledImageQB456_6.tif + -mask ${INPUTDATA}/Classification/QB_6_mask.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml + -model ${TEMP}/clsvmModelQB456.svm + -out ${TEMP}/clLabeledImageQB456_6.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB456_6.tif ${TEMP}/clLabeledImageQB456_6.tif) @@ -295,35 +300,36 @@ SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB456_6 PROPERTIES DEPENDS apTvClTr OTB_TEST_APPLICATION(NAME apTvClImageSVMClassifierQB456_1 - APP ImageSVMClassifier + APP ImageClassifier OPTIONS -in ${INPUTDATA}/Classification/QB_1_ortho.tif - -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml - -svm ${TEMP}/clsvmModelQB456.svm - -out ${TEMP}/clLabeledImageQB456_1.tif + -imstat ${TEMP}/apTvClEstimateImageStatisticsQB456.xml + -model ${TEMP}/clsvmModelQB456.svm + -out ${TEMP}/clLabeledImageQB456_1.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB456_1.tif ${TEMP}/clLabeledImageQB456_1.tif) - SET_TESTS_PROPERTIES(apTvClImageSVMClassifierQB456_1 PROPERTIES DEPENDS apTvClTrainSVMImagesClassifierQB456) + OTB_TEST_APPLICATION(NAME apTvClKMeansImageClassification APP KMeansClassification OPTIONS -in ${INPUTDATA}/qb_RoadExtract.img - -vm ${INPUTDATA}/qb_RoadExtract_mask.png - -ts 30000 - -nc 5 - -maxit 10000 + -vm ${INPUTDATA}/qb_RoadExtract_mask.png + -ts 30000 + -nc 5 + -maxit 10000 -ct 0.0000001 -rand 121212 - -out ${TEMP}/apTvClKMeansImageClassificationFilterOuptut.tif + -out ${TEMP}/apTvClKMeansImageClassificationFilterOuptut.tif VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/apTvClKMeansImageClassificationFilterOuptut.tif ${TEMP}/apTvClKMeansImageClassificationFilterOuptut.tif ) + # --- SOMClassification --- -OTB_TEST_APPLICATION(NAME apTvClSOMClassificationSmall - APP SOMClassification +OTB_TEST_APPLICATION(NAME apTvClSOMClassificationSmall + APP SOMClassification OPTIONS -in ${INPUTDATA}/poupees_sub.png -rand 121212 -out ${TEMP}/apTvClSOMClassificationSmall.tif uint16 @@ -331,8 +337,9 @@ OTB_TEST_APPLICATION(NAME apTvClSOMClassificationSmall ${BASELINE}/apTvClSOMClassificationSmall.tif ${TEMP}/apTvClSOMClassificationSmall.tif) -OTB_TEST_APPLICATION(NAME apTvClSOMClassificationFull - APP SOMClassification + +OTB_TEST_APPLICATION(NAME apTvClSOMClassificationFull + APP SOMClassification OPTIONS -in ${INPUTDATA}/poupees_sub.png -out ${TEMP}/apTvClSOMClassificationFull.tif uint16 -vm ${INPUTDATA}/poupees_sub_c1.png @@ -355,9 +362,10 @@ OTB_TEST_APPLICATION(NAME apTvClSOMClassificationFull ${BASELINE}/apTvClSOMClassificationMap.hdr ${TEMP}/apTvClSOMClassificationMap.hdr) + # --- Fusion of classifications --- -OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsMV2Inputs - APP FusionOfClassifications +OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsMV2Inputs + APP FusionOfClassifications OPTIONS -il ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif ${OTBAPP_BASELINE}/clLabeledImageQB456_1.tif -method majorityvoting @@ -365,11 +373,11 @@ OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsMV2Inputs -out ${TEMP}/apTvFusionOfClassificationsMV2InputsOutput.tif uint16 VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/apTvFusionOfClassifications2InputsOutput.tif - ${TEMP}/apTvFusionOfClassificationsMV2InputsOutput.tif -) + ${TEMP}/apTvFusionOfClassificationsMV2InputsOutput.tif) + -OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsMV3Inputs - APP FusionOfClassifications +OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsMV3Inputs + APP FusionOfClassifications OPTIONS -il ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif ${OTBAPP_BASELINE}/clLabeledImageQB456_1.tif ${OTBAPP_BASELINE}/clLabeledImageQB1.tif @@ -378,11 +386,11 @@ OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsMV3Inputs -out ${TEMP}/apTvFusionOfClassificationsMV3InputsOutput.tif uint16 VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/apTvFusionOfClassifications3InputsOutput.tif - ${TEMP}/apTvFusionOfClassificationsMV3InputsOutput.tif -) + ${TEMP}/apTvFusionOfClassificationsMV3InputsOutput.tif) -OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSPrecision6Inputs - APP FusionOfClassifications + +OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSPrecision6Inputs + APP FusionOfClassifications OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho_C1.tif ${INPUTDATA}/Classification/QB_1_ortho_C2.tif ${INPUTDATA}/Classification/QB_1_ortho_C3.tif @@ -402,11 +410,11 @@ OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSPrecision6Inputs -out ${TEMP}/apTvFusionOfClassificationsDS6InputsPrecisionOutput.tif uint8 VALID --compare-image ${NOTOL} ${BASELINE}/QB_1_ortho_DS_FUSED_PRECISION.tif - ${TEMP}/apTvFusionOfClassificationsDS6InputsPrecisionOutput.tif -) + ${TEMP}/apTvFusionOfClassificationsDS6InputsPrecisionOutput.tif) + -OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSRecall6Inputs - APP FusionOfClassifications +OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSRecall6Inputs + APP FusionOfClassifications OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho_C1.tif ${INPUTDATA}/Classification/QB_1_ortho_C2.tif ${INPUTDATA}/Classification/QB_1_ortho_C3.tif @@ -426,11 +434,11 @@ OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSRecall6Inputs -out ${TEMP}/apTvFusionOfClassificationsDS6InputsRecallOutput.tif uint8 VALID --compare-image ${NOTOL} ${BASELINE}/QB_1_ortho_DS_FUSED_RECALL.tif - ${TEMP}/apTvFusionOfClassificationsDS6InputsRecallOutput.tif -) + ${TEMP}/apTvFusionOfClassificationsDS6InputsRecallOutput.tif) + -OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSAccuracy6Inputs - APP FusionOfClassifications +OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSAccuracy6Inputs + APP FusionOfClassifications OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho_C1.tif ${INPUTDATA}/Classification/QB_1_ortho_C2.tif ${INPUTDATA}/Classification/QB_1_ortho_C3.tif @@ -450,11 +458,11 @@ OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSAccuracy6Inputs -out ${TEMP}/apTvFusionOfClassificationsDS6InputsAccuracyOutput.tif uint8 VALID --compare-image ${NOTOL} ${BASELINE}/QB_1_ortho_DS_FUSED_ACCURACY.tif - ${TEMP}/apTvFusionOfClassificationsDS6InputsAccuracyOutput.tif -) + ${TEMP}/apTvFusionOfClassificationsDS6InputsAccuracyOutput.tif) -OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSKappa6Inputs - APP FusionOfClassifications + +OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSKappa6Inputs + APP FusionOfClassifications OPTIONS -il ${INPUTDATA}/Classification/QB_1_ortho_C1.tif ${INPUTDATA}/Classification/QB_1_ortho_C2.tif ${INPUTDATA}/Classification/QB_1_ortho_C3.tif @@ -474,13 +482,12 @@ OTB_TEST_APPLICATION(NAME apTvFusionOfClassificationsDSKappa6Inputs -out ${TEMP}/apTvFusionOfClassificationsDS6InputsKappaOutput.tif uint8 VALID --compare-image ${NOTOL} ${BASELINE}/QB_1_ortho_DS_FUSED_KAPPA.tif - ${TEMP}/apTvFusionOfClassificationsDS6InputsKappaOutput.tif -) + ${TEMP}/apTvFusionOfClassificationsDS6InputsKappaOutput.tif) # --- Compute confusion matrix --- -OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixV - APP ComputeConfusionMatrix +OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixV + APP ComputeConfusionMatrix OPTIONS -in ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif -ref vector -ref.vector.in ${INPUTDATA}/Classification/VectorData_QB1_ter.shp @@ -488,11 +495,11 @@ OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixV -out ${TEMP}/apTvComputeConfusionMatrixTconfusionVOut.csv VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/apTvComputeConfusionMatrixTconfusionVOut.csv - ${TEMP}/apTvComputeConfusionMatrixTconfusionVOut.csv -) + ${TEMP}/apTvComputeConfusionMatrixTconfusionVOut.csv) + -OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixR - APP ComputeConfusionMatrix +OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixR + APP ComputeConfusionMatrix OPTIONS -in ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif -ref raster -ref.raster.in ${INPUTDATA}/Classification/clLabeledImageQB456_1_NoData_255.tif @@ -500,11 +507,11 @@ OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixR -out ${TEMP}/apTvComputeConfusionMatrixTconfusionROut.csv VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/apTvComputeConfusionMatrixTconfusionROut.csv - ${TEMP}/apTvComputeConfusionMatrixTconfusionROut.csv -) + ${TEMP}/apTvComputeConfusionMatrixTconfusionROut.csv) + -OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraReferenceLabelsV - APP ComputeConfusionMatrix +OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraReferenceLabelsV + APP ComputeConfusionMatrix OPTIONS -in ${INPUTDATA}/Classification/QB_1_ortho_C7.tif -ref vector -ref.vector.in ${INPUTDATA}/Classification/VectorData_QB1_ter.shp @@ -512,11 +519,11 @@ OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraReferenceLabelsV -out ${TEMP}/apTvComputeConfusionMatrixExtraRefLabelsVOut.csv VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/apTvComputeConfusionMatrixExtraRefLabelsVOut.csv - ${TEMP}/apTvComputeConfusionMatrixExtraRefLabelsVOut.csv -) + ${TEMP}/apTvComputeConfusionMatrixExtraRefLabelsVOut.csv) -OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraReferenceLabelsR - APP ComputeConfusionMatrix + +OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraReferenceLabelsR + APP ComputeConfusionMatrix OPTIONS -in ${INPUTDATA}/Classification/QB_1_ortho_C7.tif -ref raster -ref.raster.in ${INPUTDATA}/Classification/clLabeledImageQB456_1_NoData_255.tif @@ -524,11 +531,11 @@ OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraReferenceLabelsR -out ${TEMP}/apTvComputeConfusionMatrixExtraRefLabelsROut.csv VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/apTvComputeConfusionMatrixExtraRefLabelsROut.csv - ${TEMP}/apTvComputeConfusionMatrixExtraRefLabelsROut.csv -) + ${TEMP}/apTvComputeConfusionMatrixExtraRefLabelsROut.csv) + -OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraProducedLabelsR - APP ComputeConfusionMatrix +OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraProducedLabelsR + APP ComputeConfusionMatrix OPTIONS -in ${INPUTDATA}/Classification/clLabeledImageQB456_1_NoData_255.tif -ref raster -ref.raster.in ${INPUTDATA}/Classification/QB_1_ortho_C8.tif @@ -536,11 +543,11 @@ OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraProducedLabelsR -out ${TEMP}/apTvComputeConfusionMatrixExtraProdLabelsROut.csv VALID --compare-ascii ${NOTOL} ${OTBAPP_BASELINE_FILES}/apTvComputeConfusionMatrixExtraProdLabelsROut.csv - ${TEMP}/apTvComputeConfusionMatrixExtraProdLabelsROut.csv -) + ${TEMP}/apTvComputeConfusionMatrixExtraProdLabelsROut.csv) + -#OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixI -# APP ComputeConfusionMatrix +#OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixI +# APP ComputeConfusionMatrix # OPTIONS -in ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif # -ref raster # -ref.raster.in ${OTBAPP_BASELINE}/clLabeledImageQB456_1.tif @@ -549,11 +556,11 @@ OTB_TEST_APPLICATION(NAME apTvComputeConfusionMatrixExtraProducedLabelsR # -out ${TEMP}/apTvComputeConfusionMatrixTconfusionROut.txt # VALID --compare-ascii ${NOTOL} # ${OTBAPP_BASELINE}/apTvComputeConfusionMatrixTconfusionROut.txt -# ${TEMP}/apTvComputeConfusionMatrixTconfusionROut.txt -#) +# ${TEMP}/apTvComputeConfusionMatrixTconfusionROut.txt) -OTB_TEST_APPLICATION(NAME apTvClassificationMapRegularization - APP ClassificationMapRegularization + +OTB_TEST_APPLICATION(NAME apTvClassificationMapRegularization + APP ClassificationMapRegularization OPTIONS -io.in ${OTBAPP_BASELINE}/clLabeledImageQB123_1.tif -io.out ${TEMP}/clLabeledImageQB123_1_CMR_r2_nodl_10_undl_7.tif -ip.radius 2 @@ -562,5 +569,5 @@ OTB_TEST_APPLICATION(NAME apTvClassificationMapRegularization -ip.undecidedlabel 7 VALID --compare-image ${NOTOL} ${OTBAPP_BASELINE}/clLabeledImageQB123_1_CMR_r2_nodl_10_undl_7.tif - ${TEMP}/clLabeledImageQB123_1_CMR_r2_nodl_10_undl_7.tif -) + ${TEMP}/clLabeledImageQB123_1_CMR_r2_nodl_10_undl_7.tif) +