gpt4 book ai didi

java - 将 RGB 转换为 HSV

转载 作者:行者123 更新时间:2023-12-01 10:49:55 26 4
gpt4 key购买 nike

嗨,我想从 RGB 转换为 HSV,我一直在遵循 easyRGB.com 的算法。但不起作用它显示比正常情况更红。我将相同的算法重写了几次并进行了修改,但我找不到错误。任何想法?有算法。

    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;
}

最佳答案

1/3(2/3)的值为0,因为您操作的是两个整数,所以结果也是整数。

请使用 1.0/3.02.0/3.0

关于java - 将 RGB 转换为 HSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33975014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com