区别
reshape
import cv2
img = cv2.imread('09.jpg')
s = img.shape
print(s)
n_rows = s[0]
n_cols = s[1]
n_channels = s[2]
res = img.reshape([250,3000 ])
cv2.imshow('res',res)
cv2.imwrite('res.jpg',res)
res2 = img.reshape([750,1000])
cv2.imshow('res2',res2)
cv2.imwrite('res2.jpg',res2)
cv2.waitKey(0)

- reshape 是对整个矩阵进行重新排布,比如原来整个图片的尺寸是 500 * 500 * 3 通道 = 750000个像素值,那么当我们对他进行 reshape 的时候,最后还是要保持 750000个像素值,一个不能多一个不能少。所以我可以让他 reshape 成 (1, 750000) 也可以 reshape 成 (3,250000)
resize
import cv2
img = cv2.imread('1.jpg')
img_resize = cv2.resize(img,(300,300))
cv2.imshow('img_resize',img_resize)
cv2.imwrite('img_resize.jpg',img_resize)
cv2.waitKey(0)

- resize 可以进行降采样和升采样,可以变成任何尺寸,不需要按照原来的 shape 的尺寸