Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!decwrl!mejac!gryphon!pnet02!dsears From: dsears@pnet02.cts.com (Doug Sears) Newsgroups: comp.sys.amiga Subject: RGB to HSV, and RGB to CMY Message-ID: <4402@gryphon.CTS.COM> Date: 10 Jun 88 07:20:39 GMT Sender: root@gryphon.CTS.COM Organization: People-Net [pnet02], Redondo Beach, CA. Lines: 65 ------------------- kodiak@amiga.UUCP (Robert R. Burns) writes: >In article <7271@swan.ulowell.edu> dpelland@hawk.ulowell.edu (David Pelland) writes: >>In article <8805271453.AA13503@jade.berkeley.edu> BBOURBIN@UMDD.BITNET (Brett S Bourbin) writes: >>>Does anyone out there know of a formula for converting a RGB (red green blue) >>>color value, into a HSV (hue saturation value) one? >> >>H = cos^-1((1/2((R-G)+(R-G)))/(((R-G)^2+(R-B)(G-B))^(1/2))) >>S = 1 - ((3*(min(RGB)))/I) >>I = (R+B+G)/3 > Most Amiga stuff I've seen uses the HSV cylinder, w/ black on >the bottom, white in the middle at the top, and fully saturated colors around >the outside of the cylinder. My favorite reference is the 1978 (?) SIGGRAPH >proceedings (but I don't have them). I think of HSV as... >H = [0 == 1 == red; .33 == green; .67 == blue] // that may be the one above? >S = 1 - min(R, G, B); // distance from "grey" >V = max(R, G, B); // non-blackness Not bad for quoting from memory. Actually, it's a hexcone, not a cylinder, unless there's more than one HSV model. The article Kodiak was referring to is probably "Color Gamut Transform Pairs", by Alvy Ray Smith, SIGGRAPH 78 Proceedings, pp. 12-19 (also reprinted in "Tutorial: Computer Graphics", 2nd ed, J.C. Beatty & K.S. Booth, eds, pp. 376-383). They introduced the hexcone model (HSV) and the triangle model (HSL). Here's their algorithm for the hexcone, RGB to HSV (R, G, B, H, S, and V all run from 0 to 1): V := max(R, G, B); Let X := min(R, G, B); S := (V - X)/V; if S=0 return; Let r := (V - R)/(V - X); g := (V - G)/(V - X); b := (V - B)/(V - X); If R=V then H := (if G=X then 5+b else 1-g); If G=V then H := (if B=X then 1+r else 3-b); else H := (if R=X then 3+g else 5-r); H := H/6; You have to watch out for when S = 0 (H is undefined). Another explanation of the hexcone model is in the September 1984 BYTE, pp. 227-246. David Pelland's formula looks like the HSL triangle model, "unbiased case". Now for a question: any hints on converting RGB to CMY or CMYB (cyan/magenta/yellow/black: subtractive color) as applied to low-cost color printers? C = 1 - R, etc. is too simple. The Neugebauer equations take into account the properties of real-life colored inks and variable overlap of dots, but they're real hard to solve (system of three NONlinear equations). Has anybody come up with a practical approach? I'm afraid I'll have to bypass the printer.device to make use of this, since it only has the one graphics function, DumpRPort(). UUCP: {ihnp4!scgvaxd!cadovax, }!gryphon!pnet02!dsears INET: dsears@pnet02.cts.com