Xref: utzoo comp.graphics:4085 comp.windows.x:7173 Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!haven!mimsy!tank!shamash!com50!midgard!dal From: dal@midgard.Midgard.MN.ORG (Dale Schumacher) Newsgroups: comp.graphics,comp.windows.x Subject: Re: Luminance from RGB Message-ID: <572@midgard.Midgard.MN.ORG> Date: 9 Jan 89 21:20:06 GMT References: <23105@apple.Apple.COM> <2263@eos.UUCP> <83604@sun.uucp> Reply-To: dal@syntel.UUCP (Dale Schumacher) Organization: The Midgard Realm, St Paul MN Lines: 23 In article <83604@sun.uucp> falk@sun.uucp (Ed Falk) writes: |In article <2263@eos.UUCP>, jbm@eos.UUCP (Jeffrey Mulligan) writes: |> From article <23105@apple.Apple.COM>, by turk@Apple.COM (Ken "Turk" Turkowski): |> > Y = (R + 2G + B) / 4 |> Y = 2R + 5G + B | out = (77*r + 151*g + 28*b)/256 ; /* NTSC weights (.3,.59,.11)*/ | |The results are correct to four decimal places and the divide is replaced |by a right-shift in a decent compiler and a byte-move in a good compiler. I don't know where you got your numbers. The values I have for the Y component of YIQ (luminance) from RGB are: R=.299 G=.587 B=.144 The following formula is the best approximation with 8-bit values: Y = (R*77 + G*150 + B*29) / 256 Which gives the weights: R=.3008 G=.5859 B=.1133, total error=.0036 Your values give the weights: R=.3008 G=.5898 B=.1094, total error=.0092 Even MY numbers don't have 4 places of accuracy, but they are a better approximation to the 3 place target values I have. Someone mentioned that the NTSC weight may have been changed recently, is that so? PS. I fully agree with the idea that more accurate values should be used if you're going to use integer, and do 3 multiplies and a 'divide' (which can be optimized if it's a power of 2) anyway.