Getting the brightness of a Grayscale pixel

2.8k views Asked by At

Basically I am trying to find the brightness of all pixels in a bitmap image. The images I am using are 24 bit bitmap images and I am not allow to use function GetBrightness(). I am getting the RGB value of the pixels, I am wondering if the RGB value is also the brightness of the pixel or can anyone recommend a method of getting the pixel brightness of a grayscale pixel?

Thanks

2

There are 2 answers

0
Clint Powell On

There are multiple methods for converting to grayscale: http://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale/

I have used the 0.21 R + 0.72 G + 0.07 B method with success. This will give you a number (between 0-255) that is the grayscale value.

0
Jonathan M On

Since luminance (brightness) is subjective, there are multiple ways to convert RBG to a luminance value. The difference is just how much weight do you give to each color.

Here's one method for relative luminance (Y):

Y = (0.2126 * R) + (0.7152 * G) + (0.0722 * B)

Here's another:

Y = (0.299 * R) + (0.587 * G) + (0.114 * B)

The first method is preferable to some because (for most people) "green light contributes the most to the intensity perceived by humans, and blue light the least". Color blindness and other differences can lessen the effect. Note that the second method puts less weight on the green value and more weight on the red value, with a smidgen extra going to the blue value.