face recognition using database AT&T, how to inputnew image, convert it into .pgm, reshape it as same as the database,input it into the database and load it to my program?

7 views (last 30 days)
hi all, i have a problem here, i have been editing using this http://www.mathworks.com/matlabcentral/fileexchange/16760-face-recognition program, the database is the same using At&T database but i want to use the recognition system so i take the new image and save it into the database, my problem is, how can i save the database that can be reshape and input the database? i shall give my program here and the screenshot
for the load database
function out=load_database()
% We load the database the first time we run the program.
persistent loaded;
persistent w;
if(isempty(loaded))
v=zeros(10304,400);
for i=1:40
cd(strcat('s',num2str(i)));
for j=1:10
a=imread(strcat(num2str(j),'.pgm'));
v(:,(i-1)*10+j)=reshape(a,size(a,1)*size(a,2),1);
end
cd ..
end
w=uint8(v); % Convert to unsigned 8 bit numbers to save memory.
end
loaded=1; % Set 'loaded' to aviod loading the database again.
out=w;
for my main program
%face recognition_ Nicholas Joy
%Loading of training set database
%the training is made up of 400 images.
%the images will be used for the recognition process.
w=load_database(); %loading database
size (w)
*%%initializations
%the initial conditions are initialized.
%the new image input and video configuarion.
%that will be used for recognition is set.
vid = videoinput('winvideo', 1, 'YUY2_160x120'); %initialize video input
triggerconfig (vid, 'manual') %configure trigger
vid.FramesPerTrigger = 1;
set (vid,'TriggerFrameDelay',20); %Set trigger delay
preview(vid);
start(vid);
trigger(vid) %Triggering snapshot
set(vid, 'ReturnedColorSpace','grayscale')
rgbImage = getdata(vid);
stop(vid);
fullImageFileName = fullfile(pwd, 'new.pgm');
imwrite(rgbImage,fullImageFileName);
B=imread('new.pgm');
r = imresize(B, [112 92]); %Resizing image to 112x92
imwrite(r,'new.pgm');
im =(r); %r contains the image we use to test the algorithm
tempimg = im(:,:,1);
r = reshape(tempimg, 10304,1);
v=w; %v contains the database
N=50; %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 mean of all images
vzm=v-uint8(single(m)*single(O)); %vzm is v with the mean removed
%%calculating eigenvectors 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 eigenvalues 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 ca correctly recognize the face.
figure (1)
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)==1),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');
the one that i "bold" is different from the previous code,
can anyone help me how to input my image, convert it as same as the database and input it to the database and can be load by my program? please help my program, for my final year project.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!