# Getting an interpolated image based on sparse pixel values

**URL:** <https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682>\
**Category:** Uncategorized\
**Created:** [March 19, 2019, 12:28am UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682 "2019-03-19T00:28:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sedghi](https://discourse.itk.org/user_avatar/discourse.itk.org/sedghi/32/317_2.png) [@sedghi](https://discourse.itk.org/u/sedghi)\
**Post date:** [March 19, 2019, 12:28am UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/1 "2019-03-19T00:28:09Z")

</div>

Lets assume that we have a 3D image of size 100x100x100, and we only want to set pixel values for 1000 locations in this 3D image. Is it possible to get the interpolated image based on these sparse pixel values? which filter should I use?

Thanks in advance for you help

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [March 19, 2019, 1:30pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/2 "2019-03-19T13:30:25Z")

</div>

I think [BSplineScatteredDataPointSetToImageFilter](https://itk.org/Doxygen/html/classitk_1_1BSplineScatteredDataPointSetToImageFilter.html) does what you want.

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [March 19, 2019, 1:49pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/3 "2019-03-19T13:49:09Z")

</div>

Also [ImageRandomNonRepeatkingIteratorWithIndex](https://itk.org/Insight/Doxygen/html/classitk_1_1ImageRandomNonRepeatingIteratorWithIndex.html) may be of interest.

---

<div class="post-metadata">

**Author:** ![sedghi](https://discourse.itk.org/user_avatar/discourse.itk.org/sedghi/32/317_2.png) [@sedghi](https://discourse.itk.org/u/sedghi)\
**Post date:** [March 19, 2019, 1:55pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/4 "2019-03-19T13:55:12Z")

</div>

I’m coding in Python. None of the above filters are implemented in ITK or SITK. Any alternatives for Python?

Thanks

---

<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:** [March 19, 2019, 2:04pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/5 "2019-03-19T14:04:48Z")

</div>

From what I gather you are trying to define a continuous domain from 1000 sparse, randomly sampled points. This reminds me of radial basis based interpolation, but there could be many ways to “define” valid interpolation. To me it does not sound like you have an image just you need to convert a sparse point set to an image.

Unfortunately, I don’t have any specific suggestions for this operation ( if this is the operation you are trying to do). I think Dzenan’s might do what you need.

---

<div class="post-metadata">

**Author:** ![sedghi](https://discourse.itk.org/user_avatar/discourse.itk.org/sedghi/32/317_2.png) [@sedghi](https://discourse.itk.org/u/sedghi)\
**Post date:** [March 19, 2019, 2:09pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/6 "2019-03-19T14:09:03Z")

</div>

You assumption is correct.  
So basically after my Bspline image registration method with 10x10x10 control points (the code is not based on ITK Registration), I end up with uncertainty scores for each of these control points. Next, I want to interpolate the Image space based on these 1000 locations and generate an Uncertainty map for my image registration algorithm

---

<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:** [March 19, 2019, 2:14pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/7 "2019-03-19T14:14:37Z")

</div>

So you 10^3 points are not random, the are in a grid pattern which nicely fits into an Image in the “fixed domain” space. If you want to have the “uncertainty map” in the “moving image domain” you would simply need to apply the b-spline transform. This can be done with the resample image filter and you can specify the output image size and an interpolator as well.

---

<div class="post-metadata">

**Author:** ![sedghi](https://discourse.itk.org/user_avatar/discourse.itk.org/sedghi/32/317_2.png) [@sedghi](https://discourse.itk.org/u/sedghi)\
**Post date:** [March 19, 2019, 2:25pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/8 "2019-03-19T14:25:23Z")

</div>

They are not in a grid pattern since they are moved from their initial positions to achieve the best similarity based on bspline deformation, but that’s true that they are not random. Here is a slice of overlaid points on a public brain image.

 ![image](https://discourse.itk.org/uploads/default/original/1X/46f33e8681a99e9e296228d40c6c88b8be86eb05.png)

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [March 19, 2019, 2:38pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/9 "2019-03-19T14:38:53Z")

</div>

For a specific operation like this, it can be helpful to [create your own classes](https://github.com/InsightSoftwareConsortium/ITKModuleTemplate) and [wrap them in Python](https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch9.html#x50-1430009).

---

<div class="post-metadata">

**Author:** ![sedghi](https://discourse.itk.org/user_avatar/discourse.itk.org/sedghi/32/317_2.png) [@sedghi](https://discourse.itk.org/u/sedghi)\
**Post date:** [March 19, 2019, 2:46pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/10 "2019-03-19T14:46:01Z")

</div>

Thank you, it’s not specific actually. Scipy has interpolation functions. I was just wondering if ITK provides it or not.

Best  
Alireza

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [March 19, 2019, 2:50pm UTC](https://discourse.itk.org/t/getting-an-interpolated-image-based-on-sparse-pixel-values/1682/11 "2019-03-19T14:50:56Z")

</div>

What you should definitely try is [adding Python wrapping](https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch9.html#x50-1430009) for [BSplineScatteredDataPointSetToImageFilter](https://itk.org/Doxygen/html/classitk_1_1BSplineScatteredDataPointSetToImageFilter.html), because that filter seems to be doing exactly what you want.
