RGB to HSI, HSI to RGB Conversion Calculator

The RGB color model is an additive system in which each color is defined by the amount of red, green, and blue light emitted. In the RGB scheme, colors are represented numerically with a set of three numbers, each of which ranges from 0 to 255. White has the highest RGB value of (255, 255, 255) while black has the lowest value of (0, 0, 0). This is consistent with the additive nature of the RGB system, since white light is the presence of all colors of light, and black is the absense of all light.

There are other three-parameter representations of colors. One such system is the HSI color model, which encodes colors according to their Hue, Saturation, andIntensity. The HSI model is used by some graphics programs and color monitors as an alternative to, or alongside the RGB representation.

In the HSI system, the hue of a color is its angle measure on a color wheel. Pure red hues are 0°, pure green hues are 120°, and pure blues are 240°. (Neutral colors--white, gray, and black--are set to 0° for convenience.) Intensity is the overall lightness or brightness of the color, defined numerically as the average of the equivalent RGB values.

The HSI definition of saturation is a measure of a color's purity/grayness. Purer colors have a saturation value closer to 1, while grayer colors have a saturation value closer to 0. (In other color models, the meanings and mathematical definitions of "saturation" are slightly different. See HSL and HSV color models for comparison.)

HSI color model

Equations to Convert RGB Values to HSI Values

Suppose R, G, and B are the red, green, and blue values of a color. The HSI intensity is given by the equation

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

Now let m be the minimum value among R, G, and B. The HSI saturation value of a color is given by the equation

S = 1 - m/I    if I > 0, or
S = 0            if I = 0.

To convert a color's overall hue, H, to an angle measure, use the following equations:

H = cos-1[ (R - ½G - ½B)/√R² + G² + B² - RG - RB - GB ]            if G ≥ B, or 
H = 360 - cos-1[ (R - ½G - ½B)/√R² + G² + B² - RG - RB - GB ]    if B > G,

where the inverse cosine output is in degrees.

Equations to Convert HSI Values to RGB Values

To convert hue, saturation, and intensity to a set of red, green, and blue values, you must first note the value of H. If H = 0, then R, G, and B are given by

R = I + 2IS
G = I - IS
B = I - IS.

If 0 < H < 120, then

R = I + IS*cos(H)/cos(60-H)
G = I + IS*[1 - cos(H)/cos(60-H)]
B = I - IS.

If H = 120, then the red, green, and blue values are

R = I - IS
G = I + 2IS
B = I - IS.

If 120 < H < 240, then

R = I - IS
G = I + IS*cos(H-120)/cos(180-H)
B = I + IS*[1 - cos(H-120)/cos(180-H)].

If H = 240 then

R = I - IS
G = I - IS
B = I + 2IS.

And if 240 < H < 360, we have

R = I + IS*[1 - cos(H-240)/cos(300-H)]
G = I - IS
B = I + IS*cos(H-240)/cos(300-H).

转载于:https://www.cnblogs.com/Matrix420/p/4237713.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值