我是靠谱客的博主 清秀枕头,这篇文章主要介绍opencv中的resize函数实现图像插值缩放,现在分享给大家,希望可以做个参考。

如果本文对您有帮助,请帮忙点赞、评论、收藏,感谢!

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中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(130)

评论列表共有 0 条评论

立即
投稿
返回
顶部