1.reszie
img = cv2.imread('./img/'+file)
print(img.shape)
height, width = img.shape[:2]
size = (300,600)
shrink = cv2.resize(img, size, interpolation = cv2.INTER_AREA)
shrink2 = cv2.resize(img, (600,300))
aa = np.resize(img, (300,600))
img.resize((300,600))
用cv2resize函数:
cv2.reszie(img, (w,h))而不是cv2.reszie(img, (h,w))
所以假如现在一张图片尺寸是(1080,1920)....(h,w) 就是1080行,1920列
你想把他变成600行,800列,(h,w)=(600, 800)
res = cv2.reszie(img, (800, 600)) ,插值方式默认,这才是对的,因为resize操作都是从先x方向在y方向
用PIL也是一样的,resize参数也是(w,h)
img= Image.open(file)path) img = img.resize([width, 32], Image.ANTIALIAS)
但是想用numpy的resize来改变图片大小是没有用的,不管是np.reszie还是直接img.resize,我看了下生成的图片根本不是,全是乱来的像素点,以后切记。用cv2的resize函数吧
2,reshape
reshape可以直接用numpy的,
img.shape=(32,32)
img2 = img.reshape((-1,32,32,1))