Commit 820b7943 authored by Jonathan Guinet's avatar Jonathan Guinet
Browse files

ENH testing repository refactoring, RSR Simulation test

parent f0618fd3
# Sources of non-templated classes.
FILE(GLOB SIMULATION_SRCS "*.cxx" )
FILE(GLOB OTBSimulation_SRCS "*.cxx" )
ADD_LIBRARY(OTBSimulation ${SIMULATION_SRCS})
ADD_LIBRARY(OTBSimulation ${OTBSimulation_SRCS})
TARGET_LINK_LIBRARIES (OTBSimulation OTBCommon OTBIO OTBLearning OTBRadiometry)
INSTALL(TARGETS OTBSimulation
RUNTIME DESTINATION ${RSR_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${RSR_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${RSR_INSTALL_LIB_DIR} COMPONENT Development)
IF(OTB_LIBRARY_PROPERTIES)
SET_TARGET_PROPERTIES(OTBSimulation PROPERTIES ${OTB_LIBRARY_PROPERTIES})
ENDIF(OTB_LIBRARY_PROPERTIES)
FILE(GLOB __files1 "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
FILE(GLOB __files2 "${CMAKE_CURRENT_SOURCE_DIR}/*.txx")
IF(NOT OTB_INSTALL_NO_LIBRARIES)
INSTALL(TARGETS OTBSimulation
RUNTIME DESTINATION ${OTB_INSTALL_BIN_DIR_CM24} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${OTB_INSTALL_LIB_DIR_CM24} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${OTB_INSTALL_LIB_DIR_CM24} COMPONENT Development)
ENDIF(NOT OTB_INSTALL_NO_LIBRARIES)
INSTALL(FILES ${__files1} ${__files2}
DESTINATION ${RSR_INSTALL_INCLUDE_DIR}
IF(NOT OTB_INSTALL_NO_DEVELOPMENT)
FILE(GLOB __files1 "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
FILE(GLOB __files2 "${CMAKE_CURRENT_SOURCE_DIR}/*.txx")
INSTALL(FILES ${__files1} ${__files2}
DESTINATION ${OTB_INSTALL_INCLUDE_DIR_CM24}/Simulation
COMPONENT Development)
ENDIF(NOT OTB_INSTALL_NO_DEVELOPMENT)
......@@ -19,7 +19,7 @@ ADD_SUBDIRECTORY(OBIA)
ADD_SUBDIRECTORY(ObjectDetection)
ADD_SUBDIRECTORY(Fuzzy)
ADD_SUBDIRECTORY(MultiTemporal)
ADD_SUBDIRECTORY(Simulation)
......
#IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
SET(BASELINE ${OTB_DATA_ROOT}/Baseline/OTB/Images)
SET(BASELINE_FILES ${OTB_DATA_ROOT}/Baseline/OTB/Files)
SET(INPUTDATA ${OTB_DATA_ROOT}/Input)
SET(SPECTRUM_DB ${OTB_DATA_ROOT}/Input/BD-CNES)
SET(TEMP ${OTBTesting_BINARY_DIR}/Temporary)
SET(SRCLASS0 ${SPECTRUM_DB}/JHU/becknic/manmade/txt)
SET(SRCLASS1 ${SPECTRUM_DB}/JHU/becknic/water/txt)
SET(SRCLASS2 ${SPECTRUM_DB}/JHU/becknic/soils/txt)
SET(SRCLASS3 ${SPECTRUM_DB}/JHU/becknic/vegetation/txt)
SET(SRCLASS4 ${SPECTRUM_DB}/JHU/becknic/rocks/sedimentary/powder/0_75/txt)
#Tolerance sur diff pixel image
SET(TOL 0.0)
SET(EPSILON 0.00001)
SET(EPSILON_PROSPECT 0.01)
SET(Simulation_TESTS1 ${CXX_TEST_PATH}/otbSimulationTests1)
SET(Simulation_TESTS2 ${CXX_TEST_PATH}/otbSimulationTests2)
SET(Simulation_TESTS3 ${CXX_TEST_PATH}/otbSimulationTests3)
SET(Simulation_TESTS4 ${CXX_TEST_PATH}/otbSimulationTests4)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbSimulation_TESTS1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ------- otb::reflectancetosurfacereflectance --------------------------
ADD_TEST(siTuReflectanceToSurfaceReflectanceFilterNew ${Simulation_TESTS1}
otbSurfaceReflectanceToReflectanceFilterNew )
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbSimulation_TESTS2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ADD_TEST(siTuSpectralResponseNew ${Simulation_TESTS2}
otbSpectralResponseNew
)
ADD_TEST(siTuSpectralResponse ${Simulation_TESTS2}
otbSpectralResponse
${SPECTRUM_DB}/JHU/becknic/manmade/txt/0092uuu.txt
2.5 #lambda
)
ADD_TEST(siTuSatelliteRSRNew ${Simulation_TESTS2}
otbSatelliteRSRNew
)
ADD_TEST(siTuSatelliteRSR ${Simulation_TESTS2}
otbSatelliteRSR
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nb band
2.5 #lambda
2 #num band
)
ADD_TEST(siTuReduceSpectralResponseNew ${Simulation_TESTS2}
otbReduceSpectralResponseNew
)
ADD_TEST(siTuReduceSpectralResponse ${Simulation_TESTS2}
otbReduceSpectralResponse
${SPECTRUM_DB}/jpl/beckman/minerals/Arsenate/txt/A01Ac.txt
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nb band
)
ADD_TEST(siTuReduceSpectralResponseClassifierRAndNIR ${Simulation_TESTS2}
otbReduceSpectralResponseClassifierRAndNIR
${SPECTRUM_DB}/JHU/becknic/manmade/txt/0092uuu.txt
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nb band
1 #red index
2 #NIR index
)
#FIXME uncomment this test and make it compatible with filters able to read filter function values (rep6S.dat)
# ADD_TEST(siTuAtmosphericEffects ${Simulation_TESTS2}
# otbAtmosphericEffects
# ${SPECTRUM_DB}/JHU/becknic/manmade/txt/0092uuu.txt
# ${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
# 4 #nb band
# 4 #day
# 12 #month
# 27.3 #zenithSolarAngle
# 152.7 #azimutSolarAngle
# 2.5 #viewingZenitalAngle
# -77.0 #viewingAzimutalAngle
# 1013. #atmoPressure
# 2.48134 #waterVaporAmount
# 0.34400 #ozoneAmount
# 1 #aerosolModelValue
# 0.199854 #aerosolOptical
# )
ADD_TEST(siTuSpatialisationTest ${Simulation_TESTS2}
otbSpatialisationTest
${TEMP}/SpatialisationTest.tif
)
ADD_TEST(siTuLabelMapToSimulatedImageFilterTest ${Simulation_TESTS2}
otbLabelMapToSimulatedImageFilterTest
${INPUTDATA}/Simulation/Shapefile/culturesWithAndWithoutPath.shp
# /home2/arnaud/PROJETS/SimuCapteur/data/largeInput.shp
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nb bands
${SPECTRUM_DB}/jpl/beckman/minerals/ #root path of spectrum
${TEMP}/LabelMapToSimulatedImageFilterTest.tif
)
ADD_TEST(siTuImageSimulationMethodWithVectorDataTest ${Simulation_TESTS2}
otbImageSimulationMethodWithVectorDataTest
${INPUTDATA}/Simulation/Shapefile/stickPolygons.shp
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nb bands
${SPECTRUM_DB}/ #root path of spectrum
3 #prolate radius
${TEMP}/ImageSimulationMethodTest.tif
${TEMP}/LabelImageSimulationMethodTest.tif
)
ADD_TEST(siTuImageSimulationMethodWithSpatialisationTest ${Simulation_TESTS2}
otbImageSimulationMethodWithSpatialisationTest
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nb bands
${SPECTRUM_DB}/ #root path of spectrum
3 #prolate radius
${TEMP}/ImageSimulationMethodWithSpatialisationTest.tif
${TEMP}/LabelImageSimulationMethodWithSpatialisationTest.tif
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbSimulation_TESTS3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#FIXME The tolerance is set to 0.01
#need to investigate differences between matlab baselines and otb implementation
ADD_TEST(siTvProspectReflTest ${Simulation_TESTS3}
--compare-ascii ${EPSILON_PROSPECT} ${BASELINE_FILES}/siTvProspectReflTest.txt
${TEMP}/siTvProspectReflTest.txt
otbProspectReflTest
30.0 #cab
10.0 #car
0.0 #CBrown
0.015 #Cw
0.009 #Cm
1.2 #N
${TEMP}/siTvProspectReflTest.txt
)
#FIXME The tolerance is set to 0.01
#need to investigate differences between matlab baselines and otb implementation
ADD_TEST(siTvProspectTransTest ${Simulation_TESTS3}
--compare-ascii ${EPSILON_PROSPECT} ${BASELINE_FILES}/siTvProspectTransTest.txt
${TEMP}/siTvProspectTransTest.txt
otbProspectTransTest
30.0 #cab
10.0 #car
0.0 #CBrown
0.015 #Cw
0.009 #Cm
1.2 #N
${TEMP}/siTvProspectTransTest.txt
)
ADD_TEST(siTvSailReflHTest ${Simulation_TESTS3}
--compare-ascii ${EPSILON} ${BASELINE_FILES}/siTvSailReflHTest.txt
${TEMP}/siTvSailReflHTest.txt
otbSailReflHTest
30.0 #cab
10.0 #car
0.0 #CBrown
0.015 #Cw
0.009 #Cm
1.2 #N
2 #LAI
50 #Angl
1 #PSoil
70 #Skyl
0.2 #HSpot
30 #TTS
0 #TTO
0 #PSI
${TEMP}/siTvSailReflHTest.txt
)
ADD_TEST(siTvSailReflVTest ${Simulation_TESTS3}
--compare-ascii ${EPSILON} ${BASELINE_FILES}/siTvSailReflVTest.txt
${TEMP}/siTvSailReflVTest.txt
otbSailReflVTest
30.0 #cab
10.0 #car
0.0 #CBrown
0.015 #Cw
0.009 #Cm
1.2 #N
2 #LAI
50 #Angl
1 #PSoil
70 #Skyl
0.2 #HSpot
30 #TTS
0 #TTO
0 #PSI
${TEMP}/siTvSailReflVTest.txt
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbSimulation_TESTS4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ADD_TEST(siTuRSRSVMClassifier ${Simulation_TESTS4}
otbReduceSpectralResponseSVMClassifier
${SRCLASS0}
${SRCLASS1}
${SRCLASS2}
${SRCLASS3}
${SRCLASS4}
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nbBands
0.1 #percentage of validation files
)
# ADD_TEST(siTuatmosphericCorrectionsRSRSVMClassifier ${Simulation_TESTS4}
# otbAtmosphericCorrectionsRSRSVMClassifier
# ${SRCLASS0}
# ${SRCLASS1}
# ${SRCLASS2}
# ${SRCLASS3}
# ${SRCLASS4}
# ${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
# 4 #nbBands
# 4 #day
# 12 #month
# 27.3 #elevation et azimuth solaire
# 152.7 #solar azimutal angle
# 2.5 #viewing zenithal angle
# -77.0 #viewing azimutal angle
# 1013. #atmo pressure
# 2.48134 #water vapour amount
# 0.34400 #ozone amount
# 1 #aerosol model type
# 0.199854 #aerosol optical
# 0.2 #percentage of validation files
# )
ADD_TEST(siTuImageSimulationMethodKMeansClassif ${Simulation_TESTS4}
otbImageSimulationMethodKMeansClassif
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nb bands
${SPECTRUM_DB}/ #root path of spectrum
3 #prolate radius
${TEMP}/siTuImageSimulationMethodKMeansClassif.tif
${TEMP}/siTuKMeansClassifLabelImage.tif
)
#warning the svm model estimation does not converge.
ADD_TEST(siTuImageSimulationMethodSVMClassif ${Simulation_TESTS4}
otbImageSimulationMethodSVMClassif
${INPUTDATA}/Radiometry/SPOT5/HRG2/rep6S.dat
4 #nb bands
${SPECTRUM_DB}/ #root path of spectrum
3 #prolate radius
${TEMP}/siTuImageSimulationMethodSVMClassif.tif
${TEMP}/siTuSVMClassifLabelImage.tif
)
# atmospheric corrections tests
SET(Simulation_SRCS1
otbSimulationTests1.cxx
otbSurfaceReflectanceToReflectanceFilterNew.cxx
)
# exploitation tests
SET(Simulation_SRCS2
otbSimulationTests2.cxx
otbSpectralResponseNew.cxx
otbSpectralResponse.cxx
otbSatelliteRSRNew.cxx
otbSatelliteRSR.cxx
otbReduceSpectralResponseNew.cxx
otbReduceSpectralResponse.cxx
otbReduceSpectralResponseClassifierRAndNIR.cxx
otbAtmosphericEffects.cxx
otbSpatialisationTest.cxx
otbLabelMapToSimulatedImageFilterTest.cxx
otbImageSimulationMethodWithVectorDataTest.cxx
otbImageSimulationMethodWithSpatialisationTest.cxx
)
# Prosail tests
SET(Simulation_SRCS3
otbSimulationTests3.cxx
otbProspectReflTest.cxx
otbProspectTransTest.cxx
otbSailReflHTest.cxx
otbSailReflVTest.cxx
)
# performance tests
SET(Simulation_SRCS4
otbSimulationTests4.cxx
otbReduceSpectralResponseSVMClassifier.cxx
otbAtmosphericCorrectionsRSRSVMClassifier.cxx
otbImageSimulationMethodKMeansClassif.cxx
otbImageSimulationMethodSVMClassif.cxx
)
OTB_ADD_EXECUTABLE(otbSimulationTests1 "${Simulation_SRCS1}" "OTBSimulation;OTBIO;OTBTesting")
OTB_ADD_EXECUTABLE(otbSimulationTests2 "${Simulation_SRCS2}" "OTBSimulation;OTBIO;OTBTesting")
OTB_ADD_EXECUTABLE(otbSimulationTests3 "${Simulation_SRCS3}" "OTBSimulation;OTBIO;OTBTesting")
OTB_ADD_EXECUTABLE(otbSimulationTests4 "${Simulation_SRCS4}" "OTBSimulation;OTBIO;OTBLearning;OTBTesting")
#ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
/*=========================================================================
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 "itkExceptionObject.h"
#include "otbMacro.h"
#include "otbAtmosphericEffects.h"
#include "otbSatelliteRSR.h"
#include "otbSpectralResponse.h"
#include "otbReduceSpectralResponse.h"
#include "otbSVMSampleListModelEstimator.h"
#include "otbSVMClassifier.h"
#include "itkListSample.h"
#include "base/ossimDirectoryTree.h"
#include "base/ossimDirectory.h"
#include "otbConfusionMatrixCalculator.h"
/*
./bin/otbAtmosphericCorrectionsRSRSVMClassifier ../data/BD-CNES/jpl/nicolet/minerals/borate/txt/ ../data/BD-CNES/jpl/nicolet/minerals/carbonate/txt/ ../data/BD-CNES/jpl/nicolet/minerals/cyclosilicate/txt/ ../data/BD-CNES/jpl/nicolet/manmade/txt/ ../data/BD-CNES/jpl/nicolet/soils/txt/ ../hg/SimuPerformances/Data/Rsr/SPOT5/HRG1/rep6S.dat 4 4 12 27.3 152.7 2.5 -77.0 1013. 2.48134 0.34400 1 0.199854
*/
int otbAtmosphericCorrectionsRSRSVMClassifier(int argc, char * argv[])
{
typedef otb::SpectralResponse< double,double> SpectralResponseType;
typedef SpectralResponseType::Pointer SpectralResponsePointerType;
typedef otb::SatelliteRSR< double,double> SatRSRType;
typedef SatRSRType::Pointer SatRSRPointerType;
typedef otb::ReduceSpectralResponse< SpectralResponseType,SatRSRType> ReduceSpectralResponseType;
typedef otb::AtmosphericEffects< SpectralResponseType,SatRSRType> AtmosphericEffectsType;
typedef AtmosphericEffectsType::AtmosphericCorrectionParametersType AtmosphericCorrectionParametersType;
typedef AtmosphericCorrectionParametersType::AerosolModelType AerosolModelType;
typedef AtmosphericCorrectionParametersType::AerosolModelType AerosolModelType;
typedef itk::VariableLengthVector<double> SampleType;
typedef itk::Statistics::ListSample<SampleType> SampleListType;
typedef itk::FixedArray<unsigned long, 1> TrainingSampleType;
typedef itk::Statistics::ListSample<TrainingSampleType> TrainingSampleListType;
typedef otb::SVMSampleListModelEstimator<SampleListType,TrainingSampleListType> SVMModelEstimatorType;
typedef otb::SVMClassifier<SampleListType,unsigned long> SVMClassifierType;
typedef SVMClassifierType::OutputType ClassifierOutputType;
typedef otb::ConfusionMatrixCalculator<TrainingSampleListType,TrainingSampleListType> ConfusionMatrixCalculatorType;
if ( argc!= 20 )
{
std::cout << argv[0] << std::endl << "\t" << "<dir_spectres_class1>" << "\t" << "<dir_spectres_class2>" << "\t" << "<dir_spectres_class3>" << "\t" << "<dir_spectres_class4>" << "\t" << "<dir_spectres_class5>" << "\t" << "<Gabarit_SAT_fileSRname>" << "\t" << "<nbBands>" << "\t" << "<day>" << "\t" << "<month>" << "\t" << "<zenithSolarAngle>" << "\t" << "<azimutSolarAngle>" << "\t" << "<viewingZenitalAngle>" << "\t" << "<viewingAzimutalAngle>" << "\t" << "<atmoPressure>" << "\t" << "<waterVaporAmount>" << "\t" << "<ozoneAmount>" << "\t" << "<aerosolModelValue>" << "\t" << "<aerosolOptical>" << "\t" << "<percentage_validation_files>" << std::endl ;
return EXIT_FAILURE;
}
/*
27.3 #elevation et azimuth solaire
4 #day
12 #month
# AtmosphericCorrectionParametersTo6SAtmosphericRadiativeTerms parameters
152.7 #solar azimutal angle
2.5 #viewing zenithal angle
-77.0 #viewing azimutal angle
1013. #atmo pressure
2.48134 #water vapour amount
0.34400 #ozone amount
1 #aerosol model type
0.199854 #aerosol optical
*/
//Get input parameters
std::vector<ossimFilename> dirSR;
dirSR.push_back(argv[1]);
dirSR.push_back(argv[2]);
dirSR.push_back(argv[3]);
dirSR.push_back(argv[4]);
dirSR.push_back(argv[5]);
const std::string fileSatG(argv[6]);
unsigned int nbBand = atoi(argv[7]);
const int day(atoi(argv[8]));
const int month(atoi(argv[9]));
const double zenithSolarAngle(static_cast<double>(atof(argv[10])));
const double azimutSolarAngle(static_cast<double>(atof(argv[11])));
const double viewingZenitalAngle(static_cast<double>(atof(argv[12])));
const double viewingAzimutalAngle(static_cast<double>(atof(argv[13])));
const double atmoPressure(static_cast<double>(atof(argv[14])));
const double waterVaporAmount(static_cast<double>(atof(argv[15])));
const double ozoneAmount(static_cast<double>(atof(argv[16])));
const int aerosolModelValue(::atoi(argv[17]));
const double aerosolOptical( static_cast<double>(atof(argv[18])) );
float percentage=atof(argv[19]);
//Instantiation
AtmosphericCorrectionParametersType::Pointer dataAtmosphericCorrectionParameters = AtmosphericCorrectionParametersType::New();
SatRSRPointerType satRSR=SatRSRType::New();
satRSR->SetNbBands(nbBand);
satRSR->Load(fileSatG);
// Set parameters
dataAtmosphericCorrectionParameters->SetSolarZenithalAngle(zenithSolarAngle);
dataAtmosphericCorrectionParameters->SetSolarAzimutalAngle(azimutSolarAngle);
dataAtmosphericCorrectionParameters->SetViewingZenithalAngle(viewingZenitalAngle);
dataAtmosphericCorrectionParameters->SetViewingAzimutalAngle(viewingAzimutalAngle);
dataAtmosphericCorrectionParameters->SetMonth(month);
dataAtmosphericCorrectionParameters->SetDay(day);
dataAtmosphericCorrectionParameters->SetAtmosphericPressure(atmoPressure);
dataAtmosphericCorrectionParameters->SetWaterVaporAmount(waterVaporAmount);
dataAtmosphericCorrectionParameters->SetOzoneAmount(ozoneAmount);
AerosolModelType aerosolModel = static_cast<AerosolModelType>(aerosolModelValue);
dataAtmosphericCorrectionParameters->SetAerosolModel(aerosolModel);
dataAtmosphericCorrectionParameters->SetAerosolOptical(aerosolOptical);
//divide into training and testing files
//90% of files are used for training and 10% for testing
std::vector<ossimFilename> trainingFiles; //contains training files for all classes
std::vector<unsigned int> trainingClasses; //contains training classes for each files
std::vector<ossimFilename> testingFiles; //contains testing files for this classes
std::vector<unsigned int> testingGTClasses; //contains testing ground truth classes for each files
unsigned int ind;
const ossimString regularExpressionPattern=".*\\.txt$";
int flags = ossimDirectory::OSSIM_DIR_DEFAULT;
for(unsigned int i=0;i<dirSR.size();i++) //for each class (directory)
{
std::vector<ossimFilename> result;
ossimDirectory * directory = new ossimDirectory();
std::cout<<"dirSR["<<i<<"] : "<<dirSR[i]<<std::endl;
directory->open(dirSR[i]);
directory->findAllFilesThatMatch(result, regularExpressionPattern, flags);
delete(directory);
directory=NULL;
std::vector<ossimFilename> training; //contains training files for this class (directory)
std::vector<ossimFilename> testing; //contains testing files for this class (directory)
training=result;
srand((unsigned int)getpid()); //init random
for(unsigned int j=0;j<static_cast <unsigned int> (percentage*result.size());j++)
{
ind = rand()%(result.size());
testing.push_back(result[ind]);
training.erase(training.begin()+j);
}
//add to global training files and testing files
for(unsigned int k=0;k<testing.size();k++)
{
std::cout<<"testing["<<k<<"] : "<< testing[k] <<std::endl;
testingFiles.push_back(testing[k]);
testingGTClasses.push_back(i);
}
for(unsigned int l=0;l<training.size();l++)
{
std::cout<<"training["<<l<<"] : "<< training[l] <<std::endl;
trainingFiles.push_back(training[l]);
trainingClasses.push_back(i); //class is the directory number
}
}
//compute spectral response for all training files
SampleListType::Pointer sampleList = SampleListType::New();
TrainingSampleListType::Pointer trainingList = TrainingSampleListType::New();
for(unsigned int i=0;i<trainingFiles.size();i++)
{
SpectralResponsePointerType spectralResponse=SpectralResponseType::New();
ReduceSpectralResponseType::Pointer reduceSpectralResponse = ReduceSpectralResponseType::New();
AtmosphericEffectsType::Pointer atmosphericEffectsFilter = AtmosphericEffectsType::New();
std::cout<<"training file : "<<trainingFiles[i]<<std::endl;
spectralResponse->Load(trainingFiles[i], 100.0);
//Compute Reduce Spectral Response
reduceSpectralResponse->SetInputSatRSR(satRSR);
reduceSpectralResponse->SetInputSpectralResponse(spectralResponse);
reduceSpectralResponse->CalculateResponse();
atmosphericEffectsFilter->SetDataAtmosphericCorrectionParameters(dataAtmosphericCorrectionParameters);
atmosphericEffectsFilter->SetInputSatRSR(satRSR);
atmosphericEffectsFilter->SetInputSpectralResponse(reduceSpectralResponse->GetReduceResponse());
atmosphericEffectsFilter->Process6S();
//Get the response in an itk::VariableLengthVector and add it to the sample list for SVMModelEstimator
SampleType sample;
TrainingSampleType trainingSample;
sample.SetSize(atmosphericEffectsFilter->GetCorrectedSpectralResponse()->Size());
std::cout<<"corrected response : [";
for(unsigned int j=0;j<atmosphericEffectsFilter->GetCorrectedSpectralResponse()->Size();j++)
{
sample[j]=atmosphericEffectsFilter->GetCorrectedSpectralResponse()->GetResponse()[j].second;
std::cout<<atmosphericEffectsFilter->GetCorrectedSpectralResponse()->GetResponse()[j].second<<" ";
}
std::cout<<"]"<<std::endl;
sampleList->PushBack(sample);
trainingSample=trainingClasses[i];
std::cout<<"training class : "<<trainingSample<<std::endl;
trainingList->PushBack(trainingSample);
}
//SVM model estimator
SVMModelEstimatorType::Pointer estimator = SVMModelEstimatorType::New();
estimator->SetInputSampleList(sampleList);
estimator