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

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?

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.

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?

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