I want to know the range of values that can be returned by this function:
public static double colorDistance(Color color1, Color color2) {
double rmean = ( color1.getRed() + color2.getRed() )/2;
int r = color1.getRed() - color2.getRed();
int g = color1.getGreen() - color2.getGreen();
int b = color1.getBlue() - color2.getBlue();
double weightR = 2 + rmean/256;
double weightG = 4.0;
double weightB = 2 + (255-rmean)/256;
return Math.sqrt(weightR*r*r + weightG*g*g + weightB*b*b);
}
I know the smallest is 0, but I'm unsure of the largest.
I made this java code to help test:
private static List<Color> allColors = new ArrayList<Color>();
public static void main(String[] args) {
for(int i=0; i<=255; i++) {
for(int j=0; j<=255; j++) {
for(int k=0; k<=255; k++) {
allColors.add(new Color(i,j,k));
}
}
}
double max = 0;
for(int i=0; i<allColors.size(); i++) {
Color c1 = allColors.get(i);
for(int j=0; j<allColors.size(); j++) {
Color c2 = allColors.get(j);
System.out.print(i);
System.out.print(" - ");
System.out.println(j);
max = Math.max(max, colorDistance(c1, c2));
}
}
System.out.print(max);
}
But its taking too long. I tried black and white, to get 765 but according to the graph on this page http://en.wikipedia.org/wiki/Color_difference there are colors whose distance is even bigger than black and white.
Does anyone know how to get the true maximum value?
Thanks