rgb to grayscale

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Do anyone know an algorithm which retieves a grey value given certain
rgb value?

I'm needing this kind of function:

$grey = RGBtoGrey('#ffffff');

where $grey (function's return value) should be a real number in [0;1]

Googling a little bit, I found an equation which seems to be aplied by
many photo-editor software

(.3*Red) + (.59*Green) + (.11*Blue)= Luminance/brightness

I'm just wondering whether someone here has better ideas...

regards - julian

Re: rgb to grayscale

Found some code:

$grey= 0.2125*$rgb['red']+ 0.7154*$rgb['green']+ 0.0721*$rgb['blue'];


julian_m wrote:
Quoted text here. Click to load it

Re: rgb to grayscale

julian_m wrote:
Quoted text here. Click to load it
Quoted text here. Click to load it

Although it might need some gamma correction, I would have thought that
the best starting point would be the size of the RGB vector - i.e.
grey = (255/442) * sqrt(red*red + green*green + blue*blue)

You tell us what looks better.


Re: rgb to grayscale

C. wrote:

Quoted text here. Click to load it

I think both formulas broduce similar results.
Anyway, judge by yourself (Be aware that you're going to open a ~1mb
htm file size, beacause I wanted to do some kind of css-art)

(I'll keep it online only a couple of days)

regards - julian

Site Timeline