Generalize rgb2gray. Fixes #18