ihs
[ XITE Reference Manual | XITE home ]
Name
ihs, rgb2ihs, ihs2rgb, rgb2ihs_byte, ihs2rgb_byte,
rgb2ihs_word, ihs2rgb_word - Convert between RGB and IHS
Syntax
#include <xite/ihs.h>
void rgb2ihs( double r, double g, double b,
double* i, double* h, double* s, int norm );
void ihs2rgb( double i, double h, double s,
double* r, double* g, double* b, int norm );
void rgb2ihs_byte( unsigned char r,
unsigned char g, unsigned char b,
unsigned char *i, unsigned char *h,
unsigned char *s );
void ihs2rgb_byte( unsigned char i,
unsigned char h, unsigned char s,
unsigned char *r, unsigned char *g,
unsigned char *b );
void rgb2ihs_word( unsigned short r,
unsigned short g, unsigned short b,
unsigned short *i, unsigned short *h,
unsigned short *s );
void ihs2rgb_word( unsigned short i,
unsigned short h, unsigned short s,
unsigned short *r, unsigned short *g,
unsigned short *b );
Description
rgb2ihs converts from RGB-space to IHS-space.
ihs2rgb converts from IHS-space to RGB-space.
rgb values are normalized
0.0 <= r <= 1.0, 0.0 <= b <= 1.0, 0.0 <= b <= 1.0,
If norm = TRUE the IHS values are normalized.
0.0 <= i <= 1.0, 0.0 <= h <= 1.0, 0.0 <= s <= 1.0,
If norm = FALSE:
0.0 <= i <= 1.0
0.0 <= h < 1.0
0.0 <= s <= Smax(I,H)
rgb2ihs_xxxx and ihs2rgb_xxxx normalize the data
in the range 0-255 for xxxx=byte and 0-65535 for xxxx=word
rgb2ihs
i = A11 * r + A12 * g + A13 * b;
u = A21 * r + A22 * g + A23 * b;
v = A31 * r + A32 * g + A33 * b;
h = atan2(v, u) , 0 <= h < 2*pi
s = sqrt(u*u + v*v)
ihs2rgb
u = s*cos(h)
v = s*sin(h)
r = i + A21 * u + A31 * v;
g = i + A22 * u + A32 * v;
b = i + A23 * u + A33 * v;
Values
A11 = A12 = A13 = 1./3.
A21 = A22 = -1./sqrt(6.)
A23 = 2./sqrt(6.)
A31 = -A32 = 1./sqrt(2.)
A33 = 0.
Normalization
i' = i / sqrt(3.0)
h' = h / 2*pi
s' = s / (Max s for (i,h))
See also
ihs2rgb(1), ihs2rgb_img(3), rgb2ihs(1), rgb2ihs_img(3)
Author
Otto Milvang