c++opencvimage-processinginterpolationbilinear-interpolation

Bilinear interpolation artifacts


im trying to do Bilinear Interpolation after rotation in c++ using openCv features, but without using bilinear interpolation implemented in openCv.

At my output images, there are always some artifacts (totaly different colours of pixels).

Im using this formula:

Bilinear interpolation formula

Im not using ceil from math.h, but cvRound() from openCV.

So my input is: lena

And my output with artifacts is:

Lena after rotation and interpolation

Im using that formula for all RGB values so for B it looks:

int l = cvRound(xn);
int k = cvRound(yn);

float a = xn-l;
float b = yn-k;

uchar B = (1-a)*(1-b)*src.at<cv::Vec3b>(l,k).val[0]+a*(1-b)*src.at<cv::Vec3b>(l+1,k).val[0]+b*(1-a)*src.at<cv::Vec3b>(l,k+1).val[0]+a*b*src.at<cv::Vec3b>(l+1,k+1).val[0];

xn and yn are coordinates in transformation MAT, they are floats.

As you can see most of the output picture is calculated as it should be, but somehow they are few artifacts, that make me no sense. I need to get rid of them.

Thanks for any advice.


Solution

  • The abnormal green pixels that you see must be caused by underflow (-1 becoming +255) in the green channel.

    Try clamping the interpolation expression to [0,255] before assignment to B.