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;
constexpr unsigned int Dimension = 2;
using OutputPixelType = unsigned char;
using ThresholdingFilterType =
auto thresholder = ThresholdingFilterType::New();
thresholder->SetLowerThreshold(-1000.0);
thresholder->SetUpperThreshold(0.0);
thresholder->SetOutsideValue(0);
thresholder->SetInsideValue(255);
using FastMarchingFilterType =
auto fastMarching = FastMarchingFilterType::New();
using ThresholdSegmentationLevelSetImageFilterType =
InternalImageType>;
const ThresholdSegmentationLevelSetImageFilterType::Pointer
thresholdSegmentation =
ThresholdSegmentationLevelSetImageFilterType::New();
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(input);
thresholder->SetInput(thresholdSegmentation->GetOutput());
using NodeContainer = FastMarchingFilterType::NodeContainer;
using NodeType = FastMarchingFilterType::NodeType;
auto seeds = NodeContainer::New();
InternalImageType::IndexType seedPosition;
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
{
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;
"speedTermImage.mha");
return EXIT_SUCCESS;
}
Binarize an input image by thresholding.
Standard exception handling object.
Solve an Eikonal equation using Fast Marching.
Templated n-dimensional image class.
Segments structures in images based on intensity values.
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
TOutputImage::Pointer ReadImage(const std::string &filename)