请各位帮忙看一下这个程序
function recognize = my_pca(path,persons,numface,numtrain,numpc)path='D:\ORLface\';
persons=2;
numface=5;
numtrain=3;
numpc=15;
rbf_var=0.1;
for i=1:persons
str=num2str(i);
if i<10
str=['0',str];
end
Folder(i,:)=;
end
BMPfile =['01.bmp';'02.bmp';'03.bmp'];
for i=1:persons
for j=1:numtrain
img_name=;
img=double(imread(img_name));
if i==1 & j==1
size_img=size(img);
Dim=size_img(1)*size_img(2);
end
img=reshape(img,Dim,1);
X(:,numtrain*(i-1)+j)=img;
end
end
all_train=persons*numtrain;
eface=zeros(Dim,1);
for i=1:all_train
eface=eface+X(:,i);
end
eface=eface/all_train;
for i=1:all_train
X(:,i)=X(:,i)-eface;
end
=wavedec2(X,1,'haar');
Xa=appcoef2(X1,X2,'haar',1);
for i=1:all_train,
for j=i:all_train,
Xa(i,j) = exp(-norm(X(:,i)-X(:,j))^2/rbf_var);
Xa(j,i) = Xa(i,j);
end
end
unita=ones(all_train,all_train)/all_train;
Xcal=Xa-unita*Xa-Xa*unita+unita*Xa*unita;
=eig(Xa);
D=real(diag(D));
for i=1:all_train,
V(:,i)=V(:,i)/(sqrt(D(i)));
end
Features_Xcal=zeros(all_train,numpc);
Features_Xcal=Xcal*V(:,1:numpc);
numtest=numface-numtrain;
for i=1:persons
for j=(numtrain+1):numface
img_name=;
img=double(imread(img_name));
img=reshape(img,Dim,1);
Y(:,numtest*(i-1)+(j-numtrain))=img;
end
end
all_test=persons*numtest;
for i=1:all_test
Y(:,i)=Y(:,i)-eface;
end
=wavedec2(Y,1,'haar');
Ya=appcoef2(Y1,Y2,'haar',1);
unitb=ones(all_test,all_train)/all_train;
Ya=zeros(all_test,all_train);
for i=1:all_test,
for j=1:all_train,
Ya(i,j)=exp(-norm(Y(:,i)-X(:,j))^2/rbf_var);
end
end
Ycal=Ya-unitb*Xa-Ya*unita+unitb*Xa*unita;
Features_Ycal=zeros(all_test,numpc);
Features_Ycal=Ycal*V(:,1:numpc);
err=0;
Xclass=zeros(all_train,1);
Yclass=zeros(all_test,1);
Yresult=zeros(all_test,1);
for xc=1:all_train
Xclass(ac)=ceil(ac/numtrain);
end
for yc=1:all_test
Yclass(bc)=ceil(bc/numtest);
end
for i=1:all_test
Dij=zeros(all_train,1);
for j=1:all_train
FD=Feature_Ycal(:,i)-Feature_Xcal(:,j);
Dij(j)=norm(FD);
end
=sort(Dij);
Yresult(i)=Xclass(IND(1));
if Yresult(i)~=Yclass(i)
err=err+1;
end
end
recognize=['正确识别率:',num2str((1-err/all_test)*100),'%']
请各位帮忙看一下为什么运行不了,急~~谢谢了 原帖由 9clock 于 2007-5-13 22:39 发表 http://www.chinavib.com/forum/images/common/back.gif
function recognize = my_pca(path,persons,numface,numtrain,numpc)
path='D:\ORLface\';
persons=2;
numface=5;
numtrain=3;
numpc=15;
rbf_var=0.1;
for i=1:persons
str=num2str(i);
if i
请参照置顶贴:聚宝盆把你的问题叙述清楚,特别是给出出错信息! 不好意思 这是显示的错误信息
??? Index exceeds matrix dimensions.
On line 52==> Xcal=Xa-unita*Xa-Xa*unita+unita*Xa*unita
这程序是个kpca的人脸识别程序,但是我在核函数运算(将数据由低维转到高维)部分不是很清楚,for i=1:all_train,
for j=i:all_train,
Xa(i,j) = exp(-norm(X(:,i)-X(:,j))^2/rbf_var);
Xa(j,i) = Xa(i,j);
end
end(这个部分)
所以设计可能有错,请各位多多帮助一下,谢谢了 原帖由 9clock 于 2007-5-14 13:53 发表 http://www.chinavib.com/forum/images/common/back.gif
不好意思 这是显示的错误信息
??? Index exceeds matrix dimensions.
On line 52==> Xcal=Xa-unita*Xa-Xa*unita+unita*Xa*unita
这程序是个kpca的人脸识别程序,但是我在核函数运算(将数据由低维转 ...
访问越界,这种问题自己根据出错提示的位置设置断点,然后调试一下就可以了
页:
[1]