Skip to content
Snippets Groups Projects
Commit e16412a4 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

STYLE : try/catch blocs supression in Learning testing.

parent 04a2b7f1
Branches
Tags
No related merge requests found
Showing
with 627 additions and 916 deletions
......@@ -28,82 +28,69 @@
int otbPeriodicSOM(int argc, char* argv[])
{
try
{
const unsigned int Dimension = 2;
char * inputFileName = argv[1];
char * outputFileName = argv[2];
unsigned int sizeX = atoi(argv[3]);
unsigned int sizeY = atoi(argv[4]);
unsigned int neighInitX = atoi(argv[5]);
unsigned int neighInitY= atoi(argv[6]);
unsigned int nbIterations= atoi(argv[7]);
double betaInit = atof(argv[8]);
double betaEnd= atof(argv[9]);
double initValue = atof(argv[10]);
const unsigned int Dimension = 2;
char * inputFileName = argv[1];
char * outputFileName = argv[2];
unsigned int sizeX = atoi(argv[3]);
unsigned int sizeY = atoi(argv[4]);
unsigned int neighInitX = atoi(argv[5]);
unsigned int neighInitY= atoi(argv[6]);
unsigned int nbIterations= atoi(argv[7]);
double betaInit = atof(argv[8]);
double betaEnd= atof(argv[9]);
double initValue = atof(argv[10]);
typedef double ComponentType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> MapType;
typedef otb::VectorImage<ComponentType,Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef double ComponentType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> MapType;
typedef otb::VectorImage<ComponentType,Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::PeriodicSOM<ListSampleType,MapType> SOMType;
typedef otb::ImageFileWriter<MapType> WriterType;
typedef otb::PeriodicSOM<ListSampleType,MapType> SOMType;
typedef otb::ImageFileWriter<MapType> WriterType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFileName);
reader->Update();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFileName);
reader->Update();
ListSampleType::Pointer listSample = ListSampleType::New();
ListSampleType::Pointer listSample = ListSampleType::New();
itk::ImageRegionIterator<ImageType> it(reader->GetOutput(),reader->GetOutput()->GetLargestPossibleRegion());
itk::ImageRegionIterator<ImageType> it(reader->GetOutput(),reader->GetOutput()->GetLargestPossibleRegion());
it.GoToBegin();
it.GoToBegin();
while(!it.IsAtEnd())
{
listSample->PushBack(it.Get());
++it;
}
while(!it.IsAtEnd())
{
listSample->PushBack(it.Get());
++it;
}
std::cout<<"LIST SAMPLE SIZE: "<<listSample->GetMeasurementVectorSize()<<std::endl;
std::cout<<"LIST SAMPLE SIZE: "<<listSample->GetMeasurementVectorSize()<<std::endl;
// Instantiation
SOMType::Pointer som = SOMType::New();
som->SetListSample(listSample);
SOMType::SizeType size;
size[0]=sizeX;
size[1]=sizeY;
som->SetMapSize(size);
SOMType::SizeType radius;
radius[0] = neighInitX;
radius[1] = neighInitY;
som->SetNeighborhoodSizeInit(radius);
som->SetNumberOfIterations(nbIterations);
som->SetBetaInit(betaInit);
som->SetBetaEnd(betaEnd);
som->SetMaxWeight(initValue);
som->SetRandomInit(false);
// Instantiation
SOMType::Pointer som = SOMType::New();
som->SetListSample(listSample);
SOMType::SizeType size;
size[0]=sizeX;
size[1]=sizeY;
som->SetMapSize(size);
SOMType::SizeType radius;
radius[0] = neighInitX;
radius[1] = neighInitY;
som->SetNeighborhoodSizeInit(radius);
som->SetNumberOfIterations(nbIterations);
som->SetBetaInit(betaInit);
som->SetBetaEnd(betaEnd);
som->SetMaxWeight(initValue);
som->SetRandomInit(false);
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
writer->SetInput(som->GetOutput());
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
writer->SetInput(som->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
......@@ -24,30 +24,18 @@
int otbPeriodicSOMNew(int argc, char* argv[])
{
try
{
const unsigned int Dimension = 2;
typedef float ComponentType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
// typedef itk::Statistics::ImageToListAdaptor<SOMMapType> AdaptorType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::PeriodicSOM<ListSampleType,SOMMapType> SOMType;
// Instantiation
SOMType::Pointer som = SOMType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
const unsigned int Dimension = 2;
typedef float ComponentType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
// typedef itk::Statistics::ImageToListAdaptor<SOMMapType> AdaptorType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::PeriodicSOM<ListSampleType,SOMMapType> SOMType;
// Instantiation
SOMType::Pointer som = SOMType::New();
return EXIT_SUCCESS;
}
......@@ -33,37 +33,19 @@
int otbSEMClassifierNew( int argc, char* argv[] )
{
try
{
typedef double PixelType;
typedef otb::VectorImage< PixelType, 2 > ImageType;
typedef itk::Image< unsigned char, 2 > OutputImageType;
typedef otb::SEMClassifier< ImageType, OutputImageType > ClassifType;
typedef itk::Statistics::ListSample< ImageType::PixelType > SampleType;
typedef itk::Statistics::Subsample< SampleType > ClassSampleType;
typedef double PixelType;
typedef otb::VectorImage< PixelType, 2 > ImageType;
typedef itk::Image< unsigned char, 2 > OutputImageType;
typedef otb::SEMClassifier< ImageType, OutputImageType > ClassifType;
typedef itk::Statistics::ListSample< ImageType::PixelType > SampleType;
typedef itk::Statistics::Subsample< SampleType > ClassSampleType;
typedef otb::Statistics::ModelComponentBase< ClassSampleType > ComponentType ;
typedef otb::Statistics::ModelComponentBase< ClassSampleType > ComponentType ;
ClassifType::Pointer classifier = ClassifType::New();
ComponentType::Pointer component = ComponentType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : EndCodeSnippet
//#endif
ClassifType::Pointer classifier = ClassifType::New();
ComponentType::Pointer component = ComponentType::New();
return EXIT_SUCCESS;
}
......
......@@ -28,82 +28,70 @@
int otbSOM(int argc, char* argv[])
{
try
{
const unsigned int Dimension = 2;
char * inputFileName = argv[1];
char * outputFileName = argv[2];
unsigned int sizeX = atoi(argv[3]);
unsigned int sizeY = atoi(argv[4]);
unsigned int neighInitX = atoi(argv[5]);
unsigned int neighInitY= atoi(argv[6]);
unsigned int nbIterations= atoi(argv[7]);
double betaInit = atof(argv[8]);
double betaEnd= atof(argv[9]);
double initValue = atof(argv[10]);
const unsigned int Dimension = 2;
char * inputFileName = argv[1];
char * outputFileName = argv[2];
unsigned int sizeX = atoi(argv[3]);
unsigned int sizeY = atoi(argv[4]);
unsigned int neighInitX = atoi(argv[5]);
unsigned int neighInitY= atoi(argv[6]);
unsigned int nbIterations= atoi(argv[7]);
double betaInit = atof(argv[8]);
double betaEnd= atof(argv[9]);
double initValue = atof(argv[10]);
typedef double ComponentType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> MapType;
typedef otb::VectorImage<ComponentType,Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef double ComponentType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> MapType;
typedef otb::VectorImage<ComponentType,Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::SOM<ListSampleType,MapType> SOMType;
typedef otb::ImageFileWriter<MapType> WriterType;
typedef otb::SOM<ListSampleType,MapType> SOMType;
typedef otb::ImageFileWriter<MapType> WriterType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFileName);
reader->Update();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFileName);
reader->Update();
ListSampleType::Pointer listSample = ListSampleType::New();
ListSampleType::Pointer listSample = ListSampleType::New();
itk::ImageRegionIterator<ImageType> it(reader->GetOutput(),reader->GetOutput()->GetLargestPossibleRegion());
itk::ImageRegionIterator<ImageType> it(reader->GetOutput(),reader->GetOutput()->GetLargestPossibleRegion());
it.GoToBegin();
it.GoToBegin();
while(!it.IsAtEnd())
{
listSample->PushBack(it.Get());
++it;
}
while(!it.IsAtEnd())
{
listSample->PushBack(it.Get());
++it;
}
std::cout<<"LIST SAMPLE SIZE: "<<listSample->GetMeasurementVectorSize()<<std::endl;
std::cout<<"LIST SAMPLE SIZE: "<<listSample->GetMeasurementVectorSize()<<std::endl;
// Instantiation
SOMType::Pointer som = SOMType::New();
som->SetListSample(listSample);
SOMType::SizeType size;
size[0]=sizeX;
size[1]=sizeY;
som->SetMapSize(size);
SOMType::SizeType radius;
radius[0] = neighInitX;
radius[1] = neighInitY;
som->SetNeighborhoodSizeInit(radius);
som->SetNumberOfIterations(nbIterations);
som->SetBetaInit(betaInit);
som->SetBetaEnd(betaEnd);
som->SetMaxWeight(initValue);
som->SetRandomInit(false);
// Instantiation
SOMType::Pointer som = SOMType::New();
som->SetListSample(listSample);
SOMType::SizeType size;
size[0]=sizeX;
size[1]=sizeY;
som->SetMapSize(size);
SOMType::SizeType radius;
radius[0] = neighInitX;
radius[1] = neighInitY;
som->SetNeighborhoodSizeInit(radius);
som->SetNumberOfIterations(nbIterations);
som->SetBetaInit(betaInit);
som->SetBetaEnd(betaEnd);
som->SetMaxWeight(initValue);
som->SetRandomInit(false);
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
writer->SetInput(som->GetOutput());
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
writer->SetInput(som->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
......@@ -29,68 +29,56 @@
int otbSOMActivationBuilder(int argc, char* argv[])
{
try
{
const unsigned int Dimension = 2;
char * vectorSetFileName = argv[1];
char * mapFileName = argv[2];
char * outputFileName = argv[3];
const unsigned int Dimension = 2;
char * vectorSetFileName = argv[1];
char * mapFileName = argv[2];
char * outputFileName = argv[3];
typedef float ComponentType;
typedef unsigned char OutputPixelType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef float ComponentType;
typedef unsigned char OutputPixelType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> MapType;
typedef otb::ImageFileReader<MapType> MapReaderType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> MapType;
typedef otb::ImageFileReader<MapType> MapReaderType;
typedef otb::VectorImage<ComponentType,Dimension> InputImageType;
typedef otb::ImageFileReader<InputImageType> ReaderType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::VectorImage<ComponentType,Dimension> InputImageType;
typedef otb::ImageFileReader<InputImageType> ReaderType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::Image<OutputPixelType,Dimension> OutputImageType;
typedef otb::ImageFileWriter<OutputImageType> WriterType;
typedef otb::Image<OutputPixelType,Dimension> OutputImageType;
typedef otb::ImageFileWriter<OutputImageType> WriterType;
typedef otb::SOMActivationBuilder<ListSampleType,MapType,OutputImageType> SOMActivationBuilderType;
typedef otb::SOMActivationBuilder<ListSampleType,MapType,OutputImageType> SOMActivationBuilderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(vectorSetFileName);
reader->Update();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(vectorSetFileName);
reader->Update();
ListSampleType::Pointer listSample = ListSampleType::New();
ListSampleType::Pointer listSample = ListSampleType::New();
itk::ImageRegionIterator<InputImageType> it(reader->GetOutput(),reader->GetOutput()->GetLargestPossibleRegion());
itk::ImageRegionIterator<InputImageType> it(reader->GetOutput(),reader->GetOutput()->GetLargestPossibleRegion());
it.GoToBegin();
it.GoToBegin();
while(!it.IsAtEnd())
{
listSample->PushBack(it.Get());
++it;
}
while(!it.IsAtEnd())
{
listSample->PushBack(it.Get());
++it;
}
MapReaderType::Pointer mapReader = MapReaderType::New();
mapReader->SetFileName(mapFileName);
SOMActivationBuilderType::Pointer somAct = SOMActivationBuilderType::New();
somAct->SetInput(mapReader->GetOutput());
somAct->SetListSample(listSample);
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
writer->SetInput(somAct->GetOutput());
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
MapReaderType::Pointer mapReader = MapReaderType::New();
mapReader->SetFileName(mapFileName);
SOMActivationBuilderType::Pointer somAct = SOMActivationBuilderType::New();
somAct->SetInput(mapReader->GetOutput());
somAct->SetListSample(listSample);
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
writer->SetInput(somAct->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
......@@ -27,33 +27,21 @@
int otbSOMActivationBuilderNew(int argc, char* argv[])
{
try
{
const unsigned int Dimension =2;
typedef float ComponentType;
typedef unsigned char OutputPixelType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> MapType;
typedef otb::VectorImage<ComponentType,Dimension> InputImageType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::Image<OutputPixelType,Dimension> OutputImageType;
typedef otb::SOMActivationBuilder<ListSampleType,MapType,OutputImageType> SOMActivationBuilderType;
// Instantiation
SOMActivationBuilderType::Pointer somAct = SOMActivationBuilderType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
const unsigned int Dimension =2;
typedef float ComponentType;
typedef unsigned char OutputPixelType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> MapType;
typedef otb::VectorImage<ComponentType,Dimension> InputImageType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::Image<OutputPixelType,Dimension> OutputImageType;
typedef otb::SOMActivationBuilder<ListSampleType,MapType,OutputImageType> SOMActivationBuilderType;
// Instantiation
SOMActivationBuilderType::Pointer somAct = SOMActivationBuilderType::New();
return EXIT_SUCCESS;
}
......@@ -32,96 +32,83 @@
int otbSOMClassifier(int argc, char* argv[] )
{
try
{
if (argc != 4)
{
if (argc != 4)
{
std::cout << "Usage : " << argv[0] << " inputImage modelFile outputImage"
<< std::endl ;
return EXIT_FAILURE;
}
}
const char * imageFilename = argv[1];
const char * mapFilename = argv[2];
const char * outputFilename = argv[3];
const char * imageFilename = argv[1];
const char * mapFilename = argv[2];
const char * outputFilename = argv[3];
typedef double InputPixelType;
typedef int LabelPixelType;
const unsigned int Dimension = 2;
typedef itk::VariableLengthVector<InputPixelType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
typedef otb::VectorImage<InputPixelType,Dimension> InputImageType;
typedef otb::ImageFileReader< InputImageType > ReaderType;
typedef otb::ImageFileReader<SOMMapType> SOMReaderType;
typedef itk::Statistics::ListSample< PixelType > SampleType;
typedef otb::SOMClassifier<SampleType,SOMMapType,LabelPixelType> ClassifierType;
typedef otb::Image<LabelPixelType, Dimension > OutputImageType;
typedef itk::ImageRegionIterator< OutputImageType> OutputIteratorType;
typedef otb::ImageFileWriter<OutputImageType> WriterType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( imageFilename );
reader->Update();
std::cout << "Image read" << std::endl;
SOMReaderType::Pointer somreader = SOMReaderType::New();
somreader->SetFileName(mapFilename);
somreader->Update();
std::cout<<"SOM map read"<<std::endl;
SampleType::Pointer listSample = SampleType::New();
itk::ImageRegionIterator<InputImageType> it(reader->GetOutput(),reader->GetOutput()->GetLargestPossibleRegion());
typedef double InputPixelType;
typedef int LabelPixelType;
const unsigned int Dimension = 2;
typedef itk::VariableLengthVector<InputPixelType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
typedef otb::VectorImage<InputPixelType,Dimension> InputImageType;
typedef otb::ImageFileReader< InputImageType > ReaderType;
typedef otb::ImageFileReader<SOMMapType> SOMReaderType;
typedef itk::Statistics::ListSample< PixelType > SampleType;
typedef otb::SOMClassifier<SampleType,SOMMapType,LabelPixelType> ClassifierType;
typedef otb::Image<LabelPixelType, Dimension > OutputImageType;
typedef itk::ImageRegionIterator< OutputImageType> OutputIteratorType;
typedef otb::ImageFileWriter<OutputImageType> WriterType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( imageFilename );
reader->Update();
std::cout << "Image read" << std::endl;
SOMReaderType::Pointer somreader = SOMReaderType::New();
somreader->SetFileName(mapFilename);
somreader->Update();
std::cout<<"SOM map read"<<std::endl;
SampleType::Pointer listSample = SampleType::New();
itk::ImageRegionIterator<InputImageType> it(reader->GetOutput(),reader->GetOutput()->GetLargestPossibleRegion());
it.GoToBegin();
it.GoToBegin();
while(!it.IsAtEnd())
{
listSample->PushBack(it.Get());
++it;
}
while(!it.IsAtEnd())
{
listSample->PushBack(it.Get());
++it;
}
ClassifierType::Pointer classifier = ClassifierType::New() ;
classifier->SetSample(listSample.GetPointer());
classifier->SetMap(somreader->GetOutput());
classifier->Update() ;
ClassifierType::Pointer classifier = ClassifierType::New() ;
classifier->SetSample(listSample.GetPointer());
classifier->SetMap(somreader->GetOutput());
classifier->Update() ;
OutputImageType::Pointer outputImage = OutputImageType::New();
outputImage->SetRegions( reader->GetOutput()->GetLargestPossibleRegion());
outputImage->Allocate();
OutputImageType::Pointer outputImage = OutputImageType::New();
outputImage->SetRegions( reader->GetOutput()->GetLargestPossibleRegion());
outputImage->Allocate();
ClassifierType::OutputType* membershipSample = classifier->GetOutput();
ClassifierType::OutputType::ConstIterator m_iter = membershipSample->Begin();
ClassifierType::OutputType::ConstIterator m_last = membershipSample->End();
ClassifierType::OutputType* membershipSample = classifier->GetOutput();
ClassifierType::OutputType::ConstIterator m_iter = membershipSample->Begin();
ClassifierType::OutputType::ConstIterator m_last = membershipSample->End();
OutputIteratorType outIt(outputImage,outputImage->GetLargestPossibleRegion());
outIt.GoToBegin();
OutputIteratorType outIt(outputImage,outputImage->GetLargestPossibleRegion());
outIt.GoToBegin();
while (m_iter != m_last && !outIt.IsAtEnd())
while (m_iter != m_last && !outIt.IsAtEnd())
{
outIt.Set(m_iter.GetClassLabel());
++m_iter ;
++outIt;
outIt.Set(m_iter.GetClassLabel());
++m_iter ;
++outIt;
}
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFilename);
writer->SetInput(outputImage);
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFilename);
writer->SetInput(outputImage);
writer->Update();
return EXIT_SUCCESS;
}
......
......@@ -28,32 +28,19 @@
int otbSOMClassifierNew(int argc, char* argv[] )
{
try
{
typedef double InputPixelType;
typedef int LabelPixelType;
const unsigned int Dimension = 2;
typedef double InputPixelType;
typedef int LabelPixelType;
const unsigned int Dimension = 2;
typedef itk::VariableLengthVector<InputPixelType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
typedef otb::VectorImage<InputPixelType,Dimension> InputImageType;
typedef itk::Statistics::ListSample< PixelType > SampleType;
typedef otb::SOMClassifier<SampleType,SOMMapType,LabelPixelType> ClassifierType;
typedef itk::VariableLengthVector<InputPixelType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
typedef otb::VectorImage<InputPixelType,Dimension> InputImageType;
typedef itk::Statistics::ListSample< PixelType > SampleType;
typedef otb::SOMClassifier<SampleType,SOMMapType,LabelPixelType> ClassifierType;
ClassifierType::Pointer classifier = ClassifierType::New() ;
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
ClassifierType::Pointer classifier = ClassifierType::New() ;
return EXIT_SUCCESS;
}
......
......@@ -23,62 +23,49 @@
int otbSOMMap(int argc, char* argv[])
{
try
{
const unsigned int Dimension = 2;
typedef float InternalPixelType;
typedef itk::VariableLengthVector<InternalPixelType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
const unsigned int Dimension = 2;
typedef float InternalPixelType;
typedef itk::VariableLengthVector<InternalPixelType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
// Instantiation
SOMMapType::Pointer somMap = SOMMapType::New();
// Instantiation
SOMMapType::Pointer somMap = SOMMapType::New();
// Allocation of the som map
SOMMapType::RegionType region;
SOMMapType::IndexType index;
SOMMapType::SizeType size;
index.Fill(0);
size.Fill(64);
region.SetIndex(index);
region.SetSize(size);
somMap->SetRegions(region);
somMap->SetNumberOfComponentsPerPixel(3);
somMap->Allocate();
// Allocation of the som map
SOMMapType::RegionType region;
SOMMapType::IndexType index;
SOMMapType::SizeType size;
index.Fill(0);
size.Fill(64);
region.SetIndex(index);
region.SetSize(size);
somMap->SetRegions(region);
somMap->SetNumberOfComponentsPerPixel(3);
somMap->Allocate();
// Filling with null pixels
PixelType nullPixel;
nullPixel.SetSize(3);
nullPixel.Fill(0);
somMap->FillBuffer(nullPixel);
// Filling with null pixels
PixelType nullPixel;
nullPixel.SetSize(3);
nullPixel.Fill(0);
somMap->FillBuffer(nullPixel);
// Definition of a non-null pixel
PixelType winner;
winner.SetSize(3);
winner.Fill(1);
index.Fill(32);
somMap->SetPixel(index,winner);
// Definition of a non-null pixel
PixelType winner;
winner.SetSize(3);
winner.Fill(1);
index.Fill(32);
somMap->SetPixel(index,winner);
// Test of the GetWinner method
SOMMapType::IndexType winnerIndex = somMap->GetWinner(winner);
if(winnerIndex!=index)
{
std::cout<<"Bad GetWinner function return."<<std::endl;
return EXIT_FAILURE;
}
// Test of the GetWinner method
SOMMapType::IndexType winnerIndex = somMap->GetWinner(winner);
if(winnerIndex!=index)
{
std::cout<<"Bad GetWinner function return."<<std::endl;
return EXIT_FAILURE;
}
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
......@@ -22,27 +22,14 @@
int otbSOMMapNew(int argc, char* argv[])
{
try
{
const unsigned int Dimension = 2;
typedef float ComponentType;
typedef itk::RGBPixel<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
// Instantiation
SOMMapType::Pointer somMap = SOMMapType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
const unsigned int Dimension = 2;
typedef float ComponentType;
typedef itk::RGBPixel<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
// Instantiation
SOMMapType::Pointer somMap = SOMMapType::New();
return EXIT_SUCCESS;
}
......@@ -24,30 +24,18 @@
int otbSOMNew(int argc, char* argv[])
{
try
{
const unsigned int Dimension = 2;
typedef float ComponentType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
// typedef itk::Statistics::ImageToListAdaptor<SOMMapType> AdaptorType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::SOM<ListSampleType,SOMMapType> SOMType;
// Instantiation
SOMType::Pointer som = SOMType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
const unsigned int Dimension = 2;
typedef float ComponentType;
typedef itk::VariableLengthVector<ComponentType> PixelType;
typedef itk::Statistics::EuclideanDistance<PixelType> DistanceType;
typedef otb::SOMMap<PixelType,DistanceType,Dimension> SOMMapType;
// typedef itk::Statistics::ImageToListAdaptor<SOMMapType> AdaptorType;
typedef itk::Statistics::ListSample<PixelType> ListSampleType;
typedef otb::SOM<ListSampleType,SOMMapType> SOMType;
// Instantiation
SOMType::Pointer som = SOMType::New();
return EXIT_SUCCESS;
}
......@@ -27,34 +27,17 @@
int otbSVMClassifierNew(int argc, char* argv[] )
{
try
{
typedef double InputPixelType;
typedef int LabelPixelType;
typedef itk::PointSet< InputPixelType, 2 > PointSetType ;
typedef itk::Statistics::PointSetToListAdaptor< PointSetType >
DataSampleType;
typedef otb::SVMClassifier< DataSampleType, LabelPixelType > ClassifierType ;
ClassifierType::Pointer classifier = ClassifierType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
typedef double InputPixelType;
typedef int LabelPixelType;
typedef itk::PointSet< InputPixelType, 2 > PointSetType ;
typedef itk::Statistics::PointSetToListAdaptor< PointSetType >
DataSampleType;
typedef otb::SVMClassifier< DataSampleType, LabelPixelType > ClassifierType ;
ClassifierType::Pointer classifier = ClassifierType::New();
return EXIT_SUCCESS;
}
......
......@@ -14,7 +14,7 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
......@@ -32,44 +32,41 @@
int otbSVMClassifierPointSet(int argc, char* argv[] )
{
try
namespace stat = itk::Statistics ;
if (argc != 2)
{
namespace stat = itk::Statistics ;
if (argc != 2)
{
std::cout << "Usage : " << argv[0] << " modelFile"
<< std::endl ;
return EXIT_FAILURE;
}
const char * modelFilename = argv[1];
}
const char * modelFilename = argv[1];
std::cout << "Building the pointset" << std::endl;
std::cout << "Building the pointset" << std::endl;
typedef double InputPixelType;
typedef int LabelPixelType;
typedef std::vector<InputPixelType> InputVectorType;
const unsigned int Dimension = 2;
typedef double InputPixelType;
typedef int LabelPixelType;
typedef std::vector<InputPixelType> InputVectorType;
const unsigned int Dimension = 2;
typedef itk::PointSet< InputVectorType, Dimension >
MeasurePointSetType;
typedef itk::PointSet< InputVectorType, Dimension >
MeasurePointSetType;
MeasurePointSetType::Pointer mPSet = MeasurePointSetType::New();
MeasurePointSetType::Pointer mPSet = MeasurePointSetType::New();
typedef MeasurePointSetType::PointType MeasurePointType;
typedef MeasurePointSetType::PointType MeasurePointType;
typedef MeasurePointSetType::PointsContainer MeasurePointsContainer;
typedef MeasurePointSetType::PointsContainer MeasurePointsContainer;
MeasurePointsContainer::Pointer mCont = MeasurePointsContainer::New();
MeasurePointsContainer::Pointer mCont = MeasurePointsContainer::New();
unsigned int pointId;
unsigned int pointId;
for(pointId = 0; pointId<20; pointId++)
{
for(pointId = 0; pointId<20; pointId++)
{
MeasurePointType mP;
......@@ -87,57 +84,57 @@ int otbSVMClassifierPointSet(int argc, char* argv[] )
mPSet->SetPointData( pointId, measure );
}
}
mPSet->SetPoints( mCont );
mPSet->SetPoints( mCont );
std::cout << "PointSet built" << std::endl;
std::cout << "PointSet built" << std::endl;
typedef itk::Statistics::PointSetToListAdaptor< MeasurePointSetType >
SampleType;
SampleType::Pointer sample = SampleType::New();
sample->SetPointSet( mPSet );
typedef itk::Statistics::PointSetToListAdaptor< MeasurePointSetType >
SampleType;
SampleType::Pointer sample = SampleType::New();
sample->SetPointSet( mPSet );
std::cout << "Sample set to Adaptor" << std::endl;
std::cout << "Sample set to Adaptor" << std::endl;
/** preparing classifier and decision rule object */
typedef otb::SVMModel< SampleType::MeasurementVectorType::ValueType, LabelPixelType > ModelType;
/** preparing classifier and decision rule object */
typedef otb::SVMModel< SampleType::MeasurementVectorType::ValueType, LabelPixelType > ModelType;
ModelType::Pointer model = ModelType::New();
ModelType::Pointer model = ModelType::New();
model->LoadModel( modelFilename );
model->LoadModel( modelFilename );
std::cout << "Model loaded" << std::endl;
std::cout << "Model loaded" << std::endl;
int numberOfClasses = model->GetNumberOfClasses();
int numberOfClasses = model->GetNumberOfClasses();
typedef otb::SVMClassifier< SampleType, LabelPixelType > ClassifierType ;
typedef otb::SVMClassifier< SampleType, LabelPixelType > ClassifierType ;
ClassifierType::Pointer classifier = ClassifierType::New() ;
ClassifierType::Pointer classifier = ClassifierType::New() ;
classifier->SetNumberOfClasses(numberOfClasses) ;
classifier->SetModel( model );
classifier->SetSample(sample.GetPointer()) ;
classifier->Update() ;
classifier->SetNumberOfClasses(numberOfClasses) ;
classifier->SetModel( model );
classifier->SetSample(sample.GetPointer()) ;
classifier->Update() ;
/* Build the class map */
/* Build the class map */
std::cout << "classifier get output" << std::endl;
ClassifierType::OutputType* membershipSample =
classifier->GetOutput() ;
std::cout << "Sample iterators" << std::endl;
ClassifierType::OutputType::ConstIterator m_iter =
membershipSample->Begin() ;
ClassifierType::OutputType::ConstIterator m_last =
membershipSample->End() ;
double error = 0.0;
pointId = 0;
while (m_iter != m_last)
{
std::cout << "classifier get output" << std::endl;
ClassifierType::OutputType* membershipSample =
classifier->GetOutput() ;
std::cout << "Sample iterators" << std::endl;
ClassifierType::OutputType::ConstIterator m_iter =
membershipSample->Begin() ;
ClassifierType::OutputType::ConstIterator m_last =
membershipSample->End() ;
double error = 0.0;
pointId = 0;
while (m_iter != m_last)
{
ClassifierType::ClassLabelType label = m_iter.GetClassLabel();
InputVectorType measure;
......@@ -153,24 +150,10 @@ int otbSVMClassifierPointSet(int argc, char* argv[] )
++pointId;
++m_iter ;
}
}
std::cout << "Error = " << error/pointId << std::endl;
std::cout << "Error = " << error/pointId << std::endl;
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......
......@@ -14,7 +14,7 @@
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
......@@ -35,151 +35,135 @@
int otbSVMImageModelEstimatorModelAccessor( int argc, char* argv[] )
{
try
{
const char* inputImageFileName = argv[1];
const char* trainingImageFileName = argv[2];
const char* outputModelFileName = argv[3];
typedef double InputPixelType;
const unsigned int Dimension = 2;
const char* inputImageFileName = argv[1];
const char* trainingImageFileName = argv[2];
const char* outputModelFileName = argv[3];
typedef double InputPixelType;
const unsigned int Dimension = 2;
typedef otb::VectorImage< InputPixelType, Dimension > InputImageType;
typedef otb::VectorImage< InputPixelType, Dimension > InputImageType;
typedef otb::Image< int, Dimension > TrainingImageType;
typedef otb::Image< int, Dimension > TrainingImageType;
typedef otb::SVMImageModelEstimator< InputImageType,
TrainingImageType > EstimatorType;
typedef otb::SVMImageModelEstimator< InputImageType,
TrainingImageType > EstimatorType;
typedef otb::ImageFileReader< InputImageType > InputReaderType;
typedef otb::ImageFileReader< TrainingImageType > TrainingReaderType;
typedef otb::ImageFileReader< InputImageType > InputReaderType;
typedef otb::ImageFileReader< TrainingImageType > TrainingReaderType;
InputReaderType::Pointer inputReader = InputReaderType::New();
TrainingReaderType::Pointer trainingReader = TrainingReaderType::New();
InputReaderType::Pointer inputReader = InputReaderType::New();
TrainingReaderType::Pointer trainingReader = TrainingReaderType::New();
inputReader->SetFileName( inputImageFileName );
trainingReader->SetFileName( trainingImageFileName );
inputReader->SetFileName( inputImageFileName );
trainingReader->SetFileName( trainingImageFileName );
inputReader->Update();
trainingReader->Update();
inputReader->Update();
trainingReader->Update();
EstimatorType::Pointer svmEstimator = EstimatorType::New();
EstimatorType::Pointer svmEstimator = EstimatorType::New();
svmEstimator->SetInputImage( inputReader->GetOutput() );
svmEstimator->SetTrainingImage( trainingReader->GetOutput() );
svmEstimator->SetNumberOfClasses( 2 );
svmEstimator->SetInputImage( inputReader->GetOutput() );
svmEstimator->SetTrainingImage( trainingReader->GetOutput() );
svmEstimator->SetNumberOfClasses( 2 );
svmEstimator->Update();
svmEstimator->Update();
typedef EstimatorType::SVMModelPointer SVMModelPointer;
typedef EstimatorType::SVMModelType SVMModelType;
SVMModelPointer ptrModel = svmEstimator->GetModel();
typedef EstimatorType::SVMModelPointer SVMModelPointer;
typedef EstimatorType::SVMModelType SVMModelType;
SVMModelPointer ptrModel = svmEstimator->GetModel();
std::ofstream f;
unsigned int nbClass = ptrModel->GetNumberOfClasses();
unsigned int nbSupportVector = ptrModel->GetNumberOfSupportVectors();
std::ofstream f;
unsigned int nbClass = ptrModel->GetNumberOfClasses();
unsigned int nbSupportVector = ptrModel->GetNumberOfSupportVectors();
f.open(outputModelFileName);
f << "Test methods of SVMModel class:"<<std::endl;
f << " - GetNumberOfClasses() "<< nbClass<<std::endl;
f << " - GetNumberOfHyperplane() "<< ptrModel->GetNumberOfHyperplane()<<std::endl;
f << " - GetNumberOfSupportVectors() "<< nbSupportVector<<std::endl;
f.open(outputModelFileName);
f << "Test methods of SVMModel class:"<<std::endl;
f << " - GetNumberOfClasses() "<< nbClass<<std::endl;
f << " - GetNumberOfHyperplane() "<< ptrModel->GetNumberOfHyperplane()<<std::endl;
f << " - GetNumberOfSupportVectors() "<< nbSupportVector<<std::endl;
f << " - GetSupportVectors() [nb support vector][]"<<std::endl;
svm_node ** SVs = ptrModel->GetSupportVectors();
if( SVs == NULL )
f << " - GetSupportVectors() [nb support vector][]"<<std::endl;
svm_node ** SVs = ptrModel->GetSupportVectors();
if( SVs == NULL )
{
itkGenericExceptionMacro(<<"SVs NULL");
itkGenericExceptionMacro(<<"SVs NULL");
}
for(unsigned int i=0;i<nbSupportVector;i++)
for(unsigned int i=0;i<nbSupportVector;i++)
{
if( SVs[i] == NULL ) itkGenericExceptionMacro(<<"SVs "<<i<<" NULL");
f << std::endl;
f << " SV["<<i<<"]:";
const svm_node *p = SVs[i];
/* for(unsigned int j=0;j<nbSupportVector;j++)
{
if( SVs[i] == NULL ) itkGenericExceptionMacro(<<"SVs "<<i<<" NULL");
f << std::endl;
f << " SV["<<i<<"]:";
const svm_node *p = SVs[i];
/* for(unsigned int j=0;j<nbSupportVector;j++)
{
f << " SV["<<i<<"]["<<j<<"]:";*/
if( svmEstimator->GetKernelType() == PRECOMPUTED)
{
f << " "<<p->value;
if( svmEstimator->GetKernelType() == PRECOMPUTED)
{
f << " "<<p->value;
}
else
{
while(p->index != -1)
{
f << " ["<<p->index << ";"<<p->value<<"] ";
p++;
}
}
f << std::endl;
// }
}
else
{
while(p->index != -1)
{
f << " ["<<p->index << ";"<<p->value<<"] ";
p++;
}
}
f << std::endl;
// }
}
f << " - GetRho() [nr_class*(nr_class-1)/2]"<<std::endl;
unsigned int taille = nbClass*(nbClass-1)/2;
double * rhos = ptrModel->GetRho();
if( rhos == NULL )
f << " - GetRho() [nr_class*(nr_class-1)/2]"<<std::endl;
unsigned int taille = nbClass*(nbClass-1)/2;
double * rhos = ptrModel->GetRho();
if( rhos == NULL )
{
itkGenericExceptionMacro(<<"rhos NULL");
itkGenericExceptionMacro(<<"rhos NULL");
}
f << std::setprecision(10) <<" ";
for(unsigned int i=0;i<taille;i++)
f << std::setprecision(10) <<" ";
for(unsigned int i=0;i<taille;i++)
{
f << " " << rhos[i];
f << " " << rhos[i];
}
f << std::endl;
f << " - GetAlpha() [nb class-1][nb support vector]"<<std::endl;
double ** alphas = ptrModel->GetAlpha();
if( alphas == NULL )
f << std::endl;
f << " - GetAlpha() [nb class-1][nb support vector]"<<std::endl;
double ** alphas = ptrModel->GetAlpha();
if( alphas == NULL )
{
itkGenericExceptionMacro(<<"alphas NULL");
itkGenericExceptionMacro(<<"alphas NULL");
}
for(unsigned int i=0;i<nbClass-1;i++)
for(unsigned int i=0;i<nbClass-1;i++)
{
if( alphas[i] == NULL ) itkGenericExceptionMacro(<<"alphas "<<i<<" NULL");
f << " ";
for(unsigned int j=0;j<nbSupportVector;j++)
if( alphas[i] == NULL ) itkGenericExceptionMacro(<<"alphas "<<i<<" NULL");
f << " ";
for(unsigned int j=0;j<nbSupportVector;j++)
{
f << " " << alphas[i][j];
f << " " << alphas[i][j];
}
}
f << std::endl;
f << " - Evaluate() (double) -> "<<ptrModel->Evaluate()<<std::endl;
f << std::endl;
f << " - Evaluate() (double) -> "<<ptrModel->Evaluate()<<std::endl;
typedef SVMModelType::ValuesType ValuesType;
ValuesType _evaluateHyperplaneDistance;
_evaluateHyperplaneDistance = ptrModel->EvaluateHyperplaneDistance();
typedef SVMModelType::ValuesType ValuesType;
ValuesType _evaluateHyperplaneDistance;
_evaluateHyperplaneDistance = ptrModel->EvaluateHyperplaneDistance();
f << " - EvaluateHyperplaneDistance() VariableLenghtVector() nb value(s): "<<_evaluateHyperplaneDistance.Size()<<std::endl;
for(unsigned int i=0;i<_evaluateHyperplaneDistance.Size();i++)
f << " - EvaluateHyperplaneDistance() VariableLenghtVector() nb value(s): "<<_evaluateHyperplaneDistance.Size()<<std::endl;
for(unsigned int i=0;i<_evaluateHyperplaneDistance.Size();i++)
{
f << " "<<_evaluateHyperplaneDistance[i]<<std::endl;
f << " "<<_evaluateHyperplaneDistance[i]<<std::endl;
}
f << "end"<<std::endl;
f.close();
f << "end"<<std::endl;
f.close();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : EndCodeSnippet
//#endif
return EXIT_SUCCESS;
}
......
......@@ -31,38 +31,22 @@
int otbSVMImageModelEstimatorNew( int argc, char* argv[] )
{
try
{
typedef double InputPixelType;
const unsigned int Dimension = 2;
typedef double InputPixelType;
const unsigned int Dimension = 2;
typedef otb::VectorImage< InputPixelType, Dimension > InputImageType;
typedef otb::Image< InputPixelType, Dimension > TrainingImageType;
typedef std::vector<double> VectorType;
typedef otb::SVMImageModelEstimator< InputImageType,
TrainingImageType > EstimatorType;
EstimatorType::Pointer svmModel = EstimatorType::New();
typedef otb::VectorImage< InputPixelType, Dimension > InputImageType;
typedef otb::Image< InputPixelType, Dimension > TrainingImageType;
typedef std::vector<double> VectorType;
typedef otb::SVMImageModelEstimator< InputImageType,
TrainingImageType > EstimatorType;
EstimatorType::Pointer svmModel = EstimatorType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : EndCodeSnippet
//#endif
return EXIT_SUCCESS;
}
......
......@@ -28,37 +28,21 @@
int otbSVMMembershipFunctionLoadModel( int argc, char* argv[] )
{
try
{
typedef std::vector<double> VectorType;
typedef otb::SVMMembershipFunction< VectorType > FunctionType;
FunctionType::Pointer membershipFunction = FunctionType::New();
typedef FunctionType::SVMModelType ModelType;
ModelType::Pointer model = ModelType::New();
model->LoadModel( argv[1] );
membershipFunction->SetModel( model );
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : EndCodeSnippet
//#endif
typedef std::vector<double> VectorType;
typedef otb::SVMMembershipFunction< VectorType > FunctionType;
FunctionType::Pointer membershipFunction = FunctionType::New();
typedef FunctionType::SVMModelType ModelType;
ModelType::Pointer model = ModelType::New();
model->LoadModel( argv[1] );
membershipFunction->SetModel( model );
return EXIT_SUCCESS;
}
......
......@@ -28,29 +28,12 @@
int otbSVMMembershipFunctionNew( int argc, char* argv[] )
{
try
{
typedef std::vector<double> VectorType;
typedef otb::SVMMembershipFunction< VectorType > FunctionType;
FunctionType::Pointer membershipFunction = FunctionType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : EndCodeSnippet
//#endif
typedef std::vector<double> VectorType;
typedef otb::SVMMembershipFunction< VectorType > FunctionType;
FunctionType::Pointer membershipFunction = FunctionType::New();
return EXIT_SUCCESS;
}
......
......@@ -30,115 +30,99 @@
int otbSVMModelAccessor( int argc, char* argv[] )
{
try
{
typedef unsigned char InputPixelType;
typedef unsigned char LabelPixelType;
const unsigned int Dimension = 2;
typedef otb::Image< InputPixelType, Dimension > InputImageType;
typedef otb::SVMModel< InputPixelType, LabelPixelType > ModelType;
ModelType::Pointer ptrModel = ModelType::New();
ptrModel->LoadModel(argv[1]);
// ototo
std::ofstream f;
unsigned int nbClass = ptrModel->GetNumberOfClasses();
unsigned int nbSupportVector = ptrModel->GetNumberOfSupportVectors();
f.open(argv[2]);
f << "Test methods of SVMModel class:"<<std::endl;
f << " - GetNumberOfClasses() "<< nbClass<<std::endl;
f << " - GetNumberOfHyperplane() "<< ptrModel->GetNumberOfHyperplane()<<std::endl;
f << " - GetNumberOfSupportVectors() "<< nbSupportVector<<std::endl;
f << " - GetSupportVectors() [nb support vector][]"<<std::endl;
svm_node ** SVs = ptrModel->GetSupportVectors();
if( SVs == NULL )
typedef unsigned char InputPixelType;
typedef unsigned char LabelPixelType;
const unsigned int Dimension = 2;
typedef otb::Image< InputPixelType, Dimension > InputImageType;
typedef otb::SVMModel< InputPixelType, LabelPixelType > ModelType;
ModelType::Pointer ptrModel = ModelType::New();
ptrModel->LoadModel(argv[1]);
// ototo
std::ofstream f;
unsigned int nbClass = ptrModel->GetNumberOfClasses();
unsigned int nbSupportVector = ptrModel->GetNumberOfSupportVectors();
f.open(argv[2]);
f << "Test methods of SVMModel class:"<<std::endl;
f << " - GetNumberOfClasses() "<< nbClass<<std::endl;
f << " - GetNumberOfHyperplane() "<< ptrModel->GetNumberOfHyperplane()<<std::endl;
f << " - GetNumberOfSupportVectors() "<< nbSupportVector<<std::endl;
f << " - GetSupportVectors() [nb support vector][]"<<std::endl;
svm_node ** SVs = ptrModel->GetSupportVectors();
if( SVs == NULL )
{
itkGenericExceptionMacro(<<"SVs NULL");
itkGenericExceptionMacro(<<"SVs NULL");
}
for(unsigned int i=0;i<nbSupportVector;i++)
for(unsigned int i=0;i<nbSupportVector;i++)
{
if( SVs[i] == NULL ) itkGenericExceptionMacro(<<"SVs "<<i<<" NULL");
f << std::endl;
f << " SV["<<i<<"]:";
const svm_node *p = SVs[i];
while(p->index != -1)
{
f << " ["<<p->index << ";"<<p->value<<"] ";
p++;
}
f << std::endl;
if( SVs[i] == NULL ) itkGenericExceptionMacro(<<"SVs "<<i<<" NULL");
f << std::endl;
f << " SV["<<i<<"]:";
const svm_node *p = SVs[i];
while(p->index != -1)
{
f << " ["<<p->index << ";"<<p->value<<"] ";
p++;
}
f << std::endl;
}
f << " - GetRho() [nr_class*(nr_class-1)/2]"<<std::endl;
unsigned int taille = nbClass*(nbClass-1)/2;
double * rhos = ptrModel->GetRho();
if( rhos == NULL )
f << " - GetRho() [nr_class*(nr_class-1)/2]"<<std::endl;
unsigned int taille = nbClass*(nbClass-1)/2;
double * rhos = ptrModel->GetRho();
if( rhos == NULL )
{
itkGenericExceptionMacro(<<"rhos NULL");
itkGenericExceptionMacro(<<"rhos NULL");
}
f << " ";
for(unsigned int i=0;i<taille;i++)
f << " ";
for(unsigned int i=0;i<taille;i++)
{
f << " " << rhos[i];
f << " " << rhos[i];
}
f << std::endl;
f << " - GetAlpha() [nb class-1][nb support vector]"<<std::endl;
double ** alphas = ptrModel->GetAlpha();
if( alphas == NULL )
f << std::endl;
f << " - GetAlpha() [nb class-1][nb support vector]"<<std::endl;
double ** alphas = ptrModel->GetAlpha();
if( alphas == NULL )
{
itkGenericExceptionMacro(<<"alphas NULL");
itkGenericExceptionMacro(<<"alphas NULL");
}
for(unsigned int i=0;i<nbClass-1;i++)
for(unsigned int i=0;i<nbClass-1;i++)
{
if( alphas[i] == NULL ) itkGenericExceptionMacro(<<"alphas "<<i<<" NULL");
f << " ";
for(unsigned int j=0;j<nbSupportVector;j++)
if( alphas[i] == NULL ) itkGenericExceptionMacro(<<"alphas "<<i<<" NULL");
f << " ";
for(unsigned int j=0;j<nbSupportVector;j++)
{
f << " " << alphas[i][j];
f << " " << alphas[i][j];
}
}
f << std::endl;
f << " - Evaluate() (double) -> "<<ptrModel->Evaluate()<<std::endl;
f << std::endl;
f << " - Evaluate() (double) -> "<<ptrModel->Evaluate()<<std::endl;
typedef ModelType::ValuesType ValuesType;
ValuesType _evaluateHyperplaneDistance;
_evaluateHyperplaneDistance = ptrModel->EvaluateHyperplaneDistance();
typedef ModelType::ValuesType ValuesType;
ValuesType _evaluateHyperplaneDistance;
_evaluateHyperplaneDistance = ptrModel->EvaluateHyperplaneDistance();
f << " - EvaluateHyperplaneDistance() VariableLenghtVector() nb value(s): "<<_evaluateHyperplaneDistance.Size()<<std::endl;
for(unsigned int i=0;i<_evaluateHyperplaneDistance.Size();i++)
f << " - EvaluateHyperplaneDistance() VariableLenghtVector() nb value(s): "<<_evaluateHyperplaneDistance.Size()<<std::endl;
for(unsigned int i=0;i<_evaluateHyperplaneDistance.Size();i++)
{
f << " "<<_evaluateHyperplaneDistance[i]<<std::endl;
f << " "<<_evaluateHyperplaneDistance[i]<<std::endl;
}
f << "end"<<std::endl;
f.close();
f << "end"<<std::endl;
f.close();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : EndCodeSnippet
//#endif
return EXIT_SUCCESS;
}
......
......@@ -29,40 +29,24 @@
int otbSVMModelAllocateProblem( int argc, char* argv[] )
{
try
{
typedef unsigned char InputPixelType;
typedef unsigned char LabelPixelType;
const unsigned int Dimension = 2;
typedef otb::Image< InputPixelType, Dimension > InputImageType;
typedef otb::SVMModel< InputPixelType, LabelPixelType > ModelType;
ModelType::Pointer svmModel = ModelType::New();
int nbExamples = 100;
int nbComponents = 100;
long int elements = nbExamples * nbComponents;
svmModel->AllocateProblem(nbExamples, elements);
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : EndCodeSnippet
//#endif
typedef unsigned char InputPixelType;
typedef unsigned char LabelPixelType;
const unsigned int Dimension = 2;
typedef otb::Image< InputPixelType, Dimension > InputImageType;
typedef otb::SVMModel< InputPixelType, LabelPixelType > ModelType;
ModelType::Pointer svmModel = ModelType::New();
int nbExamples = 100;
int nbComponents = 100;
long int elements = nbExamples * nbComponents;
svmModel->AllocateProblem(nbExamples, elements);
return EXIT_SUCCESS;
}
......
......@@ -45,39 +45,24 @@ public:
int otbSVMModelGenericKernelLoadSave( int argc, char* argv[] )
{
try
{
typedef unsigned char InputPixelType;
typedef unsigned char LabelPixelType;
const unsigned int Dimension = 2;
typedef otb::Image< InputPixelType, Dimension > InputImageType;
typedef otb::SVMModel< InputPixelType, LabelPixelType > ModelType;
ModelType::Pointer svmModel = ModelType::New();
otb::LinearKernelFunctor lFunctor;
svmModel->SetKernelFunctor(&lFunctor);
svmModel->LoadModel(argv[1]);
svmModel->SaveModel(argv[2]);
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char InputPixelType;
typedef unsigned char LabelPixelType;
const unsigned int Dimension = 2;
typedef otb::Image< InputPixelType, Dimension > InputImageType;
typedef otb::SVMModel< InputPixelType, LabelPixelType > ModelType;
ModelType::Pointer svmModel = ModelType::New();
otb::LinearKernelFunctor lFunctor;
svmModel->SetKernelFunctor(&lFunctor);
svmModel->LoadModel(argv[1]);
svmModel->SaveModel(argv[2]);
return EXIT_SUCCESS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment