[OpenCV4] 缩放图像之 cv :: resize() 与插值方法

官方API文档:参考链接

对应头文件:#include <opencv2/imgproc.hpp>

1.参数解释

src:输入图像

dst:输出图像

dsize:输出图像的尺寸,如果传入参数0,则按照以下公式计算

dsize = Size(round(fx*src.col, fy*src.rows))

fx:水平方向的缩放因子,如果取默认参数0,则按照以下公式计算

(double)dsize.width  / src.cols

fy:垂直方向的缩放因子,如果取默认参数0,则按照以下公式计算

(double)dsize.height / src.rows 

interpolation:插值方法,对于缩小图片的情况,cv::resize()函数会

默认选择INTER_AREA作为插值方法,对于放大图片的操作,通常最

最好选用cv::INTER_CUBIC(较慢),或者使用快速效果稍弱的

cv::INTER_LINER插值方法

注意:dsize和(fx,fy)参数不能同时取0

2.插值标记

InterpolationFlags是一个元组:

enum cv::InterpolationFlags

在头文件:#include <opencv2/imgproc.hpp> 中定义

官方API文档:参考链接

2.1 INTER_NEAREST

nearest neighbor interpolation 最近邻插值

 

2.2 INTER_LINEAR

nearest neighbor interpolation 双线性插值

 

2.3 INTER_CUBIC

bicubic interpolation 双三次插值

 

2.4 INTER_AREA

resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method 像素区域重采样插值

该方法是缩小图像时的推荐方法,不会产生摩尔纹;当该方法被用于放大图片的时候,其效果与最近邻插值的效果相似

 

2.5 INTER_LANCZOS4

Lanczos interpolation over 8x8 neighborhood 

使用Lanczos resampling方法的插值方法,该方法以Cornelius Lanczos的名字命名,使用Lanczos Kernel 来进行重建插值

OpenCV提供的是8*8像素区域的邻域的采样

 

2.6 INTER_LINEAR_EXACT

Bit exact bilinear interpolation 位精确双线性插值

 

2.7 INTER_MAX

mask for interpolation codes 掩码插值

 

2.8 WARP_FILL_OUTLIERS

flag, fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero 填充满放大后的目标图像,如果目标图像中对应原图的像素已经溢出,则将其置0

 

2.9 WARP_INVERSE_MAP

flag, inverse transformation 反变换 

For example, linearPolar or logPolar transforms:

  • flag is not set: dst(ρ,ϕ)=src(x,y)
  • flag is set: dst(x,y)=src(ρ,ϕ)

当使用这个Flag的时候,对应的变换反过来

3.Demo

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值