HSI: Hue Saturation Intensity.

RGB to HSI (Gonzalez and Woods)

  
        I = 1/3(R+G+B)

        S = 1 - ( 3/(R+G+B))*a    where a is the minimum of R, G and B

        H = cos^(-1) ( (0.5*((R-G)+(R-B))) / ((R-G)^2 + (R-B)*(G-B))^(0.5) )

        If S = 0, H is meaningless.
    
        If (B/I) > (G/I) then H = 360 - H since H is an angle in degrees we
        then normalise to 0,1 with H=H/360
HSI to RGB (Gonzalez and Woods)
        First we restore H to degrees with H = 360*H

        If 0 < H <= 120 then
    
            B = 1/3(1-S)
            R = 1/3(1+ [(S cos H) / (cos(60 - H))] )
            G = 1 - (B+R)

        If 120 < H <= 240 then

            H = H - 120
            R = 1/3(1-S)
            G = 1/3(1+ [(S cos H) / (cos(60 - H))] )
            B = 1 - (R+G)

        If 240 < H <= 360 then

            H = H - 240
            G = 1/3(1-S)
            B = 1/3(1+ [(S cos H) / (cos(60 - H))] )
            R = 1 - (G+B)		

HSV: Hue Saturation Value

RGB to HSV (Travis) 

  Given RGB values, find the max and min.

  V = max
  S = (max-min) / max

  If S = 0, H is undefined
  else
    R1 = (max-R) / (max-min)
    G1 = (max-G) / (max-min)
    G2 = (max-B) / (max-min)

    if 		R = max and G = min, 	H = 5 + B1
    else if   	R = max and G not= min, H = 1 - G1
    else if   	G = max and B = min,	H = R1 + 1
    else if   	G = max and B not=main,	H = 3 - B1
    else if   	R = max,		H = 3 + G1
    else				H = 5 - R1

    H = H*60 (converts to degrees so S and V lie between 0
    and 1, H between 0 and 360)

HSV to RGB (Travis) 
  Convert H degrees to a hexagon section
    hex = H / 360

  main_colour = int(hex)
  sub_colour  = hex - main_colour
  var1 = (1-S)*V
  var2 = (1 -(S * sub_colour)) * V
  var3 = (1 -(S * (1 - sub_colour))) * V

  then

    if main_colour = 0, R = V, G = var3, B = var1
       main_colour = 1, R = var2, G = V, B = var1
       main_colour = 2, R = var1, G = V, B = var3
       main_colour = 3, R = var1, G = var2, B = V 
       main_colour = 4, R = var3, G = var1, B = V
       main_colour = 5, R = V, G = var1, B = var2


where int(x) converts x to an integer value. 
(N.B. I haven't implemented this transform.) 

RGB to HSV (Foley and VanDam) 

  max = maximum of RGB
  min = minimum of RGB

  V = max
  S = (max - min) / max

  if S = 0, H is undefined, else
    delta = max-min

    if R = max, H = (G-b)/delta
    if G = max, H = 2 + (B-R)/delta
    if B = max, H = 4 + (R-G)/delta

    H = H*60
    if H < 0, H = H + 360

HSV to RGB (Foley and VanDam) 
  if S = 0 and H = undefined, R = G = B = V

  if H = 360, H = 0
  H = H / 60
  i = floor(H)
  f = H - i
  p = V*(1-S)
  q = V*(1-(S*f))
  t = V*(1 - (S * (1-f)))

  if i = 0, R = v, G = t, B = p
  if i = 1, R = q, G = v, B = p
  if i = 2, R = p, G = v, B = t
  if i = 3, R = p, G = q, B = v
  if i = 4, R = t, G = p, B = v
  if i = 5, R = v, G = p, B = q


where floor is the C floor function.