首页 > 其他 > 详细

opencv实现对图像的插值操作 最近邻、双线性、双三次

时间:2020-03-18 16:16:46      阅读:169      评论:0      收藏:0      [点我收藏+]

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

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 参数
 

二. 实验代码:

 1 import cv2
 2 import numpy as np 
 3 
 4 # 读入灰度图像
 5 im_path=../paojie_g.jpg
 6 img = cv2.imread(im_path,0)
 7 # 注意应该先写宽度img.shape[1]*2,再写高度img.shape[0]*2
 8 NN_interpolation = cv2.resize(img,(img.shape[1]*2,img.shape[0]*2),interpolation=cv2.INTER_NEAREST)
 9 BiLinear_interpolation =  cv2.resize(img,(img.shape[1]*2,img.shape[0]*2),interpolation=cv2.INTER_LINEAR)
10 BiCubic_interpolation = cv2.resize(img,(img.shape[1]*2,img.shape[0]*2),interpolation=cv2.INTER_CUBIC)
11 
12 cv2.imshow(NN_interpolation,NN_interpolation)
13 cv2.imwrite(NN_interpolation.jpg,NN_interpolation)
14 cv2.imshow(BiLinear_interpolation,BiLinear_interpolation)
15 cv2.imwrite(BiLinear_interpolation.jpg,BiLinear_interpolation)
16 cv2.imshow(BiCubic_interpolation,BiCubic_interpolation)
17 cv2.imwrite(BiCubic_interpolation.jpg,BiCubic_interpolation)
18 cv2.waitKey(0)
19 cv2.destroyAllWindows()

 


三. 实验结果:

技术分享图片
原图 ↑
 
技术分享图片
NN_interpolation x2 ↑
 
技术分享图片
BiLinear_interpolation  x2 ↑
 
技术分享图片
BiCubic_interpolation   x2 ↑
 

        可以看到,最近邻插值算法放大图像后,目标图像边缘出现了明显的锯齿;而双线性和双三次插值算法没有出现明显的锯齿边缘。


四. 参考内容:

  https://www.jianshu.com/p/f360462f0db4

opencv实现对图像的插值操作 最近邻、双线性、双三次

原文:https://www.cnblogs.com/wojianxin/p/12517101.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!