因为用到CNN,想把165张yale人脸图片合成一张图片
数据下载
https://blog.youkuaiyun.com/szj_huhu/article/details/76084908
.mat图片原网址和 数据集:链接:http://pan.baidu.com/s/1jIggvEu 密码:fz15
代码
# -*- coding: utf-8 -*-
'''
https://blog.youkuaiyun.com/szj_huhu/article/details/76084908
这里是165*(64*64)大小的图片,需要把图片转为
'''
import cv2
import scipy.io as scio
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
dataFile = r'F:\\Face86project\\MyFaceTest\\Yale_64x64.mat' # 单个的mat文件
data = scio.loadmat(dataFile)
print(type(data))
# 由于导入的mat文件是structure类型的,所以需要取出需要的数据矩阵
a=data['fea']
for i in range(165):
img=a[i].reshape(64,64)
new_im = Image.fromarray(img.astype(np.uint8))
'''旋转90度'''
new_im=new_im.rotate(-90)
new_im.save('Image\\'+str(i+1)+'.bmp') # 保存图片
# new_im.show()
'''float64'''
Image_row=15
Image_colume=11
Image_size=64
Image_Path='Image\\'
'''
列的个数 也就是行数吧,应该是刷行,刷列
刷x行,后面刷y列
'''
to_image=Image.new('RGB',(Image_colume*Image_size,Image_row*Image_size))
for y in range(1,Image_row+1):
for x in range(1,Image_colume+1):
Image_name=Image_Path+str(x+(y-1)*11)+'.bmp'
print(Image_name)
from_image=Image.open(Image_name)
to_image.paste(from_image,((x-1)*Image_size,(y-1)*Image_size) )
to_image.save('yale.gif')