Bicubic interpolation

Started by
0 comments, last by Barguast 14 years, 8 months ago
Hi all, I'm trying to wrap my head around interpolation. The source data is a uniform array of values which are equally spaced - much like an array of image pixels in fact. I understand bilinear interpolation, but stepping up to bicubic is causing me problems. Here is an example of what I'm trying to achieve:

d00----d10----d20----d30
|      |      |      | 
|      |      |      | 
d01----d11----d21----d31
|      |    x |      |
|      |      |      |  
d02----d12----d22----d32
|      |      |      |
|      |      |      | 
d03----d13----d23----d33

Here I have a representation of the data required to sample the point 'x'. The dXX values represent the surrounding values which serve as the interpolation input. I understand I have to weight these values based on there position relative to the point'x'. At the moment, this weight is based on the position in the containing cell - on my example, the 'x' point is roughly 3/4 the way across the cell, and 1/4 the way down. From that, I use the following equation to get the value at 'x':

float dx = 0.75; // 3/4 across
float dy = 0.25; // 1/4 down.

float x = dx;
float y = dy;
float x2 = x * x;
float x3 = x2 * x;
float y2 = y * y;
float y3 = y2 * y;

float xVal = d00 + (d10 * x) + (d01 * y) + (d20 * x2) + (d11 * x * y) + (d02 * y2) +
    (d21 * x2 * y) + (d12 * x * y2) + (d22 * x2 * y2) + (d30 * x3) + (d03 * y3) +
    (d31 * x3 * y) + (d13 * x * y3) + (d32 * x3 * y2) + (d23 * x2 * y3) + (d33 * x3 * y3);

But.. it doesn't work. I think I'm almost there, but I'm having trouble figuring out where I'm going wrong. Has anyone done this before, or can someone figure out where I'm going wrong?
Using Visual C++ 7.0
Advertisement
Gah, I post this and then finally get it working.

float dx = 0.75;float dy = 0.25;float i1 = cubic(d00, d10, d20, d30, dx);float i2 = cubic(d01, d11, d21, d31, dx);float i3 = cubic(d02, d12, d22, d32, dx);float i4 = cubic(d03, d13, d23, d33, dx);float fVal = cubic(i1, i2, i3, i4, dy);

Where cubic is
private static float cubic(float v0, float v1, float v2, float v3, float d){    float p = (v3 - v2) - (v0 - v1);    float q = (v0 - v1) - p;    float r = v2 - v0;    float s = v1;    float d2 = d * d;    float d3 = d2 * d;    return (p * (d3)) + (q * d2) + (r * d) + s;  }

It seems to be doing the trick, anyway!
Using Visual C++ 7.0

This topic is closed to new replies.

Advertisement