Bilinear Interpolation (BI) is a very useful mathematical approach that you can use to estimate any given value in a two dimensional grid.
If you don’t like Matlab (me neither), then the following C/C++ function may be useful to you. You can also easily use this code in other C-like programming languages e.g. Java with little modification. You can also use double type if the precision is of importance.
For more information on Bilinear Interpolation, you can visit the Wiki in details.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // https://helloacm.com inline float BilinearInterpolation(float q11, float q12, float q21, float q22, float x1, float x2, float y1, float y2, float x, float y) { float x2x1, y2y1, x2x, y2y, yy1, xx1; x2x1 = x2 - x1; y2y1 = y2 - y1; x2x = x2 - x; y2y = y2 - y; yy1 = y - y1; xx1 = x - x1; return 1.0 / (x2x1 * y2y1) * ( q11 * x2x * y2y + q21 * xx1 * y2y + q12 * x2x * yy1 + q22 * xx1 * yy1 ); } |
// https://helloacm.com inline float BilinearInterpolation(float q11, float q12, float q21, float q22, float x1, float x2, float y1, float y2, float x, float y) { float x2x1, y2y1, x2x, y2y, yy1, xx1; x2x1 = x2 - x1; y2y1 = y2 - y1; x2x = x2 - x; y2y = y2 - y; yy1 = y - y1; xx1 = x - x1; return 1.0 / (x2x1 * y2y1) * ( q11 * x2x * y2y + q21 * xx1 * y2y + q12 * x2x * yy1 + q22 * xx1 * yy1 ); }
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
275 wordsloading...
Last Post: C/C++ Coding Exercise - Find Minimum in Rotated Sorted Array - Leetcode Online Judge
Next Post: How To Block Google Domains in Adsense?
This code will fail if x2 == x1 or y2 == y1 as it will result in a div by zero. It should properly detect when you’re on one of the Qxx lines and collapse to a 1D interpolation.
Yes, you are absolutely right. If it is on the lines, then it is not bilingual interpolation.
Hi,
I need a detail explanation for this.
Please help regarding this
Inteligent