OpenCV图像插值方法的比较

算机视觉任务中,经常要使用图像插值方法来改变图像的尺寸,如图像金字塔、图像超分辨的预处理等,可以说图像插值方法是计算机视觉任务的基本操作。本文对opencv里的图像插值方法进行分析比较。

opencv里改变图像尺寸的函数是resize,下边是opencv2.3.14的resize函数的参考文档:

C++: void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR)

Parameters:
  • 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:

    \texttt{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

    \texttt{(double)dsize.width/src.cols}

  • fy –

    scale factor along the vertical axis; when it equals 0, it is computed as

    \texttt{(double)dsize.height/src.rows}

  • interpolation –

    interpolation method:

    • INTER_NEAREST - a nearest-neighbor interpolation
    • INTER_LINEAR - a bilinear interpolation (used by default)
    • 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.
    • INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood
    • INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood

参考文档详细内容请参考:https://docs.opencv.org/2.4.13/modules/imgproc/doc/geometric_transformations.html?highlight=resize#cv2.resize。简单说明一下,src是输入图像,dst是输出图像,dsize是输出图像的尺寸,由用户指定,fxfy是缩放因子,dsizefx、fy两组参数只能选择一组使用,interpolation是可选的插值方法。

本文主要对opencv不同的插值方法进行比较,也就是INTER_NEAREST、INTER_LINEAR、INTER_AREA、INTER_CUBICINTER_LANCZOS4。实验所使用的图像为Art:

Art 1390×1110

原始图像尺寸为1390×1110,选用的缩放因子为3,使用PSNR与SSIM作为评价标准。本文内容主要分为以下几个部分:

  • 插值方法之间的相似度比较
  • 插值方法下采样上采样的比较——BGR三通道
  • 插值方法下采样上采样的比较——亮度通道Y,由CV_BGR2YUV转换
  • 插值方法下采样上采样的比较——亮度通道Y,由CV_BGR2YCrCb转换

1、插值方法之间的相似度比较

对于原始尺寸1390×1110的Art图像,按照缩放因子3对原始图像进行下采样,得到低分辨率图像。使用不同的插值方法进行这一操作,比较低分辨率图像之间的相似程度,结果如下:

 nearestbilinearbicubicarealanczos4
nearest 27.261/0.85027.002/0.84328.300/0.88226.994/0.842
bilinear  50.176/0.99938.294/0.98049.538/0.998
bicubic   37.007/0.97555.615/0.999
area    36.966/0.975
lanczos4     

由上表可知,插值方法bilinear、bicubiclanczos4最相似度最高。

2、插值方法下采样上采样的比较——BGR三通道

对原始图像,按照缩放因子3对原始图像下采样再上采样,opencv读入彩色图像为BGR三通道图像,上采样下采样操作分别对每一个单通道进行。下表的结果是使用对应插值方法得到的结果原始图像(ground truth)的比较结果:

down|upnearestbilinearbicubicarealanczos4
nearest25.439/0.75628.052/0.84027.643/0.83326.863/0.80027.529/0.827
bilinear30.019/0.86933.044/0.91733.429/0.92031.278/0.89033.281/0.915
bicubic29.837/0.86633.009/0.91733.185/0.91831.101/0.88832.971/0.911
area30.734/0.87932.848/0.91034.031/0.92331.872/0.89534.208/0.925
lanczos429.807/0.86532.940/0.91633.122/0.91731.070/0.88732.915/0.911

3、插值方法下采样上采样的比较——亮度通道Y,由CV_BGR2YUV转换

对原始图像,首先将读入的BGR彩色图像使用opencv的函数CV_BGR2YUV转换到YUV三通道,然后再将Y通道分离出来,仅对Y通道做下采样再上采样。下表的结果是对Y通道使用对应的插值方法得到的结果原始图像的Y通道比较的结果:

down|upnearestbilinearbicubicarealanczos4
nearest25.604/0.766 28.243/0.84727.828/0.840 27.061/0.80827.710/0.833
bilinear30.192/0.874 33.161/0.92033.517/0.923 31.464/0.89433.365/0.917
bicubic30.006/0.871 33.124/0.920 33.271/0.92031.284/0.892 33.051/0.914
area30.914/0.884 32.991/0.91334.136/0.92632.067/0.89934.305/0.928
lanczos429.975/0.871 33.053/0.919 33.206/0.92031.250/0.891 32.995/0.913

4、插值方法下采样上采样的比较——亮度通道Y,由CV_BGR2YCrCb转换

对原始图像,首先将读入的BGR彩色图像使用opencv的函数CV_BGR2YCrCb转换到YCrCb三通道,然后再将Y通道分离出来,仅对Y通道做下采样再上采样。下表的结果是对Y通道使用对应的插值方法得到的结果原始图像的Y通道比较的结果:

down|upnearestbilinearbicubicarealanczos4
nearest25.726/0.76528.347/0.847 27.931/0.840 27.155/0.80827.812/0.833
bilinear30.271/0.87433.213/0.920 33.565/0.923 31.514/0.894 33.409/0.918
bicubic30.082/0.87133.174/0.92033.317/0.92131.330/0.89233.093/0.914
area31.002/0.88433.039/0.91434.184/0.92632.121/0.89934.350/0.928
lanczos430.051/0.87133.104/0.92033.252/0.92131.296/0.89133.035/0.914
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值