读取部分结果
程序
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from PIL import Image def ImagetoData(num=100): filename = 'face/face' data = [] for i in range(num): filename = 'face/face'+ str(i) + '.jpg' # 读取图片 im = Image.open(filename) # 显示图片 # im.show() width,height = im.size im = im.convert("L") picdata = im.getdata() picdata = list(picdata) data.append(picdata) data = np.matrix(data,'float')/255.0 return data def DatatoImage(title,Data,savename): w,h = np.shape(Data) n_col = int(w**0.5) n_row = n_col p_size = int(h**0.5) plt.figure(figsize=(2*n_col,2.26*n_row)) plt.suptitle(title,size=16) for i in range(w): plt.subplot(n_row,n_col,i+1) plt.imshow(Data[i,:].reshape((p_size,p_size)), cmap=plt.cm.gray, interpolation='nearest') plt.xticks(()) plt.yticks(()) plt.subplots_adjust(0.01, 0.05, 0.99, 0.93, 0.04, 0.) plt.savefig(savename) data = ImagetoData() title = 'face' savename='rawface.jpg' DatatoImage(title,data,savename)