int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr
<< "Usage arguments: InputImage MembershipImage numberOfClasses "
"[componentToExtract ExtractedImage]"
<< std::endl;
std::cerr
<< " The MembershipImage image written is a VectorImage, ( an image "
"with multiple components ) ";
std::cerr << "Given that most viewers can't see vector images, we will "
"optionally "
"extract a component and ";
std::cerr << "write it out as a scalar image as well." << std::endl;
return EXIT_FAILURE;
}
using BayesianInitializerType =
reader->SetFileName(argv[1]);
try
{
reader->Update();
}
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
bayesianInitializer->SetInput(reader->GetOutput());
bayesianInitializer->SetNumberOfClasses(std::stoi(argv[3]));
using WriterType =
writer->SetInput(bayesianInitializer->GetOutput());
writer->SetFileName(argv[2]);
try
{
bayesianInitializer->Update();
}
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
try
{
writer->Update();
}
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
if (argv[4] && argv[5])
{
using MembershipImageType = BayesianInitializerType::OutputImageType;
using ExtractedComponentImageType =
extractedComponentImage->CopyInformation(
bayesianInitializer->GetOutput());
extractedComponentImage->SetBufferedRegion(
bayesianInitializer->GetOutput()->GetBufferedRegion());
extractedComponentImage->SetRequestedRegion(
bayesianInitializer->GetOutput()->GetRequestedRegion());
extractedComponentImage->Allocate();
using ConstIteratorType =
using IteratorType =
ConstIteratorType cit(
bayesianInitializer->GetOutput(),
bayesianInitializer->GetOutput()->GetBufferedRegion());
IteratorType it(extractedComponentImage,
extractedComponentImage->GetLargestPossibleRegion());
const unsigned int componentToExtract = std::stoi(argv[4]);
cit.GoToBegin();
it.GoToBegin();
while (!cit.IsAtEnd())
{
it.Set(cit.Get()[componentToExtract]);
++it;
++cit;
}
using RescalerType =
OutputImageType>;
rescaler->SetInput(extractedComponentImage);
rescaler->SetOutputMinimum(0);
rescaler->SetOutputMaximum(255);
using ExtractedComponentWriterType =
rescaledImageWriter->SetInput(rescaler->GetOutput());
rescaledImageWriter->SetFileName(argv[5]);
rescaledImageWriter->Update();
}
return EXIT_SUCCESS;
}