概述
如果本文对您有帮助,请帮忙点赞、评论、收藏,感谢!
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
三种插值方法的 interpolation 参数
二. 实验代码:
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()
三. 实验结果:
原图 ↑
NN_interpolation x2 ↑
BiLinear_interpolation x2 ↑
BiCubic_interpolation x2 ↑
可以看到,最近邻插值算法放大图像后,目标图像边缘出现了明显的锯齿;而双线性和双三次插值算法没有出现明显的锯齿边缘。
四. 参考内容:
https://www.jianshu.com/p/f360462f0db4
最后
以上就是清秀枕头为你收集整理的opencv中的resize函数实现图像插值缩放的全部内容,希望文章能够帮你解决opencv中的resize函数实现图像插值缩放所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复