[comp.graphics] Color Picking

datta@cpsc.ucalgary.ca (Slarti) (12/14/89)

Not being a regular subscriber to this group, I hope this message does not
rehash something which has already been discussed heavily.

What I would like to do is load in a color graphics format that is stored
with 24 bit planes and display it on an 8 bit device.  This in itself is not
difficult, but what I need is a method of choosing 256 colors that can best
be used to represent the image, without dithering or the like.  I can get
pictures to display fine with the default pallette for my machine, but I
feel they could be better if the colors were set appropriately.

Does an algorithm to do this exist?  I would assume it involves some sort
of vector math in RGBspace.  If anyone knows of a method, or has some code,
I would really appreciate it.

E-Mail responses would be preferred, but I'll keep my eye on the net for a
bit.

TIA

darcy@druid.uucp (D'Arcy J.M. Cain) (12/15/89)

In article <2241@cs-spool.calgary.UUCP> datta@cs-sun-fsb.UUCP (Slarti) writes:
>
>What I would like to do is load in a color graphics format that is stored
>with 24 bit planes and display it on an 8 bit device.  This in itself is not
>difficult, but what I need is a method of choosing 256 colors that can best
>be used to represent the image, without dithering or the like.  I can get
I wrote two different programs to do this.  The first simply did straight bit
shifting to get 24 bits to 8.

The other method was very slow but was able to get closer. I built a pallete
in memory by scanning the 24 bit image for colours.  If I passed 256 colours
then I reduced the colour resolution of one of the elements (blue first, then
green, then red then blue again ...) Eventually you wound up with the best
256 colours (actually a little less usually) that describe the image.  Just
a quick and dirty shot at the problem but it seemed to work.  In fact every
time I tried to optimize it, it took longer but was not as good a result.

The biggest problem with that approach is the length of time it took.  Of
course that would depend on the type of image.  I was working on 1024X1024
digitized photographs.


-- 
D'Arcy J.M. Cain (darcy@druid)     |   Thank goodness we don't get all 
D'Arcy Cain Consulting             |   the government we pay for.
West Hill, Ontario, Canada         |
No disclaimers.  I agree with me   |

lmiller@aerospace.aero.org (Lawrence H. Miller) (12/29/89)

In article <2241@cs-spool.calgary.UUCP> datta@cs-sun-fsb.UUCP (Slarti) writes:
>
>What I would like to do is load in a color graphics format that is stored
>with 24 bit planes and display it on an 8 bit device.  This in itself is not
>difficult, but what I need is a method of choosing 256 colors that can best
>be used to represent the image, without dithering or the like.

Heckbert at Pixar has the best published algorithm on this.  However,
Paul Raveling at ISI (raveling@isi.edu) has been working on enhancements,
including fidelity criteria, that should be available in published form
soon.  Here is the Heckbert citation in refer format:

%A Paul Heckbert
%T Color Image Quantization for Frame Buffer Display
%J Computer Graphics
%D July, 1982
%V 16
%N 3
%P 297-307
%X Presents a method for selecting the N best colors to represent an image
digitized at M (M >> N) colors.  The methods presented are ``uniform
quantization'' and ``median cut.''  In uniform quantization, the N most
frequent colors are selected.  Median cut uses an adaptvie algorithm to
find the N ``best'' colors, and generally produces better results.  Typical
quantization levels are eight bits per pixel.  Dithering also increases the
quality of the final images.