| 空间首页 | 生活日记 | 原创作品 | 博客文章 | 共享资源 | 新闻网摘 | 我的收藏 | 社区活动 | 博客留言 |
进入后台
|
文章分类
最新评论
文章存档在图像放大算法中,双线性插值简单而有效,可以让结果图像显得平滑而不是呈现锯齿状。它的原理很简单,把临近四个点的像素值与相应的贡献系数相乘后加起来就可以了。
下面的代码是用于FerryMan Fractal中的图象插值算法:
//bilinear interpolation
int x1 = ((int)x) % bp.bmWidth;
int y1 = ((int)y) % bp.bmHeight;
int x2 = (u1 + 1) % bp.bmWidth;
int y2 = (v1 + 1) % bp.bmHeight;
// calculate fractional parts of u and v
float fracx = x - floorf(x);
float fracy = y - floorf(y);
// calculate weight factors
float w1 = (1.0f - fracx) * (1.0f - fracy);
float w2 = fracx * (1.0f - fracy);
float w3 = (1.0f - fracx) * fracy;
float w4 = fracx * fracy;
// get the result
return point(x1, y1) * w1 + point(x2, y1) * w2 + point(x1, y2) * w3 + point(x2, y2) * w4;学习