static void
int
main()
{
CreateImage(image);
using MembershipFunctionPointerVector = std::vector<MembershipFunctionPointer>;
kmeansEstimator->SetInputImage(image);
kmeansEstimator->SetNumberOfModels(3);
kmeansEstimator->SetThreshold(0.01);
kmeansEstimator->SetOffsetAdd(0.01);
kmeansEstimator->SetOffsetMultiply(0.01);
kmeansEstimator->SetMaxSplitAttempts(10);
kmeansEstimator->Update();
classifier->SetDecisionRule(decisionRule);
classifier->SetNumberOfClasses(3);
using ClassLabelVectorObjectType = ClassifierType::ClassLabelVectorObjectType;
using ClassLabelVectorType = ClassifierType::ClassLabelVectorType;
using MembershipFunctionVectorObjectType = ClassifierType::MembershipFunctionVectorObjectType;
using MembershipFunctionVectorType = ClassifierType::MembershipFunctionVectorType;
MembershipFunctionPointerVector kmeansMembershipFunctions = kmeansEstimator->GetMembershipFunctions();
classifier->SetMembershipFunctions(membershipFunctionsVectorObject);
MembershipFunctionVectorType & membershipFunctionsVector = membershipFunctionsVectorObject->Get();
for (auto & kmeansMembershipFunction : kmeansMembershipFunctions)
{
membershipFunctionsVector.push_back(kmeansMembershipFunction.GetPointer());
}
classifier->SetClassLabels(classLabelsObject);
ClassLabelVectorType & classLabelsVector = classLabelsObject->Get();
classLabelsVector.push_back(50);
classLabelsVector.push_back(150);
classLabelsVector.push_back(250);
sample->SetImage(image);
classifier->SetInput(sample);
classifier->Update();
outputImage->SetRegions(image->GetLargestPossibleRegion());
outputImage->Allocate();
outputImage->FillBuffer(0);
const ClassifierType::MembershipSampleType * membershipSample = classifier->GetOutput();
ClassifierType::MembershipSampleType::ConstIterator membershipIterator = membershipSample->Begin();
outputImage->GetLargestPossibleRegion());
while (membershipIterator != membershipSample->End())
{
int classLabel = membershipIterator.GetClassLabel();
outputIterator.Set(classLabel);
++membershipIterator;
++outputIterator;
}
return EXIT_SUCCESS;
}
void
{
start[0] = 0;
start[1] = 0;
size[0] = 200;
size[1] = 300;
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
redPixel[0] = 255;
redPixel[1] = 0;
redPixel[2] = 0;
greenPixel[0] = 0;
greenPixel[1] = 255;
greenPixel[2] = 0;
blackPixel[0] = 0;
blackPixel[1] = 0;
blackPixel[2] = 0;
while (!imageIterator.IsAtEnd())
{
if (imageIterator.GetIndex()[0] > 100 && imageIterator.GetIndex()[0] < 150 && imageIterator.GetIndex()[1] > 100 &&
imageIterator.GetIndex()[1] < 150)
{
imageIterator.Set(redPixel);
}
else if (imageIterator.GetIndex()[0] > 50 && imageIterator.GetIndex()[0] < 70 && imageIterator.GetIndex()[1] > 50 &&
imageIterator.GetIndex()[1] < 70)
{
imageIterator.Set(greenPixel);
}
else
{
imageIterator.Set(blackPixel);
}
++imageIterator;
}
}