Can I use PCA effectively on a greyscale image?

25 次查看(过去 30 天)
Hello!
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 个评论
Image Analyst
Image Analyst 2015-12-21
If you think of a PCA coordinate system as a 3-D rotation of an original system, then I think that might help you. Imagine you have a cigar shape gamut (scatterplot of points in RGB color space). If the cigar didn't align with any of the R, G, or B axes but was at some crazy angle, then you could do PCA on it to get a new rotated system where one PC axis does through the main axis of the cigar, and the two others are perpendicular to that and lie in the small cross-sectional plane of the cigar. But with only 1 axis, how can you think that you can rotate it?
What about my last question where I said "better yet, just show your real image and tell us what you want to measure in it and we'll tell you if PCA is the best approach or if there is a better approach." Can you do that, or are you just trying to get a theoretical intuitive understanding of what PCA is and can do?
Neo
Neo 2015-12-21
编辑:Neo 2015-12-21
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:

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2015-12-18
Sure. For example,
I = double(imread('cameraman.tif'));
X = reshape(I,[],4);
coeff = pca(X);
This would correlate vertical quarters of the image.
  36 个评论
Image Analyst
Image Analyst 2015-12-29
By the way, here is one of the "average faces" of females constructed from eigenfaces. It's often asserted that the average face is the most attractive. However high fashion models that walk the catwalks seldom have faces that look like "average"
Neo
Neo 2015-12-29
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

请先登录,再进行评论。

更多回答(4 个)

mugahid albadawy
mugahid albadawy 2017-2-9
i ve already used the same function for dicom image but it's not working properly

Stefan Karlsson
Stefan Karlsson 2015-12-27
I think the answer by Walter, while technically correct, confounds a VERY simple topic. Being technically correct here amounts to what exactly?
  9 个评论
Stefan Karlsson
Stefan Karlsson 2015-12-28
well.... I guess I will have to apologize for my inacuracies. You will get something useful from PCA over a single gray scale image:
you will get the global variance of the image, but that is the only thing. I do not disagree with anything that Walter says, it is technically correct.
Question: What is a Jumbo Jet made up of? I answer: mechanical parts, engines, fuel. While Walter answers by reference to the elements of the periodic table. What is the "right" answer depends only on the context the original question was posed...
(scale selection!) With that I leave this short but fun exchange. Maybe we should quickly note that PCA is actually not the best tool for what the question was about. I would guess Neo should use non-negative matrix factorization, or some other similar flavor. For photographic images, negative values are not allowed in neither basis nor coefficients....
sorry if i was harsh in my original reply.
Image Analyst
Image Analyst 2015-12-28
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.

请先登录,再进行评论。


Stefan Karlsson
Stefan Karlsson 2015-12-28
... 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.

Aya Ahmed
Aya Ahmed 2020-4-5
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 ..

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by