#include "itkUnaryFunctorImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
int main(
int argc,
char* argv[])
{
if (argc != 7)
{
std::cerr << "Missing Parameters " << argc << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage output lambda iterations optimizerTemperature" << std::endl;
std::cerr << " useRandomValue" << std::endl;
return 1;
}
const unsigned int Dimension = 2;
using InternalPixelType = double;
using LabelledPixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
const char* inputFilename = argv[1];
const char* outputFilename = argv[2];
reader->SetFileName(inputFilename);
writer->SetFileName(outputFilename);
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();
if ((bool)(atoi(argv[6])) == true)
{
sampler->InitializeSeed(0);
optimizer->InitializeSeed(1);
markovFilter->InitializeSeed(2);
}
unsigned int nClass = 4;
energyFidelity->SetNumberOfParameters(2 * nClass);
EnergyFidelityType::ParametersType parameters;
parameters.SetSize(energyFidelity->GetNumberOfParameters());
parameters[0] = 10.0;
parameters[1] = 10.0;
parameters[2] = 80.0;
parameters[3] = 10.0;
parameters[4] = 150.0;
parameters[5] = 10.0;
parameters[6] = 220.0;
parameters[7] = 10.0;
energyFidelity->SetParameters(parameters);
OptimizerType::ParametersType param(1);
param.Fill(atof(argv[5]));
optimizer->SetParameters(param);
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->SetOptimizer(optimizer);
markovFilter->SetSampler(sampler);
markovFilter->SetInput(reader->GetOutput());
using RescaleType = itk::RescaleIntensityImageFilter<LabelledImageType, LabelledImageType>;
RescaleType::Pointer rescaleFilter = RescaleType::New();
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
rescaleFilter->SetInput(markovFilter->GetOutput());
writer->SetInput(rescaleFilter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}