Commit c58064be authored by Cyrille Valladeau's avatar Cyrille Valladeau

Markov testing.

parent d09faa0c
......@@ -27,7 +27,7 @@ int otbMRFOptimizerICM(int argc, char * argv[])
MRFOptimizerICMType::Pointer object = MRFOptimizerICMType::New();
if ( object->operator()(-1) != true || object->operator()(1) != false || object->operator()(0) != false )
if ( object->Compute(-1) != true || object->Compute(1) != false )
{
return EXIT_FAILURE;
}
......
......@@ -35,7 +35,7 @@ int otbMRFOptimizerMetropolis(int argc, char * argv[])
object->SetParameters(param);
// USED TO OVERPASS RANDOM CALCULATION
object->SetValueInsteadRandom(1);
//object->SetValueInsteadRandom(1);
std::ofstream file;
file.open(outputFile);
......@@ -43,7 +43,7 @@ int otbMRFOptimizerMetropolis(int argc, char * argv[])
file<<"Compute(0) : "<<object->Compute(0.)<<std::endl;
file<<"Compute(-1.) : "<<object->Compute(-1.)<<std::endl;
file<<"Compute(1.) avec m_ValueInsteadRandom<proba*1000 : "<<object->Compute(1.)<<std::endl;
object->SetValueInsteadRandom( 10000 );
//object->SetValueInsteadRandom( 10000 );
file<<"Compute(1.) avec m_ValueInsteadRandom>=proba*1000: "<<object->Compute(1.)<<std::endl;
file.close();
......
......@@ -31,7 +31,7 @@ int otbMRFSamplerNew(int argc, char * argv[])
typedef otb::Image<PixelType, 2> ImageType;
typedef otb::MRFSampler< ImageType, ImageType> MRFSamplerType;
MRFSamplerType::Pointer object = MRFSamplerType::New();
//MRFSamplerType::Pointer object = MRFSamplerType::New();
return EXIT_SUCCESS;
}
......
......@@ -52,7 +52,7 @@ int otbMRFSamplerRandom(int argc, char * argv[])
readerLab->Update();
// USED TO OVERPASS RANDOM CALCULATION
object->SetValueInsteadRandom(300);
// object->SetValueInsteadRandom(300);
ImageType::IndexType idIn;
LabelType::IndexType idLab;
......
......@@ -52,7 +52,7 @@ int otbMRFSamplerRandomMAP(int argc, char * argv[])
readerLab->Update();
// USED TO OVERPASS RANDOM CALCULATION
object->SetValueInsteadRandom(300);
//object->SetValueInsteadRandom(300);
ImageType::IndexType idIn;
LabelType::IndexType idLab;
......
......@@ -27,71 +27,56 @@
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbImage.h"
#include "otbMarkovClassificationFilter.h"
#include "otbMarkovRandomFieldFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "otbMRFEnergy.h"
#include "otbMRFEnergyPotts.h"
#include "otbMRFEnergyGaussianClassification.h"
#include "otbMRFOptimizerMetropolis.h"
#include "otbMRFSamplerRandom.h"
int otbMarkovClassificationFilter( int argc, char* argv[] )
int otbMarkovRandomFieldFilter(int argc, char* argv[] )
{
//std::cerr << " inputImage inputInitialization output lambda iterations temperature" << std::endl;
const unsigned int Dimension = 2;
typedef double InternalPixelType;
typedef unsigned char LabelledPixelType;
typedef double InternalPixelType;
typedef unsigned char LabelledPixelType;
typedef otb::Image<InternalPixelType, Dimension> InputImageType;
typedef otb::Image<LabelledPixelType, Dimension> LabelledImageType;
typedef otb::ImageFileReader< InputImageType > ReaderType;
typedef otb::ImageFileReader< LabelledImageType > ReaderLabelledType;
typedef otb::ImageFileWriter< LabelledImageType > WriterType;
typedef otb::Image<LabelledPixelType, Dimension> LabelledImageType;
typedef otb::ImageFileReader< InputImageType > ReaderType;
typedef otb::ImageFileWriter< LabelledImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
ReaderLabelledType::Pointer reader2 = ReaderLabelledType::New();
WriterType::Pointer writer = WriterType::New();
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
const char * inputFilename = argv[1];
const char * labelledFilename = argv[2];
const char * outputFilename = argv[3];
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
reader->SetFileName( inputFilename );
reader2->SetFileName( labelledFilename );
writer->SetFileName( outputFilename );
typedef otb::MarkovClassificationFilter<InputImageType,
LabelledImageType> MarkovClassificationFilterType;
typedef otb::MarkovRandomFieldFilter
<InputImageType,LabelledImageType> MarkovRandomFieldFilterType;
typedef otb::MRFSamplerRandom< InputImageType, LabelledImageType> SamplerType;
typedef otb::MRFOptimizerMetropolis OptimizerType;
typedef otb::MRFEnergyPotts<LabelledImageType, LabelledImageType> EnergyRegularizationType;
typedef otb::MRFEnergyGaussianClassification<InputImageType,
LabelledImageType> EnergyFidelityType;
MarkovClassificationFilterType::Pointer markovFilter = MarkovClassificationFilterType::New();
EnergyRegularizationType::Pointer energyRegularization = EnergyRegularizationType::New();
EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New();
OptimizerType::Pointer optimizer = OptimizerType::New();
SamplerType::Pointer sampler = SamplerType::New();
typedef otb::MRFOptimizerMetropolis OptimizerType;
typedef otb::MRFEnergyPotts
<LabelledImageType, LabelledImageType> EnergyRegularizationType;
typedef otb::MRFEnergyGaussianClassification
<InputImageType, LabelledImageType> EnergyFidelityType;
MarkovRandomFieldFilterType::Pointer markovFilter = MarkovRandomFieldFilterType::New();
EnergyRegularizationType::Pointer energyRegularization = EnergyRegularizationType::New();
EnergyFidelityType::Pointer energyFidelity = EnergyFidelityType::New();
OptimizerType::Pointer optimizer = OptimizerType::New();
SamplerType::Pointer sampler = SamplerType::New();
unsigned int nClass = 4;
itk::VariableLengthVector<double> mean;
itk::VariableLengthVector<double> stdDev;
mean.SetSize(nClass);
stdDev.SetSize(nClass);
mean[0]=10;
mean[1]=80;
mean[2]=150;
mean[3]=220;
stdDev[0]=10;
stdDev[1]=10;
stdDev[2]=10;
stdDev[3]=10;
energyFidelity->SetNumberOfParameters(2*nClass);
EnergyFidelityType::ParametersType parameters;
parameters.SetSize(energyFidelity->GetNumberOfParameters());
......@@ -104,25 +89,24 @@ int otbMarkovClassificationFilter( int argc, char* argv[] )
parameters[6]=220.0;//Class 3 mean
parameters[7]=10.0; //Class 3 stde
energyFidelity->SetParameters(parameters);
OptimizerType::ParametersType paramOpt(1);
paramOpt.Fill(atof(argv[6]));
optimizer->SetParameters(paramOpt);
markovFilter->SetNumberOfClasses(nClass);
markovFilter->SetValueInsteadRandom(500); // Unable rand() calculation
markovFilter->SetMaximumNumberOfIterations(atoi(argv[5]));
markovFilter->SetErrorTolerance(-1.0);
markovFilter->SetLambda(atof(argv[4]));
optimizer->SetParameters(atoi(argv[5]));
markovFilter->SetNumberOfClasses(nClass);
markovFilter->SetMaximumNumberOfIterations(atoi(argv[4]));
markovFilter->SetErrorTolerance(0.0);
markovFilter->SetLambda(atof(argv[3]));
markovFilter->SetNeighborhoodRadius(1);
markovFilter->SetEnergyRegularization(energyRegularization);
markovFilter->SetEnergyFidelity(energyFidelity);
markovFilter->SetEnergyRegularization(static_cast<MarkovRandomFieldFilterType::EnergyRegularizationPointer>(energyRegularization));
markovFilter->SetEnergyFidelity(static_cast<MarkovRandomFieldFilterType::EnergyFidelityPointer>(energyFidelity));
markovFilter->SetOptimizer(optimizer);
markovFilter->SetSampler(sampler);
markovFilter->SetTrainingInput(reader2->GetOutput());
markovFilter->SetInput(reader->GetOutput());
typedef itk::RescaleIntensityImageFilter< LabelledImageType, LabelledImageType > RescaleType;
typedef itk::RescaleIntensityImageFilter
< LabelledImageType, LabelledImageType > RescaleType;
RescaleType::Pointer rescaleFilter = RescaleType::New();
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
......@@ -130,8 +114,8 @@ int otbMarkovClassificationFilter( int argc, char* argv[] )
rescaleFilter->SetInput( markovFilter->GetOutput() );
writer->SetInput( rescaleFilter->GetOutput() );
writer->Update();
writer->Update();
return 0;
......
......@@ -19,17 +19,17 @@
#pragma warning ( disable : 4786 )
#endif
#include "otbMarkovClassificationFilter.h"
#include "otbMarkovRandomFieldFilter.h"
#include "otbImage.h"
int otbMarkovClassificationFilterNew(int argc, char * argv[])
int otbMarkovRandomFieldFilterNew(int argc, char * argv[])
{
typedef double PixelType;
typedef otb::Image<PixelType, 2> ImageType;
typedef otb::MarkovClassificationFilter< ImageType, ImageType> MarkovClassificationFilterType;
typedef otb::Image<PixelType, 2> ImageType;
typedef otb::MarkovRandomFieldFilter< ImageType, ImageType> MarkovRandomFieldFilterType;
MarkovClassificationFilterType::Pointer object = MarkovClassificationFilterType::New();
MarkovRandomFieldFilterType::Pointer object = MarkovRandomFieldFilterType::New();
return EXIT_SUCCESS;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment