Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!unmvax!ogccse!cvedc!nosun!fpssun.fps.com!celit!hutch From: hutch@fps.com (Jim Hutchison) Newsgroups: comp.graphics Subject: Re: Color quantization: flesh tones (really RGB->YIQ) Keywords: color rgb yiq quantization Message-ID: <643@celit.fps.com> Date: 19 Sep 89 16:56:02 GMT References: <6087@pt.cs.cmu.edu> <124742@sun.Eng.Sun.COM> <1212@midgard.Midgard.MN.ORG> Sender: daemon@fps.com Reply-To: hutch@fps.com (Jim Hutchison) Organization: FPS Computing Lines: 35 In <1212@midgard.Midgard.MN.ORG> dal@midgard.Midgard.MN.ORG (Dale Schumacher): [... In NTSC ...] >I thought Y was the intensity (luminance) component... and the most >bandwidth is used for the luminance, with less for the color components. >Here are the integer [0..255] pixel value formulae that I use: > Y = (((77 * R) + (150 * G) + (29 * B)) / 256); > I = (((153 * R) + (-70 * G) + (-82 * B)) / 256); > Q = (((54 * R) + (-134 * G) + (80 * B)) / 256); > R = (((256 * Y) + (245 * I) + (159 * Q)) / 256); > G = (((256 * Y) + (-70 * I) + (-167 * Q)) / 256); > B = (((256 * Y) + (-283 * I) + (436 * Q)) / 256); >The above forms the heart of a utility I wrote to set the luminance (Y) >of a color image from a monochrome image. I use this in convolutions, >particularly for edge sharpening, such that I do the convolution only >on the luminance component, then recombine the output with the original >color image. It would seem that by using these equations, you might end up with a fair amount of error in the process of remapping the colors. Atleast you will want to round-up in order to halve the error. E.g. Y = ((77 * R) + (150 * G) + (29 * B) + 128) / 256; Or, you could use the scaled numbers for the convolution and only rescale them when you reconvert to RGB. This might make your convolution algorithm to messy, perhaps you might want to just save the error from the original RGB->YIQ conversion and add that back into the RGB at the end. Have you noticed the error in your output? Is it significant enough to cause darkening of image or loss of shadow detail? /* Jim Hutchison {dcdwest,ucbvax}!ucsd!celerity!hutch */ /* Disclaimer: I am not an official spokesman for FPS computing */