Can I use PCA effectively on a greyscale image?

17 visualizaciones (últimos 30 días)
Neo el 18 de Dic. de 2015
Respondida: Aya Ahmed el 5 de Abr. de 2020
I found this code online:
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,[]);
provided from another commentary form I was reading and I was wondering if there was any code that performed PCA that did not give the pc as a color channel. I don't want to do PCA on the colors of the image composite I want something else (not sure what else is but something not color), so applying PCA to a gray scale image.
Thanks for you any and all suggestions.
  4 comentarios
Neo el 21 de Dic. de 2015
Editada: Neo el 21 de Dic. de 2015
Oh I see, but just because an image is not RGB, it doesn't necessarily mean that it has only one axis, it might mean that the image has axes that are not related like in a RGB image. And let me get a picture for you to give an idea of what I am talking about actually, great suggestion. I read your response to quickly. Here ya go:

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Dic. de 2015
Sure. For example,
I = double(imread('cameraman.tif'));
X = reshape(I,[],4);
coeff = pca(X);
This would correlate vertical quarters of the image.
  36 comentarios
Neo el 29 de Dic. de 2015
Haha, thanks Analyst. But I am more concerned with how I can feed multiple images into the PCA code so that I can get more than one PC from the image. Do you have an average face answer to that? Cheers, Neo Cornel

Iniciar sesión para comentar.

Más respuestas (4)

mugahid albadawy
mugahid albadawy el 9 de Feb. de 2017
i ve already used the same function for dicom image but it's not working properly

Stefan Karlsson
Stefan Karlsson el 27 de Dic. de 2015
I think the answer by Walter, while technically correct, confounds a VERY simple topic. Being technically correct here amounts to what exactly?
  9 comentarios
Image Analyst
Image Analyst el 28 de Dic. de 2015
Nah, you were fine. But is a little frustrating waiting for Neo to verbalize what features he wants to characterize in his image. It's almost like he heard about PCA and thought that it sounded cool and wanted to apply it to his image without considering if it was appropriate or not, or whether there might be better methods. I still don't know what kind of result he would want.

Iniciar sesión para comentar.

Stefan Karlsson
Stefan Karlsson el 28 de Dic. de 2015
... I guess one can also give another piece of advice to anyone who stumbles onto this looking for info on PCA. Read the posts by Image Analyst. They are as high in quality as they usually are.
  1 comentario
Neo el 28 de Dic. de 2015
I'd say Walter Roberson was also very high quality as well.

Iniciar sesión para comentar.

Aya Ahmed
Aya Ahmed el 5 de Abr. de 2020
Neo can you tell me please ..
i want to make feature extraction using PCA ,using matlab code on galaxy grayscale image ,
I was wondering if you could help me with a few steps or even code to make feature extraction from images .
I would like to extract the features of galaxy images and then classify them in the classification learner app.
The data I have is a set of galaxy imagse.
The aim is to extract the features and then compare them in the classification app with each other.
Any help is appreciated!
i want to know how pca work ? does it work in gray images only ??
Thanks ..


Community Treasure Hunt

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

Start Hunting!

Translated by