来自:https://blog.csdn.net/helimin12345/article/details/82117848
sensor、codec、display device都是基于pixel的,高分辨率图像能呈现更多的detail,由于sensor制造和chip的限制,我们需要用到图像插值(scaler/resize)技术,这种方法代价小,使用方便。同时,该技术还可以放大用户希望看到的感兴趣区域。图像缩放算法往往基于插值实现,常见的图像插值算法包括最近邻插值(Nearest-neighbor)、双线性插值(Bilinear)、双立方插值(bicubic)、lanczos插值、方向插值(Edge-directed interpolation)、example-based插值、深度学习等算法。 插值缩放的原理是基于目标分辨率中的点,将其按照缩放关系对应到源图像中,寻找源图像中的点(不一定是整像素点),然后通过源图像中的相关点插值得到目标点。本篇文章,我们介绍Nearest-neighbor和Bilinear插值的原理及C实现。 插值算法原理如下:

1. Nearest-neighbor 最近邻插值,是指将目标图像中的点,对应到源图像中后,找到最相邻的整数点,作为插值后的输出。如下图所示,P为目标图像对应到源图像中的点,Q11、Q12、Q21、Q22是P点周围4个整数点,Q12与P离的最近,因此P点的值等于Q12的值。

由于图像中像素具有邻域相关性,因此,用这种拷贝的方法会产生明显的锯齿。
2. Bilinear 双线性插值使用周围4个点插值得到输出,双线性插值,是指在xy方法上,都是基于线性距离来插值的。 如图1,目标图像中的一点对应到源图像中点P(x,y),我们先在x方向插值:

然后,进行y方向插值:

可以验证,先进行y方向插值再进行x方向插值,结果也是一样的。值得一提的是,双线性插值在单个方向上是线性的,但对整幅图像来说是非线性的。
效果比较 将720x480分辨率图像放大到1080p,1:1截取局部画面如下,左边是最近邻放大的效果,右边是双线性效果,可以看到,双线性放大的锯齿要明显比最近邻小。

Matlab 常用的matlab缩放方法有两种,如下
B = imresize(A, scale, method) B = imresize(A, 0.5, ‘bicubic’)使用双立方插值将宽高各缩小1/2 B = imresize(A, outputSize, method) B = imresize(A, [1080,1920], ‘bilinear’)使用双线性插值缩放到1920x1080分辨率

参考 [1] https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation [2] https://en.wikipedia.org/wiki/Bilinear_interpolation |