rgb to grayscale

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • julian_m

    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('#fff fff');

    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

  • lorento

    #2
    Re: rgb to grayscale

    Found some code:

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

    --



    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('#fff fff');
    >
    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

    Comment

    • C.

      #3
      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('#fff fff');
      <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.

      Comment

      • julianmlp@gmail.com

        #4
        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)


        regards - julian

        Comment

        Working...