snikfreak
Newbie level 4
Hello,
im doing some thesis on face recognition system using eigenfaces/PCA. i've found useful codes and i tried to edit them but the equations seemed complicated,
here is the original code
w=load_database();
ri=round(400*rand(1,1)); % Randomly pick an index.
r=w,ri); % r contains the image we later on will use to test the algorithm
v=w,[1:ri-1 ri+1:end]); % v contains the rest of the 399 images.
N=20; % Number of signatures used for each image.
%% Subtracting the mean from v
O=uint8(ones(1,size(v,2)));
m=uint8(mean(v,2)); % m is the maen of all images.
vzm=v-uint8(single(m)*single(O)); % vzm is v with the mean removed.
%% Calculating eignevectors of the correlation matrix
% We are picking N of the 400 eigenfaces.
L=single(vzm)'*single(vzm);
[V,D]=eig(L);
V=single(vzm)*V;
V=V,end:-1:end-(N-1)); % Pick the eignevectors corresponding to the 10 largest eigenvalues.
%% Calculating the signature for each image
cv=zeros(size(v,2),N);
for i=1:size(v,2);
cv(i,=single(vzm,i))'*V; % Each row in cv is the signature for one image.
end
%% Recognition
% Now, we run the algorithm and see if we can correctly recognize the face.
subplot(121);
imshow(reshape(r,112,92));title('Looking for ...','FontWeight','bold','Fontsize',16,'color','red');
subplot(122);
p=r-m; % Subtract the mean
s=single(p)'*V;
z=[];
for i=1:size(v,2)
z=[z,norm(cv(i,-s,2)];
if(rem(i,20)==0),imshow(reshape(v,i),112,92)),end;
drawnow;
end
[a,i]=min(z);
subplot(122);
imshow(reshape(v,i),112,92));title('Found!','FontWeight','bold','Fontsize',16,'color','red');
-------------------------------------
as you understand, the system picks randomly photo from the database and recognize it,
what i would like to do is, to select the desired photo to be recognized !!
here is the editing code
w=load_database();
ri=uigetfile('*.pgm');
r=ri;
v=w;
N=20;
O=uint8(ones(1,size(v,2)));
m=uint8(mean(v,2));
vzm=v-uint8(single(m)*single(O));
L=single(vzm)'*single(vzm);
[V,D]=eig(L);
V=single(vzm)*V;
V=V,end:-1:end-(N-1));
cv=zeros(size(v,2),N);
for i=1:size(v,2);
cv(i,=single(vzm,i))'*V;
end
subplot(121);
imshow(reshape(r,112,92));title('Looking for ...','FontWeight','bold','Fontsize',16,'color','red');
subplot(122);
p=r-m; % Subtract the mean
s=single(p)'*V;
z=[];
for i=1:size(v,2)
z=[z,norm(cv(i,-s,2)];
if(rem(i,20)==0),imshow(reshape(v,i),112,92)),end;
drawnow;
end
[a,i]=min(z);
subplot(122);
imshow(reshape(v,i),112,92));title('Found!','FontWeight','bold','Fontsize',16,'color','red');
----------------------------------------------------
i tried to editi it but it didnt work, it says
??? Error using ==> reshape
To RESHAPE the number of elements must not change.
Error in ==> Test3 at 21
imshow(reshape(r,112,92));title('Looking for
...','FontWeight','bold','Fontsize',16,'color','red');
COULD YOU PLEASE HELP ME WITH EDITING THAT CODE, I WILL BE THANKFUL FOR YOUR HELP !!
YOU ARE APPRECIATED !!
THANKS,
---------- Post added at 09:10 ---------- Previous post was at 09:08 ----------
I'm Using AT&T Database,
You may download it from here for those will help me with editing,
**broken link removed**
im doing some thesis on face recognition system using eigenfaces/PCA. i've found useful codes and i tried to edit them but the equations seemed complicated,
here is the original code
w=load_database();
ri=round(400*rand(1,1)); % Randomly pick an index.
r=w,ri); % r contains the image we later on will use to test the algorithm
v=w,[1:ri-1 ri+1:end]); % v contains the rest of the 399 images.
N=20; % Number of signatures used for each image.
%% Subtracting the mean from v
O=uint8(ones(1,size(v,2)));
m=uint8(mean(v,2)); % m is the maen of all images.
vzm=v-uint8(single(m)*single(O)); % vzm is v with the mean removed.
%% Calculating eignevectors of the correlation matrix
% We are picking N of the 400 eigenfaces.
L=single(vzm)'*single(vzm);
[V,D]=eig(L);
V=single(vzm)*V;
V=V,end:-1:end-(N-1)); % Pick the eignevectors corresponding to the 10 largest eigenvalues.
%% Calculating the signature for each image
cv=zeros(size(v,2),N);
for i=1:size(v,2);
cv(i,=single(vzm,i))'*V; % Each row in cv is the signature for one image.
end
%% Recognition
% Now, we run the algorithm and see if we can correctly recognize the face.
subplot(121);
imshow(reshape(r,112,92));title('Looking for ...','FontWeight','bold','Fontsize',16,'color','red');
subplot(122);
p=r-m; % Subtract the mean
s=single(p)'*V;
z=[];
for i=1:size(v,2)
z=[z,norm(cv(i,-s,2)];
if(rem(i,20)==0),imshow(reshape(v,i),112,92)),end;
drawnow;
end
[a,i]=min(z);
subplot(122);
imshow(reshape(v,i),112,92));title('Found!','FontWeight','bold','Fontsize',16,'color','red');
-------------------------------------
as you understand, the system picks randomly photo from the database and recognize it,
what i would like to do is, to select the desired photo to be recognized !!
here is the editing code
w=load_database();
ri=uigetfile('*.pgm');
r=ri;
v=w;
N=20;
O=uint8(ones(1,size(v,2)));
m=uint8(mean(v,2));
vzm=v-uint8(single(m)*single(O));
L=single(vzm)'*single(vzm);
[V,D]=eig(L);
V=single(vzm)*V;
V=V,end:-1:end-(N-1));
cv=zeros(size(v,2),N);
for i=1:size(v,2);
cv(i,=single(vzm,i))'*V;
end
subplot(121);
imshow(reshape(r,112,92));title('Looking for ...','FontWeight','bold','Fontsize',16,'color','red');
subplot(122);
p=r-m; % Subtract the mean
s=single(p)'*V;
z=[];
for i=1:size(v,2)
z=[z,norm(cv(i,-s,2)];
if(rem(i,20)==0),imshow(reshape(v,i),112,92)),end;
drawnow;
end
[a,i]=min(z);
subplot(122);
imshow(reshape(v,i),112,92));title('Found!','FontWeight','bold','Fontsize',16,'color','red');
----------------------------------------------------
i tried to editi it but it didnt work, it says
??? Error using ==> reshape
To RESHAPE the number of elements must not change.
Error in ==> Test3 at 21
imshow(reshape(r,112,92));title('Looking for
...','FontWeight','bold','Fontsize',16,'color','red');
COULD YOU PLEASE HELP ME WITH EDITING THAT CODE, I WILL BE THANKFUL FOR YOUR HELP !!
YOU ARE APPRECIATED !!
THANKS,
---------- Post added at 09:10 ---------- Previous post was at 09:08 ----------
I'm Using AT&T Database,
You may download it from here for those will help me with editing,
**broken link removed**