Converts RGB to HSV.
@access		public
@static
@param		array	rgb		RGB-Color as array
@return		array
342383
public static function rgb2hsv( $rgb )
	{
#		return self::rgb2hsv_2( $rgb );
		list( $r, $g, $b ) = $rgb;
		$v	= max( $r, $g, $b );
		$t	= min( $r, $g, $b );
		$s	= ( $v == 0 ) ? 0 : ( $v - $t ) / $v;
		if( $s == 0 )
			$h	= 0;
		else
		{
			$a	= $v - $t;
			$cr	= ( $v - $r ) / $a;
			$cg	= ( $v - $g ) / $a;
			$cb	= ( $v - $b ) / $a;
			$h	= ( $r == $v ) ? $cb - $cg : ( ( $g == $v ) ? 2 + $cr - $cb : ( ( $b == $v ) ? $h = 4 + $cg - $cr : 0 ) );
			$h	= 60 * $h;
			$h	= ( $h < 0 ) ? $h + 360 : $h;
		}
		return array( round( $h ), round( $s * 100 ), round( $v / 2.55 ) );
	}
57300
def set_color_hsv(self, hue, saturation, value):
        """"""
        try:
            data = "action=on&color={};{};{}".format(hue, saturation, value)
            request = requests.post(
                '{}/{}/{}'.format(self.resource, URI, self._mac),
                data=data, timeout=self.timeout)
            if request.status_code == 200:
                self.data['on'] = True
        except requests.exceptions.ConnectionError:
            raise exceptions.MyStromConnectionError()
189632
public function uncolor($codes = array())
    {
        $nums = array();
        $result = array();
        $patts = array('/^' . chr(27) . '\[/', '/m$/');
        foreach ($codes as $code) {
            $esc = preg_replace($patts, '', $code);
            if (preg_match('/^((?:\d+;)*\d*)$/', $esc, $matches)) {
                if ($matches[0] != '') {
                    $nums = array_merge($nums, explode(';', $matches[0]));
                }
            } else {
                throw new InvalidArgumentException("Bad escape sequence $esc");
            }
        }
        foreach ($nums as $num) {
            $num += 0; // Strip leading zeroes
            if (isset($this->ATTRIBUTES_R[$num])) {
                $result[] = $this->ATTRIBUTES_R[$num];
            } else {
                throw new InvalidArgumentException("No name for escape sequence $num");
            }
        }
        return $result;
    }
147171
def hsv_to_rgb(self,HSV):
        ""
        gammaRGB = self._ABC_to_DEF_by_fn(HSV,hsv_to_rgb)
        return self._ungamma_rgb(gammaRGB)
1117470
def RGB_to_HSV(cobj, *args, **kwargs):
    
    var_R = cobj.rgb_r
    var_G = cobj.rgb_g
    var_B = cobj.rgb_b

    var_max = max(var_R, var_G, var_B)
    var_min = min(var_R, var_G, var_B)

    var_H = __RGB_to_Hue(var_R, var_G, var_B, var_min, var_max)

    if var_max == 0:
        var_S = 0
    else:
        var_S = 1.0 - (var_min / var_max)

    var_V = var_max

    return HSVColor(
        var_H, var_S, var_V)
727697
def rgb2hsv(arr):
    """"""
    arr = np.asanyarray(arr)
    if arr.ndim != 3 or arr.shape[2] != 3:
        raise ValueError("the input array must have a shape == (.,.,3)")
    arr = as_float_image(arr)

    out = np.empty_like(arr)

    # -- V channel
    out_v = arr.max(-1)

    # -- S channel
    delta = arr.ptp(-1)
    # Ignore warning for zero divided by zero
    old_settings = np.seterr(invalid='ignore')
    out_s = delta / out_v
    out_s[delta == 0.] = 0.

    # -- H channel
    # red is max
    idx = (arr[:, :, 0] == out_v)
    out[idx, 0] = (arr[idx, 1] - arr[idx, 2]) / delta[idx]

    # green is max
    idx = (arr[:, :, 1] == out_v)
    out[idx, 0] = 2. + (arr[idx, 2] - arr[idx, 0]) / delta[idx]

    # blue is max
    idx = (arr[:, :, 2] == out_v)
    out[idx, 0] = 4. + (arr[idx, 0] - arr[idx, 1]) / delta[idx]
    out_h = (out[:, :, 0] / 6.) % 1.
    out_h[delta == 0.] = 0.

    np.seterr(**old_settings)

    # -- output
    out[:, :, 0] = out_h
    out[:, :, 1] = out_s
    out[:, :, 2] = out_v

    # remove NaN
    out[np.isnan(out)] = 0
    return out
