function [imgRow,imgCol,FaceContainer,faceLabel]=ReadFaces(nFacesPerPerson, nPerson, bTest)
% 读入ORL人脸库的指定数目的人脸前前五张(训练)
%
% 输入:nFacesPerPerson --- 每个人需要读入的样本数,默认值为 5
% nPerson --- 需要读入的人数,默认为全部 40 个人
% bTest --- bool型的参数。默认为0,表示读入训练样本(前5张);如果为1,表示读入测试样本(后5张)
%
% 输出:FaceContainer --- 向量化人脸容器,nPerson * 10304 的 2 维矩阵,每行对应一个人脸向量
if nargin==0 %default value
nFacesPerPerson=5;%前5张用于训练
nPerson=40;%要读入的人数(每人共10张,前5张用于训练)
bTest = 0;
elseif nargin < 3
bTest = 0;
end
img=imread('D:\Program Files\MATLAB\machine vision\feature extraction\code\PCA_ORL\Data\ORL\s1/1.pgm');%为计算尺寸先读入一张
[imgRow,imgCol]=size(img);
FaceContainer = zeros(nFacesPerPerson*nPerson, imgRow*imgCol);
faceLabel = zeros(nFacesPerPerson*nPerson, 1);
% 读入训练数据
for i=1:nPerson
i1=mod(i,10); % 个位
i0=char(i/10);
strPath='D:\Program Files\MATLAB\machine vision\feature extraction\code\PCA_ORL\Data\ORL\s';
if( i0~=0 )
strPath=strcat(strPath,'0'+i0);
end
strPath=strcat(strPath,'0'+i1);
strPath=strcat(strPath,'/');
tempStrPath=strPath;
for j=1:nFacesPerPerson
strPath=tempStrPath;
if bTest == 0 % 读入训练数据
strPath = strcat(strPath, '0'+j);
else
strPath = strcat(strPath, num2str(5+j));
end
strPath=strcat(strPath,'.pgm');
img=imread(strPath);
%把读入的图像按列存储为行向量放入向量化人脸容器faceContainer的对应行中
FaceContainer((i-1)*nFacesPerPerson+j, :) = img(:)';
faceLabel((i-1)*nFacesPerPerson+j) = i;
end % j
end % i
% 保存人脸样本矩阵
save('D:\Program Files\MATLAB\machine vision\feature extraction\code\PCA_ORL\Mat\FaceMat.mat', 'FaceContainer')
基于PCA的人脸特征提取
4星 · 超过85%的资源 需积分: 20 176 浏览量
2017-12-05
15:04:03
上传
评论 3
收藏 6.32MB RAR 举报
apple_t29
- 粉丝: 0
- 资源: 10
最新资源
- Unity WebGL(IIS)配置pdf文档
- 三菱PLC例程源码电机高低速变换
- 【matlab / python / tkinter / BasicSR】基于EDVR SRCNN FSRCNN 的超分辨率部署
- 3400-CMN3400-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 336P-VB一款SOT23封装P-Channel场效应MOS管
- untitled0 - 副本.py
- 基于python+opencv开发的图片批量去黑边+裁剪+压缩工具源码+开发文档+实用教程(期末大作业&课设&项目开发)
- 三菱PLC例程源码电镀线程序
- 从PDF文件中读取表格内容并写入到EXCEL文档的pyton小程序
- 3365-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