int
main(int argc, char * argv[])
{
if (argc < 8)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage";
std::cerr << " seedX seedY InitialDistance";
std::cerr << " LowerThreshold";
std::cerr << " UpperThreshold";
std::cerr << " [CurvatureScaling == 1.0]";
std::cerr << std::endl;
return EXIT_FAILURE;
}
using InternalPixelType = float;
using OutputPixelType = unsigned char;
using ThresholdingFilterType =
thresholder->SetLowerThreshold(-1000.0);
thresholder->SetUpperThreshold(0.0);
thresholder->SetOutsideValue(0);
thresholder->SetInsideValue(255);
reader->SetFileName(argv[1]);
writer->SetFileName(argv[2]);
using FastMarchingFilterType =
using ThresholdSegmentationLevelSetImageFilterType =
InternalImageType>;
thresholdSegmentation =
thresholdSegmentation->SetPropagationScaling(1.0);
if (argc > 8)
{
thresholdSegmentation->SetCurvatureScaling(std::stod(argv[8]));
}
else
{
thresholdSegmentation->SetCurvatureScaling(1.0);
}
thresholdSegmentation->SetMaximumRMSError(0.02);
thresholdSegmentation->SetNumberOfIterations(1200);
thresholdSegmentation->SetUpperThreshold(std::stod(argv[7]));
thresholdSegmentation->SetLowerThreshold(std::stod(argv[6]));
thresholdSegmentation->SetIsoSurfaceValue(0.0);
thresholdSegmentation->SetInput(fastMarching->GetOutput());
thresholdSegmentation->SetFeatureImage(reader->GetOutput());
thresholder->SetInput(thresholdSegmentation->GetOutput());
writer->SetInput(thresholder->GetOutput());
using NodeContainer = FastMarchingFilterType::NodeContainer;
using NodeType = FastMarchingFilterType::NodeType;
seedPosition[0] = std::stoi(argv[3]);
seedPosition[1] = std::stoi(argv[4]);
const double initialDistance = std::stod(argv[5]);
NodeType node;
const double seedValue = -initialDistance;
node.SetValue(seedValue);
node.SetIndex(seedPosition);
seeds->Initialize();
seeds->InsertElement(0, node);
fastMarching->SetTrialPoints(seeds);
fastMarching->SetSpeedConstant(1.0);
try
{
reader->Update();
const InternalImageType * inputImage = reader->
GetOutput();
fastMarching->SetOutputRegion(inputImage->GetBufferedRegion());
fastMarching->SetOutputSpacing(inputImage->GetSpacing());
fastMarching->SetOutputOrigin(inputImage->GetOrigin());
fastMarching->SetOutputDirection(inputImage->GetDirection());
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
std::cout << std::endl;
std::cout << "Max. no. iterations: "
<< thresholdSegmentation->GetNumberOfIterations() << std::endl;
std::cout << "Max. RMS error: "
<< thresholdSegmentation->GetMaximumRMSError() << std::endl;
std::cout << std::endl;
std::cout << "No. elpased iterations: "
<< thresholdSegmentation->GetElapsedIterations() << std::endl;
std::cout << "RMS change: " << thresholdSegmentation->GetRMSChange()
<< std::endl;
mapWriter->SetInput(fastMarching->GetOutput());
mapWriter->SetFileName("fastMarchingImage.mha");
mapWriter->Update();
speedWriter->SetInput(thresholdSegmentation->GetSpeedImage());
speedWriter->SetFileName("speedTermImage.mha");
speedWriter->Update();
return EXIT_SUCCESS;
}