天天看点

python 图像读入 reshape尺寸时的问题

可以用matplotlib模块中的image模块进行图像的读取

#coding=utf-8
import matplotlib.pyplot as plt
import matplotlib.image as mimage


image=mimage.imread('lala.jpg')

print image.shape
# show a picture
image=image.reshape(1,-1)  
#-1是根据数组大小进行维度的自动推断

 #若使用的是image=image.reshape成一行,分别为R一块, G块 ,B一块
# t=imgX1[222,:].reshape(3,32,32)
# print('t=  ' ,t.shape)
# image=np.transpose(t,(1,2,0))
image=image.reshape(1186,1920,3)

print(image.shape)

plt.imshow(image)
plt.axis('off')
plt.show()