computer vision - Face recognition using PCA on Matlab -
i'm trying classify set of images using pca on matlab. training set contains ~1800 images of 380 persons, each image person's unique label (id). testing set contains ~750 images of same 380 persons (different images), each image person's corresponding label (id). images 160 x 128 pixels.
my code follows.
img_train{i}
contains i-th original image in training set, img_test{i}
contains i-th original image in testing set.
euclide_dist = zeros(total_trainimagefiles,1); num_correct_labels = 0; % reshape 2d training images 1d image vectors train_img = zeros(irow*icol,total_trainimagefiles); = 1 : total_trainimagefiles temp = reshape(img_train{i}',irow*icol,1); train_img(:,i) = temp; end % calculate mean image vector mean_face = mean(train_img,2); % subtract mean face training images centred_data = train_img - repmat(mean_face, 1, total_trainimagefiles); % determine eigenvectors , eigenvalues using svd [u, d, v] = svd(centred_data,0); d = 10; % generate feature vectors training set subsequent classification % keep top 'd' eigenvectors eigenvectors = u(:,1:d); % project training images facespace generate training feature vectors train_features = eigenvectors' * centred_data; % classify testing images = 1 : total_testimagefiles % reshape 2d test image 1d image vectors test_img = reshape(img_test{i}',irow*icol,1); % subtract mean face test image centred_test_img = double(test_img) - mean_face; % project test image onto facespace test_features = eigenvectors' * centred_test_img; % calculate euclidian distance of projected trained images projected test image j = 1 : total_trainimagefiles edist = (norm(train_features(:,j) - test_features))^2; euclide_dist(j) = edist; end % find minimum distance , compare class labels [euclide_dist_min,train_index] = min(euclide_dist); predicted_labels(i) = training_label(train_index); if training_label(train_index) == testing_label(i) num_correct_labels = num_correct_labels + 1; end end % calculate accuracy accuracy = double(num_correct_labels) / double(total_trainimagefiles);
i've tried d = 10 , d = 50, accuracy low, ~1.5% 2.5%. wrong code?
Comments
Post a Comment