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

📄 peldamain.m

📁 PCA、LDA人脸检测
💻 M
字号:
function [errorrate,result]=PELDAmain(eignum)
% PELDAMAIN is used to simulate the process of ELDA design and
% classification with PCA dimension reduction
% eignum specify the number of ELDA 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);

%构造初始的训练样本集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

%对初始训练样本集sampleset用PCA方法降到m-1维
dim=m-1;
Wtpca=PCADesign(n,m,sampleset,dim);
sampleset=Wtpca*sampleset;

%构造相应的样本标记samplelabel
samplelabel=zeros(1,m);
for i=1:m
    j=i;
    k=0;
    while j>5
        j=j-5;
        k=k+1;
    end
    samplelabel(1,i)=k+1;
end

classnum=40;
%根据降维样本集确定ELDA变换矩阵
Wtelda=ELDADesign(dim,m,sampleset,classnum,samplelabel,eignum);

%确定总的变换矩阵
Wt=Wtelda*Wtpca;

%确定每个类的类中心
classcenter=zeros(eignum,40);
for i=1:40
    classcenter(:,i)=Wtelda*(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=MinDisClassifier(eignum,40,classcenter,Wt*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 + -