# Using "short" data directly as input to the N4BiasFieldCorrectionImageFilter

**URL:** <https://discourse.itk.org/t/using-short-data-directly-as-input-to-the-n4biasfieldcorrectionimagefilter/4081>\
**Category:** Engineering\
**Created:** [April 28, 2021, 8:32am UTC](https://discourse.itk.org/t/using-short-data-directly-as-input-to-the-n4biasfieldcorrectionimagefilter/4081 "2021-04-28T08:32:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@Tamar](https://discourse.itk.org/u/Tamar)\
**Post date:** [April 28, 2021, 8:32am UTC](https://discourse.itk.org/t/using-short-data-directly-as-input-to-the-n4biasfieldcorrectionimagefilter/4081/1 "2021-04-28T08:32:00Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [April 28, 2021, 3:07pm UTC](https://discourse.itk.org/t/using-short-data-directly-as-input-to-the-n4biasfieldcorrectionimagefilter/4081/2 "2021-04-28T15:07:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [April 28, 2021, 3:16pm UTC](https://discourse.itk.org/t/using-short-data-directly-as-input-to-the-n4biasfieldcorrectionimagefilter/4081/3 "2021-04-28T15:16:13Z")

</div>

Hello,

There is an example of getting the buffer here: [SimpleITK/ImageGetBuffer.cs at master · SimpleITK/SimpleITK · GitHub](https://github.com/SimpleITK/SimpleITK/blob/master/Examples/CSharp/ImageGetBuffer.cs)

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

> <https://github.com/SimpleITK/SimpleITK/pull/766/files>

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