cv2.resize()
cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])
src,待处理图像
dsize,目标尺寸,数值自定义,以元组形式输入
fx,x轴水平方向方向缩放比例
fy,竖直y轴反向缩放比例
interpolation,插值类型自定义:INTER_NEAREST,INTER_LINEAR,INTER_AREA,INTER_CUBIC,INTER_LANCZOS4
使用实例
import cv2
im = imread('A://image.png'),cv2.IMREAD_UNCHANGED)
scale = 0.5
height = int(im.shape[0]*scale)
width = int(im.shape[1]*scale)
# width = 512
desireSize = (width,height)
res = cv2.resize(im,dsize,interpolation = cv2.INTER_AREA)
cv2.imwrite('A://resized_image.png',res)
mask = cv2.resize(mask_512.astype(np.float32),
(w, h),
interpolation = cv2.INTER_LINEAR)