Check error rate from Principal Component Analysis

2 views (last 30 days)
Hello, For the Matlab code given to find the Principal Component Analysis found here, how do you go about extracting the error rate of the recognition system with the test data? Here is the code that is posted on the Matlab Exchange website:
%%%face recognition by Kalyan Sourav Dash %%%
clear all
close all
clc
datapath = uigetdir('C:\Documents and Settings\KsDash\My Documents\MATLAB','Select path of TRAINING IMAGES');
testpath = uigetdir('C:\Documents and Settings\KsDash\My Documents\MATLAB','select path of TEST IMAGES');
prompt = {'Enter test image name (a number between 1 to 60):'};
dlg_title = 'Input of PCA-Based Face Recognition System';
num_lines= 1;
def = {' '};
TestImage = inputdlg(prompt,dlg_title,num_lines,def);
TestImage = strcat(testpath,'\',char(TestImage),'.jpg');
D = dir(datapath);
imgcount = 0;
for i=1 : size(D,1)
if not(strcmp(D(i).name,'.')|strcmp(D(i).name,'..')|strcmp(D(i).name,'Thumbs.db'))
imgcount = imgcount + 1; % Number of all images in the training database
end
end
X = [];
for i = 1 : imgcount
str = strcat(datapath,'\',int2str(i),'.jpg');
img = imread(str);
[r c] = size(img);
temp = reshape(img',r*c,1);
X = [X temp];
end
m = mean(X,2); % Computing the average face image m = (1/P)*sum(Xj's) (j = 1 : P)
imgcount = size(X,2);
A = [];
for i=1 : imgcount
temp = double(X(:,i)) - m;
A = [A temp];
end
L= A' * A;
[V,D]=eig(L); %%V : eigenvector matrix D : eigenvalue matrix
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 = A * L_eig_vec;
projectimg = [ ]; % projected image vector matrix
for i = 1 : size(A,2)
temp = eigenfaces' * A(:,i);
projectimg = [projectimg temp];
end
test_image = imread(TestImage);
test_image = test_image(:,:,1);
[r c] = size(test_image);
temp = reshape(test_image',r*c,1); % creating (MxN)x1 image vector from the 2D image
temp = double(temp)-m; % mean subtracted vector
projtestimg = eigenfaces'*temp; % projection of test image onto the facespace
euclide_dist = [ ];
for i=1 : size(eigenfaces,2)
temp = (norm(projtestimg-projectimg(:,i)))^2;
euclide_dist = [euclide_dist temp];
end
[euclide_dist_min recognized_index] = min(euclide_dist);
recognized_img = strcat(int2str(recognized_index),'.jpg');
%recog_img = facerecog(datapath,TestImage);
selected_img = strcat(datapath,'\',recognized_img);
select_img = imread(selected_img);
imshow(select_img);
title('Recognized Image');
test_img = imread(TestImage);
figure,imshow(test_img);
title('Test Image');
result = strcat('the recognized image is : ',recognized_img);
disp(result);

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!