Parent Topic: ALGORITHM
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.