I saw VodkaRocks4Breakfast's post a few weeks ago, and I remembered it today when I needed to grayscale some images. I made a simple matlab function to do this, so I thought I would make it available for anyone else who might be interested:
function imGray = rgb2grayPCA(imRGB) % Use Principal Components Analysis to convert an RGB image to grayscale % Reshape RGB image to column vectors of each color [y x z] = size(imRGB); imRGB = reshape(imRGB, [ x*y z ]); % Get PC's of image imRGB = double(imRGB); [PC V] = eig(cov(imRGB)); [~, iV] = sort(diag(V),1,'descend'); PC = PC(:,iV); % Use PC's to create grayscale image imGray = imRGB*PC; imGray = imGray(:,1); % Convert grayscale image to 8-bit integer imGray = imGray - min(imGray); imGray = imGray / max(imGray) * 255; imGray = uint8(imGray); % Reshape grayscale image to dimensions of original RGB image imGray = reshape(imGray, [ y x ]); end
[link][2 comments]