#include "itkUnaryFunctorImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
int main(
int argc,
char* argv[])
{
if (argc != 8)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage inputInitialization 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();
ReaderLabelledType::Pointer reader2 = ReaderLabelledType::New();
WriterType::Pointer writer = WriterType::New();
const char* inputFilename = argv[1];
const char* labelledFilename = argv[2];
const char* outputFilename = argv[3];
reader->SetFileName(inputFilename);
reader2->SetFileName(labelledFilename);
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[7])) == true)
{
sampler->InitializeSeed(0);
optimizer->InitializeSeed(1);
markovFilter->InitializeSeed(2);
}
unsigned int nClass = 256;
optimizer->SetSingleParameter(atof(argv[6]));
markovFilter->SetNumberOfClasses(nClass);
markovFilter->SetMaximumNumberOfIterations(atoi(argv[5]));
markovFilter->SetErrorTolerance(0.0);
markovFilter->SetLambda(atof(argv[4]));
markovFilter->SetNeighborhoodRadius(1);
markovFilter->SetEnergyRegularization(energyRegularization);
markovFilter->SetEnergyFidelity(energyFidelity);
markovFilter->SetOptimizer(optimizer);
markovFilter->SetSampler(sampler);
markovFilter->SetTrainingInput(reader2->GetOutput());
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());
try
{
writer->Update();
}
catch (itk::ExceptionObject& err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return -1;
}
return EXIT_SUCCESS;
}