1209413
public function color($codes = array())
    {
        $attribute = '';
        foreach ($codes as $code) {
            $code = strtolower($code);
            if (isset($this->ATTRIBUTES[$code])) {
                $attribute .= "{$this->ATTRIBUTES[$code]};";
            } else {
                throw new InvalidArgumentException("Invalid attribute name $code");
            }
        }
        $attribute = substr($attribute, 0, -1);
        return empty($attribute) ? FALSE : chr(27) . "[$attribute" . "m";
    }
596518
public function image_colorize($rgb)
	{
		imageTrueColorToPalette($this->imageResized, true, 256);
		$numColors = imageColorsTotal($this->imageResized);

		for ($x = 0; $x < $numColors; $x++)
		{
			list($r, $g, $b) = array_values(imageColorsForIndex($this->imageResized, $x));

			// calculate grayscale in percent
			$grayscale = ($r + $g + $b) / 3 / 0xff;

			imageColorSet($this->imageResized, $x,
				$grayscale * $rgb[0],
				$grayscale * $rgb[1],
				$grayscale * $rgb[2]
			);

		}

		return true;
	}
134843
def hex_to_hsv(color):
    
    color = normalize(color)
    color = color[1:]
    # color=tuple(ord(c)/255.0 for c in color.decode('hex'))
    color = (int(color[0:2], base=16) / 255.0, int(color[2:4],
                                                   base=16) / 255.0, int(color[4:6], base=16) / 255.0)
    return colorsys.rgb_to_hsv(*color)
8720
public static function rgbaValueToRgbaComponents($rgb)
    {
        self::throwExceptionIfNotRgbaValue($rgb);

        $alpha = self::rgbaValueToAlphaComponent($rgb);

        if (0 === $alpha) {
            $alpha = 0xFF;
        }

        return [
            'R' => self::rgbaValueToRedComponent($rgb),
            'G' => self::rgbaValueToGreenComponent($rgb),
            'B' => self::rgbaValueToBlueComponent($rgb),
            'A' => $alpha
        ];
    }
98303
public static function ToHexStringArray ($rgb) {
		$rgb = trim($rgb, '#');
		if ($rgb === '' || ($range = strlen($rgb) / 3) > 2) {
			return false;
		}

		$hex_array = [substr($rgb, 0, $range), substr($rgb, 1 * $range, $range), substr($rgb, 2 * $range, $range)];
		if ($range === 1) {
			$hex_array[0] .= $hex_array[0];
			$hex_array[1] .= $hex_array[1];
			$hex_array[2] .= $hex_array[2];
		}

		return $hex_array;
	}
1356010
def hsv(self):
        
        r, g, b = self.color
        hsv = colorsys.rgb_to_hsv(r, g, b)
        hsv = (int(round(hsv[0] * 360)), hsv[1], hsv[2])
        return self._append_alpha_if_necessary(hsv)
18464
public static function rgbToHex($rgb, $withHash = TRUE)
	{
		if (is_string($rgb)) {
			$rgbString = $rgb;

			// TODO : use regex
			$rgbString = str_replace(' ','', $rgbString);
			$rgbString = str_replace('rgb','', $rgbString);
			$rgbString = str_replace('(','', $rgbString);
			$rgbString = str_replace(')','', $rgbString);

			if (strpos($rgbString, ',') !== 0){
				$rgb = explode(',', $rgbString);
			} else {
				throw new InvalidArgumentException('Param was not an RGB in string');
			}
		}

		if (is_array($rgb)){
			if (isset($rgb['r']) && isset($rgb['g']) && isset($rgb['b'])){
				$rgb[0] = $rgb['r'];
				$rgb[1] = $rgb['g'];
				$rgb[2] = $rgb['b'];
			}

			if (empty($rgb) || !isset($rgb[0]) || !isset($rgb[1]) || !isset($rgb[2])) {
				throw new InvalidArgumentException('Param was not an RGB array');
			}
		} else {
			throw new InvalidArgumentException('Param was not an RGB array or string');
		}


		// Convert RGB to HEX
		$hex[0] = dechex($rgb[0]);
		$hex[1] = dechex($rgb[1]);
		$hex[2] = dechex($rgb[2]);

		if ($withHash) {
			return strtoupper('#' . sprintf("%02s%02s%02s", $hex[0], $hex[1], $hex[2]));

		} else {
			return strtoupper(sprintf("%02s%02s%02s", $hex[0], $hex[1], $hex[2]));
		}
	}
