import matplotlib.pyplot as plt
img = plt.imread('orig.png')
rows,cols,colors = img.shape
img_size = rows*cols*colors
img_1D_vector = img.reshape(img_size)
img2 = img_1D_vector.reshape(rows,cols,colors)
Note that the img.shapetuple returns, and the multiple assignment rows,cols,colorsas described above allows you to calculate the number of elements needed to convert to and from a 1D vector.
img img2, :
plt.imshow(img)
plt.show()
plt.imshow(img2)
plt.show()
, python plt.show() , .
matplotlib.pyplot. jpg tif .. png , float32 dtype, jpg tif, , uint8 dtype (dtype = ); , , .
, .