How to cinvert RGB values into a single grayscale value

M
Posted By
moham14
Mar 2, 2004
Views
974
Replies
15
Status
Closed
Does anyone know how photoshop converts RGB values into a single grayscale value when we convert a color image into grayscale mode?

I’m looking for a function like f that receives r,g,b and then gives gr.

gr = f(r,g,b)

I’ve checked some test values in photoshop and the function should the same results too.

for all entries that r,g,b are equal the result should be the same:

r=m , g=m , b=m ===> f(m,m,m) = m

it means that when the color itself is gray then it should not be changed during convertion.

other test values and results:

f(255, 0, 0) = 130 maximum pure red = 130, 130, 130 in grayscale
f(0, 255, 0) = 220 maximum pure green = 220, 220, 220 in grayscale
f(0, 0, 255) = 70 maximum pure blue = 70, 70, 70 in grayscale

it means that green in monitor seems brighter than other two and red seems
brighter than blue.

f(255, 255, 0) = 248
f(255, 0, 255) = 145
f( 0, 255, 255) = 228

2669458-25

Must-have mockup pack for every graphic designer πŸ”₯πŸ”₯πŸ”₯

Easy-to-use drag-n-drop Photoshop scene creator with more than 2800 items.

AM
Andrew Morton
Mar 2, 2004
Different weights are applied to each channel.
http://www.jasonwaltman.com/thesis/filter-grayscale.html

Andrew
W
westin*nospam
Mar 2, 2004
(Tom keen) writes:

Does anyone know how photoshop converts RGB values into a single grayscale value when we convert a color image into grayscale mode?
I’m looking for a function like f that receives r,g,b and then gives gr.

gr = f(r,g,b)

I’ve checked some test values in photoshop and the function should the same results too.

for all entries that r,g,b are equal the result should be the same:
r=m , g=m , b=m ===> f(m,m,m) = m

it means that when the color itself is gray then it should not be changed during convertion.

other test values and results:

f(255, 0, 0) = 130 maximum pure red = 130, 130, 130 in grayscale
f(0, 255, 0) = 220 maximum pure green = 220, 220, 220 in grayscale
f(0, 0, 255) = 70 maximum pure blue = 70, 70, 70 in grayscale

it means that green in monitor seems brighter than other two and red seems
brighter than blue.

f(255, 255, 0) = 248
f(255, 0, 255) = 145
f( 0, 255, 255) = 228

That’s exactly true. Display areas of pure red, green, and blue on your monitor. Which looks brightest?

Actually, the weights for this depend on the particular display. So you really need to get some info from the color profile to do this correctly.


-Stephen H. Westin
Any information or opinions in this message are mine: they do not represent the position of Cornell University or any of its sponsors.
B
bhilton665
Mar 2, 2004
From: (Tom keen)

Does anyone know how photoshop converts RGB values into a single grayscale value when we convert a color image into grayscale mode?

