Is there any c++ function similar to smoothbivariatespline from scipy.interpolate

46 Views Asked by At

Here is the python code:

dispX = SmoothBivariateSpline(x, y, z, bbox=[0, 2859, 0, 2399],kx=1,ky=1)
result = dispX.ev(mc,yc)    

I want to convert the above code to c++.x,y,z are 1D numpy arrays with same size. And in the next line I want to evaluate spline at points mc,yc (also bilinear extrapolation is carried out).
If you guys know anything similar to this function in c++ please do help

Thanks

I tried boost,gsl.. in boost there was no extrapolation, gsl is for structured data I have unstructured data, opencv and ipp didn’t have any function related to spline

1

There are 1 best solutions below

0
Mohamed Mahmoud On

I believe there isn't a direct equivalent function in the standard library. However, a library like Eigen can calculate spline interpolation.

You can try it an see if it achieves the same result. this is an example code.

#include <Eigen/Dense>
using namespace Eigen;

int main() {
    // Example data
    VectorXd x(5), y(5), z(5);
    double new_x = 2.5;
    double new_y = 1.5;

    BicubicSpline<double> spline(x, y, z); // Construct the spline
    // Evaluate the spline at the new point
    double interpolated_value = spline(new_x, new_y);

    return 0;
}

You can find the link to the library here https://eigen.tuxfamily.org/index.php?title=Main_Page