怎样把一个位图从rgb转换到hsi呢?

解决方案 »

  1.   

    I=(R+G+B)/3
    S=1-3*[min(R,G,B)]/(R+G+B)
    H的式子比较复杂,这里打不出来
      

  2.   

    RGB<=>YCrCb 
    Y=0.299*R + 0.587*G + 0.114*B
    Cr=(R-Y)*0.713 + 128
    Cb=(B-Y)*0.564 + 128R=Y + 1.403*(Cr - 128)
    G=Y - 0.344*(Cr - 128) - 0.714*(Cb - 128)
    B=Y + 1.773*(Cb - 128)RGB=>HSV 
    V=max(R,G,B)
    S=(V-min(R,G,B))*255/V   if V!=0, 0 otherwise       (G - B)*60/S,  if V=R
    H= 180+(B - R)*60/S,  if V=G
       240+(R - G)*60/S,  if V=Bif H<0 then H=H+360
    The hue values calcualted using the above formulae vary from 0° to 360° so they are divided by 2 to fit into 8-bit destination format. 
      

  3.   

    我采用SDL做过BMP->YV12图像格式转换,一个个象素转换是没有问题的,主要是注意各分量在内存中的位置问题。