Saturday 17 September 2011

RGB TO HSV COLOR MODELS


RGB  TO HSV COLOR MODELS


#include "math.h"
#define MIN(a,b) (a<b?a:b)
#define MAX(a,b) (a>b?a:b)
#define NO_HUE -1
void rgbtohsv(float r,float g,float b,float *h,float *s,float *v)
{
float max=MAX(r,MAX(g,b)),min=MIN(r,MIN(g,b));
float delta=max-min;
*v=max;
if(max!=0.0)
*s=delta/max;
else
*s=0.0;
if(*s==0.0) *h=NO_HUE;
else
{
if(r==max)
*h=(g-b)/delta;
else if(g==max)
*h=2+(b-r)/delta;
else if(b==max)
*h=4+(r-g)/delta;
*h*=60.0;
if(*h<0)*h+=360.0;
*h/=360.0;
}
printf("H=%f S= %f  V=%f",*h,*s,*v);
}
void main()
{
float a,b,c,d,e,f;
clrscr();
printf("Enter the RGB and HSV values :");
scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f);
rgbtohsv(a,b,c,&d,&e,&f);
getch();
}

  OUTPUT

Enter RGB and HSV Values:
0.1
0.2
0.3
0.4
0.5
0.6

H= 0.5833
S= 0.6667
V= 0.3000

0 comments:

Post a Comment