795199
public static void rgbToHsv( double r , double g , double b , double []hsv ) {
		// Maximum value
		double max = r > g ? ( r > b ? r : b) : ( g > b ? g : b );
		// Minimum value
		double min = r < g ? ( r < b ? r : b) : ( g < b ? g : b );
		double delta = max - min;

		hsv[2] = max;

		if( max != 0 )
			hsv[1] = delta / max;
		else {
			hsv[0] = Double.NaN;
			hsv[1] = 0;
			return;
		}

		double h;
		if( r == max )
			h = ( g - b ) / delta;
		else if( g == max )
			h = 2 + ( b - r ) / delta;
		else
			h = 4 + ( r - g ) / delta;

		h *= d60_F64;
		if( h < 0 )
			h += PI2_F64;

		hsv[0] = h;
	}
469964
def rgb_to_hsl_hsv(a, isHSV=True):
    
    R, G, B = a.T

    m = np.min(a, 1).T
    M = np.max(a, 1).T

    C = M - m #chroma
    Cmsk = C != 0

    # Hue
    H = np.zeros(R.shape, int)
    mask = (M == R) & Cmsk
    H[mask] = np.mod(60 * (G[mask] - B[mask]) / C[mask], 360)
    mask = (M == G) & Cmsk
    H[mask] = (60 * (B[mask] - R[mask]) / C[mask] + 120)
    mask = (M == B) & Cmsk
    H[mask] = (60 * (R[mask] - G[mask]) / C[mask] + 240)
    H *= 255
    H /= 360 # if you prefer, leave as 0-360, but don't convert to uint8


    # Saturation
    S = np.zeros(R.shape, int)

    if isHSV:
        # This code is for HSV:
        # Value
        V = M

        # Saturation
        S[Cmsk] = ((255 * C[Cmsk]) / V[Cmsk])
        # H, S, and V are now defined as integers 0-255
        return np.array((H.swapaxes(0, 1), S.swapaxes(0, 1), V.swapaxes(0, 1))).T
    else:
        # This code is for HSL:
        # Value
        L = 0.5 * (M + m)

        # Saturation
        S[Cmsk] = ((C[Cmsk]) / (1 - np.absolute(2 * L[Cmsk]/255.0 - 1)))
        # H, S, and L are now defined as integers 0-255
        return np.array((H.swapaxes(0, 1), S.swapaxes(0, 1), L.swapaxes(0, 1))).T
1165974
public static void rgbToHsv_F32(Planar<GrayF32> rgb , Planar<GrayF32> hsv ) {
		GrayF32 R = rgb.getBand(0);
		GrayF32 G = rgb.getBand(1);
		GrayF32 B = rgb.getBand(2);

		GrayF32 H = hsv.getBand(0);
		GrayF32 S = hsv.getBand(1);
		GrayF32 V = hsv.getBand(2);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0,hsv.height,row->{
		for( int row = 0; row < hsv.height; row++ ) {
			int indexRgb = rgb.startIndex + row*rgb.stride;
			int indexHsv = hsv.startIndex + row*hsv.stride;
			int endRgb = indexRgb+hsv.width;

			for( ; indexRgb < endRgb; indexHsv++ , indexRgb++) {

				float r = R.data[indexRgb];
				float g = G.data[indexRgb];
				float b = B.data[indexRgb];

				float max = r > g ? ( r > b ? r : b) : ( g > b ? g : b );
				float min = r < g ? ( r < b ? r : b) : ( g < b ? g : b );

				float delta = max - min;

				V.data[indexHsv] = max;

				if( max != 0 )
					S.data[indexHsv] = delta / max;
				else {
					H.data[indexHsv] = Float.NaN;
					S.data[indexHsv] = 0;
					continue;
				}

				float h;
				if( r == max )
					h = ( g - b ) / delta;
				else if( g == max )
					h = 2 + ( b - r ) / delta;
				else
					h = 4 + ( r - g ) / delta;

				h *= d60_F32;
				if( h < 0 )
					h += PI2_F32;

				H.data[indexHsv] = h;
			}
		}
		//CONCURRENT_ABOVE });
	}
841660
public function toHSV()
    {
        list($red, $green, $blue) = $this->toRGB();
        $red /= 255;
        $green /= 255;
        $blue /= 255;

        $maxRGB = max($red, $green, $blue);
        $minRGB = min($red, $green, $blue);
        $chroma = $maxRGB - $minRGB;

        $value = 100 * $maxRGB;

        if ($chroma == 0) {
            return [0, 0, $value];
        }

        $saturation = 100 * ($chroma / $maxRGB);

        if ($red == $minRGB) {
            $h = 3 - (($green - $blue) / $chroma);
        } elseif ($blue == $minRGB) {
            $h = 1 - (($red - $green) / $chroma);
        } else {
            $h = 5 - (($blue - $red) / $chroma);
        }

        $hue = 60 * $h;

        return [
            round($hue),
            round($saturation),
            round($value),
        ];
    }