Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try {
                if (args.Length < 2)
                {
                    Console.WriteLine("Usage: DicomSeriesReader <input_directory> <output_file>");
                    return;
                }

                Console.WriteLine("Reading Dicom directory: " + args[0]);
                ImageSeriesReader reader = new ImageSeriesReader();

                VectorString dicom_names = ImageSeriesReader.GetGDCMSeriesFileNames(args[0]);
                reader.SetFileNames(dicom_names);

                Image image = reader.Execute();

                VectorUInt32 size = image.GetSize();
                Console.WriteLine("Image size: " + size[0] + " " + size[1] + " " + size[2]);

                Console.WriteLine("Writing image: " + args[1]);
                ImageFileWriter writer = new ImageFileWriter();
                writer.SetFileName(args[1]);
                writer.Execute(image);

                if (Environment.GetEnvironmentVariable("SITK_NOSHOW") == null)
                {
                    SimpleITK.Show(image, "Dicom Series");
                }
            } catch (Exception ex) {
                Console.WriteLine("Usage: DicomSeriesReader <input_directory> <output_file>");
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try {
                // Create an image
                PixelIDValueEnum pixelType = PixelIDValueEnum.sitkUInt8;
                VectorUInt32     imageSize = new VectorUInt32(new uint[] { 128, 128 });
                Image            image     = new Image(imageSize, pixelType);

                // Create a face image
                VectorDouble faceSize   = new VectorDouble(new double[] { 64, 64 });
                VectorDouble faceCenter = new VectorDouble(new double[] { 64, 64 });
                Image        face       = SimpleITK.GaussianSource(pixelType, imageSize, faceSize, faceCenter);

                // Create eye images
                VectorDouble eyeSize    = new VectorDouble(new double[] { 5, 5 });
                VectorDouble eye1Center = new VectorDouble(new double[] { 48, 48 });
                VectorDouble eye2Center = new VectorDouble(new double[] { 80, 48 });
                Image        eye1       = SimpleITK.GaussianSource(pixelType, imageSize, eyeSize, eye1Center, 150);
                Image        eye2       = SimpleITK.GaussianSource(pixelType, imageSize, eyeSize, eye2Center, 150);

                // Apply the eyes to the face
                face = SimpleITK.Subtract(face, eye1);
                face = SimpleITK.Subtract(face, eye2);
                face = SimpleITK.BinaryThreshold(face, 200, 255, 255);


                // Create the mouth
                VectorDouble mouthRadii  = new VectorDouble(new double[] { 30, 20 });
                VectorDouble mouthCenter = new VectorDouble(new double[] { 64, 76 });
                Image        mouth       = SimpleITK.GaussianSource(pixelType, imageSize, mouthRadii, mouthCenter);
                mouth = SimpleITK.BinaryThreshold(mouth, 200, 255, 255);
                mouth = SimpleITK.Subtract(255, mouth);

                // Paste the mouth onto the face
                VectorUInt32 mouthSize = new VectorUInt32(new uint[] { 64, 18 });
                VectorInt32  mouthLoc  = new VectorInt32(new int[] { 32, 76 });
                face = SimpleITK.Paste(face, mouth, mouthSize, mouthLoc, mouthLoc);

                // Apply the face to the original image
                image = SimpleITK.Add(image, face);

                // Display the results
                if (Environment.GetEnvironmentVariable("SITK_NOSHOW") == null)
                {
                    SimpleITK.Show(image, "Hello World: CSharp", true);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try {
                if (args.Length < 2)
                {
                    Console.WriteLine("Usage: N4BiasFieldCorrection inputImage outputImage"
                                      + " [shrinkFactor] [maskImage] [numberOfIterations]"
                                      + " [numberOfFittingLevels]\n");

                    return;
                }
                // Read input image
                Image inputImage = sitk.ReadImage(args[0], PixelIDValueEnum.sitkFloat32);
                Image image      = inputImage;


                Image maskImage;
                if (args.Length > 3)
                {
                    maskImage = sitk.ReadImage(args[3], PixelIDValueEnum.sitkUInt8);
                }
                else
                {
                    maskImage = sitk.OtsuThreshold(image, 0, 1, 200);
                }

                if (args.Length > 2)
                {
                    uint   s       = UInt32.Parse(args[2]);
                    uint[] s_array = new uint[image.GetDimension()];
                    for (uint i = 0; i < image.GetDimension(); i++)
                    {
                        s_array[i] = s;
                    }
                    VectorUInt32 shrink = new VectorUInt32(s_array);
                    image     = sitk.Shrink(inputImage, shrink);
                    maskImage = sitk.Shrink(maskImage, shrink);
                }

                N4BiasFieldCorrectionImageFilter corrector
                    = new N4BiasFieldCorrectionImageFilter();

                uint numFittingLevels = 4;

                if (args.Length > 5)
                {
                    numFittingLevels = UInt32.Parse(args[5]);
                }

                if (args.Length > 4)
                {
                    uint   it       = UInt32.Parse(args[4]);
                    uint[] it_array = new uint[numFittingLevels];
                    for (uint i = 0; i < numFittingLevels; i++)
                    {
                        it_array[i] = it;
                    }
                    VectorUInt32 iterations = new VectorUInt32(it_array);
                    corrector.SetMaximumNumberOfIterations(iterations);
                }

                Image corrected_image = corrector.Execute(image, maskImage);

                Image log_bias_field = corrector.GetLogBiasFieldAsImage(inputImage);

                Image bias_field = sitk.Divide(inputImage, sitk.Exp(log_bias_field));

                sitk.WriteImage(corrected_image, args[1]);

                if (Environment.GetEnvironmentVariable("SITK_NOSHOW") == null)
                {
                    SimpleITK.Show(corrected_image, "N4 Corrected");
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }