0

I have a matrix of size 28x22. The first row, last two rows, first column and last two columns (marked in red and green color) are empty. These columns and rows are supposed to be filled by bicubic interpolation.

I have read several posts on SO and internet about bicubic interpolation but unfortunately, I am not able to understand it. Furthermore, I read that bicubic interpolation need the knowledge of 4x4 grid around the pixel that need to be interpolated. However, since the rows and columns are at boundary so, I don't have a 4 x 4 grid around them.

image

skm
  • 5,015
  • 8
  • 43
  • 104

1 Answers1

1

Prologue

you need to extrapolate the unknown areas. You need to decide from what info you want to extrapolate the data. For example you want to use points near the unknonw area or use points dispersed along the whole known area. Both approaches are valid but have different results matching different needs.

I will be using the close points to the unknown area. Let me start with simpler case:

  1. 1D Linear extrapolation

    Linear extrapolation uses line formed by 2 known points. so for example assume this vector:

    1D linear extrapolation

    The x axis is the vector/array index and y axis is value of the cell. So I took 2 last known points (blue) and form a line from it (green). Where it intersects next array positions there are your extrapolated values (red). So in C++ it looks like this:

    float a[8]={ 1.0,2.0,4.0,8.0,10.0,7.0,0.0,0.0 }; // your vector (last two numbers are unknown)
    a[6]=a[4]+((a[5]-a[4])*2.0); // =4.0
    a[7]=a[4]+((a[5]-a[4])*3.0); // =1.0
    
  2. 1D cubic extrapolation

    It is similar to #1 but instead of line you use 4 control point cubic curve in parametric polynomial form. Most cubic curves are constructed so that if parameter t=0 you will obtain second control point and if t=1 you will obtain third control point. If you use t=<0,1> then you will iterate between them smoothly. Hove ever we need to expand the range after the last control point so t>=3 with step 1 for next point position. So:

    1D cubic extrapolation

    float a[8]={ 1.0,2.0,4.0,8.0,10.0,7.0,0.0,0.0 }; // your vector (last two numbers are unknown)
    float a0,a1,a2,a3; // your cubic curve polynomial coefficients (computed from 4 control points a[2],a[3],a[4],a[5])
    float t; // curve parameter
    // here compute the a0,a1,a2,a3
    t=3.0; a[6]=a0+a1*t+a2*t*t+a3*t*t*t*t;
    t=4.0; a[7]=a0+a1*t+a2*t*t+a3*t*t*t*t;
    

    Now how to obtain the a0,a1,a2,a3 coefficients? Yo can use any interpolation polynomial. My favorite is this (bullet #3):

    So here it is (hope I did not some silly index mistake while replacing pi with a[2+i]):

    float  d1,d2;
    d1=0.5*(a[4]-a[2]);
    d2=0.5*(a[5]-a[3]);
    a0=a[3];
    a1=d1;
    a2=(3.0*(a[4]-a[3]))-(2.0*d1)-d2;
    a3=d1+d2+(2.0*(-a[4]+a[3]));
    
  3. 2D Bi-cubic extrapolation

    This is just separating the problem into set of 1D cubic extrapolations. If you look at the graphs from #2 from above you will see for bi-cubic this:

    2D bi-cubic extrapolation

    So first you compute unknown columns (which you can) and then from it compute the missing rows (or vice versa).

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380