static void Main(String[] args)
    {
        try
        {
            // Setup input and output images
            UInt32 dim = UInt32.Parse(args[0]);
            itkImageBase input =  itkImage.New(itkPixelType.F,  dim);
            itkImageBase output = itkImage.New(itkPixelType.UC, dim);

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

            // Apply the Rescale Intensity filter
            FilterType filterRescale = FilterType.New(input, output);
            filterRescale.RemoveAllObservers();
            filterRescale.SetInput(input);
            filterRescale.OutputMinimum = 000.0F;
            filterRescale.OutputMaximum = 255.0F;
            filterRescale.Update();
            filterRescale.GetOutput(output);

            // Write the output to disk
            output.Write(args[2]);

            // Clean up
            filterRescale.Dispose();
            input.Dispose();
            output.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }
Example #2
0
    static void Main(String[] args)
    {
        try
        {
            // Setup 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 filter
            FilterType filter = FilterType.New(input, output);
            filter.SetInput(input);
            filter.Update();
            filter.GetOutput(output);

            // Write the output to disk
            output.Write(args[2]);

            // Clean up
            filter.Dispose();
            input.Dispose();
            output.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    } // end main
    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());
        }
    }
    static void Main(string[] args)
    {
        try
        {
            // Create an explicit image type
            itkImageBase image = itkImage_SS3.New();

            // Read the DICOM image from the given directory  
            image.ReadDicomDirectory(args[0]);

            // Display some image information
            Console.WriteLine(String.Format("Name={0}",image.Name));
            Console.WriteLine(String.Format("PixelType={0}",image.PixelType));
            Console.WriteLine(String.Format("Dimension={0}",image.Dimension));
            Console.WriteLine(String.Format("Size={0}",image.Size));
            Console.WriteLine(String.Format("Spacing={0}",image.Spacing));
            Console.WriteLine(String.Format("Origin={0}",image.Origin));
            Console.WriteLine(String.Format("Buffer={0}",image.Buffer));

            // Write the image to disk
            image.Write(args[1]);

            // Dispose of the image
            // Note: the image will be automatically disposed when it goes
            // out of scope, however it is good practice to dispose of
            // objects when they are no longer required.
            image.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    } // end main
Example #5
0
    static void Main(string[] args)
    {
        try
        {
            // Create a managed array to import
            const Int32 Width = 256;
            const Int32 Height = 256;
            List<float> list = new List<float>(Width * Height);
            for (int j = 0; j < Height; j++)
            {
                for (int i = 0; i < Width; i++)
                {
                    if (i == j)
                        list.Add(Convert.ToSingle(i));
                    else
                        list.Add(0.0F);
                }
            }

            // Pin the managed array for use with unmanaged code
            float[] array = list.ToArray();
            GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);

            // Setup for import
            itkImportImageFilter_F2 importer = itkImportImageFilter_F2.New();
            itkSize size = new itkSize(Width, Height);
            itkIndex index = new itkIndex(0, 0);
            importer.Region = new itkImageRegion(size, index);
            importer.Spacing = new itkSpacing(1.0, 1.0);
            importer.Origin = new itkPoint(0.0, 0.0);
            importer.SetImportPointer(handle.AddrOfPinnedObject(), (uint)list.Count, false);

            // Perform import
            itkImageBase output = itkImage_F2.New();
            importer.UpdateLargestPossibleRegion();
            importer.GetOutput(output);
            output.Write(args[0]);

            // Display some image information
            Console.WriteLine(String.Format("{0}", output));

            // Cleanup
            output.Dispose();
            importer.Dispose();
            handle.Free();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    } // end main
Example #6
0
    static void Main(string[] args)
    {
        try
        {
            // Read an explicitly typed image
            itkImageBase input = itkImage_UC2.New();
            input.Read(args[0]);

            // Allocate an empty output image
            itkImageBase output = itkImage_UC2.New();
            itkImageRegion region = input.LargestPossibleRegion;
            output.SetRegions(region);
            output.Allocate();
            output.FillBuffer(0);
            output.Spacing = input.Spacing;
            output.Origin = input.Origin;

            // Create iterators to walk the input and output images
            itkImageRegionConstIterator_IUC2 inputIt;
            itkImageRegionIterator_IUC2 outputIt;
            inputIt = new itkImageRegionConstIterator_IUC2(input, region);
            outputIt = new itkImageRegionIterator_IUC2(output, region);

            // Walk the images using the iterators
            foreach (itkPixel pixel in inputIt)
            {
                outputIt.Set(pixel);
                outputIt++;
            }

            // Write the output image
            output.Write(args[1]);

            // Dispose of the images
            input.Dispose();
            output.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    } // end main
    static void Main(string[] args)
    {
        try
        {
            // Create the initial, feature and output images
            itkPixelType pixeltype = itkPixelType.F;
            uint Dimension = UInt32.Parse(args[0]);
            itkImageBase initial = itkImage.New(pixeltype, Dimension);
            itkImageBase speed = itkImage.New(pixeltype, Dimension);
            itkImageBase output  = itkImage.New(pixeltype, Dimension);
            Console.WriteLine("Reading initial: " + args[1]);
            initial.Read(args[1]);
            Console.WriteLine("Reading speed: " + args[2]);
            speed.Read(args[2]);

            // Level Set
            LevelSetType levelset = LevelSetType.New(initial, speed,
                                                     pixeltype);
            levelset.Started += new itkEventHandler(LevelSetStarted);
            levelset.Iteration += new itkEventHandler(LevelSetIteration);
            levelset.Ended += new itkEventHandler(LevelSetEnded);
            levelset.SetInitialImage(initial);
            levelset.SetFeatureImage(speed);
            levelset.PropagationScaling = 5.0;
            levelset.CurvatureScaling = 3.0;
            levelset.AdvectionScaling = 1.0;
            levelset.MaximumRMSError = 0.01;
            levelset.NumberOfIterations = 600;
            levelset.Update();
            levelset.GetOutput(output);

            // Write the output image to disk
            Console.WriteLine("Writing output: " + args[3]);
            output.Write(args[3]);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }
Example #8
0
    static void Main(string[] args)
    {
        try
        {
            // Setup typedefs
            itkPixelType pixel = itkPixelType.D;
            itkDimension dim = new itkDimension(3);
            itkMeshTraits traits = itkMeshTraits.Static();

            // Create mesh
            itkMesh mesh = itkMesh.New(pixel, dim, traits);
            itkRegularSphereMeshSource source = 
                itkRegularSphereMeshSource.New(mesh);
            source.Center = new itkPoint(32.0, 32.0, 32.0);
            source.Scale = new itkVector(32.0, 32.0, 32.0);
            source.Resolution = 4;
            source.Update();
            source.GetOutput(mesh);

            // Convert mesh to image
            itkImageBase output = itkImage.New(itkPixelType.UC, dim.Dimension);
            itkTriangleMeshToBinaryImageFilter filter = 
                itkTriangleMeshToBinaryImageFilter.New(mesh, output);
            filter.SetInput(mesh);
            filter.Tolerance = 0.001;
            filter.Size = new itkSize(100, 100, 100);
            filter.Update();
            filter.GetOutput(output);
            output.Write(args[0]);

            // Cleanup
            filter.Dispose();
            output.Dispose();
            mesh.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    } // end main
    static void Main(string[] args)
    {
        try
        {
            // One of the benefits of ManagedITK is the ability to easily
            // choose the image type at run-time, rather than compile-time.

            // Use the image type from the command line to create an image
            itkImageBase image = itkImage.New(args[0]);

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

            // Display some image information
            Console.WriteLine(String.Format("Name={0}",image.Name));
            Console.WriteLine(String.Format("PixelType={0}",image.PixelType));
            Console.WriteLine(String.Format("Dimension={0}",image.Dimension));
            Console.WriteLine(String.Format("Size={0}",image.Size));
            Console.WriteLine(String.Format("Spacing={0}",image.Spacing));
            Console.WriteLine(String.Format("Origin={0}",image.Origin));
            Console.WriteLine(String.Format("Buffer={0}",image.Buffer));

            // Write the image to disk
            image.Write(args[2]);

            // Dispose of the image
            // Note: the image will be automatically disposed when it goes
            // out of scope, however it is good practice to dispose of
            // objects when they are no longer required.
            image.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    } // end main
Example #10
0
    static void Main(string[] args)
    {
        try
        {
            // Read the fixed image from the command line
            itkImageBase imageFixed = ImageType.New();
            imageFixed.Read(args[0]);

            // Create a moving image
            itkImageBase imageMoving = itkImage.New(imageFixed);

            // Create the interpolator
            InterpolatorType interpolator = InterpolatorType.New();

            // Create the transform
            TransformType transform = TransformType.New();
            transform.Translate(new itkVector(7.5, 12.0));
            Console.WriteLine("START: " + transform.Parameters.ToString());

            // Make the moving image by resampling the fixed image
            // with known parameters
            ResampleType filterResample = ResampleType.New();
            filterResample.SetInput(imageFixed);
            filterResample.SetInterpolator(interpolator);
            filterResample.SetTransform(transform);
            filterResample.OutputSize = imageFixed.Size;
            filterResample.OutputSpacing = imageFixed.Spacing;
            filterResample.Update();
            filterResample.GetOutput(imageMoving);
            imageMoving.DisconnectPipeline();
            imageFixed.DisconnectPipeline();

            // Write out the fixed and moving images
            imageFixed.Write(AddSuffixToFileName(args[0], "_FIXED"));
            imageMoving.Write(AddSuffixToFileName(args[0], "_MOVING"));

            // Reset the transform initial parameters
            transform.Translate(new itkVector(0.0, 0.0));

            // Create metric
            MetricType metric = MetricType.New();
            
            // Create optimiser
            OptimizerType optimizer = OptimizerType.New();
            optimizer.Iteration += new itkEventHandler(optimizer_Iteration);
            optimizer.MaximumStepLength = 4.00;
            optimizer.MinimumStepLength = 0.01;
            optimizer.NumberOfIterations = 200;

            // Create registration method
            RegistrationType registration = RegistrationType.New();
            registration.SetFixedImage(imageFixed);
            registration.SetMovingImage(imageMoving);
            registration.SetTransform(transform);
            registration.SetInterpolator(interpolator);
            registration.SetMetric(metric);
            registration.SetOptimizer(optimizer);
            registration.InitialTransformParameters = transform.Parameters;
            registration.StartRegistration();

            // Rotate the moving image with the found parameters
            filterResample.SetInput(imageMoving);
            filterResample.SetInterpolator(interpolator);
            filterResample.SetTransform(transform);
            filterResample.OutputSize = imageMoving.Size;
            filterResample.OutputSpacing = imageMoving.Spacing;
            filterResample.Update();
            filterResample.GetOutput(imageMoving);
            imageMoving.DisconnectPipeline();

            // Write out the results
            Console.WriteLine("END:   " + transform.Parameters.ToString());
            imageMoving.Write(AddSuffixToFileName(args[0], "_REGISTERED"));
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }
      static void Main(string[] args)
      {
          try
          {
              // Setup typedefs
              itkPixelType pixel = itkPixelType.D;
              itkDimension dim = new itkDimension(3);
              itkMeshTraits traits = itkMeshTraits.Static();

              // Compute gradient
              Console.WriteLine("Reading gradient: " + args[0]);
              itkImageBase gradient = itkImage_CVD33.New();
              gradient.Read(args[0]);

              // Create initial mesh
              Console.WriteLine("Creating initial mesh");
              itkMesh meshIn = itkMesh.New(pixel, dim, traits);
              itkRegularSphereMeshSource source = itkRegularSphereMeshSource.New(meshIn);
              source.Center = new itkPoint(20.0, 20.0, 20.0);
              source.Scale = new itkVector(5.0, 5.0, 5.0);
              source.Resolution = 4;
              source.Update();
              source.GetOutput(meshIn);
              meshIn.DisconnectPipeline();

              // Convert triangle mesh to simplex mesh
              Console.WriteLine("Converting triangle mesh to simplex mesh");
              itkSimplexMesh simplexIn = itkSimplexMesh.New(pixel, dim, traits);
              itkTriangleMeshToSimplexMeshFilter convertToSimplex =
                  itkTriangleMeshToSimplexMeshFilter.New(meshIn, simplexIn);
              convertToSimplex.SetInput(meshIn);
              convertToSimplex.Update();
              convertToSimplex.GetOutput(simplexIn);
              simplexIn.DisconnectPipeline();

              // Deform the simplex mesh
              Console.WriteLine("Deforming simplex mesh");
              itkSimplexMesh simplexOut = itkSimplexMesh.New(pixel, dim, traits);
              itkDeformableSimplexMesh3DBalloonForceFilter deform =
                  itkDeformableSimplexMesh3DBalloonForceFilter.New(simplexIn, simplexOut);
              deform.Alpha = 0.8;   // Internal force scaling
              deform.Beta = 0.8;    // External force scaling
              deform.Gamma = 0.1;   // Reference metric scaling
              deform.Rigidity = 3;  // Mesh smoothness (0=high curvature, 9=smooth)
              deform.Kappa = 0.1;   // Internal balloon force scaling
              deform.Iterations = 200;
              deform.SetGradient(gradient);
              deform.SetInput(simplexIn);
              deform.Progress += new itkProgressHandler(FilterProgress);
              deform.Update();
              deform.GetOutput(simplexOut);
              simplexOut.DisconnectPipeline();
              Console.WriteLine();

              // Convert simplex mesh to triangle mesh
              Console.WriteLine("Converting simplex mesh to triangle mesh");
              itkMesh meshOut = itkMesh.New(pixel, dim, traits);
              itkSimplexMeshToTriangleMeshFilter convertToTriangle =
                  itkSimplexMeshToTriangleMeshFilter.New(simplexOut, meshOut);
              convertToTriangle.SetInput(simplexOut);
              convertToTriangle.Update();
              convertToTriangle.GetOutput(meshOut);
              meshOut.DisconnectPipeline();

              // Convert mesh to image
              Console.WriteLine("Converting mesh to image: " + Path.GetFileName(args[1]));
              itkImageBase output = itkImage_UC3.New();
              itkTriangleMeshToBinaryImageFilter filter =
                  itkTriangleMeshToBinaryImageFilter.New(meshOut, output);
              filter.SetInput(meshOut);
              filter.Tolerance = 0.001;
              filter.Size = gradient.Size;
              filter.Spacing = gradient.Spacing;
              filter.Origin = gradient.Origin;
              filter.GetOutput(output);
              filter.Update();
              output.Write(args[1]);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
      }