In my java code, I have two hashmaps, and I want to get the intersection as a value. The keys are ARGB values of a color (integer) and its value is the frequency (integer). Basically each hashmap was generated from an image.
I want to determine a value that represents how close the maps are to each other. The higher the value the more close the two maps are to each other. Of course it can't be perfectly strict because in real life two colors can look the same but have slightly different ARGB values, which is where the tolerance part comes in.
So far I got this:
private int colorCompare(Result otherResult) {
HashMap<Integer, Integer> colorMap1 = getColorMap();
HashMap<Integer, Integer> colorMap2 = otherResult.getColorMap();
int sum = 0;
for (Map.Entry<Integer, Integer> entry : colorMap1.entrySet()) {
Integer key = entry.getKey();
Integer value = entry.getValue();
if (colorMap2.containsKey(key)) {
sum += value + colorMap2.get(key);
}
}
return sum;
}
public double CloseTo(Pixel otherpixel) {
Color mycolor = getColor();
Color othercolor = otherpixel.getColor();
double rmean = ( mycolor.getRed() + othercolor.getRed() )/2;
int r = mycolor.getRed() - othercolor.getRed();
int g = mycolor.getGreen() - othercolor.getGreen();
int b = mycolor.getBlue() - othercolor.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);
}
Does anyone know how to incorporate the tolerance part into it as I have no idea...
Thanks