⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcamain.m

📁 PCA、LDA人脸检测
💻 M
字号:
function [errorrate,result]=PCAmain(eignum)
% PCAmain is used to simulate the process of PCA design and
% classification
% eignum specify the number of PCA eigenvectors
%
% errorrate is the error rate
% result will return the concrete result about classification

%读取所有的人脸图象的数据
data=zeros(56*46*400,1);
fid=fopen('facedata','r');
[data,count]=fread(fid,56*46*400,'uint8');
fclose(fid);
data=reshape(data,56*46,400);

%构造PCA的训练样本集sampleset
n=56*46;
m=200;
sampleset=zeros(56*46,200);
for i=1:m
    j=i;
    k=0;
    while j>5
        j=j-5;
        k=k+1;
    end
    sampleset(:,i)=data(:,10*k+j);
end

%根据训练样本集确定变换矩阵
PCADesign(n,m,sampleset,eignum);

%确定每个类的类中心
classcenter=zeros(n,40);
for i=1:40
    classcenter(:,i)=(sampleset(:,5*i-4)+sampleset(:,5*i-3)+sampleset(:,5*i-2)+sampleset(:,5*i-1)+sampleset(:,5*i))/5;
end

%对所有测试样本进行分类并统计分类结果
errornum=0;
term=zeros(200,3);
for i=1:m
    j=i;
    k=0;
    while j>5
        j=j-5;
        k=k+1;
    end
    class=PCAClassifier(n,40,classcenter,data(:,10*k+j+5));
    term(i,:)=[k+1,10*k+j+5,class];
    if k+1~=class 
        errornum=errornum+1;
    end
end
errorrate=errornum/m;
result=term;
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -