static void
PrintCommandLineUsage(const int argc, const char * const argv[])
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage seedX seedY";
std::cerr << " Sigma SigmoidAlpha SigmoidBeta TimeThreshold StoppingValue";
std::cerr
<< " smoothingOutputImage gradientMagnitudeOutputImage sigmoidOutputImage"
<< std::endl;
for (int qq = 0; qq < argc; ++qq)
{
std::cout << "argv[" << qq << "] = " << argv[qq] << std::endl;
}
}
int
main(int argc, char * argv[])
{
if (argc != 13)
{
PrintCommandLineUsage(argc, argv);
return EXIT_FAILURE;
}
using InternalPixelType = float;
using OutputPixelType = unsigned char;
using ThresholdingFilterType =
auto thresholder = ThresholdingFilterType::New();
const InternalPixelType timeThreshold = std::stod(argv[8]);
thresholder->SetLowerThreshold(0.0);
thresholder->SetUpperThreshold(timeThreshold);
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();
smoothing->SetInput(input);
gradientMagnitude->SetInput(smoothing->GetOutput());
sigmoid->SetInput(gradientMagnitude->GetOutput());
fastMarching->SetInput(sigmoid->GetOutput());
thresholder->SetInput(fastMarching->GetOutput());
smoothing->SetTimeStep(0.125);
smoothing->SetNumberOfIterations(5);
smoothing->SetConductanceParameter(9.0);
const double sigma = std::stod(argv[5]);
gradientMagnitude->SetSigma(sigma);
const double alpha = std::stod(argv[6]);
const double beta = std::stod(argv[7]);
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]);
NodeType node;
constexpr double seedValue = 0.0;
node.SetValue(seedValue);
node.SetIndex(seedPosition);
seeds->Initialize();
seeds->InsertElement(0, node);
fastMarching->SetTrialPoints(seeds);
try
{
auto caster1 = CastFilterType::New();
caster1->SetInput(smoothing->GetOutput());
caster1->SetOutputMinimum(0);
caster1->SetOutputMaximum(255);
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
try
{
auto caster2 = CastFilterType::New();
caster2->SetInput(gradientMagnitude->GetOutput());
caster2->SetOutputMinimum(0);
caster2->SetOutputMaximum(255);
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
try
{
auto caster3 = CastFilterType::New();
caster3->SetInput(sigmoid->GetOutput());
caster3->SetOutputMinimum(0);
caster3->SetOutputMaximum(255);
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
fastMarching->SetOutputSize(input->GetBufferedRegion().GetSize());
const double stoppingTime = std::stod(argv[9]);
fastMarching->SetStoppingValue(stoppingTime);
try
{
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
try
{
auto caster4 = CastFilterType::New();
caster4->SetInput(fastMarching->GetOutput());
caster4->SetOutputMinimum(0);
caster4->SetOutputMaximum(255);
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
auto mapWriter = InternalWriterType::New();
mapWriter->SetInput(fastMarching->GetOutput());
mapWriter->SetFileName("FastMarchingFilterOutput4.mha");
mapWriter->Update();
auto speedWriter = InternalWriterType::New();
speedWriter->SetInput(sigmoid->GetOutput());
speedWriter->SetFileName("FastMarchingFilterOutput3.mha");
speedWriter->Update();
auto gradientWriter = InternalWriterType::New();
gradientWriter->SetInput(gradientMagnitude->GetOutput());
gradientWriter->SetFileName("FastMarchingFilterOutput2.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...
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.
constexpr unsigned int Dimension
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
TOutputImage::Pointer ReadImage(const std::string &filename)