How to convert existing image to black and white?
Hello, I am working on my function to convert to black and white. I was wondering how to start this?
I know that when a image is black and white it has the same R,G,B values. So in a colored image (R,G,B) = (10,20,30), but in black in white it should be (10+20+30)/3 = 20, so Black and white image would have values of (20,20,20)
So :
R[x][y] = (R[i][j]+G[i][j]+B[i][j])/3
G[x][y] = (R[i][j]+G[i][j]+B[i][j])/3
B[x][y] = (R[i][j]+G[i][j]+B[i][j])/3
My question is how do i start this? use a for loop like this?
Code:
for (y = 0; y < HEIGHT; y++)
for (x = 0; x < WIDTH; x++) {
R[x][y] =
G[x][y] =
B[x][y] =
Instructions:
Change a Color Image to Black and White
A black and white image is the one that the intensity values are the same for all color channels, red, green, and
blue, at each pixel. To change a color image to grey, assign a new intensity, which is given by (R+G+B)=3,
to all the color channels at a pixel. The R; G;B are the old intensity values for the red, the green, and the
blue channels at the pixel. You need to define and implement the following function to do the job.
Code:
/* change color image to black and white */
void BlackNWhite(unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]);