int
main(int argc, char * argv[])
{
if (argc < 10)
{
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 << " PropagationScaling" << 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 CastFilterType =
using SmoothingFilterType =
InternalImageType>;
auto smoothing = SmoothingFilterType::New();
using GradientFilterType =
InternalImageType>;
using SigmoidFilterType =
auto gradientMagnitude = GradientFilterType::New();
auto sigmoid = SigmoidFilterType::New();
sigmoid->SetOutputMinimum(0.0);
sigmoid->SetOutputMaximum(1.0);
using FastMarchingFilterType =
auto fastMarching = FastMarchingFilterType::New();
using CurvesFilterType =
auto geodesicActiveContour = CurvesFilterType::New();
const double propagationScaling = std::stod(argv[9]);
geodesicActiveContour->SetPropagationScaling(propagationScaling);
geodesicActiveContour->SetCurvatureScaling(1.0);
geodesicActiveContour->SetAdvectionScaling(1.0);
geodesicActiveContour->SetMaximumRMSError(0.02);
geodesicActiveContour->SetNumberOfIterations(800);
smoothing->SetInput(input);
gradientMagnitude->SetInput(smoothing->GetOutput());
sigmoid->SetInput(gradientMagnitude->GetOutput());
geodesicActiveContour->SetInput(fastMarching->GetOutput());
geodesicActiveContour->SetFeatureImage(sigmoid->GetOutput());
thresholder->SetInput(geodesicActiveContour->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;
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);
auto caster1 = CastFilterType::New();
auto caster2 = CastFilterType::New();
auto caster3 = CastFilterType::New();
auto caster4 = CastFilterType::New();
caster1->SetInput(smoothing->GetOutput());
caster1->SetOutputMinimum(0);
caster1->SetOutputMaximum(255);
caster2->SetInput(gradientMagnitude->GetOutput());
caster2->SetOutputMinimum(0);
caster2->SetOutputMaximum(255);
caster3->SetInput(sigmoid->GetOutput());
caster3->SetOutputMinimum(0);
caster3->SetOutputMaximum(255);
caster4->SetInput(fastMarching->GetOutput());
caster4->SetOutputMinimum(0);
caster4->SetOutputMaximum(255);
fastMarching->SetOutputSize(input->GetBufferedRegion().GetSize());
try
{
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
std::cout << std::endl;
std::cout << "Max. no. iterations: "
<< geodesicActiveContour->GetNumberOfIterations() << std::endl;
std::cout << "Max. RMS error: "
<< geodesicActiveContour->GetMaximumRMSError() << std::endl;
std::cout << std::endl;
std::cout << "No. elpased iterations: "
<< geodesicActiveContour->GetElapsedIterations() << std::endl;
std::cout << "RMS change: " << geodesicActiveContour->GetRMSChange()
<< std::endl;
auto mapWriter = InternalWriterType::New();
mapWriter->SetInput(fastMarching->GetOutput());
mapWriter->SetFileName("CurvesImageFilterOutput4.mha");
mapWriter->Update();
auto speedWriter = InternalWriterType::New();
speedWriter->SetInput(sigmoid->GetOutput());
speedWriter->SetFileName("CurvesImageFilterOutput3.mha");
speedWriter->Update();
auto gradientWriter = InternalWriterType::New();
gradientWriter->SetInput(gradientMagnitude->GetOutput());
gradientWriter->SetFileName("CurvesImageFilterOutput2.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...
Segments structures in images based on user supplied edge potential map.
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...
Writes image data to a single file.
Templated n-dimensional image class.
Applies a linear transformation to the intensity levels of the input Image.
Computes the sigmoid function pixel-wise.
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
TOutputImage::Pointer ReadImage(const std::string &filename)