Color RGB

ArrayList colors;

BufferedImage bi;

privatedouble colorVariety(){// 0-100

for(int i = 0; i<w; i++){

for(int j = 0; j><h; j++){

int rgb = bi.getRGB(i,j);

if(colors.contains(rgb) ==false){

colors.add(rgb);

}

}

}

return (1.0*colors.size() / (w*h));

}

The above code took a really long time to run with larger images. Since there are only 16581375 different colors, I was thinking of making a boolean[] that long and then mapping each rgb to a boolean and finally counting how many booleans are true.

The problem is, how do I map an rgb to a number from 0-16581374 ?

Tell me if you have any different solutions to the problem also.

Thanks>

[1333 byte] By [Nethera] at [2007-11-26 13:48:56]
# 1
I don't know what you're up to, but wouldn't a HashSet be more appropriate instead of a List?kind regards,Jos
JosAHa at 2007-7-8 1:25:11 > top of Java-index,Java Essentials,Java Programming...
# 2
Thank you, this is what I needed.
Nethera at 2007-7-8 1:25:11 > top of Java-index,Java Essentials,Java Programming...
# 3
Do you understand why this makes a difference?
es5f2000a at 2007-7-8 1:25:11 > top of Java-index,Java Essentials,Java Programming...
# 4
i think soStoring the rgb values inside the hashmap is about the same speed as storing them in an arraylist, but with the hashmap, I dont have to iterate through, checking to see if the rgb value is already contained.
Nethera at 2007-7-8 1:25:11 > top of Java-index,Java Essentials,Java Programming...
# 5
:)
es5f2000a at 2007-7-8 1:25:11 > top of Java-index,Java Essentials,Java Programming...