圖像的擴(kuò)大與縮小有專門的一個(gè)函數(shù),cv2.resize(),那么關(guān)于伸縮需要確定的就是縮放比例,可以是x與y方向相同倍數(shù),也可以單獨(dú)設(shè)置x與y的縮放比例。另外一個(gè)就是在縮放以后圖像必然就會(huì)變化,這就又涉及到一個(gè)插值問題。那么這個(gè)函數(shù)中,縮放有幾種不同的插值(interpolation)方法,在縮小時(shí)推薦cv2.INTER_ARER,擴(kuò)大是推薦cv2.INTER_CUBIC和cv2.INTER_LINEAR。默認(rèn)都是cv2.INTER_LINEAR
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('flower.jpg')
# 插值:interpolation
# None本應(yīng)該是放圖像大小的位置的,后面設(shè)置了縮放比例,
#所有就不要了
res1 = cv2.resize(img,None,fx=2,fy=2,interpolation=cv2.INTER_CUBIC)
#直接規(guī)定縮放大小,這個(gè)時(shí)候就不需要縮放因子
height,width = img.shape[:2]
res2 = cv2.resize(img,(2*width,2*height),interpolation=cv2.INTER_CUBIC)
plt.subplot(131)
plt.imshow(img)
plt.subplot(132)
plt.imshow(res1)
plt.subplot(133)
plt.imshow(res2)
來源:https://blog.csdn.net/on2way/article/details/46801063
cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
(消化后補(bǔ)全)