#include "itkUnaryFunctorImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkLabelStatisticsImageFilter.h"
int main(
int argc,
char* argv[])
{
if (argc != 8)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputClassificationImage outputClassification outputClassificationScaled lambda iterations temperature " << std::endl;
std::cerr << " useRandomValue" << std::endl;
return 1;
}
const unsigned int Dimension = 2;
using LabelledPixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
const char* inputFilename = argv[1];
const char* outputFilename = argv[2];
const char* outputScaledFilename = argv[3];
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[7])) == true)
{
sampler->InitializeSeed(0);
optimizer->InitializeSeed(1);
markovFilter->InitializeSeed(2);
}
using LabelledStatType = itk::LabelStatisticsImageFilter<LabelledImageType, LabelledImageType>;
LabelledStatType::Pointer labelledStat = LabelledStatType::New();
labelledStat->SetInput(reader->GetOutput());
labelledStat->SetLabelInput(reader->GetOutput());
labelledStat->Update();
unsigned int nClass = labelledStat->GetNumberOfLabels();
optimizer->SetSingleParameter(0.0);
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(reader->GetOutput());
markovFilter->SetInput(reader->GetOutput());
writer->SetInput(markovFilter->GetOutput());
writer->Update();
using RescaleType = itk::RescaleIntensityImageFilter<LabelledImageType, LabelledImageType>;
RescaleType::Pointer rescaleFilter = RescaleType::New();
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
rescaleFilter->SetInput(markovFilter->GetOutput());
writer->SetFileName(outputScaledFilename);
writer->SetInput(rescaleFilter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}