firefly
firefly

Reputation: 201

What exactly is returned from PCA in MatLab?

I = double(image1Cropped);
X = reshape(I,size(I,1)*size(I,2),3 );
coeff1 = pca(X);

What exactly is happening in the above 3 lines of code? Why covert an image into double before passing into reshape? What is the purpose of reshape? What is returned from pca(X)? Could I use coeff1 to compare images (for example, comparing faces)?

Upvotes: 0

Views: 51

Answers (1)

Ander Biguri
Ander Biguri

Reputation: 35525

From PCA, the principal conponents are returned. Of course.

Check the documentation or any online course to understand what a PCA is.

As PCA is a mathematical tool, it needs floating point data to work, that's why there is a double in the first line, it is converting the data (most likely uint8) into floating point data.

reshape is reshaping your image to a huge matrix of size(I,1)*size(I,2),3, so every X(ii,:) will be 3 of length.

My guess here is that the image is a RGB image, and that this code tries to get the "principal colours" of the image. What the code does is transform you data to points of 3 values, Red, Green and Blue (as opposed to the normal XYZ) and then getting the principal components of the image. The principal components will be "the principal 3 Colors (conbinations of RGB)" that are in the image.

If you search "PCA of an RGB image" on Google you will find lots of information of how/why to do this.

Upvotes: 1

Related Questions