-3

I am currently writing a MEX file for Matlab in C to first rotate an image and then interpolate it bicubically. While researching I found a partial implementation of bicubic interpolation in C++ on https://www.paulinternet.nl/?page=bicubic. However, the code there only interpolates a 4 by 4 area and returns only a single interpolated value instead of enough values to fill the initial area.

Can anybody tell me how bicubic interpolation is applied to an entire image? Is the image divided into 4x4 chunks that are then interpolated? How do I get values for the entire area of the image? Also, what exactly are "x" and "y" in the function "bicubicInterpolate"?

double cubicInterpolate (double p[4], double x) {
    return p[1] + 0.5 * x*(p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0])));
}

double bicubicInterpolate (double p[4][4], double x, double y) {
    double arr[4];
    arr[0] = cubicInterpolate(p[0], y);
    arr[1] = cubicInterpolate(p[1], y);
    arr[2] = cubicInterpolate(p[2], y);
    arr[3] = cubicInterpolate(p[3], y);
    return cubicInterpolate(arr, x);
}

I tried to discern that from the code from this post "https://stackoverflow.com/questions/20923956/bicubic-interpolation", but I do not understand how the fraction is calculated.

Thank you for your help.

talonmies
  • 70,661
  • 34
  • 192
  • 269
Zazs
  • 1
  • 1
  • 1
    You seem to have some misunderstanding on interpolation and image resampling, in general. A bicubic interpolation only requires 4x4 area to calculate, but then you can sample as many points as you want inside the inner 2x2 area. You do this for all and every patch of adjacent pixels in the image. Yes, this is many times. Please take some time to read some tutorials on this, its out of scope for stackoverflwo to teach maths, in general – Ander Biguri Apr 18 '21 at 14:23

1 Answers1

0

Okay, I think I found a solution. During rotation, the original coordinates of a pixel are stored as floating-point numbers. These coordinates are then given to the bicubic interpolation algorithm. The algorithm samples the surrounding 4x4 square to calculate the colour or value of the pixel. This value is then returned to the rotation algorithm and stored at the new coordinates of the pixel. The Fraction or in this case "x" is the floored value of either the origin row or column.

Zazs
  • 1
  • 1