Hi all,
I’m programmatically categorising colours in an image. I’m storing the colours and their values(frequency that they turn up) in a TreeMap. I’m using a single TreeMap for each colour range (ROYGBIV).
What i’m specifically trying to do is trying to access the .intValue() using that method, of a key in my 2D array of TreeMaps.
I have an ArrayList with 7 TreeMaps in it (I know, inefficient) and when I use
myTreeMap.get(arrayIndex).get(key).intValue();
it throws an error telling me that the intValue() method doesn’t exist. The irritating thing is that when I use a single TreeMap without the extra .get() it works just fine.
Is there a different way I should be accessing this method in this case?
Help gratefully recieved.
Thanks.
import java.util.Map;
import java.util.TreeMap;
ArrayList<TreeMap> colourRanges = new ArrayList<TreeMap>();
color tempC;
void setup() {
colorMode(HSB, 360, 100, 100);
for (int j = 0; j < 7; j++) colourRanges.add(new TreeMap());
for (int i = 0; i < 50; i++) populate2DArray();
for (int i = 0; i < colourRanges.size(); i++) printArray(colourRanges.get(i) + " | " + colourRanges.get(i).size());
}
void populate2DArray() {
tempC = color(random(360), random(100), random(100));
int fam = colorRangeCheck(tempC); //checks the colour range
if (colourRanges.get(fam).containsKey(tempC)) { //checks if the colour is already in the range
int value = (colourRanges.get(fam).get(tempC)).intValue(); //gets the current number of entries for this colour
colourRanges.get(fam).put(tempC, new Integer(value + 1)); //iterates the value by one, re adds
} else //
colourRanges.get(fam).put(tempC, 1);
}
int colorRangeCheck(int c) {
int range = -1;
float h = hue(c);
if (h >= 350 && h <= 360 ||
h >= 0 && h <= 14) range = 0; //r
else if (h > 14 && h <= 45) range = 1; //o
else if (h > 45 && h <= 65) range = 2; //y
else if (h > 65 && h <= 155) range = 3; //g
else if (h > 155 && h <= 260) range = 4; //b
else if (h > 260 && h <= 290) range = 5; //i
else if (h > 290 && h <= 350) range = 6; //v
return range;
}
edit: typos