% This function uses principle component analysis to convert an RGB image
% to a gray scale image.
% Copyrighted by Tyler L. Coye
function [gray] = impca(im)
im = im2double(im);
lab = rgb2lab(im);
f = 0;
wlab = reshape(bsxfun(@times,cat(3,1-f,f/2,f/2),lab),[],3);
[C,S] = pca(wlab);
S = reshape(S,size(lab));
S = S(:,:,1);
gray = (S-min(S(:)))./(max(S(:))-min(S(:)));
end
Tyler Coye (2021). Convert RGB images to Gray Scale with Principle Component Analysis (https://www.mathworks.com/matlabcentral/fileexchange/50874-convert-rgb-images-to-gray-scale-with-principle-component-analysis), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.