-
-
Notifications
You must be signed in to change notification settings - Fork 23
Grayscale
Nick edited this page Nov 16, 2019
·
1 revision
The grayscale transformation is very easy. A pixel is gray if each color channel (red, green, blue) have the same value. That means each color has the same amount and the pixel is just a brightness value from black to white.
This implementation multiplies each channel with a different factor. The factors are given by the ITU-R BT.709-Standard for HDTV. The green channel has the biggest factor. That means the green channel has the biggest influence for the gray image. The calculated "color" value in the rgb variable is set to each channel.
rgb = (int) ((((p >> 16) & 0xFF) * 0.2125) + (((p >> 8) & 0xFF) * 0.7154) + ((p & 0xFF) * 0.0721));
rgb = (rgb << 16) | (rgb << 8) | (rgb);
In that way you will get an grayscale image weighted by the color channels.