Program to Change RGB color model to HSV color model | C # program change RGB Color Model to HSV Color Model ; R , G , B values are divided by 255 to change the range from 0. .255 to 0. .1 ; h , s , v = hue , saturation , value double cmax = Math . Max ( r , Math . Max ( g , b ) ) ; maximum of r , g , b double cmin = Math . Min ( r , Math . Min ( g , b ) ) ; minimum of r , g , b double diff = cmax - cmin ; diff of cmax and cmin . ; if cmax and cmax are equal then h = 0 ; if cmax equal r then compute h ; if cmax equal g then compute h ; if cmax equal b then compute h ; if cmax equal zero ; compute v ; Driver Code ; rgb_to_hsv ( 45 , 215 , 0 ) ; rgb_to_hsv ( 31 , 52 , 29 ) ;
using System ; class GFG { static void rgb_to_hsv ( double r , double g , double b ) { r = r / 255.0 ; g = g / 255.0 ; b = b / 255.0 ; double h = - 1 , s = - 1 ; if ( cmax == cmin ) h = 0 ; else if ( cmax == r ) h = ( 60 * ( ( g - b ) / diff ) + 360 ) % 360 ; else if ( cmax == g ) h = ( 60 * ( ( b - r ) / diff ) + 120 ) % 360 ; else if ( cmax == b ) h = ( 60 * ( ( r - g ) / diff ) + 240 ) % 360 ; if ( cmax == 0 ) s = 0 ; else s = ( diff / cmax ) * 100 ; double v = cmax * 100 ; Console . WriteLine ( " ( " + h + " ▁ " + s + " ▁ " + v + " ) " ) ; } public static void Main ( String [ ] args ) { rgb_to_hsv ( 129 , 88 , 47 ) ; } }