Summary:
双线性插值(Bilinear Interpolation) - 马语者 - 博客园
Intro:
双线性插值(Bilinear Interpolation):双线性插值是用原图像中4(2*2)个点计算新图像中1个点,效果略逊于双三次插值,速度比双三次插值快,属于一种平衡美,在很多框架中属于默认算法。
1. Nearest Interpolation
最近邻法不需要计算只需要寻找原图中对应的点,所以最近邻法速度最快,但是会破坏原图像中像素的渐变关系
2. Linear Interpolation
3. Bilinear Interpolation
双线性插值实际上是从2个方向一共进行了3次单线性插值
如图所示,先在x方向求2次单线性插值,获得R1(x, y1)、R2(x, y2)两个临时点,再在y方向计算1次单线性插值得出P(x, y)(实际上调换2次轴的方向先y后x也是一样的结果)
===> 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:
or
===> 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:
几何中心点重合对应公式
==> 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:
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,那么源图像和目标图像各个像素之间的对应关系如下。如果没有这个中心对齐,根据基本公式去算,就会得到左边这样的结果;而用了对齐,就会得到右边的结果:
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"