function PCA = jayhw7(q)

Data={'texture11.jpg','texture12.jpg','texture21.jpg','texture22.jpg','texture31.jpg','texture32.jpg','texture41.jpg','texture42.jpg','texture51.jpg','texture52.jpg','texture61.jpg','texture62.jpg'};
n = numel(Data);

% initialise imstack 
 img=double(imread('texture11.jpg'));
 imstack=cat(3,img);

% add images to the stack
for x=2 : n
   img=double(imread(char(Data(x))));
   imstack=cat(3,imstack,img);
end

% obtain principal component 
[X, R] = imstack2vectors(imstack);
P = princomp(X, q);

% % principal components images 
for i=1:q
    g1 = P.Y(:,i);
    g1 = reshape(g1, 128, 128);
    figure;
    imshow(g1,[]); 
end

% reconstruct original image
for j=1:12
    h1=P.X(:,j);
    h1=reshape(h1,128,128);
    figure;
    imshow(h1,[]);    
end
%  covariance matrix for Y
Cov = P.Cy;

% Find the eigenvalues
Ev = diag(Cov)

% The mean square error
error=P.ems

return;
