#include <iostream>
#include <string>
#include <cmath>
#define NUM_CLASSES 3
#define MAX_NUM_ITER 1
int
main(int argc, char * argv[])
{
if (argc != 4)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage trainimage outputImage" << std::endl;
return EXIT_FAILURE;
}
std::cout << "Gibbs Prior Test Begins: " << std::endl;
constexpr unsigned short NUMBANDS = 1;
constexpr unsigned short NDIMENSION = 3;
using VecImageType =
ReaderType::Pointer inputimagereader = ReaderType::New();
ReaderType::Pointer trainingimagereader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
inputimagereader->SetFileName(argv[1]);
trainingimagereader->SetFileName(argv[2]);
writer->SetFileName(argv[3]);
VecImageType::Pointer vecImage = VecImageType::New();
using VecImagePixelType = VecImageType::PixelType;
region.SetIndex(index);
vecImage->SetLargestPossibleRegion(region);
vecImage->SetBufferedRegion(region);
vecImage->Allocate();
enum
{
VecImageDimension = VecImageType::ImageDimension
};
VecIterator vecIt(vecImage, vecImage->GetBufferedRegion());
inputimagereader->Update();
trainingimagereader->Update();
ClassIterator inputIt(inputimagereader->GetOutput(),
inputimagereader->GetOutput()->GetBufferedRegion());
using DataVector = VecImageType::PixelType;
DataVector dblVec;
while (!vecIt.IsAtEnd())
{
dblVec[0] = inputIt.Get();
vecIt.Set(dblVec);
++vecIt;
++inputIt;
}
using VecImagePixelType = VecImageType::PixelType;
using MembershipFunctionType =
stat::MahalanobisDistanceMembershipFunction<VecImagePixelType>;
using MembershipFunctionPointer = MembershipFunctionType::Pointer;
using MembershipFunctionPointerVector =
std::vector<MembershipFunctionPointer>;
using ImageGaussianModelEstimatorType =
MembershipFunctionType,
ClassImageType>;
ImageGaussianModelEstimatorType::Pointer applyEstimateModel =
ImageGaussianModelEstimatorType::New();
applyEstimateModel->SetNumberOfModels(NUM_CLASSES);
applyEstimateModel->SetInputImage(vecImage);
applyEstimateModel->SetTrainingImage(trainingimagereader->GetOutput());
applyEstimateModel->Update();
std::cout << " site 1 " << std::endl;
applyEstimateModel->Print(std::cout);
MembershipFunctionPointerVector membershipFunctions =
applyEstimateModel->GetMembershipFunctions();
std::cout << " site 2 " << std::endl;
DecisionRuleType::Pointer myDecisionRule = DecisionRuleType::New();
std::cout << " site 3 " << std::endl;
using ClassifierType =
using ClassifierPointer = ClassifierType::Pointer;
ClassifierPointer myClassifier = ClassifierType::New();
myClassifier->SetNumberOfClasses(NUM_CLASSES);
myClassifier->SetDecisionRule((DecisionRuleBasePointer)myDecisionRule);
for (unsigned int i = 0; i < NUM_CLASSES; ++i)
{
myClassifier->AddMembershipFunction(membershipFunctions[i]);
}
using GibbsPriorFilterType =
GibbsPriorFilterType::Pointer applyGibbsImageFilter =
GibbsPriorFilterType::New();
applyGibbsImageFilter->SetNumberOfClasses(NUM_CLASSES);
applyGibbsImageFilter->SetMaximumNumberOfIterations(MAX_NUM_ITER);
applyGibbsImageFilter->SetClusterSize(10);
applyGibbsImageFilter->SetBoundaryGradient(6);
applyGibbsImageFilter->SetObjectLabel(1);
applyGibbsImageFilter->SetInput(vecImage);
applyGibbsImageFilter->SetClassifier(myClassifier);
applyGibbsImageFilter->SetTrainingImage(trainingimagereader->GetOutput());
applyGibbsImageFilter->Update();
std::cout << "applyGibbsImageFilter: " << applyGibbsImageFilter;
writer->SetInput(applyGibbsImageFilter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}