/// <summary>Main entry point.</summary>
        public static int Main(string[] args)
        {
            int success = ExitSuccess;
            try {
                Image image = new Image(100, 100, PixelId.sitkInt8);
                Image image2 = new Image(100, 100, PixelId.sitkInt8);

                image += 10;
                image -= 1;
                CheckHash(image, "1cda91cc1bf474a25d6365f7fa7ef1fc75b3c7c9", ref success);
                image *= 2;
                image /= 3;
                CheckHash(image, "856f68940ff670209aa9d60f38fc4cca1880f647", ref success);

                // image with just one 7 reset zero
                image *= 0;
                VectorUInt32 idx = new VectorUInt32();
                idx.Add(0);
                idx.Add(0);
                image.SetPixelAsInt8( idx, 7 );

                // Unary operators
                CheckHash(-image, "fe7e0c8ac8252189cf5766a352397bc62dd42e4d", ref success);
                CheckHash(+image, "6cccaa2d5c958e79ebd5ca4a0b00bee747797c8d", ref success);
                CheckHash(!image, "f4695dbf5bc9ea2796b2e4f360ea4b5ecbf70c37", ref success);
                CheckHash(~image, "746470f03126f653cc23265e0b1c1fe16a952745", ref success);
                CheckHash(image, "6cccaa2d5c958e79ebd5ca4a0b00bee747797c8d", ref success);

                // Comparison operators
                CheckHash( image < 7, "f4695dbf5bc9ea2796b2e4f360ea4b5ecbf70c37", ref success);
                CheckHash( image > 7, "f907b7bf318b79fd6b9da589646f8b1dac77d0c8", ref success);
                CheckHash( image <= 7, "cef864600fc947062ac359fe9a7cc049c7273b8e", ref success);
                CheckHash( image >= 7, "52f583bfeb07a6c4c5a26b28f8ae180bf8e0079b", ref success);

                CheckHash( image < image2, "f907b7bf318b79fd6b9da589646f8b1dac77d0c8", ref success);
                CheckHash( image > image2, "52f583bfeb07a6c4c5a26b28f8ae180bf8e0079b", ref success);
                CheckHash( image <= image2, "f4695dbf5bc9ea2796b2e4f360ea4b5ecbf70c37", ref success);
                CheckHash( image >= image2, "cef864600fc947062ac359fe9a7cc049c7273b8e", ref success);

                // Binary bitwise operators
                image &= 5;;
                image |= 7;
                image ^= 8;
                CheckHash(image, "0c26e6610c876b83cf681688eb8e80b952a394ce", ref success);

                image &= image;
                image ^= image;
                image |= image;
                CheckHash( image, "f907b7bf318b79fd6b9da589646f8b1dac77d0c8", ref success);  // just zeros

                // image of 1s
                image *= 0;
                image += 1;

                image += image;
                image -= image;
                image *= image;
                image /= image;
                CheckHash(image, "287046eafd10b9984977f6888ea50ea50fe846b5", ref success);

            } catch (Exception ex) {
                success = ExitFailure;
                Console.WriteLine(ex);
            }
            return success;
        }
