Bicubic Interpolation in CUDA and C / How is bicubic interpolation applied to an entire image?

533 views Asked by At

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.

1

There are 1 answers

0
Zazs On BEST ANSWER

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.