码迷,mamicode.com
首页 > 编程语言 > 详细

Python批量读取人脸图片与数据互相转换

时间:2015-11-01 11:19:24      阅读:521      评论:0      收藏:0      [点我收藏+]

标签:

读取部分结果

技术分享

程序

# -*- 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)

 

Python批量读取人脸图片与数据互相转换

标签:

原文地址:http://www.cnblogs.com/theskulls/p/4927320.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!