如果本文对您有帮助,请帮忙点赞、评论、收藏,感谢!
python 为例
一. 函数原型
dst=cv.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])
参数含义:
src:input image.
dst:output image; it has the size dsize (when it is non-zero) or the size computed from src.size(), fx, and fy; the type of dst is the same as of src.
dsize:output image size; if it equals zero, it is computed as:
dsize = Size(round(fx*src.cols), round(fy*src.rows))
Either dsize or both fx and fy must be non-zero.
fx :scale factor along the horizontal axis; when it equals 0, it is computed as
(double)dsize.width/src.cols
fy :scale factor along the vertical axis; when it equals 0, it is computed as
(double)dsize.height/src.rows
interpolation:interpolation method, see InterpolationFlags
二. 实验代码:
import cv2
import numpy as np
# 读入灰度图像
im_path='../paojie_g.jpg'
img = cv2.imread(im_path,0)
# 注意应该先写宽度img.shape[1]*2,再写高度img.shape[0]*2
NN_interpolation = cv2.resize(img,(img.shape[1]*2,img.shape[0]*2),interpolation=cv2.INTER_NEAREST)
BiLinear_interpolation = cv2.resize(img,(img.shape[1]*2,img.shape[0]*2),interpolation=cv2.INTER_LINEAR)
BiCubic_interpolation = cv2.resize(img,(img.shape[1]*2,img.shape[0]*2),interpolation=cv2.INTER_CUBIC)
cv2.imshow('NN_interpolation',NN_interpolation)
cv2.imwrite('NN_interpolation.jpg',NN_interpolation)
cv2.imshow('BiLinear_interpolation',BiLinear_interpolation)
cv2.imwrite('BiLinear_interpolation.jpg',BiLinear_interpolation)
cv2.imshow('BiCubic_interpolation',BiCubic_interpolation)
cv2.imwrite('BiCubic_interpolation.jpg',BiCubic_interpolation)
cv2.waitKey(0)
cv2.destroyAllWindows()
三. 实验结果:
可以看到,最近邻插值算法放大图像后,目标图像边缘出现了明显的锯齿;而双线性和双三次插值算法没有出现明显的锯齿边缘。
四. 参考内容:
https://www.cnblogs.com/wojianxin/p/12517101.html
https://blog.csdn.net/Ibelievesunshine/article/details/104943436