int
main(int argc, char * argv[])
{
if (argc < 9)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " InputImage InitialModel OutputImage";
std::cerr << " CannyThreshold ";
std::cerr << " CannyVariance ";
std::cerr << " AdvectionWeight";
std::cerr << " InitialModelIsovalue";
std::cerr << " MaximumIterations";
std::cerr << " [OutputSpeedImage]" << std::endl;
return EXIT_FAILURE;
}
using InternalPixelType = float;
using OutputPixelType = unsigned char;
using ThresholdingFilterType =
ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
thresholder->SetUpperThreshold(10.0);
thresholder->SetLowerThreshold(0.0);
thresholder->SetOutsideValue(0);
thresholder->SetInsideValue(255);
ReaderType::Pointer reader1 = ReaderType::New();
ReaderType::Pointer reader2 = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader1->SetFileName(argv[1]);
reader2->SetFileName(argv[2]);
writer->SetFileName(argv[3]);
using DiffusionFilterType =
InternalImageType>;
DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();
diffusion->SetNumberOfIterations(5);
diffusion->SetTimeStep(0.125);
diffusion->SetConductanceParameter(1.0);
using CannySegmentationLevelSetImageFilterType =
InternalImageType>;
CannySegmentationLevelSetImageFilterType::Pointer cannySegmentation =
CannySegmentationLevelSetImageFilterType::New();
cannySegmentation->SetAdvectionScaling(::std::stod(argv[6]));
cannySegmentation->SetCurvatureScaling(1.0);
cannySegmentation->SetPropagationScaling(0.0);
cannySegmentation->SetMaximumRMSError(0.01);
cannySegmentation->SetNumberOfIterations(::std::stoi(argv[8]));
cannySegmentation->SetThreshold(::std::stod(argv[4]));
cannySegmentation->SetVariance(::std::stod(argv[5]));
cannySegmentation->SetIsoSurfaceValue(::std::stod(argv[7]));
diffusion->SetInput(reader1->GetOutput());
cannySegmentation->SetInput(reader2->GetOutput());
cannySegmentation->SetFeatureImage(diffusion->GetOutput());
thresholder->SetInput(cannySegmentation->GetOutput());
writer->SetInput(thresholder->GetOutput());
try
{
writer->Update();
}
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
std::cout << std::endl;
std::cout << "Max. no. iterations: "
<< cannySegmentation->GetNumberOfIterations() << std::endl;
std::cout << "Max. RMS error: " << cannySegmentation->GetMaximumRMSError()
<< std::endl;
std::cout << std::endl;
std::cout << "No. elpased iterations: "
<< cannySegmentation->GetElapsedIterations() << std::endl;
std::cout << "RMS change: " << cannySegmentation->GetRMSChange()
<< std::endl;
if (argc > 9)
{
const char * speedImageFileName = argv[9];
cannySegmentation->GenerateSpeedImage();
using SpeedImageType =
CannySegmentationLevelSetImageFilterType::SpeedImageType;
SpeedWriterType::Pointer speedWriter = SpeedWriterType::New();
speedWriter->SetInput(cannySegmentation->GetSpeedImage());
speedWriter->SetFileName(speedImageFileName);
try
{
speedWriter->Update();
}
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Exception caught ! while writing the speed image"
<< std::endl;
std::cerr << "Filename : " << speedImageFileName << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}