A true color image can be converted to a gray scale image by preserving the luminance(brightness) of the image.
Here the RGB image is a combination of RED, BLUE AND GREEN colors.
The RGB image is 3 dimensional. In an image ,
at a particular position say ( i,j)
Image(i,j,1) gives the value of RED pixel.
Image(i,j,2) gives the value of BLUE pixel.
Image(i,j,3) gives the value of GREEN pixel.
The combination of these primary colors are normalized with R+G+B=1;
This gives the neutral white color.
The grayscale image is obtained from the RGB image by combining 30% of RED , 60% of GREEN and 11% of BLUE.
This gives the brightness information of the image. The resulting image will be two dimensional. The value 0 represents black and the value 255 represents white. The range will be between black and white values.
%0.2989 * R + 0.5870 * G + 0.1140 * B
%Without using for loop: