## How to cinvert RGB values into a single grayscale value

### How to cinvert RGB values into a single grayscale value

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

### How to cinvert RGB values into a single grayscale value

Different weights are applied to each channel.
http://www.jasonwaltman.com/thesis/filter-grayscale.html

Andrew

### How to cinvert RGB values into a single grayscale value

> 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.

### How to cinvert RGB values into a single grayscale value

>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.

Quote:>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

### How to cinvert RGB values into a single grayscale value

> >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.

### How to cinvert RGB values into a single grayscale value

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

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

>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

### How to cinvert RGB values into a single grayscale value

> Different weights are applied to each channel.
> http://www.jasonwaltman.com/thesis/filter-grayscale.html

> Andrew

110 54 26 12

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

### How to cinvert RGB values into a single grayscale value

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

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

> >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.

Quote:> 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.

Quote:> 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.

### How to cinvert RGB values into a single grayscale value

> > >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.

### How to cinvert RGB values into a single grayscale value

>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 ...

### How to cinvert RGB values into a single grayscale value

> >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.

### How to cinvert RGB values into a single grayscale value

>> Did you transpose the G and B numbers?

>Right you are.

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

### How to cinvert RGB values into a single grayscale value

> >> Did you transpose the G and B numbers?

> >Right you are.

> 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.

### How to cinvert RGB values into a single grayscale value

> >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,

thats 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

### How to cinvert RGB values into a single grayscale value

> >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.

Hi,
Is there a well known or standard algorithm to convert a series of
color RGB values to grayscale?
--

-re

########################################################################
#                            Ramiro Estrugo                            #

#                  http://www.fateware.com/~restrugo                   #
########################################################################