[comp.graphics] RGB to Hue/Saturation/Luminence

agollum@engr.uky.edu (Kenneth Herron) (06/26/89)

I'm writing a program to convert Amiga IFF images to cross-stitch
patterns  (trying to get my wife interested in the darn thing :-).
Part of the conversion requires averaging the colors of several pixels
and reducing the color table by averaging "close" colors.  The methods
I have in mind for these steps requires the hue, saturation, & luminence
of the colors in question.  Does anyone have the formulas to convert
from RGB to HSL?  Or know of a good algorithm for doing these things?
(more details available on request)

Thanx in advance,
Kenneth Herron

foss@iris.ucdavis.edu (Jim Alves-Foss) (06/27/89)

In article <2922@ukecc.engr.uky.edu> agollum@ukecc.UUCP (Kenneth Herron) writes:
>....  Does anyone have the formulas to convert
>from RGB to HSL?  Or know of a good algorithm for doing these things?
>(more details available on request)

The book:
David F. Rogers, "Procedural Elements for Computer Graphics", McGraw-Hill 1985
has pseudocode algorithms for RGB<-->(HLS|HSV) starting on page 401. His 
descriptions of these methods is also understandable.

If you can't find it, I'll dig up my 'C' versions and send them to you.

-Jim Alves-Foss (foss@iris.ucdavis.edu)  /* Of course these are MY opinions */

jlg@hpfcdq.HP.COM (Jeff Gerckens) (06/28/89)

/ hpfcdq:comp.graphics / agollum@engr.uky.edu (Kenneth Herron) /  1:51 pm  Jun 25, 1989 /
> I'm writing a program to convert Amiga IFF images to cross-stitch
> patterns  (trying to get my wife interested in the darn thing :-).
> Part of the conversion requires averaging the colors of several pixels
> and reducing the color table by averaging "close" colors.  The methods
> I have in mind for these steps requires the hue, saturation, & luminence
> of the colors in question.  Does anyone have the formulas to convert
> from RGB to HSL?  Or know of a good algorithm for doing these things?
> (more details available on request)
> 
> Thanx in advance,
> Kenneth Herron

Any good text on computer graphics will have the information.
Particularly Roger's "Procedural Elements for Computer Graphics"
or Foley and Van Dam's "Fundamentals of Interactive Computer
Graphics".

You may not want to use HSL for the averaging. HSL can produce 
very "unexpected" results because of its nature as a cylindrical
space.  RGB should give results that are "as good" in most cases.
CIELUV or CIELAB will give the best results, but involve cumbersome
translations.

You may also experience some difficulty with translating the colors
on the screen into thread colors unless oyu do some thread to screen
matching.

-- Jeff Gerckens, Graphics Technology Division, Hewlett-Packard