Simple color contrasting color to grayscale conversion via PCA

Alec Jacobson

December 29, 2013

weblog/

I remembered a nice paper about trying to do a better job converting color images to grayscale so that parts of a color image with similar intensities but different hues show up contrasted in the grayscale version. They solve this with a dense global optimization. There have been a few follow ups I haven't read yet. But I thought I'd try out a really simple, perhaps naive, conversion technique. I simply convert an RGB image to Lab (or ntsc's yiq) colorspace and then conduct principal component analysis (PCA) an a weighted combination of these vectors. This gives me a poor man's multi-dimensional scaling of the supposedly perceptually metric LAB colorspace. Actually with the right weighting parameters this works pretty well.

monet sunset pca luma gray

From left to right, compare the original, PCA grayscale, bare "Lightness" L channel, matlab's rgb2gray.

Here's the matlab code to compute this:

im = im2double(imread('~/Downloads/sunset.png'));
%lab = rgb2lab(im);
lab = rgb2ntsc(im); % not really lab but similar idea
f = 0.45;
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(:)));

Here're some various results for different weighting factors f.

monet sunset pca parameter range