1
嗨我想從rgb轉換爲hsv,我一直在關注easyRGB.com中的算法。但不起作用,它顯示比正常情況更多的紅色。我重寫了幾次相同的算法並進行了修改,但找不到錯誤。任何想法?有算法。將RGB轉換爲HSV
public static double[] RGB2HSV(double[] tmp){
double R = tmp[0]/255.0;
double G = tmp[1]/255.0;
double B = tmp[2]/255.0;
double min = Math.min(Math.min(R, G), B);
double max = Math.max(Math.max(R, G), B);
double delta = max - min;
double H = max;
double S = max;
double V = max;
if(delta == 0){
H = 0;
S = 0;
}else{
S = delta/max;
double delR = (((max - R)/6) + (delta/2))/delta;
double delG = (((max - G)/6) + (delta/2))/delta;
double delB = (((max - B)/6) + (delta/2))/delta;
if(R == max){
H = delB - delG;
}else if(G == max){
H = (1/3) + delR - delB;
}else if(B == max){
H = (2/3) + delG - delR;
}
if(H < 0) H += 1;
if(H > 1) H -= 1;
}
double[] hsv = new double[3];
hsv[0] = H;
hsv[1] = S;
hsv[2] = V;
return hsv;
}
真誠感謝我的真實,愚蠢的錯誤。我不敢相信我一直在試圖解決這個問題,並沒有意識到這一點。謝謝! –