代码位置:5-ImageResize.py
import cv2
img = cv2.imread('./res/aero3.jpg')
print(img.shape[:2])
height, width = img.shape[:2]
reSize1 = cv2.resize(img, (2*width, 2*height), interpolation=cv2.INTER_CUBIC)
reSize2 = cv2.resize(img, (int(width/2), int(height/2)), interpolation=cv2.INTER_CUBIC)
cv2.imshow('reSize1', reSize1)
cv2.imshow('reSize2', reSize2)
cv2.waitKey()
cv2.destroyAllWindows()
- width, height = img.shape[:2] 获取图片的宽、高,image.shape是一个数组,取前两位
- 第一个是放大第二个是缩小,参数要转化成int类型。
interpolation参数说明:
interpolation 选项 | 所用的插值方法 |
---|---|
INTER_NEAREST | 最近邻插值 |
INTER_LINEAR | 双线性插值(默认设置) |
INTER_AREA | 使用像素区域关系进行重采样。 它可能是图像抽取的首选方法,因为它会产生无云纹理的结果。 但是当图像缩放时,它类似于INTER_NEAREST方法。 |
INTER_CUBIC | 4x4像素邻域的双三次插值 |
INTER_LANCZOS4 | 8x8像素邻域的Lanczos插值 |