I think it’s 30% Red, 59% Green, 11% Blue for a straight greyscale conversion. From memory, so you should verify these numbers, but I think that’s it (and I don’t care enough to look it up πŸ™‚

You can use the Channel Mixer to combine R-G-B channels -> Monochrome in any percentage if you want something different.

it means that green in monitor seems brighter than other two and red seems brighter than blue.

f(255, 255, 0) = 248
f(255, 0, 255) = 145
f( 0, 255, 255) = 228

That would make sense, given the higher % of the green channel in the numbers I gave above.

Bill
W
westin*nospam
Mar 2, 2004
(Bill Hilton) writes:

From: (Tom keen)

Does anyone know how photoshop converts RGB values into a single grayscale value when we convert a color image into grayscale mode?

I think it’s 30% Red, 59% Green, 11% Blue for a straight greyscale conversion. From memory, so you should verify these numbers, but I think that’s it (and I don’t care enough to look it up πŸ™‚

It depends on the display. The numbers you gave are for the 1953 NTSC phosphors, which nobody uses any more. Chances are excellent that the weights for your monitor will be different.

<snip>


-Stephen H. Westin
Any information or opinions in this message are mine: they do not represent the position of Cornell University or any of its sponsors.
B
bhilton665
Mar 2, 2004
Does anyone know how photoshop converts RGB values into a single grayscale value when we convert a color image into grayscale mode?

(Bill Hilton) writes:

it’s 30% Red, 59% Green, 11% Blue for a straight greyscale conversion.

From: westin* (Stephen H. Westin)

It depends on the display. The numbers you gave are for the 1953 NTSC phosphors, which nobody uses any more. Chances are excellent that the weights for your monitor will be different.

I have to disagree with you … why would the program convert RGB to grayscale differently for different monitors?

I checked again in a few Photoshop books I rely on and the 30/59/11 weighting is what John Paul Caponigro, Bruce Fraser, Dan Margulis and Barry Haynes all agree is taking place with the basic Image > Mode > Grayscale command. This is a wide range of experts and I seriously doubt that you are right and all of them are wrong.

Maybe you’re referring to how the image gets displayed on the screen when it’s run thru the monitor ICM profile, but that’s totally different than how the pixel values get converted when creating a new grayscale file.

Bill
M
moham14
Mar 2, 2004
"Andrew Morton" …
Different weights are applied to each channel.
http://www.jasonwaltman.com/thesis/filter-grayscale.html
Andrew

110 54 26 12
Thanks for your reply. The article gives this :

gr = (.30 * r) +(.59 * g) +(.11 * b)

and as you see this is a linear function. But the results that photoshop makes are not linear for example:

f(0, 128, 0) = 110 110 = .859 * g
f(0, 64, 0) = 54 54 = .843 * g
f(0, 64, 0) = 26 26 = .812 * g
f(0, 32, 0) = 12 12 = .750 * g
W
westin*nospam
Mar 2, 2004
(Bill Hilton) writes:

Does anyone know how photoshop converts RGB values into a single grayscale value when we convert a color image into grayscale mode?

(Bill Hilton) writes:

it’s 30% Red, 59% Green, 11% Blue for a straight greyscale conversion.

From: westin* (Stephen H. Westin)

It depends on the display. The numbers you gave are for the 1953 NTSC phosphors, which nobody uses any more. Chances are excellent that the weights for your monitor will be different.

I have to disagree with you … why would the program convert RGB to grayscale differently for different monitors?

Because the individual red, green and blue channels are *different colors* on different monitors, so they have different relative luminances.

I checked again in a few Photoshop books I rely on and the 30/59/11 weighting is what John Paul Caponigro, Bruce Fraser, Dan Margulis and Barry Haynes all agree is taking place with the basic Image > Mode > Grayscale command. This is a wide range of experts and I seriously doubt that you are right and all of them are wrong.

Perhaps Photoshop does it that way. If so, it is at best an approximation. I just tried it in Photoshop 6; here’s what I got for an sRGB profile.

255,0,0 -> 130
0,255,0 -> 220
0,0,255 -> 69

Assuming a gamma of 2.2 (an approximation to real sRGB), I get weights of .227, .723, .056.

Maybe you’re referring to how the image gets displayed on the screen when it’s run thru the monitor ICM profile, but that’s totally different than how the pixel values get converted when creating a new grayscale file.

To convert a color image to a grayscale image while retaining relative luminance of each color, you need to perform the Y part of the RGB->XYZ transformation. And that transformation depends on the particular RGB primaries involved.

See <http://www.poynton.com/ColorFAQ.html>, especially < http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html# RTFToC9>, "What weighting of red, green and blue corresponds to brightness?"


-Stephen H. Westin
Any information or opinions in this message are mine: they do not represent the position of Cornell University or any of its sponsors.
W
westin*nospam
Mar 3, 2004
westin* (Stephen H. Westin) writes:

(Bill Hilton) writes:

From: (Tom keen)

Does anyone know how photoshop converts RGB values into a single grayscale value when we convert a color image into grayscale mode?

I think it’s 30% Red, 59% Green, 11% Blue for a straight greyscale conversion. From memory, so you should verify these numbers, but I think that’s it (and I don’t care enough to look it up πŸ™‚

It depends on the display. The numbers you gave are for the 1953 NTSC phosphors, which nobody uses any more. Chances are excellent that the weights for your monitor will be different.

<snip>

Values for sRGB:

gray = 0.2126*R + 0.7152*B + 0.0722*G

where R, G, B, are linear RGB values. See

<http://www.srgb.com/basicsofsrgb.htm> for more complete information.


-Stephen H. Westin
Any information or opinions in this message are mine: they do not represent the position of Cornell University or any of its sponsors.
B
bhilton665
Mar 3, 2004
From: westin* (Stephen H. Westin)

Values for sRGB:

gray = 0.2126*R + 0.7152*B + 0.0722*G

Did you transpose the G and B numbers? I seriously doubt blue is weighted 10x of green …
W
westin*nospam
Mar 3, 2004
(Bill Hilton) writes:

From: westin* (Stephen H. Westin)

Values for sRGB:

gray = 0.2126*R + 0.7152*B + 0.0722*G

Did you transpose the G and B numbers? I seriously doubt blue is weighted 10x of green …

Right you are.


-Stephen H. Westin
Any information or opinions in this message are mine: they do not represent the position of Cornell University or any of its sponsors.
B
bhilton665
Mar 3, 2004
Did you transpose the G and B numbers?

From: westin* (Stephen H. Westin)

Right you are.

About time I got something right in this thread πŸ™‚

I don’t know where the 30/59/11 % numbers I quoted originally came from … I felt safe in quoting them since I’d read it in Caponigro, Margulis, Fraser, Blatner etc but I can’t duplicate those exact numbers either when I create patches and convert to grayscale in various working spaces. I even tried ColorMatch RGB thinking the guys I quoted were all Mackies but that still didn’t convert precisely to the formula, so I’m bowing out of this thread as I obviously was misinterpreting what the gurus had written (or, God forbid, they were wrong :).

The only thing that you (Stephen … whom I usually agree with) wrote that I have trouble grasping is that the conversion formula depends on the monitor type. I can see differences for different working spaces when I ran test cases but I’m having problems agreeing it’s monitor-type dependent too.

Bill
W
westin*nospam
Mar 3, 2004
(Bill Hilton) writes:

Did you transpose the G and B numbers?

From: westin* (Stephen H. Westin)

Right you are.

About time I got something right in this thread πŸ™‚

I don’t know where the 30/59/11 % numbers I quoted originally came from … I felt safe in quoting them since I’d read it in Caponigro, Margulis, Fraser, Blatner etc but I can’t duplicate those exact numbers either when I create patches and convert to grayscale in various working spaces. I even tried ColorMatch RGB thinking the guys I quoted were all Mackies but that still didn’t convert precisely to the formula, so I’m bowing out of this thread as I obviously was misinterpreting what the gurus had written (or, God forbid, they were wrong :).

The only thing that you (Stephen … whom I usually agree with) wrote that I have trouble grasping is that the conversion formula depends on the monitor type. I can see differences for different working spaces when I ran test cases but I’m having problems agreeing it’s monitor-type dependent too.

Well, I think that’s a terminology problem on my part. I think of a profile/working space as a particular display for which the image is being targeted. That’s what I meant; if you are using a Sony Trinitron as your working space, you will presumably get results different from those for sRGB. Is that any clearer?


-Stephen H. Westin
Any information or opinions in this message are mine: they do not represent the position of Cornell University or any of its sponsors.
H
hoffmann
Mar 3, 2004
(Bill Hilton) wrote in message news:…
From: westin* (Stephen H. Westin)

Values for sRGB:

gray = 0.2126*R + 0.7152*B + 0.0722*G

Did you transpose the G and B numbers? I seriously doubt blue is weighted 10x of green …

Bill,

thatΒ΄s colorimetrically correct but is 100% Blue is really ten times darker than 100% Green … ?

http://www.fho-emden.de/~hoffmann/gray10012001.pdf

Best regards —Gernot Hoffmann
H
hoffmann
Mar 3, 2004
(Bill Hilton) wrote in message news:…
From: westin* (Stephen H. Westin)

Values for sRGB:

gray = 0.2126*R + 0.7152*B + 0.0722*G

Did you transpose the G and B numbers? I seriously doubt blue is weighted 10x of green …

Yes, of course, B and G swapped.

G.H.
B
bhilton665
Mar 3, 2004
(Bill Hilton) writes:

The only thing that you (Stephen) wrote that I have trouble grasping is that the conversion formula depends on the monitor type.

From: westin* (Stephen H. Westin)

Well, I think that’s a terminology problem on my part. I think of a profile/working space as a particular display for which the image is being targeted.

OK, I see where you’re coming from but I’m used to different definitions … to me "working space" is a device-independent abstract space (like sRGB or Adobe RGB) that’s chosen for a particular gamut and is easy to work in because it’s gray-balanced and perceptually uniform. As opposed to device-specific profiles (like a monitor or printer or scanner ICM profile), which are almost never uniformly gray balanced (ie, equal RGB values aren’t gray thru the entire range).

If I target the file to a "particular display" or print profile I call this soft-proofing. I’m getting most of this terminology from Blatner/Fraser’s "Real World Photoshop" and "Real World Color Management", which relies heavily on the ICC color management flow for terminology.

That’s what I meant; if you are using a Sony Trinitron
as your working space, you will presumably get results different from those for sRGB. Is that any clearer?

I wouldn’t use a monitor profile for my working space (as I defined ‘working space’ above), this was what Photoshop used back in V5 days but now they suggest using an abstract space for the working space.

I agree that if you soft-proof to different displays (or even to your own monitor) or printers the image on-screen will look different. But this is done "on-the-fly" as the color management software temporarily changes the RGB values to mimic what you’ll see on a different device.

The RGB -> Grayscale conversion should convert to a specific set of numbers (what we’re discussing in this entire thread is exactly what formula is used to make the conversion) but once it’s converted the numbers in the file stay the same, and I don’t think you would convert to different numbers in the file if you have different monitor types. I agree that those numbers will get translated to LOOK different with different soft-proofs (whether monitor or printer proofs), I think that’s where we share common ground?

Bill

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

Related Discussion Topics

Nice and short text about related topics in discussion sections