I found this code demo for pca and I think that it shows that pca is literally just making the dimensions really small. The line of code X is the one doing all fancy modes of the image not pca. Is my understnading correct or am I missing something?

4 vues (au cours des 30 derniers jours)
I = double(imread('peppers.png'));
X = reshape(I,size(I,1)*size(I,2),3);
coeff = pca(X);
Itransformed = X*coeff;
Ipc1 = reshape(Itransformed(:,1),size(I,1),size(I,2));
Ipc2 = reshape(Itransformed(:,2),size(I,1),size(I,2));
Ipc3 = reshape(Itransformed(:,3),size(I,1),size(I,2));
figure, imshow(Ipc1,[]);
figure, imshow(Ipc2,[]);
figure, imshow(Ipc3,[]);

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Août 2015
To determine whether your assessment is accurate, replace the line
coeff = pca(X);
with
coeff = eye(3);
which is the 3 x 3 identity matrix. If the reshape() is doing the work and the pca() is not contributing anything then the output you get back will look the same as you get in the pca() case. If the output you get back is significantly different than what you get in the pca() case then the pca() has done something useful.
Note: what that code demo is doing is essentially determining the correlation that the three color planes (Red, Green, Blue) have with each other.
  3 commentaires
Neo
Neo le 3 Août 2015
I got the exact same output. Thanks again for your response.
Neo
Neo le 3 Août 2015
If the point of the code was to show the correlation channels what was the point of using PCa? I just shrunk the image which was overruled by the reshape code.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 3 Août 2015
For what it's worth, attached is the image PCA code I got from an Image Processing Toolbox developer at the Mathworks.
  4 commentaires
Image Analyst
Image Analyst le 3 Août 2015
Hmmm... It sounds like you're just starting to learn about PCA, but I'm not really able to give a course on it. However I'll try to give a short intuitive description. The peppers image is probably not really the best image for illustrating the concept. Imagine that you took every pixel in the image and plotted it in a 3D space with R, G, and B being the axes - essentially you're doing a scatterplot of the 3D color gamut, like this image:
Now PCA creates several "basis" images that can be used, with the proper weightings, to recreate any arbitrary image. So if you had rgbImage, and then created 3 PCA images, you could get rgbImage from a sum of the 3 basis images: rgbImage = a*PC1+b*PC2+c*PC3.
Now, let's pretend that all we had in the image was the baboon's nose - nothing else. If that were the case, all you'd see is the reddish pixels in the color gamut above. Now notice that, in this RGB color space at least, the reddish pixels do not lie along any nice axis. They're not aligned with either the R, G, or B axes so you'd have a hard time getting the cigar-shaped red group of pixels segmented out, which would allow you to identify the reddish pixels in the original image. However, if we were to define a new coordinate system where one axis went right down the "spine" of that reddish cigar shape, and the two other axes were perpendicular to that, then you could get it. The PC1 axis would go down the spine of the red scatter points, and the PC2 and PC3 axes would be normal to PC1 and perpendicular to each other. So, in essence PCI would from from the white/light blue end of the cigar shape down to the red end of the cigar shape. PC1 would be a measure of how red the points are . PC2 and PC3 are a measure of how far the points are from the PC1 axes - essentially the radius. So the PC1 image would look like the nose, and the PC2 and PC3 images wouldn't look like much of anything - not much structure, just mostly noise.
So if you wanted, you could do dimensionality reduction by throwing away the PC2 and PC3 images because they're not useful to you if your goal is only to get the reddish pixels in that image.
You can even have more PC images than 3. For example, you've probably heard of "eigenfaces" where you can essentially build up an image of any face through a weighted average of 30 or 50 eigenface images. The more you use, the more accurate you can build the target image. Each PC image is a little less impactful than the one before it and you can reach a point of diminishing returns. Any given PC image might not look like a face. As you get to higher and higher order PC images, they look less and less recognizable as a face. See this.
Does that explain it a little better?
Neo
Neo le 4 Août 2015
Oh wow yes! I believe that demonstration is a much better example of the code! I wish you had commented first or that I could make multiple best answers because you have given an insight into PCA with such small detail. Thanks and if I have more questions that don't require such effort for an answer I will post again. Thanks analyst!

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by