[ITK] Using ITK library in .Net (Visual Studio)

Dan Mueller dan.muel at gmail.com
Sun Aug 7 01:30:29 EDT 2016


Hi Matthias,

To import the 2d array into SimpleITK you can use the ImportAsXXX function.
You need to make sure you match your pixel types correctly (e.g. if your
buffer is float, using ImportAsFloat, etc).

Here is some C# code that might help you.

using System;
using System.Runtime.InteropServices;
using sitk = itk.simple.SimpleITK;
using simple = itk.simple;

namespace itk.simple {
public class ImageProcessing {
    public static void Main(string[] args) {
        try {
            var size = new simple.VectorUInt32(2) { 256, 256 };
            var spacing = new simple.VectorDouble(2) { 1.0, 1.0 };
            var buffer = new float[size[0] * size[1]];
            GCHandle bufferPinned = GCHandle.Alloc(buffer,
GCHandleType.Pinned); // Pin managed array
            IntPtr bufferPtr = bufferPinned.AddrOfPinnedObject(); // Get
address of array
            // Import buffer as SimpleITK image
            var input = sitk.ImportAsFloat(bufferPtr, size, spacing);
            // Compute regional maxima
            var maxima = sitk.RegionalMaxima(input, backgroundValue: 0,
foregroundValue: 255, fullyConnected: true);
            sitk.WriteImage(maxima, @"C:\Temp\maxima.mha");
            bufferPinned.Free(); // Free pinned array
        } catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
}
}

Hope this helps.

Cheers, Dan

On 7 August 2016 at 09:22, Matthias B <matthias.b at hotmail.com> wrote:

> Hey,
>
> I'm programming in VB.Net, I succesfully added the ITK managed C# library
> wrapper to my VS project.
> Now I'm able to use the ITK C# functions in VB.Net.
>
> My goal is to use a regional maxima filter (ITK) on a 2D-array that I
> declared in VB.Net
>
> I have really no idea how to do this and if this is even possible.
>
> Hope somebody can help me with this.
>
> Thank you, Matthias
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Virusvrij.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
> <#m_-7220795038837665703_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160807/6c3a61ab/attachment.html>


More information about the Community mailing list