opencv函数
cv2.resize(img, (w, h), interpolation=cv2.INTER_CUBIC)
插值方法
opencv提供了5种插值方法:
interpolation | 插值方法 | 说明 |
---|---|---|
INTER_NEAREST | 最近邻插值 | 选取离目标点最近的点作为新的插入点 |
INTER_LINEAR | 双线性插值(默认) | 以距离为权重 |
INTER_AREA | 区域插值 | 像素关系重采样 |
INTER_CUBIC | 4x4像素邻域的双三次插值 | 16个采样点加权平均 |
INTER_LANCZOS4 | 8x8像素邻域的Lanczos插值 | 模板权重 |
总结
如果要缩小图像,推荐使用INTER_AREA插值;
如果要放大图像,INTER_CUBIC。
PIL函数
img.resize((width, height),Image.ANTIALIAS)
插值方法
PIL提供了4种插值方法:
interpolation | 插值方法 |
---|---|
Nearest | 最近邻插值 |
Bilinear | 双线性插值 |
Bicubic | 两次立方插值算法 |
Antialias | Lanczos算法 |