Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bilinear & Bicubic Interpolation

Started by smkc_be Oct 1, 2001 at 9:22 PM 0 replies 1.6k views
Original Post
smkc_be
smkc_be
Does anyone know the algorithm for Bilinear or Bicubic Interpolation for doing arbitrary scaling to a 2D image? I''ve looked all over the net, but haven''t seen any good descriptions of the technique and no listing of the algorithms. Thanks
marcus256
marcus256
quote:
Original post by smkc_be
Does anyone know the algorithm for Bilinear or Bicubic Interpolation for doing arbitrary scaling to a 2D image? I''ve looked all over the net, but haven''t seen any good descriptions of the technique and no listing of the algorithms. Thanks


Bilinear is actually very simple. Bilinear interpolation between four pixels with the following orientation (hope this figure works):

+---> x
|
|
\/
y


p1 p2
x--------x
| |
| |
| |
x--------x
p3 p4

float p1, p2, p3, p4; // monochrome pixel values
float x, y; // (x,y) ranging (0..1)
float p12, p34; // temporary results
float p; // result

p12 = p1 * (1.0-x) + p2 * x;
p34 = p3 * (1.0-x) + p4 * x;
p = p12 * (1.0-y) + p34 * y;


You get the general idea: perform linear interpolation along X twice, and then perform linear interpolation along Y once (between the two "x-values).
Trilinear interpolation is similar, except you interpolate between 8 points (resulting in 7 interpolation operations).

Bicubic interpolation is also similar, but you use 16 points instead of 4 points (still 3 interpolation operations).

Linear interpolation uses the "weighting factors" (1-x) and x. Cubic interpolation uses four weighting factors (one for each point):

w1 = -(1.0/6.0)*x*(x-1.0)*(x-2.0);
w2 = (1.0/2.0)*(x*x-1.0)*(x-2.0);
w3 = -(1.0/2.0)*x*(x+1.0)*(x-2.0);
w4 = (1.0/6.0)*x*(x*x-1.0);

(snippet from some old code I had on my disk)

Hope you understand what I mean...

Anyway: here are a few words of advice:

- Cubic interpolation does not look THAT much better than linear interpolation (important for sound, not for images)
- Using interpolation for resampling images only works for upsampling (magnifying). Minification must be done using low pass filtering - and THEN interpolation (this is what is called MipMapping).

/Marcus

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.