资源简介
NULL
博文链接:https://gongwanlu.iteye.com/blog/1018161

代码片段和文件信息
%**********************************************
% Aim : The first AI program homework
% title : PCA for face recognition
% Author : GongWanlu & Hufei
% Version : 1.0 final
% Submit Time : 2011-04-07
%**********************************************
% %%%%%%%%%%%%%%%%%%%%%%INITIAL
clear all
clc
close all
% %%%%%%%%%%%%%%%%%%%%%%Some variables according to the Yale Face DB
Num_subject = 15;
Num_image = 11;
Train_num_image = 8; %for every subject we choose 8 to train
Test_num_image = 9; %choose the left 3 images to test
% %%%%%%%%%%%%%%%%%%%%%%Load Data
Data = [];
for i=1:Num_subject
for j=1:Train_num_image
path = sprintf(‘FaceDB_yaleA/%03d/%02d.jpg‘ij);
pic = imread (path); %read one picture
%Make Data Add pic into Data
pic_line = pic(1:147*137); %The pic size is 147*137
%pic_line is 1*N N=147*137. from up to
%downleft to right.
%Reshape 2D image to 1D image
%vectors
Data = [Data;double(pic_line)]; %add pic_line into Data
end
end
% End of Load Data
%%%%%%%%%%%%%%%%%%%%%%%Substract mean from Data and make covariance from centering Data
samplemean = mean(Data); %mean pic 1*N
for k = 1:(Num_subject * Train_num_image)
xmean(k:)=Data(k:)-samplemean; %Normalize
end %xmean is M*N each line is one pic
%data(mean data) be normalized
sigma = xmean *xmean‘; %M*M here is 120*120
[V D]=eig(sigma); %calculate the eigenvalue&eigenvector
%eigenvalue in Dand vectors in V
D1=diag(D); %the eigenvalues
%%%%%%%%%%%%%%%%%%%%%%%% Sorting and eliminating eigenvalues
% At first : sort desc
Dsort=flipud(D1);
Vsort=fliplr(V);
%choose part eigenvalues
Dsum = sum(Dsort); %sum of the eigenvalueswe only choose 80%
%we have different ways to choose
%eigenvalues we need90%or>1……
temp_sum = 0;
p = 0;
while(temp_sum/Dsum<0.8)
p = p+1;
temp_sum = sum(Dsort(1:p));
end
%End of sort part
%%%%%%%%%%%%%%%%%%%%%%%Train Step: get the coordinate system
i=1;
while(i<=p && Dsort(i)>0)
face_base(:i) = Dsort(i)^(-1/2) * xmean‘ * Vsort (:i);
i=i+1;
end
% Dsort(i)^(-1/2) used to normalize make variance=1
% face_base is N*p
% xmean‘ * Vsort (:i); is change small matrix to big matrix. CHACHENG(Chinese)
%next sentence is vary important is our train result
allcoor = Data * face_base;
%End of training
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Draw part
%draw CDF
x = Dsort (1:p);
x = flipud (x);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4982 2011-04-08 00:32 PCA.m
----------- --------- ---------- ----- ----
4982 1
- 上一篇:模糊PID控制器
- 下一篇:LMDMATLAB代码
相关资源
- matlab优化工具箱讲解
- SVM工具箱(matlab中运行)
- 冈萨雷斯数字图像处理matlab版(第三
- k近邻算法matlab实现
- 基于BP神经网络对几种字体0-9的数字识
- 龚纯《精通MATLAB最优化计算》随书源
- 图像的二进小波分解matlab源码(保证
- p文件,MATLAB的
- MRF matlab源码
- GMM(matlab源码)
- kalman工具箱 用matlab编写 包附全部函数
- 偏最小二乘分析matlab工具包
- 粒子群算法matlab工具箱
- curvelet matlab工具箱
- matlab的pde工具箱使用方法
- MATLAB数字信号处理85个实用案例精讲入
- 医学图像重建作业matlab源码
- 粒子群算法优化pid源码 matlab仿真.ra
- MATLAB控制工程工具箱技术手册
- pca源码matlab
- lvq学习算法源码matlab
- MATLAB电机仿真精华50例PDF+源码
- MAX插件工具合集
- rbf神经网络求解机器人的运动学逆解
- 通用弹道仿真计算程序V1.0-源码
- CARS-PLS 用于光谱数据或色谱数据变量
- matlab模式识别工具箱PRTOOLS及使用说明
- MATLAB_FEM_ToolBox_examples
- 四元数MATLAB工具箱
- 代理模型MATLAB工具箱FAC Viana
评论
共有 条评论