using System;
using System.Globalization;
namespace itk.simple.examples
{
public class Program
{
static void Main(string[] args)
{
if (args.Length < 8)
{
Console.WriteLine("Missing Parameters ");
Console.WriteLine("Usage: " + System.AppDomain.CurrentDomain.FriendlyName +
"inputImage initialModel outputImage cannyThreshold " +
"cannyVariance advectionWeight initialModelIsovalue maximumIterations ");
return;
}
string inputFilename = args[0];
string initialModelFilename = args[1];
string outputFilename = args[2];
double cannyThreshold = double.Parse(args[3], CultureInfo.InvariantCulture);
double cannyVariance = double.Parse(args[4], CultureInfo.InvariantCulture);
double advectionWeight = double.Parse(args[5], CultureInfo.InvariantCulture);
double intialModelIsovalue = double.Parse(args[6], CultureInfo.InvariantCulture);
uint maxIterations = uint.Parse(args[7], CultureInfo.InvariantCulture);
SitkImage inputImage = SimpleITK.ReadImage(inputFilename, PixelId.sitkFloat32);
SitkImage initialModel = SimpleITK.ReadImage(initialModelFilename, PixelId.sitkFloat32);
GradientAnisotropicDiffusionImageFilter diffusion=new GradientAnisotropicDiffusionImageFilter();
diffusion.SetConductanceParameter(1.0);
diffusion.SetTimeStep(0.125);
diffusion.SetNumberOfIterations(5);
SitkImage diffusedImage=diffusion.Execute(inputImage);
CannySegmentationLevelSetImageFilter cannySegmentation = new CannySegmentationLevelSetImageFilter();
cannySegmentation.SetAdvectionScaling(advectionWeight);
cannySegmentation.SetCurvatureScaling(1.0);
cannySegmentation.SetPropagationScaling(0.0);
cannySegmentation.SetMaximumRMSError(0.01);
cannySegmentation.SetNumberOfIterations(maxIterations);
cannySegmentation.SetThreshold(cannyThreshold);
cannySegmentation.SetVariance(cannyVariance);
cannySegmentation.SetIsoSurfaceValue(intialModelIsovalue);
SitkImage output = cannySegmentation.Execute(initialModel, diffusedImage);
BinaryThresholdImageFilter thresholder= new BinaryThresholdImageFilter();
thresholder.SetUpperThreshold(10.0);
thresholder.SetLowerThreshold(0.0);
thresholder.SetOutsideValue(0);
thresholder.SetInsideValue(255);
output=thresholder.Execute(output);
SimpleITK.WriteImage(output,outputFilename);
Console.WriteLine("");
Console.WriteLine("Max. no. iterations: {0}", cannySegmentation.GetNumberOfIterations());
Console.WriteLine("Max. RMS error: {0}", cannySegmentation.GetMaximumRMSError());
Console.WriteLine("");
Console.WriteLine("No. elpased iterations: {0}", cannySegmentation.GetElapsedIterations());
Console.WriteLine("RMS change: {0}", cannySegmentation.GetRMSChange());
}
}
}