By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

rgb to grayscale

P: n/a
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]
range

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

Jul 4 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Found some code:

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

--
http://blog.deshot.com
http://www.immersivelounge.com

julian_m wrote:
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]
range

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
Jul 4 '06 #2

P: n/a
C.
julian_m wrote:
Do anyone know an algorithm which retieves a grey value given certain
rgb value?

I'm needing this kind of function:

$grey = RGBtoGrey('#ffffff');
<snip>
(.3*Red) + (.59*Green) + (.11*Blue)= Luminance/brightness

I'm just wondering whether someone here has better ideas...
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.

C.

Jul 4 '06 #3

P: n/a

C. wrote:
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.
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)
http://choringa.com.ar/test.htm

regards - julian

Jul 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.