双线性插值的C/C++代码

双线性插值,英文也叫 Bilinear Interpolation 是个对数据非常不错拟合方法.可以想像成在二维网格下对X和Y方向上的两次插值.具体的公式什么的就不多说了

Bilinear_interpolation 学习笔记:双线性插值的C/C++代码 学习笔记

双线性插值

这个插值方法估计很多做研究的都需要用上(当然我不使用matlab), 于是我把公式翻译成C/C++函数, 欢迎使用.如果精度不够,可以改成 双精度 double 类型.

 1 inline float 
 2 BilinearInterpolation(float q11, float q12, float q21, float q22, float x1, float x2, float y1, float y2, float x, float y) 
 3 {
 4     float x2x1, y2y1, x2x, y2y, yy1, xx1;
 5     x2x1 = x2 - x1;
 6     y2y1 = y2 - y1;
 7     x2x = x2 - x;
 8     y2y = y2 - y;
 9     yy1 = y - y1;
10     xx1 = x - x1;
11     return 1.0 / (x2x1 * y2y1) * (
12         q11 * x2x * y2y +
13         q21 * xx1 * y2y +
14         q12 * x2x * yy1 +
15         q22 * xx1 * yy1
16     );
17 }
原文地址:https://www.cnblogs.com/ybqjymy/p/14262413.html