static void Main(String[] args)
    {
        try
        {
            // Create input and output images
            itkImageBase input = itkImage.New(args[0]);
            itkImageBase output = itkImage.New(input);

            // Read the input image
            input.Read(args[1]);

            // Apply the Sigmoid filter
            FilterType filter = FilterType.New(input, output);
            filter.Started += new itkEventHandler(filter_Started);
            filter.Progress += new itkProgressHandler(filter_Progress);
            filter.Ended += new itkEventHandler(filter_Ended);
            filter.SetInput(input);
            filter.GetOutput(output);
            filter.Alpha = Double.Parse(args[2]);
            filter.Beta  = Double.Parse(args[3]);

            // Write the output to disk
            // NOTE: Any upstream filters will be automatically updated
            output.Write(args[4]);

            // Clean up
            filter.Dispose();
            input.Dispose();
            output.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }
        public void Apply()
        {
            if (this.SelectedImageGraphicProvider == null)
            {
                return;
            }

            ImageGraphic image = this.SelectedImageGraphicProvider.ImageGraphic;

            if (image == null)
            {
                return;
            }

            if (!(image is GrayscaleImageGraphic))
            {
                return;
            }

            itkImageBase input  = ItkHelper.CreateItkImage(image as GrayscaleImageGraphic);
            itkImageBase output = itkImage.New(input);

            ItkHelper.CopyToItkImage(image as GrayscaleImageGraphic, input);

            String mangledType            = input.MangledTypeString;
            CastImageFilterType castToIF2 = CastImageFilterType.New(mangledType + "IF2");

            SmoothingFilterType smoothingFilter = SmoothingFilterType.New("IF2IF2");

            smoothingFilter.TimeStep             = 0.125;
            smoothingFilter.NumberOfIterations   = 5;
            smoothingFilter.ConductanceParameter = 9.0;

            GradientMagnitudeFilterType gradientMagnitudeFilter = GradientMagnitudeFilterType.New("IF2IF2");

            gradientMagnitudeFilter.Sigma = 1.0;

            SigmoidFilterType sigmoidFilter = SigmoidFilterType.New("IF2IF2");

            sigmoidFilter.OutputMinimum = 0.0;
            sigmoidFilter.OutputMaximum = 1.0;
            sigmoidFilter.Alpha         = -0.5; //-0.3
            sigmoidFilter.Beta          = 3.0;  //2.0

            FastMarchingFilterType fastMarchingFilter = FastMarchingFilterType.New("IF2IF2");
            double seedValue = 0.0;

            int[]    seedPosition = { 256, 256 };// user input
            itkIndex seedIndex    = new itkIndex(seedPosition);

            itkLevelSetNode[] trialPoints = { new itkLevelSetNode(seedValue, seedIndex) };
            fastMarchingFilter.TrialPoints   = trialPoints;
            fastMarchingFilter.StoppingValue = 100;

            BinaryThresholdFilterType binaryThresholdFilter = BinaryThresholdFilterType.New("IF2" + mangledType); //to UC2?

            binaryThresholdFilter.UpperThreshold = 100.0;                                                         //200
            binaryThresholdFilter.LowerThreshold = 0.0;
            binaryThresholdFilter.OutsideValue   = 0;
            if (image.BitsPerPixel == 16)
            {
                binaryThresholdFilter.InsideValue = (image as GrayscaleImageGraphic).ModalityLut.MaxInputValue;//32767;
            }
            else
            {
                binaryThresholdFilter.InsideValue = 255;
            }

            //intensityFilterType intensityFilter = intensityFilterType.New("UC2" + mangledType);
            //intensityFilter.OutputMinimum = 0;
            //if (image.BitsPerPixel == 16)
            //    intensityFilter.OutputMaximum = (image as GrayscaleImageGraphic).ModalityLut.MaxInputValue;//32767;
            //else
            //    intensityFilter.OutputMaximum = 255;

            // Make data stream connections
            castToIF2.SetInput(input);
            smoothingFilter.SetInput(castToIF2.GetOutput());
            gradientMagnitudeFilter.SetInput(smoothingFilter.GetOutput());
            sigmoidFilter.SetInput(gradientMagnitudeFilter.GetOutput());
            fastMarchingFilter.SetInput(sigmoidFilter.GetOutput());
            binaryThresholdFilter.SetInput(fastMarchingFilter.GetOutput());
            //intensityFilter.SetInput(binaryThresholdFilter.GetOutput());

            //smoothingFilter.Update();
            fastMarchingFilter.OutputSize = input.BufferedRegion.Size;//?
            binaryThresholdFilter.Update();

            binaryThresholdFilter.GetOutput(output);
            ItkHelper.CopyFromItkImage(image as GrayscaleImageGraphic, output);
            image.Draw();

            input.Dispose();
            output.Dispose();
        }