MATLAB: Can I use PCA effectively on a greyscale image

image analysisImage Processing ToolboxpcaStatistics and Machine Learning Toolbox

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.

Best Answer

Sure. For example,
I = double(imread('cameraman.tif'));
X = reshape(I,[],4);
coeff = pca(X);
This would correlate vertical quarters of the image.