Parent Topic: IHS
R = Red, G = Green, B = Blue
I = Intensity, H = Hue, S = Saturation
K2 = 1 / sqrt(2)
K3 = 1 / sqrt(3)
K6 = 1 / sqrt(6)
PI is the constant PI (3.14159)
RadToDeg = 180 / PI (factor to convert radians to degrees)
B1 = K6 * (2*B - R - G)
X1 = K2 * (G - R)
I = K3 * (R + G + B)
If (B1 = 0) then
If (R <= G) H = 90
If (G < R) H = 270
If (B1 <> 0) then
H = RadToDeg * atan(X1 / B1)
If (G > R and H < 0) H = H + 180
If (G < R and H > 0) H = H + 180
If (G = R and R > B) H = 180
If (H < 0) H = H + 360
If (H >= 360) H = H - 360
If output channels are all 8-bit, then Intensity, Hue, and
Saturation values are scaled between 0 and 255:
I = I * (255 / 442) H = H * (255 / 360) S = S * (255 / 208.2066)The above algorithm was derived from the following references:
Kruse, F.A. and G.L. Raines, 1984. "A Technique For Enhancing Digital Colour Images by Contrast Stretching in Munsell Colour Space", Proceedings of the International Symposium on Remote Sensing of Environment, 3rd Thematic Conference, Environmental Research Institute of Michigan, Colorado Springs, Colorado, pp. 755-773. Bonham-Carter, Graeme F., 1994. Geographic Informations Systems for Geoscientists: Modelling with GIS. Computer Methods in the Geosciences, Volume 13, published by Pergamon (Elsevier Science Ltd), pp. 120-125.
R = Red, G = Green, B = Blue I = Intensity, H = Hue, S = Saturation Max = Maximum(R,G,B) Min = Minimum(R,G,B) Delta = Max - Min I = Max If (Max <> 0) S = Delta / Max If (Max = 0) S = 0 If (S = 0) H = 0 (Hue is undefined) If (R = Max) H = (G - B) / Delta (between yellow and magenta) If (G = Max) H = 2 + (B - R) / Delta (between cyan and yellow) If (B = Max) H = 4 + (R - G) / Delta (between magenta and cyan) H = H * 60 (convert Hue to degrees) If (H < 0) H = H + 360 (Hue must be positive) If (H >= 360) H = H - 360 (Hue must be less than 360)If output channels are all 8-bit, then Hue and Saturation values are scaled between 0 and 255:
H = H * (255 / 360) S = S * 255The above algorithm was obtained from page 592 of the following text book:
Foley, J.D., A. van Dam, S.K. Feiner and J.F. Hughes, 1990. Computer Graphics: Principles and Practice (second edition). Addison-Wesley Publishing Company.