MATLAB Answers

0

Principal Component Analysis (PCA) to extract first two principal components from sample covariance matrix of X and project X onto those two components.

Asked by Alberto Dallolio on 19 Nov 2015
Hi everybody, I'm trying to solve this problem I'm facing to from several hours. I have 3 classes of images and for each class I have 72 pictures, totally 216 images. I have already read all the pixels of each image and I have defined the matrix containing all pixels, X (216x49152). My goal is to standardize X, use PCA to extract first two principal components from sample covariance matrix of X, project X onto those two components and finally make some scatter plot to make considerations.
The problem I found is that using princomp function I would need much more available memory. Thus I decided to compute the correlation matrix of the standardized version of X (sigma = X_std * X_std'). In fact, if the matrix is standardized computing the correlation matrix is equivalent to compute the coariance matrix (right??).
Anyway, applying the function PCACOV to sigma (correlation matrix) I get a squared matrix of PCA coefficients. How can I project my matrix onto the first 2 components?? How can I use a scatter-plot with dierent colors standing for different classes??
That's the code:
clear all
a = dir('*.png');
nfiles = length(a);
X = [];
%% Images acquisition
for i=1:216
filename = a(i).name;
I = imread(filename,'png');
ImgVector = I(:);
ImgVector = ImgVector';
X(i,:) = ImgVector;
end
X_std = zscore(X);
sigma = X_std*X_std';
[COEFF] = pcacov(sigma);

  0 Comments

Sign in to comment.

Tags

0 Answers