Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# how does PhotoShop convert color to grayscale?

Posted on 1999-06-28
Medium Priority
283 Views
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 ?
0
Question by:eugeneng
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 23

Expert Comment

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

LVL 2

Accepted Solution

wuxz earned 3340 total points
ID: 1308290
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

Author Comment

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

LVL 2

Expert Comment

ID: 1308292
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

LVL 2

Expert Comment

ID: 1308293

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 Comment

ID: 1308294
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

LVL 2

Expert Comment

ID: 1308295
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 Comment

ID: 1308296
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

LVL 2

Expert Comment

ID: 1308297
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user intâ€¦
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messaâ€¦
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastrâ€¦
###### Suggested Courses
Course of the Month5 days, 11 hours left to enroll