Error using * Inner matrix dimensions must agree.
이전 댓글 표시
function [ ] = Eigenfaces( )
z=[];
ta=[];
for i=1
str=int2str(i);
str=strcat(str,'.JPG');
im=imread(str);
im=rgb2gray(im);
im=imresize(im,[256 256]);
temp=reshape(im,65536,1);
z=[z temp];m=mean(z,2); end
for i=1:size(z,2)
t=double(z(:,i))-m;
ta=[ta t];
end
R=ta'*ta;
[v,d]=eig(R);
L_eig_vec=[];
for i=1:size(v,2)
if(d(i,i)>1)
L_eig_vec=[ L_eig_vec ; v(:,i) ];
end
end
Eigenfaces = ta*L_eig_vec;
disp('eig finished');
projectedimages = [];
Train_Number = size(ta,2);
for i = 1 : Train_Number
temp = Eigenfaces'*ta(:,i); he
projectedimages = [projectedimages temp];
end
target=eye(Train_Number);
save latest.mat
end
채택된 답변
추가 답변 (2개)
Sulaymon Eshkabilov
2019년 5월 19일
Hi,
I could not find any problem with your corrected for a few .jpg images (created) to process that I've played with.
There was another minor typo (see below given): temp = Eigenfaces'*ta(:,i); %he
The only thing might be the casue I think is that the file extention has to be unique in all of your files, e.g. jpg or jpeg (if mixed then fix them). Noe that your code works with *.jpg only! if you would use *.jpeg then correct the code for *.jpeg extension. I could not generate your problem with my MATLAB. I've tested it with 2017a and 2019a so far. Btw, what version of MATLAB are you using?
function [ ] = Eigenfaces( )
z=[];
ta=[];
for ii=1:100
str=int2str(ii);
str=strcat(str,'.JPG');
im=imread(str);
im=rgb2gray(im);
im=imresize(im,[256 256]);
temp=reshape(im,65536,1);
z=[z temp];m=mean(z,2);
end
for i=1:size(z,2)
t=double(z(i,:))-m;
ta=[ta t];
end
R=ta'*ta;
[v,d]=eig(R);
L_eig_vec=[];
for i=1:size(v,2)
if(d(i,i)>1)
L_eig_vec=[ L_eig_vec ; v(:,i) ];
end
end
Eigenfaces = ta*L_eig_vec;
disp('eig finished');
projectedimages = [];
Train_Number = size(ta,2);
for i = 1 : Train_Number
temp = Eigenfaces'*ta(:,i); %he
projectedimages = [projectedimages temp];
end
target=eye(Train_Number);
save latest.mat
end
Good luck.
댓글 수: 2
Bereket Ayalew
2019년 5월 19일
편집: Bereket Ayalew
2019년 5월 19일
madhan ravi
2019년 5월 20일
Sulaymon Eshkabilov's answer moved here for consistency:
Hi,
The problem is resolved. I have picked up my old pc with MATLAB 2013b and managed to generate your problem. The problem was with the accuracy level and algorith used in eigen-value computation with eig(). In later versions of MATLAB, the most appropriate (accurate) algorithm is chosen automatically, but in older versions this is not the case. Also, a size selection of arrays has been changed in later version - it is rather automatic and well accustomated without a user notice. Anyhow, I have done some small changes and adjusted the code to MATLAB 2013b (2013a - hopefully) with eigenvalue computing algorithm with Choleky decomposition.
Here is the complete code:
function [ ] = Eigenfaces( )
z=[];
ta=[];
for ii=1:4
str=int2str(ii);
str=strcat(str,'.jpg');
im=imread(str);
im=rgb2gray(im);
im=imresize(im,[256 256]);
temp=reshape(im,65536,1);
z=[z temp]; m=mean(z,2);
end
for i=1:size(z,2)
t=double(z(:,i))-m;
ta=[ta t];
end
R=ta'*ta;
[v,d]=eig(R, R, 'chol');
L_eig_vec=[];
for i=1:size(v,2)
if(d(i,i)>1)
L_eig_vec=[ L_eig_vec ; v(i,i) ];
end
end
Eigenfaces = ta*L_eig_vec;
disp('eig finished');
projectedimages = [];
Train_Number = size(ta,2);
for i = 1 : Train_Number
temp = Eigenfaces'*ta(:,i);
projectedimages = [projectedimages temp];
end
target=eye(Train_Number);
save latest.mat
end
Good luck. Don't forget Thumbs UP ... :)
Sulaymon Eshkabilov
2019년 5월 20일
Hi,
The problem is resolved. I have picked up my old pc with MATLAB 2013b and managed to generate your problem. The problem was with the accuracy level and algorith used in eigen-value computation with eig(). In later versions of MATLAB, the most appropriate (accurate) algorithm is chosen automatically, but in older versions this is not the case. Also, a size selection of arrays has been changed in later version - it is rather automatic and well accustomated without a user notice. Anyhow, I have done some small changes and adjusted the code to MATLAB 2013b (2013a - hopefully) with eigenvalue computing algorithm with Choleky decomposition.
Here is the complete code:
function [ ] = Eigenfaces( )
z=[];
ta=[];
for ii=1:4
str=int2str(ii);
str=strcat(str,'.jpg');
im=imread(str);
im=rgb2gray(im);
im=imresize(im,[256 256]);
temp=reshape(im,65536,1);
z=[z temp]; m=mean(z,2);
end
for i=1:size(z,2)
t=double(z(:,i))-m;
ta=[ta t];
end
R=ta'*ta;
[v,d]=eig(R, R, 'chol');
L_eig_vec=[];
for i=1:size(v,2)
if(d(i,i)>1)
L_eig_vec=[ L_eig_vec ; v(i,i) ];
end
end
Eigenfaces = ta*L_eig_vec;
disp('eig finished');
projectedimages = [];
Train_Number = size(ta,2);
for i = 1 : Train_Number
temp = Eigenfaces'*ta(:,i);
projectedimages = [projectedimages temp];
end
target=eye(Train_Number);
save latest.mat
end
Good luck. Don't forget Thumbs UP ... :)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!