inaccurate result of pca face recognition

2 views (last 30 days)
NURUL FARHANAH
NURUL FARHANAH on 30 Jul 2022
Answered: aditi bagora on 25 Sep 2023
hi, can you guys please help me. i don't know where i did wrong. i've use PCA method for face recognition. and for the recognition process i've used euclidean distance. but the result of input test image is different from recognized image.
this coding has 320 training images and 80 test images.
%calculate training feature vector
train_featureVec=[];
for i=1:size(faceRegistered,2)
train_featureVec(:,i)=normal(:,i)'*pca_project;
end
%load the test image database
for i=1:80
test_im{i,1}=imread(sprintf('AT&T Test/test_im (%d).jpg',i));
end
faceTest = zeros(112*92,80*1);
%row=total pixel,column=total images
%calculate test feature vectors
weightTest=[];
for j=1:size(faceTest,2)
%find weight of test image
weightTest(:,j)=faceTest(:,j)-u1(:,1);
test_featureVec(:,j)=normal(:,j)'*pca_project;
end
%recognition process
dist_mat =[];
for a=1:80
input_filename=imread(sprintf('AT&T Test/test_im (%d).jpg',a));
test_featureVec1=test_featureVec(:,a);
for b=1:320
registered_filename=faceRegistered;
train_featureVec1=train_featureVec(:,b);
diff_vector=test_featureVec1-train_featureVec1;
dist_mat(1,b)=sqrt(sum(abs(diff_vector)).^2);
end
%recognition process
minimum= min(dist_mat);
[r,c]=find(dist_mat==minimum) %find the position of the minimum distance
if size(c)==size([1 2]) % !!!error has been fix here!!!
c=c(1,2);
count=c;
else
count=c; %count=column with minimun distance
end
%classRP=classRegisteredPerson(count,:); % Class of Registered Person
%display input vs recognized face from training set
result_filename = ['AT&T Database/train_im (',num2str(count) ,').jpg'];
result_face_image = imread(result_filename);
%Show the input face vs recognized face
figure(3);
subplot(121);
imshow(input_filename);
title('Input Face');
subplot(122)
imshow(result_face_image);
title('Recognized Face');
end

Answers (1)

aditi bagora
aditi bagora on 25 Sep 2023
It appears that the problem lies in how values are assigned to the "dist_mat" matrix. Currently, the indexing used is (1, b), which means that only the distance corresponding to the last test image is being stored in the matrix. To resolve this issue, you can employ the following approach to ensure all distances are properly stored.
dist_mat (a, b) = sqrt(sum(abs(diff_vector)). ^2)
Also, to find minimum distance and column with minimum distance for a test image. You can use the “dist_mat” by indexing.
[minimum, count] = min (dist_mat (i, :)) where i, is index of test image.
Hope the provided approach helps you in getting accurate results.

Categories

Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!