Hue, Saturation & Brightness algorithm Standards

Hey! It aint that hard!
Post Reply
Gerry
BIG GIANT HEAD I Get Free Beer
BIG GIANT HEAD I Get Free Beer
Posts: 5727
Joined: 12/04/01, 12:00 am
Location: Perth, Western Australia
Contact:

Post by Gerry » 04/18/03, 9:23 am

<acronym title="Hue Saturation Value">HSV</acronym>, <acronym title="Hue Saturation Brightness">HSB</acronym>, <acronym title="Hue Saturation Light">HSL</acronym>, these and possibly others all mean the exact same and just as there is no standard for what the color space is called there is also no standard for what each <acronym title="Red Green Blue">RGB</acronym> coverts to as a HSV value, every application or algorithm I have come across all have a different take on it so and all would convert the same RGB value to different HSV values. It's crazy, I'm just wondering if anybody knows why there isn't a standard formula for the conversion.

<small>note: I put this thread here as there will probably be code somewhere down the line if the topic takes off, was tossing up between this forum and "Free Beer"</small>
I answer rhetorical questions for my own enjoyment.

Gerry
BIG GIANT HEAD I Get Free Beer
BIG GIANT HEAD I Get Free Beer
Posts: 5727
Joined: 12/04/01, 12:00 am
Location: Perth, Western Australia
Contact:

Post by Gerry » 04/19/03, 7:13 pm

Maybe I should change that title due to the fact that I'm the only one who even looked at the topic. :evil:

Anyway, does anybody know what the algroithm that PhotoShop uses to figure out their version of HSV?
I answer rhetorical questions for my own enjoyment.

vaxen
Member *****
Posts: 69
Joined: 11/26/02, 12:00 am
Location: USSA
Contact:

Post by vaxen » 04/24/03, 7:32 pm

Hi gerry. Here is something that may interest you. Hope it is helpful.


RGB to HSV conversion algorithm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RGB are the red, green, blue primary colors (0-1)
Max is the maximum function
Min is the minimum function

/* determine the value */
V = Max(R,G,B)
/* determine saturation */
Temp = Min(R,G,B)
if V = 0 then
S = 0
else
S = (V-Temp)/V
endif
/* determine the hue */
if S = 0 then
H = Undefined
else
Cr = (V-R)/(V-Temp)
Cg = (V-G)/(V-Temp)
Cb = (V-B)/(V-Temp)
/* the color is between yellow and magenta */
if R = V then H = Cb - Cg
/* the color is between cyan and yellow */
if G = V then H = 2 + Cr - Cb
/* the color is between magenta and cyan */
if B = V then H = 4 + Cg - Cr
/* convert to degrees */
H = 60*H
/* prevent negative value */
if H < 0 then H = H + 360
endif
finish




<font class=editedby>[ This Message was edited by: vaxen on 2003-04-25 03:47 ]</font>

Gerry
BIG GIANT HEAD I Get Free Beer
BIG GIANT HEAD I Get Free Beer
Posts: 5727
Joined: 12/04/01, 12:00 am
Location: Perth, Western Australia
Contact:

Post by Gerry » 04/25/03, 4:37 am

Not sure if that's one of the algorithms I've already come across or not but I'll try it out. Thanx Vax.
I answer rhetorical questions for my own enjoyment.

Post Reply