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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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 |