i need help to pick a particular image from the database instead of randomly picking an image

1 view (last 30 days)
i need help to pick a particular image from the database instead of randomly picking an image in the following program:
w=load_database();
%%Initializations
% We randomly pick an image from our database and use the rest of the
% images for training. Training is done on 399 pictues. We later
% use the randomly selectted picture to test the algorithm.
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');

Accepted Answer

Walter Roberson
Walter Roberson on 31 Jan 2013
Change
ri=round(400*rand(1,1)); % Randomly pick an index.
to be the number of the image you want to use.
  2 Comments
geethi
geethi on 31 Jan 2013
am new in matlab... so cud u tell me wer exactly i shud make changes...i mean suppose if the image i want is 1.pgm wat i shud do

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!