Formula to determine brightness of RGB color

前端 未结 20 3136
猫巷女王i
猫巷女王i 2020-11-21 23:16

I\'m looking for some kind of formula or algorithm to determine the brightness of a color given the RGB values. I know it can\'t be as simple as adding the RGB values toget

20条回答
  •  梦毁少年i
    2020-11-22 00:00

    I think what you are looking for is the RGB -> Luma conversion formula.

    Photometric/digital ITU BT.709:

    Y = 0.2126 R + 0.7152 G + 0.0722 B
    

    Digital ITU BT.601 (gives more weight to the R and B components):

    Y = 0.299 R + 0.587 G + 0.114 B
    

    If you are willing to trade accuracy for perfomance, there are two approximation formulas for this one:

    Y = 0.33 R + 0.5 G + 0.16 B
    
    Y = 0.375 R + 0.5 G + 0.125 B
    

    These can be calculated quickly as

    Y = (R+R+B+G+G+G)/6
    
    Y = (R+R+R+B+G+G+G+G)>>3
    

提交回复
热议问题