# Get Interpolated image value for (x,y,z) point coordinate (BSpline)

**URL:** https://discourse.vtk.org/t/get-interpolated-image-value-for-x-y-z-point-coordinate-bspline/4726
**Category:** Support
**Created:** [November 24, 2020, 4:35pm UTC](https://discourse.vtk.org/t/get-interpolated-image-value-for-x-y-z-point-coordinate-bspline/4726 "2020-11-24T16:35:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![IVarha](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/i/9e8a1a/32.png) [@IVarha](https://discourse.vtk.org/u/IVarha)
#### Post date: [November 24, 2020, 4:35pm UTC](https://discourse.vtk.org/t/get-interpolated-image-value-for-x-y-z-point-coordinate-bspline/4726/1 "2020-11-24T16:35:04Z")

</div>

Hello vtk Support community,

I am using vtk for processing of 3d Nifti images and want to get interpolated value from (x,y,z)- I entered them in voxel coordinate space.  
W  
this-\>bspline\_coeff = vtkSmartPointer::New();  
this-\>bspline\_coeff-\>SetInputData(this-\>niimg);  
this-\>bspline\_coeff-\>SetSplineDegree(5);  
this-\>bspline\_coeff-\>Update();  
//this should be a result  
auto result = this-\>bspline\_coeff-\>Evaluate(x);

**But it returns a completely different result from my control point (return something around zero whereas this coordinate value is 6)**

\*another solution I tried was: \*  
auto interp = vtkSmartPointer::New();  
this-\>bspline\_coeff = vtkSmartPointer::New();  
this-\>bspline\_coeff-\>SetInputData(this-\>niimg);  
this-\>bspline\_coeff-\>SetSplineDegree(5);  
this-\>bspline\_coeff-\>Update();  
interp-\>Initialize(bspline\_coeff-\>GetOutput());

_auto result = interp-\>Interpolate(x[0],x[1],x[2],0);_

However I did not get any reasonable result.  
It looks like I somehow misuse this program. Could somebody please help to get a correct result?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 25, 2020, 4:46am UTC](https://discourse.vtk.org/t/get-interpolated-image-value-for-x-y-z-point-coordinate-bspline/4726/2 "2020-11-25T04:46:54Z")

</div>

The problem might be the coordinates. The `Evaluate()` method takes physical data coords, i.e. coords measured in millimetres.

Also, try to get your code working with the SplineDegree=3 (cubic spline) before trying SplineDegree=5.

---

<div class="post-metadata">

### Author: ![IVarha](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/i/9e8a1a/32.png) [@IVarha](https://discourse.vtk.org/u/IVarha)
#### Post date: [November 25, 2020, 12:54pm UTC](https://discourse.vtk.org/t/get-interpolated-image-value-for-x-y-z-point-coordinate-bspline/4726/3 "2020-11-25T12:54:03Z")

</div>

You are right, However it looks like it’s not exactly coords like in nifty.

Nifty define are transform matrix (usually)  
vx 0 0 px  
0 vy 0 py  
0 0 vz pz  
0 0 0 1

Whereas looks like in VTK coordinates:  
vx 0 0 0  
0 vy 0 0  
0 0 vz 0  
0 0 0 1

Am I right?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 25, 2020, 3:35pm UTC](https://discourse.vtk.org/t/get-interpolated-image-value-for-x-y-z-point-coordinate-bspline/4726/4 "2020-11-25T15:35:54Z")

</div>

That’s right. When vtkNIFTIImageReader creates the ImageData, only the spacing goes into the image. You can use reader-\>GetQFormMatrix() to get orientation and position.

The source code contains additional information:  
[https://gitlab.kitware.com/vtk/vtk/-/blob/master/IO/Image/vtkNIFTIImageReader.cxx#L707](https://gitlab.kitware.com/vtk/vtk/-/blob/master/IO/Image/vtkNIFTIImageReader.cxx#L707)