Beispiel #2
0
        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);

            // Read input image

            SitkImage inputImage = SimpleITK.ReadImage(inputFilename, PixelIDValueEnum.sitkFloat32);

            //  The input image will be processed with a few iterations of
            //  feature-preserving diffusion.  We create a filter and set the
            //  appropriate parameters.

            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();

            //VectorUIntList trialPoints; Add trialPoints into list if using multiple seeds. Here we only use one seedpoint

            VectorUInt32 trialPoint = new VectorUInt32(3);

            trialPoint.Add(seedPosition[0]);
            trialPoint.Add(seedPosition[1]);
            trialPoint.Add(seedPosition[2]);

            fastMarching.AddTrialPoint(trialPoint);

            //  Since the front representing the contour will propagate continuously
            //  over time, it is desirable to stop the process once a certain time has
            //  been reached. This allows us to save computation time under the
            //  assumption that the region of interest has already been computed. The
            //  value for stopping the process is defined with the method
            //  SetStoppingValue(). In principle, the stopping value should be a
            //  little bit higher than the threshold value.

            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);
        }
        static void Main(string[] args)
        {
            try {
                if (args.Length < 1) {
                    Console.WriteLine("Usage: RTKFirstReconstruction <output>");
                    return;
                }

                // Defines the RTK geometry object
                ThreeDCircularProjectionGeometry geometry = new ThreeDCircularProjectionGeometry();
                uint numberOfProjections = 360;
                float firstAngle = 0;
                float angularArc = 360;
                float sid = 600; // source to isocenter distance in mm
                float sdd = 1200; // source to detector distance in mm
                float isox = 0; // X coordinate on the projection image of isocenter
                float isoy = 0; // Y coordinate on the projection image of isocenter
                for (int x = 0; x < numberOfProjections; x++)
                  {
                  float angle = firstAngle + x * angularArc / numberOfProjections;
                  geometry.AddProjection(sid, sdd, angle, isox, isoy);
                  }
                ConstantImageSource constantImageSource = new ConstantImageSource();
                VectorDouble origin = new VectorDouble(3);
                origin.Add(-127.0);
                origin.Add(-127.0);
                origin.Add(-127.0);
                VectorUInt32 sizeOutput = new VectorUInt32(3);
                sizeOutput.Add(256);
                sizeOutput.Add(256);
                sizeOutput.Add(numberOfProjections);
                VectorDouble spacing = new VectorDouble(3);
                spacing.Add(1.0);
                spacing.Add(1.0);
                spacing.Add(1.0);

                constantImageSource.SetOrigin(origin);
                constantImageSource.SetSpacing(spacing);
                constantImageSource.SetSize(sizeOutput);
                constantImageSource.SetConstant(0.0);
                Image source = constantImageSource.Execute();

                RayEllipsoidIntersectionImageFilter rei = new RayEllipsoidIntersectionImageFilter();
                VectorDouble semiprincipalaxis = new VectorDouble(3);
                semiprincipalaxis.Add(50.0);
                semiprincipalaxis.Add(50.0);
                semiprincipalaxis.Add(50.0);

                VectorDouble center = new VectorDouble(3);
                center.Add(0.0);
                center.Add(0.0);
                center.Add(0.0);
                // Set GrayScale value, axes, center...
                rei.SetDensity(20);
                rei.SetAngle(0);
                rei.SetCenter(center);
                rei.SetAxis(semiprincipalaxis);
                rei.SetGeometry(geometry);
                Image reiImage = rei.Execute(source);

                // Create reconstructed image
                ConstantImageSource constantImageSource2 = new ConstantImageSource();
                VectorUInt32 sizeOutput2 = new VectorUInt32(3);
                sizeOutput2.Add(256);
                sizeOutput2.Add(256);
                sizeOutput2.Add(256);
                constantImageSource2.SetOrigin(origin);
                constantImageSource2.SetSpacing(spacing);
                constantImageSource2.SetSize(sizeOutput2);
                constantImageSource2.SetConstant(0.0);
                Image source2 = constantImageSource2.Execute();

                Console.WriteLine("Performing reconstruction");
                FDKConeBeamReconstructionFilter feldkamp = new FDKConeBeamReconstructionFilter();
                feldkamp.SetGeometry(geometry);
                feldkamp.SetTruncationCorrection(0.0);
                feldkamp.SetHannCutFrequency(0.0);
                Image image = feldkamp.Execute(source2, reiImage);

                ImageFileWriter writer = new ImageFileWriter();
                writer.SetFileName(args[0]);
                writer.Execute(image);

            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            try {
                if (args.Length < 1)
                {
                    Console.WriteLine("Usage: RTKFirstReconstruction <output>");
                    return;
                }

                // Defines the RTK geometry object
                ThreeDCircularProjectionGeometry geometry = new ThreeDCircularProjectionGeometry();
                uint  numberOfProjections = 360;
                float firstAngle          = 0;
                float angularArc          = 360;
                float sid  = 600;  // source to isocenter distance in mm
                float sdd  = 1200; // source to detector distance in mm
                float isox = 0;    // X coordinate on the projection image of isocenter
                float isoy = 0;    // Y coordinate on the projection image of isocenter
                for (int x = 0; x < numberOfProjections; x++)
                {
                    float angle = firstAngle + x * angularArc / numberOfProjections;
                    geometry.AddProjection(sid, sdd, angle, isox, isoy);
                }
                ConstantImageSource constantImageSource = new ConstantImageSource();
                VectorDouble        origin = new VectorDouble(3);
                origin.Add(-127.0);
                origin.Add(-127.0);
                origin.Add(-127.0);
                VectorUInt32 sizeOutput = new VectorUInt32(3);
                sizeOutput.Add(256);
                sizeOutput.Add(256);
                sizeOutput.Add(numberOfProjections);
                VectorDouble spacing = new VectorDouble(3);
                spacing.Add(1.0);
                spacing.Add(1.0);
                spacing.Add(1.0);

                constantImageSource.SetOrigin(origin);
                constantImageSource.SetSpacing(spacing);
                constantImageSource.SetSize(sizeOutput);
                constantImageSource.SetConstant(0.0);
                Image source = constantImageSource.Execute();

                RayEllipsoidIntersectionImageFilter rei = new RayEllipsoidIntersectionImageFilter();
                VectorDouble semiprincipalaxis          = new VectorDouble(3);
                semiprincipalaxis.Add(50.0);
                semiprincipalaxis.Add(50.0);
                semiprincipalaxis.Add(50.0);

                VectorDouble center = new VectorDouble(3);
                center.Add(0.0);
                center.Add(0.0);
                center.Add(0.0);
                // Set GrayScale value, axes, center...
                rei.SetDensity(20);
                rei.SetAngle(0);
                rei.SetCenter(center);
                rei.SetAxis(semiprincipalaxis);
                rei.SetGeometry(geometry);
                Image reiImage = rei.Execute(source);


                // Create reconstructed image
                ConstantImageSource constantImageSource2 = new ConstantImageSource();
                VectorUInt32        sizeOutput2          = new VectorUInt32(3);
                sizeOutput2.Add(256);
                sizeOutput2.Add(256);
                sizeOutput2.Add(256);
                constantImageSource2.SetOrigin(origin);
                constantImageSource2.SetSpacing(spacing);
                constantImageSource2.SetSize(sizeOutput2);
                constantImageSource2.SetConstant(0.0);
                Image source2 = constantImageSource2.Execute();

                Console.WriteLine("Performing reconstruction");
                FDKConeBeamReconstructionFilter feldkamp = new FDKConeBeamReconstructionFilter();
                feldkamp.SetGeometry(geometry);
                feldkamp.SetTruncationCorrection(0.0);
                feldkamp.SetHannCutFrequency(0.0);
                Image image = feldkamp.Execute(source2, reiImage);

                ImageFileWriter writer = new ImageFileWriter();
                writer.SetFileName(args[0]);
                writer.Execute(image);
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
        /// <summary>Main entry point.</summary>
        public static int Main(string[] args)
        {
            int success = ExitSuccess;

            try {
                Image image  = new Image(100, 100, PixelId.sitkInt8);
                Image image2 = new Image(100, 100, PixelId.sitkInt8);


                image += 10;
                image -= 1;
                CheckHash(image, "1cda91cc1bf474a25d6365f7fa7ef1fc75b3c7c9", ref success);
                image *= 2;
                image /= 3;
                CheckHash(image, "856f68940ff670209aa9d60f38fc4cca1880f647", ref success);


                // image with just one 7 reset zero
                image *= 0;
                VectorUInt32 idx = new VectorUInt32();
                idx.Add(0);
                idx.Add(0);
                image.SetPixelAsInt8(idx, 7);

                // Unary operators
                CheckHash(-image, "fe7e0c8ac8252189cf5766a352397bc62dd42e4d", ref success);
                CheckHash(+image, "6cccaa2d5c958e79ebd5ca4a0b00bee747797c8d", ref success);
                CheckHash(!image, "f4695dbf5bc9ea2796b2e4f360ea4b5ecbf70c37", ref success);
                CheckHash(~image, "746470f03126f653cc23265e0b1c1fe16a952745", ref success);
                CheckHash(image, "6cccaa2d5c958e79ebd5ca4a0b00bee747797c8d", ref success);


                // Comparison operators
                CheckHash(image < 7, "f4695dbf5bc9ea2796b2e4f360ea4b5ecbf70c37", ref success);
                CheckHash(image > 7, "f907b7bf318b79fd6b9da589646f8b1dac77d0c8", ref success);
                CheckHash(image <= 7, "cef864600fc947062ac359fe9a7cc049c7273b8e", ref success);
                CheckHash(image >= 7, "52f583bfeb07a6c4c5a26b28f8ae180bf8e0079b", ref success);

                CheckHash(image < image2, "f907b7bf318b79fd6b9da589646f8b1dac77d0c8", ref success);
                CheckHash(image > image2, "52f583bfeb07a6c4c5a26b28f8ae180bf8e0079b", ref success);
                CheckHash(image <= image2, "f4695dbf5bc9ea2796b2e4f360ea4b5ecbf70c37", ref success);
                CheckHash(image >= image2, "cef864600fc947062ac359fe9a7cc049c7273b8e", ref success);

                // Binary bitwise operators
                image &= 5;;
                image |= 7;
                image ^= 8;
                CheckHash(image, "0c26e6610c876b83cf681688eb8e80b952a394ce", ref success);

                image &= image;
                image ^= image;
                image |= image;
                CheckHash(image, "f907b7bf318b79fd6b9da589646f8b1dac77d0c8", ref success);   // just zeros


                // image of 1s
                image *= 0;
                image += 1;

                image += image;
                image -= image;
                image *= image;
                image /= image;
                CheckHash(image, "287046eafd10b9984977f6888ea50ea50fe846b5", ref success);
            } catch (Exception ex) {
                success = ExitFailure;
                Console.WriteLine(ex);
            }
            return(success);
        }