from PIL import Image import numpy as npimg1 =Image.open( " f:\cat.jpg " ) # pix_data=np.array(img1.getdata()) # print(pix_data) # np.savetxt("f:\pix_data.txt",pix_data) pix_data2 =np.array(img1.getdata()).reshape(img1.size[0],img1.size[1],
from PIL import Image import numpy as np img1=Image.open("f:\cat.jpg") #pix_data=np.array(img1.getdata()) #print(pix_data) #np.savetxt("f:\pix_data.txt",pix_data) pix_data2=np.array(img1.getdata()).reshape(img1.size[0],img1.size[1],3) pix_data3=pix_data2[0:200,0:,0:2] im=Image.fromarray(np.uint8(pix_data3)) im.show()
参考:https://stackoverflow.com/questions/384759/how-to-convert-a-pil-image-into-a-numpy-array