Calculate Black and White value for pixel.
Wednesday, October 21st, 2009Pseudo-algorithm:
We are finding the average value for the three color components…
1. Extract the Red, Green and Blue of a color.
2. Add the three values together, divide them by three.
3. Put the Red, Green and Blue values together to form the gray value.
int pixel_value = RGB(13, 152, 186); //get the red value of the pixel int red = RED_OF(pixel_value) ; //get the green value of the pixel int green = GREEN_OF(pixel_value) ; //get the blue value of the pixel int blue BLUE_OF(pixel_value) ; //average each color together to get the gray value int gray = (red + green + blue)/3; //bitwise 'or' them to make the complete RGB int gray_pixel_value = RGB_OF(gray, gray, gray);
sidenote:
Love these colors from Crayola, they bring back so many memories!