[comp.graphics] RGB -> 16 grayscale

wong@ICS.UCI.EDU (Wang-chan Wong) (03/19/91)

Hi,  I am working on a project that requires to display 256 colors with
a 16 levels grayscale (as with a gas plasma screen.)  I understand
that the following formula will compute the corresponding of graylevel
given the rgb intensity:

    grayscale= .299*red+ .587*green + .114*blue

However, given 256 colors, this formula still maps onto more than 16
distinct grayscales.  My question is: how to map exactly onto 16
grayscales?  Are there any algorithms that map onto 16 grayscales
while minimizing color collison at the same time? (i.e. I can still
view a 256 pictures in the 16 grayscales gas plasma screen.)

Thanks in advance.   -- wang

kempkec@mist.CS.ORST.EDU (Christopher Kempke) (03/19/91)

In article <5083.669373541@ics.uci.edu> wong@ICS.UCI.EDU (Wang-chan Wong) writes:
>Hi,  I am working on a project that requires to display 256 colors with
>a 16 levels grayscale (as with a gas plasma screen.)  I understand
>that the following formula will compute the corresponding of graylevel
>given the rgb intensity:
>
>    grayscale= .299*red+ .587*green + .114*blue
>
>However, given 256 colors, this formula still maps onto more than 16
>distinct grayscales.  My question is: how to map exactly onto 16
>grayscales?  Are there any algorithms that map onto 16 grayscales
>while minimizing color collison at the same time? (i.e. I can still
>view a 256 pictures in the 16 grayscales gas plasma screen.)
>
>Thanks in advance.   -- wang


	Yes, easily.  Assuming that those (red, green, blue) values are
	0-255, you just divide the resultant value by 16, and you get 16
	possible outcomes.  Now just devide your available greys into
	16 possibilities 0 = black, 15 = white.

	The fundamental "secret" here is that 256 colors will always map
	to (roughly) 256 greyscales, so you will HAVE to have multiple
	colors represented by the same grey (intensity) value.  Just
	throw away the least significant bits (as many as necessary) to
	leave yourself with the number of intensity values you want.

	You ARE losing information this way, but there's no way to reflect
	the 256 colors with only 16 greys unless you halftone, dither, or
	use some other method which actually changes the pixel pattern.

		--Chris

malak@halluc.com (Michael Malak) (03/23/91)

-> Hi,  I am working on a project that requires to display 256 colors
-> with a 16 levels grayscale (as with a gas plasma screen.)  I
-> understand that the following formula will compute the corresponding
-> of graylevel given the rgb intensity:
->
->   grayscale= .299*red+ .587*green + .114*blue
->
-> However, given 256 colors, this formula still maps onto more than 16
-> distinct grayscales.  My question is: how to map exactly onto 16
-> grayscales?  Are there any algorithms that map onto 16 grayscales

First, sort the 256 colors on their greyscale equivalent, then tally up 
how many pixels there are in the image for each of the 256 colors.  Then 
break this "histogram" into 16 equal parts (equal number of pixels per "part"; 
the tallies help you do this).  So for each of the 16 parts you have to come up 
with a greyscale value for it; simply do an average weighted by the number of 
pixels associated with each original greyscale.

You may also want to consider F&S dithering, with or without the above 
technique.

--  
Michael Malak -- sysop of Hallucination

UUCP: ...!uunet!halluc!malak
INTERNET: malak@halluc.com

ans@cs.city.ac.uk (Ashley Salisbury) (03/25/91)

In article <1991Mar19.115516.21440@lynx.CS.ORST.EDU> kempkec@mist.CS.ORST.EDU (Christopher Kempke) writes:
>In article <5083.669373541@ics.uci.edu> wong@ICS.UCI.EDU (Wang-chan Wong) writes:
>>Hi,  I am working on a project that requires to display 256 colors with
>>a 16 levels grayscale (as with a gas plasma screen.)  I understand
>>that the following formula will compute the corresponding of graylevel
>>given the rgb intensity:
>>
>>    grayscale= .299*red+ .587*green + .114*blue
>>
>>However, given 256 colors, this formula still maps onto more than 16
>>distinct grayscales.  My question is: how to map exactly onto 16
>>grayscales?  Are there any algorithms that map onto 16 grayscales
>>while minimizing color collison at the same time? (i.e. I can still
>>view a 256 pictures in the 16 grayscales gas plasma screen.)
>>
>>Thanks in advance.   -- wang
>
>
>	Yes, easily.  Assuming that those (red, green, blue) values are
>	0-255, you just divide the resultant value by 16, and you get 16
>	possible outcomes.  Now just devide your available greys into
>	16 possibilities 0 = black, 15 = white.
>
>	..colors represented by the same grey (intensity) value.  Just
>	throw away the least significant bits (as many as necessary) to
>	leave yourself with the number of intensity values you want.
>
>	You ARE losing information this way, but there's no way to reflect
>	the 256 colors with only 16 greys unless you halftone, dither, or
>	use some other method which actually changes the pixel pattern.
>
>		--Chris

	This is essentially true, however 4 bit quantisation from 256 grey
levels to 16 can look a bit poor, I would suggest that you use Floyd -Steinberg
Error diffusion to distribute the quantisation error, you get a more pleasing
picture to view, although this is more computationally expensive. Another
method is to use the dithering method of noise injection to upset the
quantisation (described in Ch.4 (?) of Digital Coding of Waveforms : principles and applications to speech and video by N.S. Jayant, and Peter Noll)

good luck,

Ashley.


P.S. The only other thing I might suggest (flames elsewhere please !) is try
frame switching on the display (if you can bear the flicker) so that you
achieve 31 grey (gray) levels ! .. I have tried this and hated the flicker,
but on an LCD or gas plasma it may be bearable (?) .. by having two closely
matched pixel values displayed at the same place on alternate display frames
the effect with vision persistance is to get an "in-between" grey tone.

ie imagine the top left corner pixel .. display say grey level 7, then
on the next display frame (1/50th or 1/60 or 1/72 or whatever of a second
later) display say grey level 8. Then on the next frame back to 7 etc.
The effect (if you are not eppileptic (?) should be a grey level of say 7.5)
this 16 grey levels can be used to give the effect of 31.

This may provide a more reasonable picture than just 16 grey levels.