双线性插值(Bilinear Interpolation)

在图像放大算法中,双线性插值简单而有效,可以让结果图像显得平滑而不是呈现锯齿状。它的原理很简单,把临近四个点的像素值与相应的贡献系数相乘后加起来就可以了。

 

// 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;

本文属Span Zhang(张友邦)原创,转载请注明出处。

中国原创分形艺术、中国原创分形软件第一站

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值