<p>I am currently tryn to run a program to use eigenfaces for face recognition o
ID: 3636438 • Letter: #
Question
<p>I am currently tryn to run a program to use eigenfaces for face recognition on Matlab.<br />The code so far is this<br /><br />clear all<br />input_dir = 'C:/Users/David/Desktop/Hdip Project/Sample Mathlab Code/Images';<br />image_dims = [108, 117];<br /><br />filenames = dir(fullfile(input_dir, '*.pgm'));<br /><br />num_images = numel(filenames);<br />images = [];<br />for n = 1:num_images<br /> filename = fullfile(input_dir, filenames(n).name);<br /> img = imread(filename);<br /> img = rgb2gray(img);<br /> %img = imresize(img, image_dims); <br /> if n == 1<br /> images = zeros(prod(image_dims), num_images);<br /> end<br /> images(:, n) = img(:);<br />end<br /><br />mean_face = mean(images, 2);<br />shifted_images = images - repmat(mean_face, 1, num_images);<br /><br />[evectors, score, evalues] = princomp(images');<br /><br />num_eigenfaces = 10;<br />evectors = evectors(:, 1:num_eigenfaces); ***<br />features = evectors' * shifted_images;<br /><br />feature_vec = evectors' * (input_image(:) - mean_face);<br />similarity_score = arrayfun(@(n) 1/(1+norm(features(:,n) - feature_vec)), 1:num_images);<br />[match_score, match_ix] = max(similarity_score);<br />figure, imshow([input_image reshape(images(:,match_ix), image_dims)]);<br />title(sprintf('matches %s, score%f', filenames(match_ix).name, match_score));</p><p>I keep getting an error at the line indicated with ***. The problem is " index exceeds matrix dimensions".</p>
<p>If anybody can help, I will provide xtra points.</p>