Error using * Inner matrix dimensions must agree.
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (2)
Sulaymon Eshkabilov
il 19 Mag 2019
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 Commenti
Bereket Ayalew
il 19 Mag 2019
Modificato: Bereket Ayalew
il 19 Mag 2019
madhan ravi
il 20 Mag 2019
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
il 20 Mag 2019
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 ... :)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!