OpenCV python resize 图像尺寸变换函数详解
cv.resize
常用的图像尺寸变换函数,计算机视觉不可能没用过,谁不需要统一数据集尺寸呐?
OpenCV函数原型: dst = cv.resize( src, dsize[, dst[, fx[, fy[, interpolation]]]] )
[]里是option项,不会有人不知道吧?
src
: 输入图片dsize
: 接受一个tuple,确定输出维数
H
∗
W
H*W
H ∗ W dst
: 选择拿那个量接这个值,python 不常用.fx
, fy
: 沿x轴,y轴的缩放系数interpolation
: 插入方式
interpolation 插值方法 cv.INTER_NEAREST 最近邻插值 cv.INTER_LINEAR 双线性插值(默认设置) cv.INTER_AREA 使用像素区域关系进行重采样 cv.INTER_CUBIC 4x4像素邻域的双三次插值 cv.INTER_LANCZOS4 8x8像素邻域的Lanczos插值
这个是按照图像平滑度的好坏排序,当然越好的算法代价越高。 官方的话: To shrink an image, it will generally look best with INTER_AREA interpolation, whereas to enlarge an image, it will generally look best with cv::INTER_CUBIC (slow) or INTER_LINEAR (faster but still looks OK).
import cv2 as cv
img = cv. imread( 'test.jpg' )
x, y = img. shape[ 0 : 2 ]
half = cv. resize( img, ( int ( y / 2 ) , int ( x / 2 ) ) )
img_test2 = cv. resize( img, ( 0 , 0 ) , fx= 0.25 , fy= 0.25 , interpolation= cv. INTER_NEAREST)