Bilinear Interpolation 双线性插值

Summary:

 双线性插值(Bilinear Interpolation) - 马语者 - 博客园

Intro:

一篇文章为你讲透双线性插值 - 知乎

双线性插值(Bilinear Interpolation):双线性插值是用原图像中4(2*2)个点计算新图像中1个点,效果略逊于双三次插值,速度比双三次插值快,属于一种平衡美,在很多框架中属于默认算法。

1. Nearest Interpolation

16ebb3abcce702389f5fa10278364d8f.png

最近邻法不需要计算只需要寻找原图中对应的点,所以最近邻法速度最快,但是会破坏原图像中像素的渐变关系

2. Linear Interpolation

e305665f4dd1873597f0c84f65904718.png

51044b42c8c42797a25c1554e3bd7868.png

41b6b54412d77682b002ffe0852578a1.png

3. Bilinear Interpolation

双线性插值实际上是从2个方向一共进行了3次单线性插值

253c0d83844fde8daa25b27677dc3db5.png

 如图所示,先在x方向求2次单线性插值,获得R1(x, y1)、R2(x, y2)两个临时点,再在y方向计算1次单线性插值得出P(x, y)(实际上调换2次轴的方向先y后x也是一样的结果)

d3e55e7131552ed3e6a95dc94b17e32b.png

 ===> as shown in section 1, since we pick the 4 anchor points by taking ceil(des_x * src_w/des_w) and floor(des_x * src_w/des_w), we have x2 - x1 = 1 and the same applies to y, and we can the simplify the result to:

d62162357f674e9283a2a876dff47115.png

 or

1b1b20a673799d36d778a0fae58657c3.png

 ===> the weight of each point is dependent on its diagonal counterpart.

===> in case of exact division, i.e. a perfect match of des_coord with src_coord, the other 3 points will naturally have weight set to 0.

see Understanding Bilinear Image Resizing | SuperComputer’s Blog

we can also rewrite the equation as:

where A, B, C, D are the value of the 4 nearest points

4. Deep Learning Correction for the base Bilinear Interpolation

The issue: 根据坐标系的不同,产生的结果不同

I. 无论我们采用什么坐标系,最左侧和最右侧(最上侧和最下侧)的点是不“公平的”

II. 整体的图像相对位置会发生变化, 产生相对的位置信息损失 ==> this is largely due to the unjustly favored origin issue

The problem: 计算机通过卷积神经网络提取图像中的深层信息,在这个过程中,我们人眼难以发现的变化也许会发生想象之外的变化

The solution:

 几何中心点重合对应公式

092fc21295cdb2e31006102d71d5c968.png

==> any constant offset can get rid of the bias for origin/axis points

==> take the pixel value of negative coord to be 0 and we get a gradual change to the src_origin

==> the proof is simple, but beware of the subtle difference between translational correction term and fixing the ratio to S_gc/D_gc:

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkBFdmVyTm9vYg,size_20,color_FFFFFF,t_70,g_se,x_16

ok, so keeping the ratio as (sw - 1) / (dw - 1) is actually align_corner = True, but the interpretation wrong; for more on "align_corner" see【上采样问题】双线性插值的几何中心点重合与align_corners_Hali_Botebie的博客-优快云博客_双线性插值几何中心

当align_corners = True时,(src) 像素被视为网格的格子上的点,拐角处的像素对齐.可知是点之间是等间距的
当align_corners = False时, (src) 像素被视为网格的交叉线上的点, 拐角处的点依然是原图像的拐角像素 ==> not necessarily, see What we should use align_corners = False - vision - PyTorch Forums,但是差值的点间却按照上图的取法取,导致点与点之间是不等距的

在这里插入图片描述

in short:

align_corners = True ==> use the ratio (sw - 1) / (dw - 1), by which we can enforce mapping of sw -1 to dw - 1

align_corners = False ==> use the ratio (sw / dw), which is the true ratio demanded by the alg. 

Guide and Example for GC-alignment: 

Bilinear interpolation – x-engineer.org

三十分钟理解:线性插值,双线性插值Bilinear Interpolation算法_Bin 的专栏-优快云博客_线性插值

 源图像和目标图像的原点(0,0)均选择左上角,然后根据插值公式计算目标图像每点像素,假设你需要将一幅5x5的图像缩小成3x3,那么源图像和目标图像各个像素之间的对应关系如下。如果没有这个中心对齐,根据基本公式去算,就会得到左边这样的结果;而用了对齐,就会得到右边的结果:

  SouthEastSouthEast

for more details, see Wiki:

https://en.wikipedia.org/wiki/Bilinear_interpolation

a full demo with code:

Understanding Bilinear Image Resizing | SuperComputer’s Blog

on the bugged implementations of and generation confusion about the term "bilinear resize"

Bilinear down/upsampling, aligning pixel grids, and that infamous GPU half pixel offset | Bart Wronski

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值