#include "itksys/SystemTools.hxx"
int
main(int argc, char * argv[])
{
if (argc < 11)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage";
std::cerr << " seedX seedY InitialDistance";
std::cerr << " Sigma SigmoidAlpha SigmoidBeta ";
std::cerr << " curvatureScaling propagationScaling" << std::endl;
return EXIT_FAILURE;
}
const std::string inputImageFile(argv[1]);
const std::string outputImageFile(argv[2]);
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(inputImageFile);
writer->SetFileName(outputImageFile);
using CastFilterType =
using SmoothingFilterType =
InternalImageType>;
using GradientFilterType =
InternalImageType>;
using SigmoidFilterType =
sigmoid->SetOutputMinimum(0.0);
sigmoid->SetOutputMaximum(1.0);
using FastMarchingFilterType =
using ShapeDetectionFilterType =
InternalImageType>;
smoothing->SetInput(reader->GetOutput());
gradientMagnitude->SetInput(smoothing->GetOutput());
sigmoid->SetInput(gradientMagnitude->GetOutput());
shapeDetection->SetInput(fastMarching->GetOutput());
shapeDetection->SetFeatureImage(sigmoid->GetOutput());
thresholder->SetInput(shapeDetection->GetOutput());
writer->SetInput(thresholder->GetOutput());
smoothing->SetTimeStep(0.125);
smoothing->SetNumberOfIterations(5);
smoothing->SetConductanceParameter(9.0);
const double sigma = std::stod(argv[6]);
gradientMagnitude->SetSigma(sigma);
const double alpha = std::stod(argv[7]);
const double beta = std::stod(argv[8]);
sigmoid->SetAlpha(alpha);
sigmoid->SetBeta(beta);
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);
const std::string outputImageFilePrefix =
itksys::SystemTools::GetFilenameWithoutExtension(outputImageFile);
caster1->SetInput(smoothing->GetOutput());
writer1->SetInput(caster1->GetOutput());
writer1->SetFileName(outputImageFilePrefix + "Smoothing.png");
caster1->SetOutputMinimum(0);
caster1->SetOutputMaximum(255);
writer1->Update();
caster2->SetInput(gradientMagnitude->GetOutput());
writer2->SetInput(caster2->GetOutput());
writer2->SetFileName(outputImageFilePrefix + "GradientMagnitude.png");
caster2->SetOutputMinimum(0);
caster2->SetOutputMaximum(255);
writer2->Update();
caster3->SetInput(sigmoid->GetOutput());
writer3->SetInput(caster3->GetOutput());
writer3->SetFileName(outputImageFilePrefix + "Sigmoid.png");
caster3->SetOutputMinimum(0);
caster3->SetOutputMaximum(255);
writer3->Update();
caster4->SetInput(fastMarching->GetOutput());
writer4->SetInput(caster4->GetOutput());
writer4->SetFileName(outputImageFilePrefix + "FastMarching.png");
caster4->SetOutputMinimum(0);
caster4->SetOutputMaximum(255);
fastMarching->SetOutputSize(
reader->GetOutput()->GetBufferedRegion().GetSize());
const double curvatureScaling = std::stod(argv[9]);
const double propagationScaling = std::stod(argv[10]);
shapeDetection->SetPropagationScaling(propagationScaling);
shapeDetection->SetCurvatureScaling(curvatureScaling);
shapeDetection->SetMaximumRMSError(0.02);
shapeDetection->SetNumberOfIterations(800);
try
{
writer->Update();
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
std::cout << std::endl;
std::cout << "Max. no. iterations: "
<< shapeDetection->GetNumberOfIterations() << std::endl;
std::cout << "Max. RMS error: " << shapeDetection->GetMaximumRMSError()
<< std::endl;
std::cout << std::endl;
std::cout << "No. elpased iterations: "
<< shapeDetection->GetElapsedIterations() << std::endl;
std::cout << "RMS change: " << shapeDetection->GetRMSChange() << std::endl;
writer4->Update();
mapWriter->SetInput(fastMarching->GetOutput());
mapWriter->SetFileName("ShapeDetectionLevelSetFilterOutput4.mha");
mapWriter->Update();
speedWriter->SetInput(sigmoid->GetOutput());
speedWriter->SetFileName("ShapeDetectionLevelSetFilterOutput3.mha");
speedWriter->Update();
gradientWriter->SetInput(gradientMagnitude->GetOutput());
gradientWriter->SetFileName("ShapeDetectionLevelSetFilterOutput2.mha");
gradientWriter->Update();
return EXIT_SUCCESS;
}
Binarize an input image by thresholding.
This filter performs anisotropic diffusion on a scalar itk::Image using the modified curvature diffus...
Standard exception handling object.
Solve an Eikonal equation using Fast Marching.
Computes the Magnitude of the Gradient of an image by convolution with the first derivative of a Gaus...
Data source that reads image data from a single file.
Writes image data to a single file.
Templated n-dimensional image class.
Applies a linear transformation to the intensity levels of the input Image.
Segments structures in images based on a user supplied edge potential map.
Computes the sigmoid function pixel-wise.
ImageBaseType::IndexType IndexType
constexpr unsigned int Dimension