Here you can find the source of rgbToHsv(byte[] rgb, float[] hsv)
public static void rgbToHsv(byte[] rgb, float[] hsv)
//package com.java2s; /*//from w w w . j ava 2 s . c o m ColorMapUtils.java (c) 2011-2013 Edward Swartz All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html */ public class Main { public static void rgbToHsv(byte[] rgb, float[] hsv) { rgbToHsv(rgb[0] & 0xff, rgb[1] & 0xff, rgb[2] & 0xff, hsv); } /** * Get hue/value/satuation. * * @param r * @param g * @param b * @param hsv * in 0-360, 0-1, 0-255 */ public static void rgbToHsv(int r, int g, int b, float[] hsv) { int theMin = Math.min(Math.min(r, g), b); int theMax = Math.max(Math.max(r, g), b); hsv[2] = theMax; float delta = (theMax - theMin); if (delta != 0) hsv[1] = delta / theMax; else { hsv[1] = 0; return; } if (r == theMax) hsv[0] = (g - b) / delta; else if (g == theMax) hsv[0] = 2 + (b - r) / delta; else hsv[0] = 4 + (r - g) / delta; hsv[0] *= 60.0; if (hsv[0] < 0) hsv[0] += 360.0; } /** * Get hue/value/satuation. * * @param rgb * @param hsv * in 0-360, 0-1, 0-255 */ public static void rgbToHsv(int[] rgb, float[] hsv) { rgbToHsv(rgb[0], rgb[1], rgb[2], hsv); } }