Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bilinear Interpolation #20

Closed
unrealwill opened this issue Dec 1, 2022 · 0 comments
Closed

Bilinear Interpolation #20

unrealwill opened this issue Dec 1, 2022 · 0 comments

Comments

@unrealwill
Copy link

I was reading your code, and noticed that the Bilinear interpolation is not doing what we usually called Bilinear interpolation, (but something that look like a usual mistake).

IntensityType Interpolation::bilinear(const cv::Mat& img, float x, float y)
{
int x0 = (int) std::floor(x);
int y0 = (int) std::floor(y);
int x1 = x0 + 1;
int y1 = y0 + 1;
float x_weight = x - x0;
float y_weight = y - y0;
float interpolated =
img.at<IntensityType>(y0, x0) * x_weight + img.at<IntensityType>(y0, x1) * (1 - x_weight) +
img.at<IntensityType>(y1, x0) * x_weight + img.at<IntensityType>(y1, x1) * (1 - x_weight) +
img.at<IntensityType>(y0, x0) * y_weight + img.at<IntensityType>(y1, x0) * (1 - y_weight) +
img.at<IntensityType>(y0, x1) * y_weight + img.at<IntensityType>(y1, x1) * (1 - y_weight);
return (IntensityType) (interpolated * 0.25f);
}

https://en.wikipedia.org/wiki/Bilinear_interpolation (see on unit square)

In Bilinear interpolation (like multi-linear interpolation) interpolated values for the vertices are exact.
There should be some crossed term xweight*yweight ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant