# 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?

2 visualizzazioni (ultimi 30 giorni)

Mostra commenti meno recenti

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,[]);

##### 0 Commenti

### Risposta accettata

Walter Roberson
il 3 Ago 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 Commenti

### Più risposte (1)

Image Analyst
il 3 Ago 2015

##### 4 Commenti

Image Analyst
il 3 Ago 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?

### Vedere anche

### Categorie

### Community Treasure Hunt

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

Start Hunting!