# how does PhotoShop convert color to grayscale?

for example, I painted color red (255,0,0), green(0,255,0), blue (0,0,255), then I select "Image"->"Mode"->"Grayscale",
the image will be converted to
117,117,117-red
204,204,204-green
64, 64, 64-blue

I'm wondering how does Photoshop get these values ?
###### Who is Participating?

Commented:
It's a formula like gray = x * r + y * g + z * b

Given three groups of rgb and output gray value, you can calc the x, y, z by yourself :)

Regards
wu xz
0

Commented:
There is a simple formula. But I can't remember. Check out some computer graphics books.
0

Author Commented:
what does x,y,z represents ? can you give an example please ?
0

Commented:
For example:

gray = 0.5 * r + 0.3 * g + 0.2 * b
so x = 0.5, y = 0.3, z = 0.2

It is a very simple math question:

0.9 = x * 0.5 + y * 0.8 + z * 0.7
0.8 = x * 0.5 + y * 0.7 + z * 0.7
0.6 = x * 0.7 + y * 0.5 + z * 0.9

Can you calc the values of x, y, z out?

Regards

0

Commented:

What you might be getting confused about is how you convert the gray value returned by the formula to RGB - most windows programmers haven't experienced using color values between 0 and 1.  Color values between 0 and 1 are just normalized color values.  In windows, the color range is from 0 to 255, so 0.5 would be equal to a value of (0.5 * 255) or (127).  Since the value is gray (R, G, and B all the same) a gray of 0.5 would be RGB(127, 127, 127).

In your example above, you said when converting the colors:

red = (117,117,117) = 117 = (117 / 255) =  ~0.46
(a gray value of 0.46)

green = (204,204,204) = 204 = (204 / 255) = 0.8
blue = (64,64,64) = 64 = (64 / 255) = ~.25

So plugging all that into the formula...

gray = (x * r) + (y * g) + (z * b)
0.46 = (x * 1.0) + (y * 0) + (z * 0)
0.46 = 1x
x = 0.46

0.8 = (x * 0) + (y * 1.0) + (z + 0)
0.8 = 1y
y = 0.8

so z = 0.25

Now that you have the values of x, y, and z, you can convert any color to a gray value.  To convert RGB(141,25,250) to gray...

gray = [0.46 * (141 / 255)] + [0.8 * (25 / 255)] + [0.25 * (250 / 255)]
gray = (0.46 * 0.55) + (0.8 * 0.10) + (0.25 * 0.98)
gray = .25 + .08 + .24
gray = .57

So your gray value is (.57 * 255), or 145.35, or RGB(145,145,145).  You can check to see if the above formula is correct by plugging RGB(141,25,250) into your version of PhotoShop, converting it to gray, and seeing if you get something similar to RGB(145,145,145).  (It could still be a little off even if the formula's correct, because of all the rounding I did...but it should be close).

Good luck!
0

Author Commented:
I had tried to put the values into the equation, but the result is wrong. For the value of RGB(141,25,250),  the converted gray scale value is 97.  By the way, if I put a gray RGB, say RGB(100,100,100), the equation does not produce the answer of gray=100 for me.
0

Commented:
Please give me three or more groups of RGB - Gray value,
like 141, 25, 250 -> 97.

I will tell you the formula.

Regards
wu xz
0

Author Commented:
sure,

RGB(255,  0,  0)-117     RGB(0  ,255,  0)-204
RGB(0  ,  0,255)-64      RGB(255,255,  0)-243
RGB(0  ,255,255)-218     RGB(255,255,255)-255
RGB(255,0  ,255)-137     RGB(100,0  ,100)-54
RGB(0  ,100,100)-86      RGB(100,100,0  )-95
RGB(100,189,64 )-162     RGB(100,109,187)-115
RGB(255,228,143)-229     RGB(187,135,0  )-143
RGB(189,0  ,168)-99      RGB(0  ,176,201)-153
RGB(163,130,118)-138     RGB(0  ,43 ,109)- 46
RGB(211,0  , 74)-99      RGB(201,201,201)- 201
RGB(255,235,120)-232     RGB(97 ,97 ,97 )- 97

note : both RGB(189,0,168) and RGB(211,0,74) with become gray scale 99 when converted.
0

Commented:
I find the formula:

gray = 0.3 * r + 0.59 * g + 0.11 * b

The value group you gave may be wrong or be calculated by other formula, but this formula I found is more common (?). You can take it as F1(Formula one) :-)

Regards
wu xz
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.