gpt4 book ai didi

java - 比较颜色深浅?

转载 作者:行者123 更新时间:2023-12-01 13:51:33 45 4
gpt4 key购买 nike

我有两种颜色,如何检查它们是否是相同颜色但只是深浅不同?我一直在尝试,但我似乎无法弄清楚,我真的不知道我在做什么哈哈...这就是我到目前为止所拥有的:

import java.awt.Color;

public class Sandbox {

public Sandbox() {
Color c = new Color(5349322);
int r, g, b;
r = c.getBlue();
g = c.getGreen();
b = c.getRed();
System.out.println("Red: " + r);
System.out.println("Green: " + g);
System.out.println("Blue: " + b);
}

private boolean FindColorTol(int intTargetColor, int Tolerance) {
Color targetColor = new Color(intTargetColor);
Color imgColor = new Color(5349322);
int targetRED = targetColor.getBlue(),
targetGREEN = targetColor.getGreen(),
targetBLUE = targetColor.getRed(),
imgRED = imgColor.getBlue(),
imgGREEN = imgColor.getGreen(),
imgBLUE = imgColor.getRed();

return false;
}

private int getLargest(int...values) {
int largest = 0;
for(int i = 0; i < values.length; i++) {
if(values.length > i + 1) {
if(values[i] > values[i + 1])
largest = values[i];
else
largest = values[i + 1];
}
}
return largest;
}

public static void main(String[] args) {
new Sandbox();
}
}

还有,为什么 Color.getRed() 返回蓝色的值,而 Color.getBlue() 返回红色的值?我用它来查找 RGB 值:http://www.colorschemer.com/online.html

我正在尝试使用它来查找图像中的指定颜色。

最佳答案

colour theory ,阴影是通过将一种颜色与不同量的黑色混合得到的。因此,您可以通过标准化它们的值来轻松检查两个 RGB 三元组是否对应于相同颜色的不同色调

max1 = max(r1,g1,b1);
max2 = max(r2,g2,b2);
if ( approxEQ(r1/max1,r2/max2,DELTA) &&
approxEQ(g1/max1,g2/max2,DELTA) &&
approxEQ(b1/max1,b2/max2,DELTA) ) {

/* Same colour, different shades */

}

(显然,max(a,b,c) 返回三个参数中最大的一个,approxEQ(a,b,d) 返回 如果 |a-b|≤d 则为 true,否则为 false。)

如果您也想检查色调,最好 converting your RGB values to HSV or HSL .

关于java - 比较颜色深浅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19916971/

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