using System;
using System.Globalization;
namespace itk.simple.examples
{
public class FastMarchingSegmentation
{
static void Main(string[] args)
{
if (args.Length < 9)
{
Console.WriteLine("Missing Parameters ");
Console.WriteLine("Usage: " + System.AppDomain.CurrentDomain.FriendlyName +
" inputImage outputImage seedX seedY " +
" Sigma SigmoidAlpha SigmoidBeta TimeThreshold");
return;
}
string inputFilename = args[0];
string outputFilename = args[1];
uint[] seedPosition = { Convert.ToUInt32(args[2]), Convert.ToUInt32(args[3]),0 };
double sigma = double.Parse(args[4], CultureInfo.InvariantCulture);
double alpha = double.Parse(args[5], CultureInfo.InvariantCulture); ;
double beta = double.Parse(args[6], CultureInfo.InvariantCulture);
double timeThreshold = double.Parse(args[7], CultureInfo.InvariantCulture);
double stoppingTime = double.Parse(args[8], CultureInfo.InvariantCulture);
SitkImage inputImage = SimpleITK.ReadImage(inputFilename,
PixelIDValueEnum.sitkFloat32);
CurvatureAnisotropicDiffusionImageFilter smoothing = new CurvatureAnisotropicDiffusionImageFilter();
smoothing.SetTimeStep(0.125);
smoothing.SetNumberOfIterations(5);
smoothing.SetConductanceParameter(9.0);
SitkImage smoothingOutput = smoothing.Execute(inputImage);
SitkImage gradientMagnitudeOutput = SimpleITK.GradientMagnitudeRecursiveGaussian(smoothingOutput, sigma);
SitkImage sigmoidOutput = SimpleITK.Sigmoid(gradientMagnitudeOutput, alpha, beta, 1.0, 0.0);
FastMarchingImageFilter fastMarching = new FastMarchingImageFilter();
VectorUInt32 trialPoint = new VectorUInt32(3);
trialPoint.Add(seedPosition[0]);
trialPoint.Add(seedPosition[1]);
trialPoint.Add(seedPosition[2]);
fastMarching.AddTrialPoint(trialPoint);
fastMarching.SetStoppingValue(stoppingTime);
SitkImage fastmarchingOutput = fastMarching.Execute(sigmoidOutput);
BinaryThresholdImageFilter thresholder = new BinaryThresholdImageFilter();
thresholder.SetLowerThreshold(0.0);
thresholder.SetUpperThreshold(timeThreshold);
thresholder.SetOutsideValue(0);
thresholder.SetInsideValue(255);
SitkImage result = thresholder.Execute(fastmarchingOutput);
SimpleITK.WriteImage(result, outputFilename);
}
}
}