Using "short" data directly as input to the N4BiasFieldCorrectionImageFilter

I am incorporating the simpleITK N4BiasFieldCorrectionImageFilter into an existing c# application as part of the image processing chain.
Is there is a way to read the input data directly from a “short” array that is stored in the memory, instead of reading it from a file path?
This will allow me to avoid having to write the pre-filtered data into a file, just to be read back from the file by the filter command SimpleITK.ReadImage(input), which is what I am now doing.
Thanks!

You could construct an Image object yourself, and then copy over the pixel data. You’d have to call the Image’s SetPixelAsInt16 method for every pixel, since I don’t think you can point the Image’s buffer to your short array. It’s not idea but better than writing out to disk and reading it back.

Hello,

There is an example of getting the buffer here: SimpleITK/ImageGetBuffer.cs at master · SimpleITK/SimpleITK · GitHub

There is an old PR which extends the example to setting the buffer here:

The CSharp image buffer interface could use some attention in SimpleITK. Contributions and suggestions are welcome :slight_smile: