Thanks for all your input, guys. This should work different from a standard conversion, as you see in Chris' version the deepest are lighter than middle ground. I found some algorithms on the web. To have an accurate conversion there should be a constant way; I'll do some experimenting.
This is what I found:
Gray RGB color code has equal red,green and blue values:
R = G = B
For each image pixel with red, green and blue values of (R,G,B):
R' = G' = B' = (R+G+B) / 3 = 0.333R + 0.333G + 0.333B
This formula can be changed with different weights for each R/G/B values.
R' = G' = B' = 0.2126R + 0.7152G + 0.0722B
Or
R' = G' = B' = 0.299R + 0.587G + 0.114B
Example
Pixel with RGB values of (30,128,255)
The red level R=30.
The green level G=128.
The blue level B=255.
R' = G' = B' = (R+G+B) / 3 = (30+128+255) / 3 = 138
so the pixel will get RGB values of:
(138,138,138)
----------------
Second option:
If each color pixel is described by a triple (R, G, B) of intensities for red, green, and blue, how do you map that to a single number giving a grayscale value? The GIMP image software has three algorithms.
The lightness method averages the most prominent and least prominent colors: (max(R, G, B) + min(R, G, B)) / 2.
The average method simply averages the values: (R + G + B) / 3.
The luminosity method is a more sophisticated version of the average method. It also averages the values, but it forms a weighted average to account for human perception. We're more sensitive to green than other colors, so green is weighted most heavily. The formula for luminosity is 0.21 R + 0.72 G + 0.07 B.
You're method looks pretty good, Kadri. I'll have a go also.