%% Part A
% a)
N = 40; % Number of subjects in the dataset
S = 10; % Number of pictures per subject
l= 112; % dimensions of each picture
w = 92;
mean_face = zeros(l,w);
vectorizedDataSet = zeros(l*w,N*S);
Sigma = zeros(N*S,N*S);
V = zeros(l*w,5);
D = zeros(5);
dataSet = zeros(l,w,N*S); % Saving space in memory to save all the images
% This is a loop that charges all the images
for i = 1:N*S
subject = fix((i-1)/S)+1;
picture = mod(i,S);
if picture==0
picture =10;
end
str = ['orl_dataset/s',num2str(subject),'/',num2str(picture),'.pgm'];
dataSet(:,:,i) = double(imread(str));
end
% This displays the last image
colormap(gray);
imagesc(dataSet(:,:,N*S));
axis square;
%b)
mean_face = % Compute the mean face here.
% Plot the average face.
%% Part B
%a) Computing vectorized face and covariance matrix.
vectorizedDataSet;% Reshape the whole dataset
vectorizedMeanFace ; % Compute the mean of vectorizedDataset. Make sure that it has the correct dimension
Sigma; %Compute the covariane matrix make sure that it has the correct dimension
%b) Computing the principal components
[V,D]; % V are the eigenvectors and D the eigenvalues
%c) Compute the principal component decomposition for any image.
x; % Save in the variable x any image that you want.
xPC; % Compute the PC of the image that you selected.
%d) This question is theoretical
%e) Perform the reconstruction of the previous image and display images
xReconstructed; % Reconstruct the image using only the coefficients xPC, V and vectorizedMeanFace
xImage; % Reshape the image to recover the original shape of the image.
xReconstructedImage; % Reshape the reconstructed image to recover the original shape of the image.
figure; % Display the original image
figure;% Display the reconstructed image