How do I compute the luminance of a pixel?
The colors are not evenly interpreted by our eyes.  When I want to make a picture gray scale, I usually go for the following calculation of the luminance of a pixel.

luminance = (r * 0.3) + (g * 0.59) + (b * 0.11)


Read more in the Stackoverflow question Formula to determine brightness of RGB color.