rgb to grayscale

This is a discussion on rgb to grayscale within the PHP Language forums, part of the PHP Programming Forums category; Do anyone know an algorithm which retieves a grey value given certain rgb value? I'm needing this kind of ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-04-2006
julian_m
 
Posts: n/a
Default rgb to grayscale

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

Reply With Quote
  #2 (permalink)  
Old 07-04-2006
lorento
 
Posts: n/a
Default Re: rgb to grayscale

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


Reply With Quote
  #3 (permalink)  
Old 07-04-2006
C.
 
Posts: n/a
Default Re: rgb to grayscale

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.

Reply With Quote
  #4 (permalink)  
Old 07-04-2006
julianmlp@gmail.com
 
Posts: n/a
Default Re: rgb to grayscale


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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0